|
From: Andrea A. <and...@ge...> - 2010-12-08 15:19:11
|
On Wed, Dec 8, 2010 at 11:55 AM, jose garcia <jos...@gm...> wrote:
> Hi Andrea
>
> I had this original code:
>
> // dataCRS is CRS from shapefile
> SimpleFeatureType schema = featureSource.getSchema();
> CoordinateReferenceSystem dataCRS =
> schema.getCoordinateReferenceSystem();
>
> // FeatureType for PostGis layer
> SimpleFeatureType featureType =
> SimpleFeatureTypeBuilder.retype(schema,
> dataCRS );
>
> When created the layer in PostGis the SRID = -1.
>
> I changed to force an EPSG projection in Feature Type as you commented and
> works ok, but the problem is that i finally end calling CRS.lookupEpsgCode
> in my code:
>
> // dataCRS is CRS from shapefile
> Integer crsCode = CRS.lookupEpsgCode(dataCRS, true);
>
> CoordinateReferenceSystem crsEpsg = CRS.decode("EPSG:" +
> crsCode);
>
> //DataStore postgisDatastore = DataStoreFinder.getDataStore(params);
> SimpleFeatureType featureType =
> SimpleFeatureTypeBuilder.retype(schema,
> crsEpsg);
>
> Not sure if there´s a better way. The shapefile has a prj file, but seem the
> only way to "map" the projection from shapefile to EPSG projection is using
> CRS.lookupEpsgCode?
Yes, it is the only way, and it does not always work, either.
.prj file syntax is really open ended, one can create whatever crs he wants,
it may match a code in the EPSG database, it may not (but if there
is an _exact_ match in the EPSG database lookupEpsgCode(crs, true)
will find it)
Cheers
Andrea
-----------------------------------------------------
Ing. Andrea Aime
Senior Software Engineer
GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584962313
fax: +39 0584962313
http://www.geo-solutions.it
http://geo-solutions.blogspot.com/
http://www.linkedin.com/in/andreaaime
http://twitter.com/geowolf
-----------------------------------------------------
|