commit | bf03526b2e9f99a004f373d5e6ce8cb384dd2df6 | [log] [tgz] |
---|---|---|
author | Adrian Stabiszewski <github@grundid.de> | Mon Jul 03 11:31:06 2017 +0200 |
committer | GitHub <noreply@github.com> | Mon Jul 03 11:31:06 2017 +0200 |
tree | 3cdc51fdee4433cab399332ced797a49d8cf5b83 | |
parent | a3ef371bebcc0c5493217717b9ff159a8d4c59fa [diff] | |
parent | 585e54b2038bccace4d39d246509b83701902ae7 [diff] |
Merge pull request #41 from lucassaldanha/patch-1 Fix typo
A small package of all GeoJson POJOs (Plain Old Java Objects) for serializing and deserializing of objects via JSON Jackson Parser.
If you know what kind of object you expect from a GeoJson file you can directly read it like this:
FeatureCollection featureCollection = new ObjectMapper().readValue(inputStream, FeatureCollection.class);
If you want to read any GeoJson file read the value as GeoJsonObject and then test for the contents via instanceOf:
GeoJsonObject object = new ObjectMapper().readValue(inputStream, GeoJsonObject.class); if (object instanceof Polygon) { ... } else if (object instanceof Feature) { ... }
and so on.
Or you can use the GeoJsonObjectVisitor to visit the right method:
GeoJsonObject object = new ObjectMapper().readValue(inputStream, GeoJsonObject.class); object.accept(visitor);
Writing Json is even easier. You just have to create the GeoJson objects and pass them to the Jackson ObjectMapper.
FeatureCollection featureCollection = new FeatureCollection(); featureCollection.add(new Feature()); String json= new ObjectMapper().writeValueAsString(featureCollection);
You can find the library in the Maven Central Repository.
<dependency> <groupId>de.grundid.opendatalab</groupId> <artifactId>geojson-jackson</artifactId> <version>1.8</version> </dependency>