Skip to content

Commit

Permalink
Merge pull request #1398 from ebocher/overpass_functions
Browse files Browse the repository at this point in the history
Add new functions to play with Overpass api
  • Loading branch information
ebocher authored Nov 8, 2024
2 parents 58b6a98 + e13bfb2 commit 47a8b90
Show file tree
Hide file tree
Showing 229 changed files with 2,079 additions and 1,851 deletions.
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
## Changelog for v2.2.4

- Add ST_EnvelopeAsText function
- Add ST_AsOverpassBbox function
- Add ST_OverpassDownloader function
- Fix bug when read GeometryCollection with the ST_GeomFromGeoJSON function
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ private H2GISOsgiDBFactory() {
* Open the connection to an existing database
* @param dbName name of the database
* @return a connection to the database
* @throws SQLException
*/
public static Connection openSpatialDataBase(String dbName) throws SQLException {
String dbFilePath = getDataBasePath(dbName);
Expand All @@ -63,8 +62,6 @@ public static Connection openSpatialDataBase(String dbName) throws SQLException
* Create a spatial database
* @param dbName filename
* @return Connection
* @throws SQLException
* @throws ClassNotFoundException
*/
public static Connection createSpatialDataBase(String dbName)throws SQLException, ClassNotFoundException {
return createSpatialDataBase(dbName,true);
Expand All @@ -88,7 +85,6 @@ private static String getDataBasePath(String dbName) {
* @param dbName DataBase name, or path URI
* @param initSpatial True to enable basic spatial capabilities
* @return DataSource
* @throws SQLException
*/
public static DataSource createDataSource(String dbName ,boolean initSpatial) throws SQLException {
return createDataSource(dbName, initSpatial, H2_PARAMETERS);
Expand All @@ -98,7 +94,6 @@ public static DataSource createDataSource(String dbName ,boolean initSpatial) th
* Create a database, init spatial funcyion and return a DataSource
* @param properties for the opening of the DataBase.
* @return a DataSource
* @throws SQLException
*/
public static DataSource createDataSource(Properties properties) throws SQLException {
return createDataSource(properties, true);
Expand All @@ -109,7 +104,6 @@ public static DataSource createDataSource(Properties properties) throws SQLExcep
* @param properties for the opening of the DataBase.
* @param initSpatial true to load the spatial functions
* @return a DataSource
* @throws SQLException
*/
public static DataSource createDataSource(Properties properties, boolean initSpatial) throws SQLException {
// Create H2 memory DataSource
Expand All @@ -127,11 +121,10 @@ public static DataSource createDataSource(Properties properties, boolean initSpa

/**
* Create a database and return a DataSource
* @param dbName
* @param initSpatial
* @param h2Parameters
* @return
* @throws SQLException
* @param dbName database name
* @param initSpatial true to init spatial functions
* @param h2Parameters database parameters
* @return a connection
*/
public static DataSource createDataSource(String dbName ,boolean initSpatial, String h2Parameters) throws SQLException {
// Create H2 memory DataSource
Expand All @@ -156,7 +149,7 @@ public static DataSource createDataSource(String dbName ,boolean initSpatial, St
*
* @param dbName path to the database
* @param h2_PARAMETERS Additional h2 parameters
* @return
* @return path to the database
*/
private static String initDBFile( String dbName, String h2_PARAMETERS ) {
String dbFilePath = getDataBasePath(dbName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public static Connection createSpatialDataBase(String dbName)throws SQLException

/**
* Return the path of the file database
* @param dbName
* @return
* @param dbName database path
* @return TODO : invalid path to be moved in test
*/
private static String getDataBasePath(String dbName) {
if(dbName.startsWith("file://")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
import org.h2gis.functions.io.kml.ST_AsKml;
import org.h2gis.functions.io.osm.OSMRead;
import org.h2gis.functions.io.osm.ST_OSMDownloader;
import org.h2gis.functions.io.overpass.ST_AsOverpassBbox;
import org.h2gis.functions.spatial.others.ST_EnvelopeAsText;
import org.h2gis.functions.io.overpass.ST_OverpassDownloader;
import org.h2gis.functions.io.shp.SHPRead;
import org.h2gis.functions.io.shp.SHPWrite;
import org.h2gis.functions.io.tsv.TSVRead;
Expand Down Expand Up @@ -347,7 +350,10 @@ public static Function[] getBuiltInsFunctions() {
new ST_CoveredBy(),
new ST_CoverageUnion(),
new FGBRead(),
new FGBWrite()
new FGBWrite(),
new ST_OverpassDownloader(),
new ST_EnvelopeAsText(),
new ST_AsOverpassBbox()
};
}

Expand Down Expand Up @@ -416,9 +422,8 @@ public static void registerSpatialTables(Connection connection) throws SQLExcept

/**
* Return a string property of the function
* @param function
* @param propertyKey
* @return
* @param function h2gis function
* @param propertyKey name of the function
*/
private static String getStringProperty(Function function, String propertyKey) {
Object value = function.getProperty(propertyKey);
Expand All @@ -428,10 +433,9 @@ private static String getStringProperty(Function function, String propertyKey) {
/**
* Return a boolean property of the function
*
* @param function
* @param propertyKey
* @param defaultValue
* @return
* @param function H2GIS function
* @param propertyKey alias
* @param defaultValue default value
*/
private static boolean getBooleanProperty(Function function, String propertyKey, boolean defaultValue) {
Object value = function.getProperty(propertyKey);
Expand All @@ -445,7 +449,7 @@ private static boolean getBooleanProperty(Function function, String propertyKey,
* @param function Function instance
* @param packagePrepend For OSGi environment only, use
* Bundle-SymbolicName:Bundle-Version:
* @throws java.sql.SQLException
* @throws java.sql.SQLException Throw an exception if the function cannot be registered
*/
public static void registerFunction(Statement st,Function function,String packagePrepend) throws SQLException {
registerFunction(st,function,packagePrepend,true);
Expand All @@ -458,7 +462,7 @@ public static void registerFunction(Statement st,Function function,String packag
* @param function Function instance
* @param packagePrepend For OSGi environment only, use Bundle-SymbolicName:Bundle-Version:
* @param dropAlias Drop alias if exists before define it.
* @throws java.sql.SQLException
* @throws java.sql.SQLException Throw an exception if the function cannot be registered
*/
public static void registerFunction(Statement st,Function function,String packagePrepend,boolean dropAlias) throws SQLException {
String functionClass = function.getClass().getName();
Expand Down Expand Up @@ -552,7 +556,7 @@ private static void registerH2GISFunctions(Connection connection, String package
* Unregister spatial type and H2GIS functions from the current connection.
*
* @param connection Active H2 connection with DROP ALIAS rights
* @throws java.sql.SQLException
* @throws java.sql.SQLException Throw an exception if the function cannot be unregistered
*/
public static void unRegisterH2GISFunctions(Connection connection) throws SQLException {
Statement st = connection.createStatement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public String getJavaStaticMethod() {
*
* @param connection input database connection
* @param fileName file to read
* @throws IOException
* @throws SQLException
* @throws IOException Throw exception is the file cannot be accessed
* @throws SQLException Throw exception is the file name contains unsupported characters
*/
public static void readAscii(Connection connection, String fileName) throws IOException, SQLException {
final String name = URIUtilities.fileFromString(fileName).getName();
Expand All @@ -81,11 +81,11 @@ public static void readAscii(Connection connection, String fileName) throws IOEx
/**
* Read the ASCII file.
*
* @param connection
* @param fileName
* @param option
* @throws IOException
* @throws SQLException
* @param connection input database connection
* @param fileName input file name
* @param option options to parse the file
* @throws IOException Throw exception is the file cannot be accessed
* @throws SQLException Throw exception is the file name contains unsupported characters
*/
public static void readAscii(Connection connection, String fileName, Value option) throws IOException, SQLException {
int zType = 2;
Expand Down Expand Up @@ -128,12 +128,12 @@ public static void readAscii(Connection connection, String fileName, Value optio
/**
* Read the ASCII file.
*
* @param connection
* @param fileName
* @param tableReference
* @param option
* @throws IOException
* @throws SQLException
* @param connection database connection
* @param fileName input file name
* @param tableReference output table name
* @param option options to parse the file
* @throws IOException Throw exception is the file cannot be accessed
* @throws SQLException Throw exception is the file name contains unsupported characters
*/
public static void readAscii(Connection connection, String fileName, String tableReference, Value option) throws IOException, SQLException {
int zType = 2;
Expand Down Expand Up @@ -163,13 +163,13 @@ public static void readAscii(Connection connection, String fileName, String tabl

/**
* Import the file
* @param connection
* @param tableReference
* @param outputFile
* @param progress
* @param ascReaderDriver
* @throws IOException
* @throws SQLException
* @param connection database connection
* @param tableReference output table name
* @param outputFile output file
* @param progress Progress visitor following the execution.
* @param ascReaderDriver {@link AscReaderDriver}
* @throws IOException Throw exception is the file cannot be accessed
* @throws SQLException Throw exception is the file name contains unsupported characters
*/
private static void importFile(Connection connection, String tableReference, File outputFile, ProgressVisitor progress, AscReaderDriver ascReaderDriver) throws IOException, SQLException {
int srid = 0;
Expand All @@ -186,17 +186,17 @@ private static void importFile(Connection connection, String tableReference, Fil
/**
* Import a small subset of ASC file.
*
* @param connection
* @param fileName
* @param tableReference
* @param connection database connection
* @param fileName input file
* @param tableReference output table name
* @param envelope Extract only pixels that intersects the provided geometry
* envelope, null to disable filter
* @param downScale Coefficient used for exporting less cells (1 all cells,
* 2 for size / 2)
* @param extractAsPolygons If true pixels are converted to polygon.
* (default false)
* @throws IOException
* @throws SQLException
* @throws IOException Throw exception is the file cannot be accessed
* @throws SQLException Throw exception is the file name contains unsupported characters
*/
public static void readAscii(Connection connection, String fileName, String tableReference, Geometry envelope, int downScale, boolean extractAsPolygons) throws IOException, SQLException {
AscReaderDriver ascReaderDriver = new AscReaderDriver();
Expand All @@ -213,17 +213,17 @@ public static void readAscii(Connection connection, String fileName, String tabl
/**
* Import a small subset of ASC file.
*
* @param connection
* @param fileName
* @param tableReference
* @param connection database connection
* @param fileName input file
* @param tableReference output table name
* @param envelope Extract only pixels that intersects the provided geometry
* envelope, null to disable filter
* @param downScale Coefficient used for exporting less cells (1 all cells,
* 2 for size / 2)
* @param extractAsPolygons If true pixels are converted to polygon.
* (default false)
* @throws IOException
* @throws SQLException
* @throws IOException Throw exception is the file cannot be accessed
* @throws SQLException Throw exception is the file name contains unsupported characters
*/
public static void readAscii(Connection connection, String fileName, String tableReference, Geometry envelope, int downScale, boolean extractAsPolygons, boolean deleteTable) throws IOException, SQLException {
AscReaderDriver ascReaderDriver = new AscReaderDriver();
Expand All @@ -241,17 +241,17 @@ public static void readAscii(Connection connection, String fileName, String tabl
/**
* Import a small subset of ASC file.
*
* @param connection
* @param fileName
* @param tableReference
* @param connection database
* @param fileName input file
* @param tableReference output table name
* @param envelope Extract only pixels that intersects the provided geometry
* envelope, null to disable filter
* @param downScale Coefficient used for exporting less cells (1 all cells,
* 2 for size / 2)
* @param extractAsPolygons If true pixels are converted to polygon.
* (default false)
* @throws IOException
* @throws SQLException
* @throws IOException Throw exception is the file cannot be accessed
* @throws SQLException Throw exception is the file name contains unsupported characters
*/
public static void readAscii(Connection connection, String fileName, String tableReference, Geometry envelope, int downScale, boolean extractAsPolygons, boolean deleteTable, String encoding, int zType) throws IOException, SQLException {
AscReaderDriver ascReaderDriver = new AscReaderDriver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ private void readHeader(Scanner scanner) throws IOException {
/**
* Read asc file
*
* @param connection
* @param fileName
* @param progress
* @param tableReference
* @param connection database connection
* @param fileName input file
* @param progress Progress visitor following the execution.
* @param tableReference output table name
* @param srid the espg code of the input file
* @throws SQLException
* @throws IOException
* @throws IOException Throw exception is the file cannot be accessed
* @throws SQLException Throw exception is the file name contains unsupported characters
*/
public String[] read(Connection connection, File fileName, ProgressVisitor progress, String tableReference,
int srid) throws SQLException, IOException {
Expand Down Expand Up @@ -260,13 +260,13 @@ public String[] read(Connection connection, File fileName, ProgressVisitor progr
/**
* Read the ascii file from inpustream
*
* @param connection
* @param inputStream
* @param progress
* @param outputTable
* @param srid
* @throws UnsupportedEncodingException
* @throws SQLException
* @param connection database connection
* @param inputStream {@link InputStream}
* @param progress Progress visitor following the execution.
* @param outputTable output table name
* @param srid output srid
* @throws UnsupportedEncodingException Throw exception is the encoding file is not supported
* @throws SQLException Throw exception is the file name contains unsupported characters
* @return output table name
*/

Expand Down Expand Up @@ -394,7 +394,7 @@ private String readAsc(Connection connection, InputStream inputStream, ProgressV
/**
* Use to set the z conversion type 1 = integer 2 = double
*
* @param zType
* @param zType value type to manage the z value
*/
public void setZType(int zType) {
this.zType = zType;
Expand All @@ -403,7 +403,7 @@ public void setZType(int zType) {
/**
* Set true to delete the input table if exists
*
* @param deleteTable
* @param deleteTable true to delete the table
*/
public void setDeleteTable(boolean deleteTable) {
this.deleteTable = deleteTable;
Expand All @@ -412,7 +412,7 @@ public void setDeleteTable(boolean deleteTable) {
/**
* Set encoding
*
* @param encoding
* @param encoding file encoding
*/
public void setEncoding(String encoding) {
this.encoding = encoding;
Expand All @@ -421,7 +421,7 @@ public void setEncoding(String encoding) {
/**
* Set to true if nodata must be imported. Default is false
*
* @param importNodata
* @param importNodata true to read to data value
*/
public void setImportNodata(boolean importNodata) {
this.importNodata = importNodata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,7 @@ else if(fileName.exists()){
* @param tableReference [[catalog.]schema.]table reference
* @param fileName File path to read
* @param csvOptions the CSV options ie "charset=UTF-8 fieldSeparator=| fieldDelimiter=,"
* @param progress
* @throws SQLException
* @throws IOException
* @param progress Progress visitor following the execution.
*/
@Override
public String[] exportTable(Connection connection, String tableReference, File fileName, String csvOptions, ProgressVisitor progress) throws SQLException, IOException {
Expand All @@ -163,9 +161,7 @@ public String[] importFile(Connection connection, String tableReference, File fi
* @param tableReference [[catalog.]schema.]table reference
* @param fileName File path to read
* @param csvOptions the CSV options ie "charset=UTF-8 fieldSeparator=| fieldDelimiter=,"
* @param progress
* @throws SQLException
* @throws IOException
* @param progress Progress visitor following the execution.
*/
@Override
public String[] importFile(Connection connection, String tableReference, File fileName,
Expand Down
Loading

0 comments on commit 47a8b90

Please sign in to comment.