Пример #1
0
 def _get_shape(self, value):
     points = json.loads(value)
     # close ring and create Polygon
     polygon = Polygon(points+[points[0]])
     polygon.srid = SRID_WSG84
     polygon.transform(SRID_RD)
     return polygon
Пример #2
0
    def get_queryset(self):
        """
        Inspired by Glen Roberton's django-geojson-tiles view
        """
        self.z, self.x, self.y = self._parse_args()
        nw = self.tile_coord(self.x, self.y, self.z)
        se = self.tile_coord(self.x + 1, self.y + 1, self.z)
        bbox = Polygon((nw, (se[0], nw[1]), se, (nw[0], se[1]), nw))
        bbox.srid = self.srid
        qs = super(TiledGeoJSONLayerView, self).get_queryset()
        qs = qs.filter(**{'%s__intersects' % self.geometry_field: bbox})
        self.bbox = bbox.extent

        # Simplification dict by zoom level
        simplifications = self.simplifications or {}
        z = self.z
        self.simplify = simplifications.get(z)
        while self.simplify is None and z < 32:
            z += 1
            self.simplify = simplifications.get(z)

        # Won't trim point geometries to a boundary
        model_field = qs.model._meta.get_field(self.geometry_field)
        self.trim_to_boundary = (self.trim_to_boundary
                                 and not isinstance(model_field, PointField)
                                 and Intersection is not None)
        if self.trim_to_boundary:
            if django.VERSION < (1, 9):
                qs = qs.intersection(bbox)
            else:
                qs = qs.annotate(
                    intersection=Intersection(self.geometry_field, bbox))
            self.geometry_field = 'intersection'

        return qs
Пример #3
0
def dict2poly(arr):
    if arr:
        if arr[-1] != arr[0]:
            arr.append(arr[0])
        poly = Polygon(arr)
        poly.srid = 4326
        return poly
    else:
        return None