Closed AndriusRimk closed 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()
Thanks for the fast response, it solved my issue.
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:
mil.nga.geopackage.GeoPackageException: Unexpected GeoPackage Geometry magic number: ����, Expected: GP
Output:
mil.nga.geopackage.GeoPackageException: Unexpected GeoPackage Geometry magic number: ����, Expected: GP at mil.nga.geopackage.geom.GeoPackageGeometryData.fromBytes(GeoPackageGeometryData.java:111) at mil.nga.geopackage.geom.GeoPackageGeometryData.<init>(GeoPackageGeometryData.java:86) at land.meridia.collect.ngageo.poc.NGAGeo.onMapReady(NGAGeo.kt:150) at com.google.android.gms.maps.zzak.zza(Unknown Source:2) at com.google.android.gms.maps.internal.zzaq.dispatchTransaction(Unknown Source:12) at com.google.android.gms.internal.maps.zzb.onTransact(Unknown Source:12) at android.os.Binder.transact(Binder.java:667) at fv.b(:com.google.android.gms.dynamite_mapsdynamite@16089052@16.0.89 (040700-239467275):14) at com.google.android.gms.maps.internal.bd.a(:com.google.android.gms.dynamite_mapsdynamite@16089052@16.0.89 (040700-239467275):4) at com.google.maps.api.android.lib6.impl.bk.run(:com.google.android.gms.dynamite_mapsdynamite@16089052@16.0.89 (040700-239467275):4) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Steps to Reproduce:
Relevant Code:
Test Files:
{ "type": "Point", "coordinates": [ 102.0, 0.5 ] }
Additional Information: