Search in sources :

Example 11 with Geometry

use of com.google.maps.android.data.Geometry in project android-maps-utils by googlemaps.

the class GeoJsonParser method parseFeature.

/**
     * Parses a single GeoJSON feature which contains a geometry and properties member both of
     * which can be null. Also parses the bounding box and id members of the feature if they exist.
     *
     * @param geoJsonFeature feature to parse
     * @return GeoJsonFeature object
     */
private static GeoJsonFeature parseFeature(JSONObject geoJsonFeature) {
    String id = null;
    LatLngBounds boundingBox = null;
    Geometry geometry = null;
    HashMap<String, String> properties = new HashMap<String, String>();
    try {
        if (geoJsonFeature.has(FEATURE_ID)) {
            id = geoJsonFeature.getString(FEATURE_ID);
        }
        if (geoJsonFeature.has(BOUNDING_BOX)) {
            boundingBox = parseBoundingBox(geoJsonFeature.getJSONArray(BOUNDING_BOX));
        }
        if (geoJsonFeature.has(FEATURE_GEOMETRY) && !geoJsonFeature.isNull(FEATURE_GEOMETRY)) {
            geometry = parseGeometry(geoJsonFeature.getJSONObject(FEATURE_GEOMETRY));
        }
        if (geoJsonFeature.has(PROPERTIES) && !geoJsonFeature.isNull(PROPERTIES)) {
            properties = parseProperties(geoJsonFeature.getJSONObject("properties"));
        }
    } catch (JSONException e) {
        Log.w(LOG_TAG, "Feature could not be successfully parsed " + geoJsonFeature.toString());
        return null;
    }
    return new GeoJsonFeature(geometry, id, properties, boundingBox);
}
Also used : Geometry(com.google.maps.android.data.Geometry) HashMap(java.util.HashMap) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) JSONException(org.json.JSONException)

Aggregations

Geometry (com.google.maps.android.data.Geometry)11 ArrayList (java.util.ArrayList)6 MultiGeometry (com.google.maps.android.data.MultiGeometry)3 HashMap (java.util.HashMap)2 LatLng (com.google.android.gms.maps.model.LatLng)1 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)1 Feature (com.google.maps.android.data.Feature)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1