Skip to content

Repository files navigation

#GeoGson

GeoGson is a Gson implementation of the GeoJson specification (with some unofficial object support)

##Types supported

  1. Circle (unofficial support)
  2. Feature
  3. LineString
  4. MultiLineString
  5. Polygon
  6. MultiPolygon
  7. Point
  8. MultiPoint

##Usage with custom gson parsers

In order for the gson to correctly inflate into geojson objects, you must make sure to include the type adapter so that gson can detect and inflate the geojson objects correctly.

GsonBuilderbuilder = newGsonBuilder();
builder.registerTypeAdapter(GeoJsonObject.class, newGeoJsonObjectAdapter());
builder.registerTypeAdapter(LngLatAlt.class, newLngLatAltAdapter());

You can use the methods found in GeoGson to automatically add these adapters to your builder object, or create a new gson instance with the adapters already added

GeoJson.getGson()
GeoJson.registerAdapters(GsonBuilderbuilder)

##Example

GsonBuilderbuilder = newGsonBuilder();
GeoJson.registerAdapters(builder);
GeoJsonObjectpoint = builder.create().fromJson("{ \"type\": \"Point\", \"coordinates\": [100.0, 0.0] }", GeoJsonObject.class);
System.out.println(pointinstanceofPoint);

This will automatically parse the provided JSON string into its correct class (in this case, a point)

##Maven

To include the project, add the following to your build.gradle

compile 'com.3sidedcube.util:GeoGson:1.6'

##License

See LICENSE

About

Simple dynamic GeoJson parsing utility for Java, with support for Elasticsearch

Resources

Stars

11 stars

Watchers

7 watching

Forks

Releases

Packages

Contributors

Languages