org.h2gis.utilities
Class SFSUtilities

java.lang.Object
  extended by org.h2gis.utilities.SFSUtilities

public class SFSUtilities
extends Object

Generic utilities function to retrieve spatial metadata trough SFS specification. Compatible with H2 and PostGIS.

Author:
Nicolas Fortin

Constructor Summary
SFSUtilities()
           
 
Method Summary
static List<String> getGeometryFields(Connection connection, String catalog, String schema, String table)
          Find geometry fields name of a table.
static List<String> getGeometryFields(Connection connection, TableLocation location)
          Find geometry fields name of a table.
static List<String> getGeometryFields(ResultSet resultSet)
          Find geometry fields name of a resultSet.
static int getGeometryType(Connection connection, TableLocation location, String fieldName)
           
static int getGeometryTypeFromGeometry(com.vividsolutions.jts.geom.Geometry geometry)
           
static String getGeometryTypeNameFromCode(int geometryTypeCode)
           
static com.vividsolutions.jts.geom.Envelope getResultSetEnvelope(ResultSet resultSet)
          Compute the full extend of a resultset using the first geometry field.
static com.vividsolutions.jts.geom.Envelope getResultSetEnvelope(ResultSet resultSet, String fieldName)
          Compute the full extend of a resultset using a specified geometry field.
static com.vividsolutions.jts.geom.Envelope getTableEnvelope(Connection connection, TableLocation location, String geometryField)
          Merge the bounding box of all geometries inside the provided table.
static boolean hasGeometryField(ResultSet resultSet)
          Check if the resultset contains a geometry field
static PreparedStatement prepareInformationSchemaStatement(Connection connection, String catalog, String schema, String table, String informationSchemaTable, String endQuery)
          For table containing catalog, schema and table name, this function create a prepared statement with a filter on this combination.
static PreparedStatement prepareInformationSchemaStatement(Connection connection, String catalog, String schema, String table, String informationSchemaTable, String endQuery, String catalog_field, String schema_field, String table_field)
          For table containing catalog, schema and table name, this function create a prepared statement with a filter on this combination.
static Connection wrapConnection(Connection connection)
          Use this only if DataSource is not available.
static DataSource wrapSpatialDataSource(DataSource dataSource)
          In order to be able to use Wrapper.unwrap(Class) and Wrapper.unwrap(Class) to get SpatialResultSet and SpatialResultSetMetaData this method wrap the provided dataSource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SFSUtilities

public SFSUtilities()
Method Detail

getGeometryTypeNameFromCode

public static String getGeometryTypeNameFromCode(int geometryTypeCode)

getGeometryTypeFromGeometry

public static int getGeometryTypeFromGeometry(com.vividsolutions.jts.geom.Geometry geometry)
Parameters:
geometry - Geometry instance
Returns:
The sfs geometry type identifier

getGeometryType

public static int getGeometryType(Connection connection,
                                  TableLocation location,
                                  String fieldName)
                           throws SQLException
Parameters:
connection - Active connection
location - Catalog, schema and table name
fieldName - Geometry field name or empty (take the first one)
Returns:
The sfs geometry type identifier
Throws:
SQLException
See Also:
GeometryTypeCodes

wrapSpatialDataSource

public static DataSource wrapSpatialDataSource(DataSource dataSource)
In order to be able to use Wrapper.unwrap(Class) and Wrapper.unwrap(Class) to get SpatialResultSet and SpatialResultSetMetaData this method wrap the provided dataSource.

Parameters:
dataSource - H2 or PostGIS DataSource
Returns:
Wrapped DataSource, with spatial methods

wrapConnection

public static Connection wrapConnection(Connection connection)
Use this only if DataSource is not available. In order to be able to use Wrapper.unwrap(Class) and Wrapper.unwrap(Class) to get SpatialResultSet and SpatialResultSetMetaData this method wrap the provided connection.

Parameters:
connection - H2 or PostGIS Connection
Returns:
Wrapped DataSource, with spatial methods

