Java Code Examples for org.geotools.data.FileDataStoreFinder#getDataStore()

The following examples show how to use org.geotools.data.FileDataStoreFinder#getDataStore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OmsShapefileFeatureReader.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@Execute
public void readFeatureCollection() throws IOException {
    if (!concatOr(geodata == null, doReset)) {
        return;
    }

    try {
        File shapeFile = new File(file);
        pm.beginTask("Reading features from shapefile: " + shapeFile.getName(), -1);
        FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
        if (store instanceof ShapefileDataStore) {
            ShapefileDataStore shpStore = (ShapefileDataStore) store;
            String shpCharset = PreferencesHandler.getShpCharset();
            if (shpCharset != null) {
                shpStore.setCharset(Charset.forName(shpCharset));
            }
        }
        SimpleFeatureSource featureSource = store.getFeatureSource();
        geodata = featureSource.getFeatures();
        store.dispose();
    } finally {
        pm.done();
    }
}
 
Example 2
Source File: OmsVectorReader.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public static ReferencedEnvelope readEnvelope( String filePath ) throws Exception {
    File shapeFile = new File(filePath);
    FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
    SimpleFeatureSource featureSource = store.getFeatureSource();
    return featureSource.getBounds();
}
 
Example 3
Source File: SpatialDbsImportUtils.java    From hortonmachine with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Create a spatial table using a shapefile as schema.
 * 
 * @param db the database to use.
 * @param shapeFile the shapefile to use.
 * @param newTableName the new name of the table. If null, the shp name is used.
 * @param forceSrid an optional srid to force the table to.
 * @return the name of the created table.
 * @param avoidSpatialIndex if <code>true</code>, no spatial index will be created. This is useful if many records 
 *          have to be inserted and the index will be created later manually.
 * @return the name of the created table.
 * @throws Exception
 */
public static String createTableFromShp( ASpatialDb db, File shapeFile, String newTableName, String forceSrid,
        boolean avoidSpatialIndex ) throws Exception {
    FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
    SimpleFeatureSource featureSource = store.getFeatureSource();
    SimpleFeatureType schema = featureSource.getSchema();
    if (newTableName == null) {
        newTableName = FileUtilities.getNameWithoutExtention(shapeFile);
    }
    return createTableFromSchema(db, schema, newTableName, forceSrid, avoidSpatialIndex);
}
 
Example 4
Source File: SpatialDbsImportUtils.java    From hortonmachine with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Import a shapefile into a table.
 * 
 * @param db the database to use.
 * @param shapeFile the shapefile to import.
 * @param tableName the name of the table to import to.
 * @param limit if > 0, a limit to the imported features is applied.
 * @param pm the progress monitor.
 * @return <code>false</code>, is an error occurred. 
 * @throws Exception
 */
public static boolean importShapefile( ASpatialDb db, File shapeFile, String tableName, int limit, IHMProgressMonitor pm )
        throws Exception {
    FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
    SimpleFeatureSource featureSource = store.getFeatureSource();
    SimpleFeatureCollection features = featureSource.getFeatures();

    return importFeatureCollection(db, features, tableName, limit, pm);

}
 
Example 5
Source File: NwwUtilities.java    From hortonmachine with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Get the feature source from a file.
 * 
 * @param path
 *            the path to the shapefile.
 * @return the feature source.
 * @throws Exception
 */
public static SimpleFeatureSource readFeatureSource( String path ) throws Exception {
    File shapeFile = new File(path);
    FileDataStore store = FileDataStoreFinder.getDataStore(shapeFile);
    SimpleFeatureSource featureSource = store.getFeatureSource();
    return featureSource;
}