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), }
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), }
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))
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), }
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), }
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)}
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), }
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)
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)
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
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
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
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
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))
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)}
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)}