getTableEnvelope

public static com.vividsolutions.jts.geom.Envelope getTableEnvelope(Connection connection,
                                                                    TableLocation location,
                                                                    String geometryField)
                                                             throws SQLException
Merge the bounding box of all geometries inside the provided table.

Parameters:
connection - Active connection (not closed by this function)
location - Location of the table
geometryField - Geometry field or empty string (take the first geometry field)
Returns:
Envelope of the table
Throws:
SQLException - If the table not exists, empty or does not contain a geometry field.

getGeometryFields

public static List<String> getGeometryFields(Connection connection,
                                             TableLocation location)
                                      throws SQLException
Find geometry fields name of a table.

Parameters:
connection - Active connection
location - Table location
Returns:
A list of Geometry fields name
Throws:
SQLException

prepareInformationSchemaStatement

public static PreparedStatement prepareInformationSchemaStatement(Connection connection,
                                                                  String catalog,
                                                                  String schema,
                                                                  String table,
                                                                  String informationSchemaTable,
                                                                  String endQuery,
                                                                  String catalog_field,
                                                                  String schema_field,
                                                                  String table_field)
                                                           throws SQLException
For table containing catalog, schema and table name, this function create a prepared statement with a filter on this combination.

Parameters:
connection - Active connection
catalog - Table catalog, may be empty
schema - Table schema, may be empty
table - Table name
informationSchemaTable - Information table location
endQuery - Additional where statement
catalog_field - Catalog field name
schema_field - Schema field name
table_field - Table field name
Returns:
Prepared statement
Throws:
SQLException

prepareInformationSchemaStatement

public static PreparedStatement prepareInformationSchemaStatement(Connection connection,
                                                                  String catalog,
                                                                  String schema,
                                                                  String table,
                                                                  String informationSchemaTable,
                                                                  String endQuery)
                                                           throws SQLException
For table containing catalog, schema and table name, this function create a prepared statement with a filter on this combination. Use "f_table_catalog","f_table_schema","f_table_name" as field names.

Parameters:
connection - Active connection
catalog - Table catalog, may be empty
schema - Table schema, may be empty
table - Table name
informationSchemaTable - Information table location
endQuery - Additional where statement
Returns:
Prepared statement
Throws:
SQLException

getGeometryFields

public static List<String> getGeometryFields(Connection connection,
                                             String catalog,
                                             String schema,
                                             String table)
                                      throws SQLException
Find geometry fields name of a table.

Parameters:
connection - Active connection
catalog - Catalog that contain schema (empty for default catalog)
schema - Schema that contain table (empty for default schema)
table - Table name (case insensitive)
Returns:
A list of Geometry fields name
Throws:
SQLException

getGeometryFields

public static List<String> getGeometryFields(ResultSet resultSet)
                                      throws SQLException
Find geometry fields name of a resultSet.

Parameters:
resultSet -
Returns:
A list of Geometry fields name
Throws:
SQLException

hasGeometryField

public static boolean hasGeometryField(ResultSet resultSet)
                                throws SQLException
Check if the resultset contains a geometry field

Parameters:
resultSet -
Returns:
true if the resultset contains one geometry field
Throws:
SQLException

getResultSetEnvelope

public static com.vividsolutions.jts.geom.Envelope getResultSetEnvelope(ResultSet resultSet)
                                                                 throws SQLException
Compute the full extend of a resultset using the first geometry field. If the resulset does not contain any geometry field throw an exception

Parameters:
resultSet -
Returns:
the full envelope of the resulSet
Throws:
SQLException

getResultSetEnvelope

public static com.vividsolutions.jts.geom.Envelope getResultSetEnvelope(ResultSet resultSet,
                                                                        String fieldName)
                                                                 throws SQLException
Compute the full extend of a resultset using a specified geometry field. If the resulset does not contain this geometry field throw an exception

Parameters:
resultSet -
fieldName -
Returns:
Throws:
SQLException


Copyright © 2015 IRSTV CNRS-FR-2488. All Rights Reserved.