Skip to content

Commit

Permalink
Merge pull request #1383 from orbisgis/shapefile_empty_geom
Browse files Browse the repository at this point in the history
Shapefile save empty geometry as null geometry
  • Loading branch information
ebocher authored May 21, 2024
2 parents 1192e5d + b894c69 commit a25c94c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Changelog for v2.2.2
- Read CPG file attached to the shapefile-
- Declare the schema for the spatial_ref_sys table
- Declare the schema for the spatial_ref_sys table
- Write empty geometry with the shapefile driver
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void writeGeometry(Geometry g) throws IOException {
shapeBuffer.putInt(++cnt);
shapeBuffer.putInt(length);
shapeBuffer.order(ByteOrder.LITTLE_ENDIAN);
if (g == null) {
if (g == null || g.isEmpty()) {
shapeBuffer.putInt(0);
} else {
shapeBuffer.putInt(type.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import static org.h2gis.unitTest.GeometryAsserts.assertGeometryEquals;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -450,6 +452,23 @@ public void linkedShpSpatialIndexFlatQueryTest() throws SQLException {
}
}

@Test
public void exportImportEmptyGeometry() throws SQLException {
Statement stat = connection.createStatement();
stat.execute("DROP TABLE IF EXISTS GEOTABLE");
stat.execute("create table GEOTABLE(idarea int primary key, the_geom GEOMETRY(POINT))");
stat.execute("insert into GEOTABLE values(1, 'POINT (0 0)'::GEOMETRY),(2, 'POINT EMPTY'::GEOMETRY);");
// Create a shape file using table area
stat.execute("CALL SHPWrite('target/points_withempty.shp', 'GEOTABLE', true)");
stat.execute("CALL SHPRead('target/points_withempty.shp', 'IMPORT_GEOTABLE')");
ResultSet res = stat.executeQuery("SELECT THE_GEOM FROM IMPORT_GEOTABLE ORDER BY idarea;");
res.next();
assertGeometryEquals("POINT(0 0)", res.getObject(1));
res.next();
assertNull(res.getObject(1));
res.close();
}

@Test
public void readSHPWithCPGFileTest() throws SQLException {
Statement st = connection.createStatement();
Expand Down

0 comments on commit a25c94c

Please sign in to comment.