Python django.contrib.gis.geos.GeometryCollection() Examples

The following are 7 code examples of django.contrib.gis.geos.GeometryCollection(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.contrib.gis.geos , or try the search function .
Example #1
Source File: datatypes.py    From arches with GNU Affero General Public License v3.0 6 votes vote down vote up
def transform_value_for_tile(self, value, **kwargs):
        if "format" in kwargs and kwargs["format"] == "esrijson":
            arches_geojson = GeoUtils().arcgisjson_to_geojson(value)
        else:
            arches_geojson = {}
            arches_geojson["type"] = "FeatureCollection"
            arches_geojson["features"] = []
            geometry = GEOSGeometry(value, srid=4326)
            if geometry.geom_type == "GeometryCollection":
                for geom in geometry:
                    arches_json_geometry = {}
                    arches_json_geometry["geometry"] = JSONDeserializer().deserialize(GEOSGeometry(geom, srid=4326).json)
                    arches_json_geometry["type"] = "Feature"
                    arches_json_geometry["id"] = str(uuid.uuid4())
                    arches_json_geometry["properties"] = {}
                    arches_geojson["features"].append(arches_json_geometry)
            else:
                arches_json_geometry = {}
                arches_json_geometry["geometry"] = JSONDeserializer().deserialize(geometry.json)
                arches_json_geometry["type"] = "Feature"
                arches_json_geometry["id"] = str(uuid.uuid4())
                arches_json_geometry["properties"] = {}
                arches_geojson["features"].append(arches_json_geometry)

        return arches_geojson 
Example #2
Source File: instance.py    From kobo-predict with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def _set_geom(self):
        xform = self.xform
        data_dictionary = xform.data_dictionary()
        geo_xpaths = data_dictionary.geopoint_xpaths()
        doc = self.get_dict()
        points = []

        if len(geo_xpaths):
            for xpath in geo_xpaths:
                geometry = [float(s) for s in doc.get(xpath, u'').split()]

                if len(geometry):
                    lat, lng = geometry[0:2]
                    points.append(Point(lng, lat))

            if not xform.instances_with_geopoints and len(points):
                xform.instances_with_geopoints = True
                xform.save()

            self.geom = GeometryCollection(points) 
Example #3
Source File: shpfile.py    From arches with GNU Affero General Public License v3.0 5 votes vote down vote up
def get_geometry_fieldnames(self, instance):
        """
        Finds GeometryCollection field in a flattened resource intance to use as the geometry of each shapefile record.
        """
        geometry_fields = []
        for k, v in instance.items():
            if isinstance(v, GeometryCollection):
                geometry_fields.append(k)
        return geometry_fields 
Example #4
Source File: geo_utils.py    From arches with GNU Affero General Public License v3.0 5 votes vote down vote up
def create_geom_collection_from_geojson(self, geojson):
        geoms = []
        for feature in geojson["features"]:
            geoms.append(GEOSGeometry(JSONSerializer().serialize(feature["geometry"])))
        return GeometryCollection(geoms) 
Example #5
Source File: datatypes.py    From arches with GNU Affero General Public License v3.0 5 votes vote down vote up
def transform_export_values(self, value, *args, **kwargs):
        wkt_geoms = []
        for feature in value["features"]:
            wkt_geoms.append(GEOSGeometry(json.dumps(feature["geometry"])))
        return GeometryCollection(wkt_geoms) 
Example #6
Source File: utils.py    From cornerwise with MIT License 5 votes vote down vote up
def geometry(feat):
    """Constructs a GEOSGeometryCollection from a GeoJSON dict.
    """
    return GeometryCollection(_geometry(feat), srid=4326) 
Example #7
Source File: adapter.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def __init__(self, geom):
        """
        Oracle requires that polygon rings are in proper orientation. This
        affects spatial operations and an invalid orientation may cause
        failures. Correct orientations are:
         * Outer ring - counter clockwise
         * Inner ring(s) - clockwise
        """
        if isinstance(geom, Polygon):
            self._fix_polygon(geom)
        elif isinstance(geom, GeometryCollection):
            self._fix_geometry_collection(geom)

        self.wkt = geom.wkt
        self.srid = geom.srid