Пример #1
0
 def add_within(self, field, point_1, point_2):
     """Adds bounding box parameters to search query."""
     self.within = {
         'field': field,
         'point_1': ensure_point(point_1),
         'point_2': ensure_point(point_2),
     }
Пример #2
0
 def add_within(self, field, point_1, point_2):
     """Adds bounding box parameters to search query."""
     from haystack.utils.geo import ensure_point
     self.within = {
         'field': field,
         'point_1': ensure_point(point_1),
         'point_2': ensure_point(point_2),
     }
Пример #3
0
 def test_ensure_point(self):
     self.assertRaises(
         SpatialError, ensure_point, [38.97127105172941, -95.23592948913574]
     )
     self.assertRaises(
         SpatialError,
         ensure_point,
         GEOSGeometry("POLYGON((-95 38, -96 40, -97 42, -95 38))"),
     )
     ensure_point(Point(-95.23592948913574, 38.97127105172941))
    def test_ensure_point(self):
        from django.contrib.gis.geos import GEOSGeometry, Point

        self.assertRaises(
            SpatialError, ensure_point, [38.97127105172941, -95.23592948913574]
        )
        self.assertRaises(
            SpatialError,
            ensure_point,
            GEOSGeometry("POLYGON((-95 38, -96 40, -97 42, -95 38))"),
        )
        ensure_point(Point(-95.23592948913574, 38.97127105172941))
Пример #5
0
 def add_dwithin(self, field, point, distance):
     """Adds radius-based parameters to search query."""
     self.dwithin = {
         'field': field,
         'point': ensure_point(point),
         'distance': ensure_distance(distance),
     }
Пример #6
0
 def add_dwithin(self, field, point, distance):
     """Adds radius-based parameters to search query."""
     from haystack.utils.geo import ensure_point, ensure_distance
     self.dwithin = {
         'field': field,
         'point': ensure_point(point),
         'distance': ensure_distance(distance),
     }
Пример #7
0
    def add_distance(self, field, point):
        """
        Denotes that results should include distance measurements from the
        point passed in.
        """
        from haystack.utils.geo import ensure_point

        self.distance_point = {"field": field, "point": ensure_point(point)}
Пример #8
0
 def add_distance(self, field, point):
     """
     Denotes that results should include distance measurements from the
     point passed in.
     """
     self.distance_point = {
         'field': field,
         'point': ensure_point(point),
     }
Пример #9
0
    def prepare(self, obj):
        value = super(LocationField, self).prepare(obj)

        if value is None:
            return None

        pnt = ensure_point(value)
        pnt_lng, pnt_lat = pnt.get_coords()
        return "%s,%s" % (pnt_lat, pnt_lng)
Пример #10
0
    def prepare(self, obj):
        from haystack.utils.geo import ensure_point

        value = super(LocationField, self).prepare(obj)

        if value is None:
            return None

        pnt = ensure_point(value)
        pnt_lng, pnt_lat = pnt.coords
        return "%s,%s" % (pnt_lat, pnt_lng)
Пример #11
0
    def prepare(self, obj):

        value = super(LocationField, self).prepare(obj)
        if value is None:
            return None

        point, distance = value
        pnt = ensure_point(point)
        pnt_lng, pnt_lat = pnt.get_coords()
        value = {
            "type" : "circle",
            "coordinates" : [pnt_lng, pnt_lat],
            "radius" : distance
        }
        return value
Пример #12
0
    def convert(self, value):
        if value is None:
            return None

        if hasattr(value, "geom_type"):
            value = ensure_point(value)
            return value

        if isinstance(value, basestring):
            lat, lng = value.split(",")
        elif isinstance(value, (list, tuple)):
            # GeoJSON-alike
            lat, lng = value[1], value[0]
        elif ininstance(value, dict):
            lat = value.get("lat", 0)
            lng = value.get("lon", 0)

        value = Point(float(lng), float(lat))
        return value
Пример #13
0
    def convert(self, value):
        from haystack.utils.geo import ensure_point, Point

        if value is None:
            return None

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

        if isinstance(value, six.string_types):
            lat, lng = value.split(',')
        elif isinstance(value, (list, tuple)):
            # GeoJSON-alike
            lat, lng = value[1], value[0]
        elif isinstance(value, dict):
            lat = value.get('lat', 0)
            lng = value.get('lon', 0)

        value = Point(float(lng), float(lat))
        return value
Пример #14
0
    def convert(self, value):
        from haystack.utils.geo import ensure_point, Point

        if value is None:
            return None

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

        if isinstance(value, six.string_types):
            lat, lng = value.split(',')
        elif isinstance(value, (list, tuple)):
            # GeoJSON-alike
            lat, lng = value[1], value[0]
        elif isinstance(value, dict):
            lat = value.get('lat', 0)
            lng = value.get('lon', 0)

        value = Point(float(lng), float(lat))
        return value
Пример #15
0
    def convert(self, value):
        from haystack.utils.geo import ensure_point

        if value is None:
            return None

        if hasattr(value, "geom_type"):
            value = ensure_point(value)
            return value

        if isinstance(value, six.string_types):
            lat, lng = value.split(",")
        elif isinstance(value, (list, tuple)):
            # GeoJSON-alike
            lat, lng = value[1], value[0]
        elif isinstance(value, dict):
            lat = value.get("lat", 0)
            lng = value.get("lon", 0)
        else:
            raise TypeError("Unable to extract coordinates from %r" % value)

        value = Point(float(lng), float(lat))
        return value
Пример #16
0
    def convert(self, value):
        from haystack.utils.geo import ensure_point, Point

        if value is None:
            return None

        if hasattr(value, "geom_type"):
            value = ensure_point(value)
            return value

        if isinstance(value, six.string_types):
            lat, lng = value.split(",")
        elif isinstance(value, (list, tuple)):
            # GeoJSON-alike
            lat, lng = value[1], value[0]
        elif isinstance(value, dict):
            lat = value.get("lat", 0)
            lng = value.get("lon", 0)
        else:
            raise TypeError("Unable to extract coordinates from %r" % value)

        value = Point(float(lng), float(lat))
        return value
 def test_ensure_point(self):
     self.assertRaises(SpatialError, ensure_point, [38.97127105172941, -95.23592948913574])
     self.assertRaises(SpatialError, ensure_point, GEOSGeometry('POLYGON((-95 38, -96 40, -97 42, -95 38))'))
     ensure_point(Point(-95.23592948913574, 38.97127105172941))
Пример #18
0
    def add_dwithin(self, field, point, distance):
        """Adds radius-based parameters to search query."""
        from haystack.utils.geo import ensure_point, ensure_distance

        self.dwithin = {"field": field, "point": ensure_point(point), "distance": ensure_distance(distance)}
Пример #19
0
    def add_within(self, field, point_1, point_2):
        """Adds bounding box parameters to search query."""
        from haystack.utils.geo import ensure_point

        self.within = {"field": field, "point_1": ensure_point(point_1), "point_2": ensure_point(point_2)}