This is an automated email from the ASF dual-hosted git repository. bchapuis pushed a commit to branch 745-daylight in repository https://gitbox.apache.org/repos/asf/incubator-baremaps.git
commit 5ce8e48d61c77aaf83c7d82842320dde6250dc4e Author: Bertil Chapuis <[email protected]> AuthorDate: Tue Aug 29 16:39:20 2023 +0200 Handle null geometries in shapefile --- .../baremaps/storage/shapefile/ShapefileDataTable.java | 7 ++++++- .../storage/shapefile/internal/DbaseByteReader.java | 1 + .../storage/shapefile/internal/ShapefileByteReader.java | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataTable.java b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataTable.java index f413ad95..680158d3 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataTable.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/ShapefileDataTable.java @@ -23,12 +23,16 @@ import org.apache.baremaps.database.schema.DataRowType; import org.apache.baremaps.database.schema.DataTableException; import org.apache.baremaps.storage.shapefile.internal.ShapefileInputStream; import org.apache.baremaps.storage.shapefile.internal.ShapefileReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A table that stores rows in a shapefile. */ public class ShapefileDataTable extends AbstractDataTable { + private static final Logger logger = LoggerFactory.getLogger(ShapefileDataTable.class); + private final ShapefileReader shapeFile; /** @@ -101,7 +105,8 @@ public class ShapefileDataTable extends AbstractDataTable { next = shapefileInputStream.readRow(); } return next != null; - } catch (IOException exception) { + } catch (IOException e) { + logger.error("Malformed shapefile", e); shapefileInputStream.close(); return false; } diff --git a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/DbaseByteReader.java b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/DbaseByteReader.java index 90db8ba9..3b545aee 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/DbaseByteReader.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/DbaseByteReader.java @@ -163,6 +163,7 @@ public class DbaseByteReader extends CommonByteReader implements AutoCloseable { // 2) Check that the immediate next byte read isn't the EOF signal. byte eofCheck = getByteBuffer().get(); + if (eofCheck == 0x1A) { return false; } else { diff --git a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java index 6e2f0581..069ac5b1 100644 --- a/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java +++ b/baremaps-core/src/main/java/org/apache/baremaps/storage/shapefile/internal/ShapefileByteReader.java @@ -272,6 +272,10 @@ public class ShapefileByteReader extends CommonByteReader { } switch (shapefileGeometryType) { + case NullShape: + loadNullRow(row); + break; + case Point: loadPointRow(row); break; @@ -291,6 +295,15 @@ public class ShapefileByteReader extends CommonByteReader { getByteBuffer().order(ByteOrder.BIG_ENDIAN); } + /** + * Load null row. + * + * @param row the row to fill. + */ + private void loadNullRow(DataRow row) { + row.set(GEOMETRY_NAME, null); + } + /** * Load point row. *
