예제 #1
0
def listToJsonArray(d):
    json = JSONArray()
    for item in d:
        if isinstance(item, dict):
            value = dictToJsonObject(item)
        else:
            value = listToJsonArray(item)
        json.put(value)

    return json
예제 #2
0
 def fromMap(cls, obj):
     if isinstance(obj, dict):
         jsonObject = JSONObject()
         for k in obj:
             jsonObject.put(k, cls.fromMap(obj[k]))
         return jsonObject
     elif isinstance(obj, list):
         jsonArray = JSONArray()
         for k in obj:
             jsonArray.put(k)
         return jsonArray
     else:
         return obj
예제 #3
0
 def fromMap(cls, obj):
     if isinstance(obj, dict):
         jsonObject = JSONObject()
         for k in obj:
             jsonObject.put(k, cls.fromMap(obj[k]))
         return jsonObject
     elif isinstance(obj, list):
         jsonArray = JSONArray()
         for k in obj:
             jsonArray.put(k)
         return jsonArray
     else:
         return obj
def layerToJSON(layer):
    jsonlayer = JSONObject()
    jsonfeatures = JSONArray()
    ftype = layer.getFeatureStore().getDefaultFeatureType()
    geomAttributeName = ftype.getDefaultGeometryAttributeName()
    for f in layer.getFeatureStore().getFeatureSet():
        jsonfeature = JSONObject()
        values = f.getValues()
        for k in values.keys():
            value = values[k]
            if k == geomAttributeName:
                wkt = value.convertToWKT()
                jsonfeature.putOnce(k, wkt)
            else:
                jsonfeature.putOnce(k, value)
        jsonfeatures.put(jsonfeature)
    jsonlayer.put("features", jsonfeatures)
    return jsonlayer