Exemplo n.º 1
0
  @Override
  public JSONObject toJSON() throws JSONException {
    JSONObject oJSONOut = new JSONObject();
    oJSONOut.put(GEOJSON_TYPE, GEOJSON_TYPE_Feature);
    oJSONOut.put(GEOJSON_GEOMETRY, mGeometry.toJSON());
    JSONObject oJSONProp = new JSONObject();

    for (int i = 0; i < mFieldData.size(); i++) {
      String key = mFields.get(i).getFieldName();
      oJSONProp.put(key, mFieldData.get(i));
    }
    oJSONOut.put(GEOJSON_PROPERTIES, oJSONProp);
    return oJSONOut;
  }
Exemplo n.º 2
0
  @Override
  public void fromJSON(JSONObject jsonObject) throws JSONException {
    if (!jsonObject.getString(GEOJSON_TYPE).equals(GEOJSON_TYPE_Feature))
      throw new JSONException("not valid geojson feature");
    JSONObject oJSONGeom = jsonObject.getJSONObject(GEOJSON_GEOMETRY);
    mGeometry = GeoGeometry.fromJson(oJSONGeom);
    JSONObject jsonAttributes = jsonObject.getJSONObject(GEOJSON_PROPERTIES);
    Iterator<String> iter = jsonAttributes.keys();
    while (iter.hasNext()) {
      String key = iter.next();
      Object value = jsonAttributes.get(key);

      mFieldData.add(value);
    }
  }