Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix estimated extend on table stored in a schema #1286

Merged
merged 2 commits into from Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Expand Up @@ -9,3 +9,4 @@
+ Add ST_AsEWKB function(#1271)
+ Add ST_Multi function (#1268)
+ Fix GeoJSON driver on H2GIS does not use the good object type for geometry (#1277)
+ Fix estimated extend on schema (#1286)
Expand Up @@ -106,4 +106,17 @@ public void testJTS() throws ParseException {
Geometry result = geomA.intersection(geomB);
System.out.println(new WKTWriter(3).write(result));
}

@Disabled
@Test
public void testST_BufferBug() throws SQLException {
Statement stat = connection.createStatement();
assertDoesNotThrow(() -> {
try {
stat.execute("SELECT ST_BUFFER('LINESTRING (307095.4 6739498.8, 307113.6 6739493.1, 307172.2 6739471.6, 307246.5 6739446.4, 307283 6739433.5, 307346 6739414.1)'::GEOMETRY, 1,'endcap=flat') ;");
} catch (JdbcSQLException e) {
throw e.getCause();
}
});
}
}
Expand Up @@ -257,7 +257,6 @@ public void readSHPConstraintTest() throws SQLException {
st.execute("drop table shptable");
}

@Disabled
@Test
public void testAddIndexOnTableLink() throws SQLException {
Statement st = connection.createStatement();
Expand Down
Expand Up @@ -61,7 +61,6 @@ public void tearDownStatement() throws Exception {
}

@Test
@Disabled
public void testFindGeometryMetadata() throws SQLException {
st.execute("DROP TABLE IF EXISTS geotable; CREATE TABLE geotable (the_geom GEOMETRY); ");
ResultSet res = st.executeQuery("SELECT TABLE_CATALOG f_table_catalog, "
Expand All @@ -86,8 +85,8 @@ public void testFindGeometryMetadata() throws SQLException {
assertEquals(0, res.getObject("SRID"));
assertEquals("GEOMETRY", res.getString("TYPE"));

st.execute("DROP TABLE IF EXISTS geotable; CREATE TABLE geotable (the_geom GEOMETRY(POINTZM, 0));" +
"INSERT INTO geotable values ('SRID=0;POINTZ(1 1 0 5)') ");
st.execute("DROP TABLE IF EXISTS geotable; CREATE TABLE geotable (the_geom GEOMETRY(POINTZm, 0));" +
"INSERT INTO geotable values ('SRID=0;POINTZM(1 1 0 5)') ");
res = st.executeQuery(
"SELECT TABLE_CATALOG f_table_catalog, "
+ " TABLE_SCHEMA f_table_schema, "
Expand Down Expand Up @@ -141,7 +140,6 @@ public void testFindGeometryMetadata() throws SQLException {
}

@Test
@Disabled
public void testFindGeometryMetadataAlterTable() throws SQLException {
st.execute("drop table if exists geo_point;\n" +
"CREATE TABLE geo_point (the_geom GEOMETRY);\n" +
Expand Down Expand Up @@ -173,7 +171,6 @@ public void testFindGeometryMetadataAlterTable() throws SQLException {
}

@Test
@Disabled
public void testFindGeometryMetadataAlterTableEmpty() throws SQLException {
st.execute("drop table if exists geo_point; CREATE TABLE geo_point (the_geom GEOMETRY);");
st.execute(" ALTER TABLE GEO_POINT ALTER COLUMN THE_GEOM type geometry(POINTZ, 4326);");
Expand Down Expand Up @@ -203,7 +200,6 @@ public void testFindGeometryMetadataAlterTableEmpty() throws SQLException {
}

@Test
@Disabled
public void testCheckSRID() throws SQLException {
st.execute("DROP TABLE IF EXISTS geotable; CREATE TABLE geotable (the_geom GEOMETRY); ");
ResultSet res = st.executeQuery(
Expand Down
Expand Up @@ -55,7 +55,7 @@
import org.locationtech.jts.io.WKTReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Disabled

public class GeometryTableUtilsTest {

private static Connection connection;
Expand All @@ -80,11 +80,11 @@ public static void tearUp() throws Exception {
connection.createStatement().execute("CREATE TABLE GEOMTABLE (geom GEOMETRY, pt GEOMETRY(POINTZM), linestr GEOMETRY(LINESTRING), "
+ "plgn GEOMETRY(POLYGON), multipt GEOMETRY(MULTIPOINT), multilinestr GEOMETRY(MULTILINESTRING), multiplgn GEOMETRY(MULTIPOLYGON), "
+ "geomcollection GEOMETRY(GEOMETRYCOLLECTION))");
connection.createStatement().execute("INSERT INTO GEOMTABLE VALUES ('POINT(1 1)', 'POINT(1 1 0 0)',"
connection.createStatement().execute("INSERT INTO GEOMTABLE VALUES ('POINT(1 1)', 'POINTZM(1 1 0 0)',"
+ " 'LINESTRING(1 1, 2 2)', 'POLYGON((1 1, 1 2, 2 2, 2 1, 1 1))', 'MULTIPOINT((1 1))',"
+ " 'MULTILINESTRING((1 1, 2 2))', 'MULTIPOLYGON(((1 1, 1 2, 2 2, 2 1, 1 1)))',"
+ " 'GEOMETRYCOLLECTION(POINT(1 1))')");
connection.createStatement().execute("INSERT INTO GEOMTABLE VALUES ('LINESTRING(1 1, 2 2)', 'POINT(2 2 0 0)',"
connection.createStatement().execute("INSERT INTO GEOMTABLE VALUES ('LINESTRING(1 1, 2 2)', 'POINTZM(2 2 0 0)',"
+ " 'LINESTRING(2 2, 1 1)', 'POLYGON((1 1, 1 3, 3 3, 3 1, 1 1))', 'MULTIPOINT((3 3))',"
+ " 'MULTILINESTRING((1 1, 3 3))', 'MULTIPOLYGON(((1 1, 1 3, 3 3, 3 1, 1 1)))',"
+ " 'GEOMETRYCOLLECTION(POINT(3 3))')");
Expand Down Expand Up @@ -545,6 +545,18 @@ public void testEstimatedExtentWithIndex() throws SQLException {
GeometryTableUtilities.getEstimatedExtent(connection, tableLocation, "THE_GEOM").getEnvelopeInternal());
}

@Test
public void testEstimatedExtentSchema() throws SQLException {
Statement statement = connection.createStatement();
statement.execute("DROP SCHEMA IF EXISTS MYSCHEMA CASCADE; CREATE SCHEMA MYSCHEMA; DROP TABLE IF EXISTS MYSCHEMA.GEOMTABLE; CREATE TABLE MYSCHEMA.GEOMTABLE (THE_GEOM GEOMETRY(GEOMETRY, 4326));");
statement.execute("INSERT INTO MYSCHEMA.GEOMTABLE VALUES (ST_GeomFromText('POLYGON ((150 360, 200 360, 200 310, 150 310, 150 360))', 4326)),(ST_GeomFromText('POLYGON ((195.5 279, 240 279, 240 250, 195.5 250, 195.5 279))', 4326) )");
TableLocation tableLocation = TableLocation.parse("myschema.geomtable", DBTypes.H2GIS);
Geometry geom = GeometryTableUtilities.getEstimatedExtent(connection, tableLocation, "the_geom");
assertNotNull(geom);
assertEquals(4326, geom.getSRID());
statement.execute("DROP SCHEMA IF EXISTS MYSCHEMA CASCADE;");
}

@Test
public void testGeometryType() throws SQLException {
TableLocation tableLocation = TableLocation.parse("GEOMTABLE", DBTypes.H2);
Expand Down
Expand Up @@ -818,7 +818,7 @@ public static Geometry getEstimatedExtent(Connection connection, TableLocation t
}
} else {
StringBuilder query = new StringBuilder("SELECT ESTIMATED_ENVELOPE('");
query.append(tableLocation.toString()).append("','").append(geometryColumnName).append("')");
query.append(tableLocation.toString()).append("','").append(TableLocation.capsIdentifier(geometryColumnName, H2GIS)).append("')");
try (ResultSet rs = connection.createStatement().executeQuery(query.toString())) {
if (rs.next()) {
result = (Geometry) rs.getObject(1);
Expand All @@ -828,8 +828,8 @@ public static Geometry getEstimatedExtent(Connection connection, TableLocation t
}
}
}
query = new StringBuilder("SELECT ENVELOPE(");
query.append(TableLocation.quoteIdentifier(geometryColumnName)).append(") FROM ").append(tableLocation.getTable());
query = new StringBuilder("SELECT ENVELOPE(");
query.append(TableLocation.capsIdentifier(geometryColumnName, H2GIS)).append(") FROM ").append(tableLocation.toString(H2GIS));
try (ResultSet rsEnv = connection.createStatement().executeQuery(query.toString())) {
if (rsEnv.next()) {
result = (Geometry) rsEnv.getObject(1);
Expand Down
Expand Up @@ -41,7 +41,6 @@
* @author Erwan Bocher (CNRS 2021)
* @author Sylvein PALOMINOS (UBS Chaire GEOTERA 2021)
*/
@Disabled
public class DBUtilsTest {

private static Connection h2Conn;
Expand Down
Expand Up @@ -36,7 +36,6 @@
*
* @author Erwan Bocher
*/
@Disabled
public class PostGIS_JTSTest {

private static Connection connection;
Expand Down