GithubHelp home page GithubHelp logo

ngageoint / simple-features-wkb-java Goto Github PK

View Code? Open in Web Editor NEW
21.0 16.0 7.0 948 KB

Simple Features Well-Known Binary Java Library

Home Page: http://ngageoint.github.io/simple-features-wkb-java

License: MIT License

Java 100.00%
wkb nga java java-library java-sdk java-libraries java-api ogc ogc-wkb simple-features well-known well-known-binary features-wkb

simple-features-wkb-java's Introduction

Simple Features WKB Java

Simple Features Well Known Binary Lib

The Simple Features Libraries were developed at the National Geospatial-Intelligence Agency (NGA) in collaboration with BIT Systems. The government has "unlimited rights" and is releasing this software to increase the impact of government investments by providing developers with the opportunity to take things in new directions. The software use, modification, and distribution rights are stipulated within the MIT license.

Pull Requests

If you'd like to contribute to this project, please make a pull request. We'll review the pull request and discuss the changes. All pull request contributions to this project will be released under the MIT license.

Software source code previously released under an open source license and then modified by NGA staff is considered a "joint work" (see 17 USC § 101); it is partially copyrighted, partially public domain, and as a whole is protected by the copyrights of the non-government authors and must be released according to the terms of the original open source license.

About

Simple Features WKB is a Java library for writing and reading Simple Feature Geometries to and from Well-Known Binary.

Usage

View the latest Javadoc

Read

// byte[] bytes = ...

Geometry geometry = GeometryReader.readGeometry(bytes);
GeometryType geometryType = geometry.getGeometryType();

Write

// Geometry geometry = ...

byte[] bytes = GeometryWriter.writeGeometry(geometry);

Installation

Pull from the Maven Central Repository (JAR, POM, Source, Javadoc)

<dependency>
    <groupId>mil.nga.sf</groupId>
    <artifactId>sf-wkb</artifactId>
    <version>2.2.3</version>
</dependency>

Build

Build & Test

Build this repository using Eclipse and/or Maven:

mvn clean install

Remote Dependencies

simple-features-wkb-java's People

Contributors

bosborn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simple-features-wkb-java's Issues

read MULTICURVE geometry

Hello, as we migrated data from Oracle (Spatial) to Postgres/Postgis (from WKT to WKB) we use your library to read the geometry from Postgres/Postgis.
We ran into problem with MULTICURVE/COMPOUND geometry, where in the specs of OGC there is the standard like non-instance class and you have it right.
But the implementation is different little bit and postgis is able to save the data like this:

st_geomfromtext('MULTICURVE(COMPOUNDCURVE(LINESTRING(3451418.006 5481808.951,3451417.787 5481809.927,3451409.995 5481806.744),LINESTRING(3451409.995 5481806.744,3451418.006 5481808.951)))')

And the software like QGIS and so on accept this, can read it from db.
So we want to know, if it is possible your parser (is the best for us) could accept and read also this geometry.

Thank you.

Add JUnit Tests

Although the geometries are tested in the GeoPackage Java and Android projects, we need some stand alone library tests.

Does it support SRID?

Hi,

I tried to use it to export geometry point as binary and use COPY command to copy it to PostGIS, but reports "ERROR: Geometry SRID (0) does not match column SRID (4326)". So my question is where can I set SRID to geometry types and then write them to binary? Thanks.
State your question
A clear and concise question.

Additional context
Add any other context or screenshots related to your question.

GeoPackageGeometryData fromBytes Unknown magic value

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:

  • SF WKB Java Version: 2.0.2
  • SF WKB Java Source: (e.g. Central Repository, Release, Source Code Build) Maven/Gradle
  • IDE Name & Version:
  • Maven Version: (mvn -version)
  • Java Version: (java -version)
  • Platform & OS:
  • Other Relevant Libraries:
    api "mil.nga.geopackage:geopackage-android:3.4.0"
    api "mil.nga.geopackage.map:geopackage-android-map:3.4.0"
    api "mil.nga.sf:sf-geojson:2.0.3"
    api "mil.nga:sf:2.0.2"

Expected Results:

  • Create GeoJson Geometry object from string.
  • GeoJson Geometry to Geometry
  • Geometry to WKB
  • Geometry to GeoPackageGeometrydata
  • Save data to FeatureRow using GEOMETRY type

