示例#1
0
文件: geos.py 项目: redhog/arwen
    def __init__(self, *arg, **kw):
        """GEOSFeature(json_data)
           GEOSFeature(geometry, property_name1=value, property_name2=value, ...)
           GEOSFeature(geometry, id, property_name1=value, property_name2=value, ...)
           GEOSFeature(geometry, id, propertiesdict)
        """
        assert len(arg) > 0 and len(arg) <= 3

        self.geometry = None
        self.properties = {}
        self.id = None

        if isinstance(arg[0], django.contrib.gis.geos.GEOSGeometry):
            self.geometry = arg[0]
        else:
            obj = symmetricjsonrpc.from_json(arg[0])
            if obj['type'].lower() == 'feature':
                self.geometry = django.contrib.gis.geos.GEOSGeometry(symmetricjsonrpc.to_json(obj['geometry']))
                if 'properties' in obj:
                    self.properties.update(obj['properties'])
                if 'id' in obj:
                    self.id = obj['id']
            else:
                self.geometry = django.contrib.gis.geos.GEOSGeometry(arg[0])

        if len(arg) > 1:
            self.id = arg[1]

        if len(arg) > 2:
            self.properties.update(arg[2])
        self.properties.update(kw)
示例#2
0
文件: geos.py 项目: redhog/arwen
 def json(self):
     res = {"type": "Feature",
            "geometry": symmetricjsonrpc.from_json(self.geometry.json),
            "properties": self.properties}
     if self.id is not None:
         res['id'] = self.id
     return symmetricjsonrpc.to_json(res)
示例#3
0
文件: geos.py 项目: redhog/arwen
 def __init__(self, arg):
     """GEOSFeatureCollection(json_data)
        GEOSFeatureCollection([json_data1, json_data2, ...])
        GEOSFeatureCollection([feature1, feature2, ...])
     """
     self.features = []
     if isinstance(arg, (types.ListType, types.TupleType)):
         for feature in arg:
             if not isinstance(feature, GEOSFeature):
                 feature = GEOSFeature(feature)
             self.features.append(feature)
     else:
         obj = symmetricjsonrpc.from_json(arg)
         assert obj['type'].lower() == "featurecollection"
         for feature in obj['features']:
             self.features.append(GEOSFeature(symmetricjsonrpc.to_json(feature)))
示例#4
0
文件: geos.py 项目: redhog/arwen
 def json(self):
     res = {"type": "FeatureCollection",
            "features": [symmetricjsonrpc.from_json(feature.json) for feature in self.features]}
     return symmetricjsonrpc.to_json(res)