Ejemplo n.º 1
0
 def add_polygon(self, field, polygon):
     """Adds polygon filter to search query."""
     from haystack.utils.geo import ensure_polygon
     self.polygon = {
         'field': field,
         'polygon': ensure_polygon(polygon),
     }
Ejemplo n.º 2
0
 def add_polygon(self, field, polygon):
     """Adds polygon filter to search query."""
     from haystack.utils.geo import ensure_polygon
     self.polygon = {
         'field': field,
         'polygon': ensure_polygon(polygon),
     }
Ejemplo n.º 3
0
    def convert(self, value):
        from haystack.utils.geo import ensure_polygon, Polygon

        if value is None:
            return None

        if hasattr(value, 'geom_type'):
            value = ensure_polygon(value)
            return value

        if isinstance(value, six.string_types):
            coords = eval(value)
            if coords != list:
                return None
        elif isinstance(value, (list, tuple)):
            coords = value
        elif isinstance(value, dict):
            geom_type = value['type']
            coords = []
            if value['coordinates']:
                coords = value['coordinates'][0]
            else:
                return None
        value = Polygon(coords)
        return value
Ejemplo n.º 4
0
    def add_shape(self, field, shape, relation):
        """"Adds geo-shape filter to search query."""

        from haystack.utils.geo import ensure_polygon, ensure_relation
        coords = [[list(x) for x in y] for y in ensure_polygon(shape).coords]
        self.shape = {
            'field': field,
            'shape': coords,
            'relation': ensure_relation(relation),
        }
Ejemplo n.º 5
0
    def prepare(self, obj):
        from haystack.utils.geo import ensure_polygon

        # Value is the actual value of the Python model's attribute
        value = super(ShapeField, self).prepare(obj)

        if value is None:
            return None
        polygon = ensure_polygon(value.buffer(0))
        coords = [[list(x) for x in y] for y in polygon.coords]
        return {'type': 'polygon', 'coordinates': coords}