ngageoint / simple-features-wkb-java

Simple Features Well-Known Binary Java Library
http://ngageoint.github.io/simple-features-wkb-java
MIT License
22 stars 10 forks source link

GeoPackageGeometryData fromBytes Unknown magic value #15

Closed AndriusRimk closed 4 years ago

AndriusRimk commented 4 years ago

Please fill out as much known and relevant information as possible. I am currently exploring how can I convert data from GeoJson formats to WKB and then store it but getting Magic value errors. From debugging it seems there is no place Converter would create magic value using POINT type.

Version Information:

Expected Results:

Observed Results:

Output:

Steps to Reproduce:

  1. Step One
  2. Step Two
  3. ...

Relevant Code:

val geometryGeoJson: mil.nga.sf.geojson.Geometry = FeatureConverter.toGeometry(geometryString)
        val geometry:Geometry = geometryGeoJson.geometry
        val writer = ByteWriter()
        writer.byteOrder = ByteOrder.BIG_ENDIAN
        GeometryWriter.writeGeometry(writer, geometry)
        val bytes: ByteArray = writer.bytes
        writer.close()
        val geoPackageData = GeoPackageGeometryData(bytes)

Test Files:

Additional Information:

bosborn commented 4 years ago

The GeoPackageGeometryData bytes constructor assumes the bytes already have the GeoPackage header bytes. Use the SRS Id constructor and then set the geometry.

Java

// simple-features-geojson-java
String point = "{ \"type\": \"Point\", \"coordinates\": [ 102.0, 0.5 ] }";
Geometry geometry = FeatureConverter.toGeometry(point).getGeometry();

// simple-features-wkb-java
ByteWriter writer = new ByteWriter();
GeometryWriter.writeGeometry(writer, geometry);
byte[] geometryBytes = writer.getBytes();
writer.close();

// geopackage-core-java and (geopackage-java or geopackage-android)
long srsId = geoPackage.getSpatialReferenceSystemDao().getOrCreateFromEpsg(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM).getSrsId();
GeoPackageGeometryData geometryData = new GeoPackageGeometryData(srsId);
geometryData.setGeometry(geometry);
//featureRow.setGeometry(geometryData);
byte[] geometryDataBytes = geometryData.toBytes();

Kotlin

// simple-features-geojson-java
val point = "{ \"type\": \"Point\", \"coordinates\": [ 102.0, 0.5 ] }"
val geometry = FeatureConverter.toGeometry(point).geometry

// simple-features-wkb-java
val writer = ByteWriter()
GeometryWriter.writeGeometry(writer, geometry)
val geometryBytes = writer.bytes
writer.close()

// geopackage-core-java and (geopackage-java or geopackage-android)
val srsId = geoPackage.spatialReferenceSystemDao.getOrCreateFromEpsg(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM.toLong()).srsId
val geometryData = GeoPackageGeometryData(srsId)
geometryData.geometry = geometry
//featureRow.setGeometry(geometryData);
val geometryDataBytes = geometryData.toBytes()
AndriusRimk commented 4 years ago

Thanks for the fast response, it solved my issue.