Hi,

I found the answer to my own question:

     CRSAuthorityFactory factory =  
ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", null);
     CoordinateReferenceSystem crs =  
factory.createCoordinateReferenceSystem("4326");

Thanks!

Greg

On Jan 14, 2009, at 12:40 PM, Greg Ederer wrote:

> Hi,
>
> I am reading a shapefile using the following code from the User Guide:
>
> File file = new File("/Users/gregederer/servers/geoserver_data/data/
> shapefiles/gaul/Africa/g2008_1.shp");//getShapeFile(args);
>
>     ShapefileDataStore shapefile = new
> ShapefileDataStore(file.toURL());
>     String typeName = shapefile.getTypeNames()[0];
>     FeatureSource featureSource = shapefile.getFeatureSource();
>     FeatureType schema = featureSource.getSchema();
>     CoordinateReferenceSystem crs =
> schema.getGeometryDescriptor().getCoordinateReferenceSystem();
>
>     MapContext map = new DefaultMapContext(crs);
>     Style style = createStyle(file, schema);
>     map.addLayer(featureSource, style);
>
>     showMap(map);
>
> in showMap():
>
>     final JMapPane mapPane = new JMapPane(new StreamingRenderer(),
> map);
>     mapPane.setMapArea(map.getLayerBounds());
>
> When I run this code against my shapefile, I get:
>
> Exception in thread "main" java.io.IOException: CRS of this map
> context is null. Unable to get bounds.
>         at
> org
> .geotools.map.DefaultMapContext.getLayerBounds(DefaultMapContext.java:
> 544)
>         at org.esv.SummaryStats.ShapeLab.showMap(ShapeLab.java:187)
>         at org.esv.SummaryStats.ShapeLab.main(ShapeLab.java:75)
>
> Is it possible that this shapefile has no CRS?  If so, is there a
> factory method that I can use to get the required
> CoordinateReferenceSystem reference?  I happen to know that this
> particular shapefile is in ESPG:4326.  What other parameters will I
> need?
>
> Thanks!
>
> Greg
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by:
> SourcForge Community
> SourceForge wants to tell your story.
> http://p.sf.net/sfu/sf-spreadtheword
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to