Panos Panos - 1 year ago 179
Java Question

create geojson using simple json java

I would like to create the following geojson using the simple-json-1.1.1 jar.

{"type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "ESPG:4326"


Any ideas on how to do that?Thanks!!

Answer Source

The code to create the geojson mentioned above is the following:

JSONObject featureCollection = new JSONObject();
featureCollection.put("type", "FeatureCollection");
JSONObject properties = new JSONObject();
properties.put("name", "ESPG:4326");
JSONObject crs = new JSONObject();
crs.put("type", "name");
crs.put("properties", properties);
featureCollection.put("crs", crs);

JSONArray features = new JSONArray();
JSONObject feature = new JSONObject();
feature.put("type", "Feature");
JSONObject geometry = new JSONObject();

JSONAray JSONArrayCoord = new JSONArray();

JSONArrayCoord.add(0, 55);
JSONArrayCoord.add(1, 55);
geometry.put("type", "Point");
geometry.put("coordinates", JSONArrayCoord);
feature.put("geometry", geometry);

featureCollection.put("features", features);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download