MCPcopy Index your code
hub / github.com/cocoahero/android-geojson

github.com/cocoahero/android-geojson @v1.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.1 ↗ · + Follow
153 symbols 250 edges 18 files 30 documented · 20% updated 10y ago★ 1799 open issues

Browse by type

Functions 135 Types & classes 18
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Android GeoJSON

A complete GeoJSON implementation for Android.

Table of Contents

Requirements

  • Android SDK 8 or Higher

Installation

Android Studio / Gradle

dependencies {
  compile 'com.cocoahero.android:geojson:1.0.+@aar'
}

Maven

<dependency>
  <groupId>com.cocoahero.android</groupId>
  <artifactId>geojson</artifactId>
  <version>1.0.0</version>
  <type>aar</type>
</dependency>

Sample Usage

Whether you need to parse existing GeoJSON from a file or web server, or create new GeoJSON from user input, this library has got you covered.

Parsing GeoJSON

If you have existing GeoJSON that you need to parse, you have three source options with this library:

  1. String
  2. JSONObject
  3. InputStream

Once you have your GeoJSON in one of the above formats, simply pass it to GeoJSON#parse.

String
String string; // A string containing GeoJSON

try {
    GeoJSONObject geoJSON; = GeoJSON.parse(string);
}
catch (JSONException e) {
    e.printStackTrace();
}
JSONObject
JSONObject json; // A JSONObject formatted as GeoJSON

GeoJSONObject geoJSON; = GeoJSON.parse(json);
InputStream
InputStream stream; // An InputStream pointing to GeoJSON

try {
    GeoJSONObject geoJSON; = GeoJSON.parse(stream);
}
catch (IOException e) {
    e.printStackTrace();
}
catch (JSONException e) {
    e.printStackTrace();
}

The returned object instance will be a subclass of GeoJSONObject, depending on the type property of the GeoJSON.

Creating GeoJSON

Parsing existing GeoJSON is only half the fun! Why not create new GeoJSON?! Simply create a new instance of which ever GeoJSONObject sub-type you would like, then call #toJSON on it to get a properly formatted JSONObject instance.

For example, the following sample code creates a GeoJSON Feature with a Point geometry.

// Create geometry
Point point = new Point(38.889462878011365, -77.03525304794312);

// Create feature with geometry
Feature feature = new Feature(point);

// Set optional feature identifier
feature.setIdentifier("MyIdentifier");

// Set optional feature properties
feature.setProperties(new JSONObject());

// Convert to formatted JSONObject
JSONObject geoJSON = feature.toJSON();

The resulting GeoJSON can be seen here.

Core symbols most depended-on inside this repo

Shape

Method 135
Class 18

Languages

Java100%

Modules by API surface

androidgeojson/src/main/java/com/cocoahero/android/geojson/Position.java18 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/PositionList.java17 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/Feature.java12 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/LineString.java11 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/Polygon.java10 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiPolygon.java10 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiPoint.java10 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/MultiLineString.java10 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/GeometryCollection.java10 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/FeatureCollection.java10 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/GeoJSONObject.java9 symbols
androidgeojson/src/main/java/com/cocoahero/android/geojson/Point.java8 symbols

For agents

$ claude mcp add android-geojson \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page