Skip to content

Commit

Permalink
Merge pull request #1281 from nicolas-f/fixgeojsonissue
Browse files Browse the repository at this point in the history
About #1277 fix GeoJson drivers cannot import large geometries
  • Loading branch information
ebocher committed Feb 21, 2022
2 parents b1f688c + 98cf46c commit e7d3904
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Expand Up @@ -7,3 +7,4 @@
+ Add new constructors to TableLocation (#1264)
+ 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)
5 changes: 5 additions & 0 deletions h2gis-functions/pom.xml
Expand Up @@ -108,6 +108,11 @@
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<!-- Build Settings -->
Expand Down
Expand Up @@ -898,8 +898,7 @@ private void setGeometry(JsonParser jp, Object[] values) throws IOException, SQL
jp.nextToken(); // FIELD_NAME type
jp.nextToken(); //VALUE_STRING Point
String geometryType = jp.getText();
Geometry geom = parseGeometry(jp, geometryType);
values[0] = ValueGeometry.getFromGeometry(geom).getBytesNoCopy();
values[0] = parseGeometry(jp, geometryType);
}
}

Expand Down
Expand Up @@ -35,13 +35,15 @@

import java.io.File;
import java.io.IOException;
import java.net.ConnectException;
import java.nio.file.Files;
import java.sql.*;
import java.util.List;
import java.util.Properties;

import org.h2gis.unitTest.GeometryAsserts;
import org.osgi.service.jdbc.DataSourceFactory;
import org.postgresql.util.PSQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -1154,6 +1156,49 @@ public void testSelectWrite() throws Exception {
}
}

@Test
public void testPostGISImport() throws Exception {
String url = "jdbc:postgresql://localhost:5432/orbisgis_db";
Properties props = new Properties();
props.setProperty("user", "orbisgis");
props.setProperty("password", "orbisgis");
props.setProperty("url", url);
DataSourceFactory dataSourceFactory = new DataSourceFactoryImpl();
try (Connection con = dataSourceFactory.createDataSource(props).getConnection()) {
GeoJsonDriverFunction geoJsonDriverFunction = new GeoJsonDriverFunction();
geoJsonDriverFunction.importFile(con, "geojsontest", new File(GeojsonImportExportTest.class.getResource("data.geojson").getFile()), true, new EmptyProgressVisitor());
try(ResultSet res = con.createStatement().executeQuery("SELECT * FROM geojsontest;")) {
assertTrue(res.next());
assertTrue(((Geometry) res.getObject(1)).equals(WKTREADER.read("POLYGON ((7.49587624983838 48.5342070572556, 7.49575955525988 48.5342516702309, 7.49564286068138 48.5342070572556, 7.49564286068138 48.534117831187, 7.49575955525988 48.5340732180938, 7.49587624983838 48.534117831187, 7.49587624983838 48.5342070572556))")));
assertEquals(-105576, res.getDouble(2), 0);
assertEquals(275386, res.getDouble(3), 0);
assertEquals(56.848998452816424, res.getDouble(4), 0);
assertEquals(55.87291487481895, res.getDouble(5), 0);
assertEquals(0.0, res.getDouble(6), 0);
assertNull(res.getString(7));
assertEquals(2, res.getDouble(8), 0);
assertEquals("2017-01-19T18:29:26+01:00", res.getString(9));
assertEquals("1484846966000", res.getBigDecimal(10).toString());
assertEquals("2017-01-19T18:29:27+01:00", res.getString(11));
assertEquals("1484846967000", res.getBigDecimal(12).toString());
assertEquals("{\"member1\":1,\"member2\":{\"member21\":21,\"member22\":22}}", res.getString(13));
assertEquals("[49,40.0,{\"member1\":1,\"member2\":{\"member21\":21,\"member22\":22}},\"string\",[13,\"string\",{\"member3\":3,\"member4\":4}]]", res.getString(14));
assertEquals("[58,47,58,57,58,49,58,51,58,58,49,57,58,58,49,58,57,56,57,58,59,58,57,58,49,47,48,57,48,58,57,57,51,56,52,57,51,57,49,58,55,58,50,48,48,52,56,57,48,58,52,48,53,50,57,54,57,47,58,57,54,54,53,56,57,55,58,58,57,58,57,57]", res.getString(15));
res.next();
}
} catch (PSQLException ex) {
if (ex.getCause() == null || ex.getCause() instanceof ConnectException) {
// Connection issue ignore
log.warn("Connection error to local PostGIS, ignored", ex);
} else {
throw ex;
}
} catch (SQLException ex) {
log.error(ex.getLocalizedMessage(), ex.getNextException());
throw ex;
}
}

@Test
public void testSelectWritePostGIS(TestInfo testInfo) throws Exception {
String url = "jdbc:postgresql://localhost:5432/orbisgis_db";
Expand Down

0 comments on commit e7d3904

Please sign in to comment.