Observed Results:

  • While constructing : GeoPackageGeometrydata(WKB(GEOMETRY)) trows expection: mil.nga.geopackage.GeoPackageException: Unexpected GeoPackage Geometry magic number: ����, Expected: GP
  • How often does this occur? Alwayse

Output:

  • Any logs, errors, or output messages?
    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@[email protected] (040700-239467275):14) at com.google.android.gms.maps.internal.bd.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040700-239467275):4) at com.google.maps.api.android.lib6.impl.bk.run(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (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:

  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:

  • The Geometry string { "type": "Point", "coordinates": [ 102.0, 0.5 ] }

Additional Information:

  • Any additional configuration, data, or information that might help with the issue?

NullPointerException when reading geometry

Version Information:

  • WKB Java Version: 1.0.5
  • WKB Java Source: Central Repository
  • IDE Name & Version: Android Studio 3.0.1
  • Maven Version: Gradle 3.0.1
  • Java Version: 1.7
  • Platform & OS: Ubuntu 14.04 LTS, 64 bit
  • Other Relevant Libraries: I am coding in Kotlin, using this Java library

Expected Results:

I am just starting to use this interesting library, and I followed the example on reading a WKB as stated in the readme, here: https://github.com/ngageoint/geopackage-wkb-java/blob/master/README.md

Basically, the code translated to Kotlin is as follows:
//wkb_geometry is the wkb as String
var reader = ByteReader(wkb_geometry.toByteArray())
reader.byteOrder= ByteOrder.BIG_ENDIAN
var geometry: Geometry = WkbGeometryReader.readGeometry(reader)

Observed Results:

However, I obtained a NullPointerException that traces to the Geometry instantiation line (the last one). This WKB I originally saved on a PostGIS database, and I have checked it is saved correctly (as I can display the geometries on my GeoServer as well as on the GIS I use)

Output:

Full (relevant) stack trace:

java.lang.NullPointerException: Attempt to invoke virtual method 'int mil.nga.wkb.geom.GeometryType.ordinal()' on a null object reference

at mil.nga.wkb.io.WkbGeometryReader.readGeometry(WkbGeometryReader.java:94)

at mil.nga.wkb.io.WkbGeometryReader.readGeometry(WkbGeometryReader.java:37)

at gt.aerobots.aegis.util.JsonHelper$Companion.toGeometry(JsonHelper.kt:31)

Steps to Reproduce:

Run the code above mentioned, to instantiate a Geometry from a wkb

Relevant Code:

Here is the wkb of the geometry that gave me this error, I tried with others but get the same error. Worth mentioning that this is a MultiPolygon object:

0106000080010000000103000080010000000F0000007835454789C456C0DFDB63124D3F2C4000000000000000004CE4512E89C456C060BF20D13F3F2C400000000000000000A42EC6388CC456C0E0A50400423F2C400000000000000000B4E3B1608CC456C060034E67433F2C400000000000000000F82138508DC456C09FD015C5473F2C400000000000000000ECD6591B8CC456C000C305BC5B3F2C4000000000000000001002AD0F8CC456C060DB367D5C3F2C40000000000000000010996DEF8AC456C0BF01756A6C3F2C4000000000000000007054A08B8AC456C0806A0C1F733F2C4000000000000000009422D81D8AC456C041CA3C5B8A3F2C4000000000000000003CCB05C489C456C03FC4FC52AA3F2C400000000000000000740315A689C456C0BFC8635EB33F2C400000000000000000E4A5630B89C456C0DFE726D6B33F2C400000000000000000F45A4F3389C456C000B07950703F2C4000000000000000007835454789C456C0DFDB63124D3F2C400000000000000000

Additional Information:

  • I am coding this app in Kotlin

  • I am able to verify that the wkb is OK, as it opens on my GeoServer and QGis

  • Further tracing the error I see it happens on line 94 of WkbGeometryReader, on the switch(geometryType) part. It seems that geometryType is null, which suggests that GeometryType.fromCode() is returning null. This means that somehow it was unable to determine the Geometry Type on the switch/case.

  • I'll try other approaches to see if I screwed up with something. Thank you for your assistance :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.