Class SpatialDbsImportUtils


  • public class SpatialDbsImportUtils
    extends Object
    Import utilities.
    Author:
    Andrea Antonello (www.hydrologis.com)
    • Constructor Detail

      • SpatialDbsImportUtils

        public SpatialDbsImportUtils()
    • Method Detail

      • createTableFromShp

        public static String createTableFromShp​(ASpatialDb db,
                                                File shapeFile,
                                                String newTableName,
                                                String forceSrid,
                                                boolean avoidSpatialIndex)
                                         throws Exception
        Create a spatial table using a shapefile as schema.
        Parameters:
        db - the database to use.
        shapeFile - the shapefile to use.
        newTableName - the new name of the table. If null, the shp name is used.
        forceSrid - an optional srid to force the table to.
        avoidSpatialIndex - if true, no spatial index will be created. This is useful if many records have to be inserted and the index will be created later manually.
        Returns:
        the name of the created table.
        Throws:
        Exception
      • createTableFromSchema

        public static String createTableFromSchema​(ASpatialDb db,
                                                   org.opengis.feature.simple.SimpleFeatureType schema,
                                                   String newTableName,
                                                   String forceSrid,
                                                   boolean avoidSpatialIndex)
                                            throws Exception
        Create a spatial table using a schema.
        Parameters:
        db - the database to use.
        schema - the schema to use.
        newTableName - the new name of the table. If null, the shp name is used.
        forceSrid - an optional srid to force the table to.
        avoidSpatialIndex - if true, no spatial index will be created. This is useful if many records have to be inserted and the index will be created later manually.
        Returns:
        the name of the created table.
        Throws:
        Exception
      • importShapefile

        public static boolean importShapefile​(ASpatialDb db,
                                              File shapeFile,
                                              String tableName,
                                              int limit,
                                              boolean useFromTextForGeom,
                                              IHMProgressMonitor pm)
                                       throws Exception
        Import a shapefile into a table.
        Parameters:
        db - the database to use.
        shapeFile - the shapefile to import.
        tableName - the name of the table to import to.
        limit - if > 0, a limit to the imported features is applied.
        useFromTextForGeom - if true, the wkt form is used to insert geometries.
        pm - the progress monitor.
        Returns:
        false, is an error occurred.
        Throws:
        Exception
      • importFeatureCollection

        public static boolean importFeatureCollection​(ASpatialDb db,
                                                      org.geotools.data.simple.SimpleFeatureCollection featureCollection,
                                                      String tableName,
                                                      int limit,
                                                      boolean useFromTextForGeom,
                                                      IHMProgressMonitor pm)
                                               throws Exception
        Import a featureCollection into a table.
        Parameters:
        db - the database to use.
        featureCollection - the featureCollection to import.
        tableName - the name of the table to import to.
        limit - if > 0, a limit to the imported features is applied.
        useFromTextForGeom - if true, the wkt form is used to insert geometries.
        pm - the progress monitor.
        Returns:
        false, is an error occurred.
        Throws:
        Exception
      • tableToFeatureFCollection

        public static org.geotools.feature.DefaultFeatureCollection tableToFeatureFCollection​(ASpatialDb db,
                                                                                              String tableName,
                                                                                              int featureLimit,
                                                                                              int forceSrid,
                                                                                              String whereStr)
                                                                                       throws SQLException,
                                                                                              Exception
        Get a table as featurecollection.
        Parameters:
        db - the database.
        tableName - the table to use.
        featureLimit - limit in feature or -1.
        forceSrid - a srid to force to or -1.
        whereStr - an optional where condition string.
        Returns:
        the extracted featurecollection.
        Throws:
        SQLException
        Exception