示例#1
0
    def to_instance(cls, ob, default=None, strict=False):
        if isinstance(ob, list):
            coords = ob
        else:
            coords = [float(x.strip()) for x in ob.split(',')]
        wkid = 21781
        if len(coords) == 2:
            x, y = coords
            if x <= 180 and y <= 180:
                wkid = 4326

            crs = Named(properties=dict(name="urn:ogc:def:crs:EPSG:%d" % wkid))

            return geojson.geometry.Point(coords, crs=crs)

        if len(coords) == 4:
            crs = Named(properties=dict(name="urn:ogc:def:crs:EPSG:%d" % wkid))
            minx, miny, maxx, maxy = coords

            return geojson.geometry.Polygon(
                [[[minx, miny], [minx, maxy], [maxx, maxy], [maxx, miny],
                  [minx, miny]]],
                crs=crs)

        else:
            raise ValueError("%r is not a simplified esri geometry", coords)
示例#2
0
    def to_instance(cls, ob, default=None, strict=False):

        mapping = geojson.mapping.to_mapping(ob)

        d = dict((str(k), mapping[k]) for k in mapping)

        wkid = 21781
        if 'spatialReference' in d.keys():
            ref = d['spatialReference']
            if 'wkid' in ref.keys():
                wkid = ref['wkid']

        crs = Named(properties=dict(name="urn:ogc:def:crs:EPSG:%d" % wkid))

        if 'x' in d.keys():
            coords = [d['x'], d['y']]

            return geojson.geometry.Point(coords, crs=crs)

        if 'xmin' in d.keys():
            minx, miny, maxx, maxy = [
                d.get(k) for k in ['xmin', 'ymin', 'xmax', 'ymax']
            ]
            coords = [[[minx, miny], [maxx, miny], [maxx, maxy], [minx, maxy],
                       [minx, miny]]]

            return geojson.geometry.Polygon(coords, crs=crs)

        if 'paths' in d.keys():
            coords = d['paths'][0]

            return geojson.geometry.LineString(coords, crs=crs)

        if 'rings' in d.keys():
            coords = d['rings']

            return geojson.geometry.Polygon(coords, crs=crs)

        return d