Search in sources :

Example 1 with DefaultQuery

use of org.geotools.data.DefaultQuery in project onebusaway-application-modules by camsys.

the class ShapefileLibrary method loadShapeFile.

public static FeatureCollection<SimpleFeatureType, SimpleFeature> loadShapeFile(File path) throws Exception {
    _log.info("loading shapefile " + path.toURI());
    ShapefileDataStore dataStore = new ShapefileDataStore(path.toURI().toURL());
    _log.info("loaded!");
    String[] typeNames = dataStore.getTypeNames();
    String typeName = typeNames[0];
    FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore.getFeatureSource(typeName);
    CoordinateReferenceSystem sourceCRS = featureSource.getInfo().getCRS();
    _log.info("using sourceCRS=" + sourceCRS + " for typeName=" + typeName);
    Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
    CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints);
    CoordinateReferenceSystem worldCRS = factory.createCoordinateReferenceSystem("EPSG:4326");
    DefaultQuery query = new DefaultQuery(typeName);
    query.setCoordinateSystem(sourceCRS);
    query.setCoordinateSystemReproject(worldCRS);
    query.setHints(hints);
    return featureSource.getFeatures(query);
}
Also used : ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) DefaultQuery(org.geotools.data.DefaultQuery) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Hints(org.geotools.factory.Hints) CRSAuthorityFactory(org.opengis.referencing.crs.CRSAuthorityFactory) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Aggregations

DefaultQuery (org.geotools.data.DefaultQuery)1 ShapefileDataStore (org.geotools.data.shapefile.ShapefileDataStore)1 Hints (org.geotools.factory.Hints)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1 CRSAuthorityFactory (org.opengis.referencing.crs.CRSAuthorityFactory)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1