Skip to content

Commit

Permalink
Merge 5a9577c into 4a3ee4d
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscouzo committed Aug 19, 2020
2 parents 4a3ee4d + 5a9577c commit 2146d78
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 241 deletions.
9 changes: 4 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ a certain bounding box.
queryset = models.Location.objects.all()
serializer_class = serializers.LocationSerializer
bbox_filter_field = 'point'
filter_backends = (InBBoxFilter, )
filter_backends = (InBBoxFilter,)
bbox_filter_include_overlapping = True # Optional
We can then filter in the URL, using Bounding Box format (min Lon, min
Expand Down Expand Up @@ -540,7 +540,7 @@ by a `TMS tile <http://wiki.openstreetmap.org/wiki/TMS>`__ address.
queryset = models.Location.objects.all()
serializer_class = serializers.LocationSerializer
bbox_filter_field = 'point'
filter_backends = (TMSTileFilter, )
filter_backends = (TMSTileFilter,)
bbox_filter_include_overlapping = True # Optional
We can then filter in the URL, using TMS tile addresses in the zoom/x/y format,
Expand Down Expand Up @@ -571,8 +571,7 @@ a certain distance of a given point.
queryset = models.Location.objects.all()
serializer_class = serializers.LocationSerializer
distance_filter_field = 'geometry'
filter_backends = (DistanceToPointFilter, )
bbox_filter_include_overlapping = True # Optional
filter_backends = (DistanceToPointFilter,)
We can then filter in the URL, using a distance and a point in (lon, lat) format. The
distance can be given in meters or in degrees.
Expand Down Expand Up @@ -605,7 +604,7 @@ Orders a queryset by distance to a given point, from the nearest to the most dis
queryset = models.Location.objects.all()
serializer_class = serializers.LocationSerializer
distance_ordering_filter_field = 'geometry'
filter_backends = (DistanceToPointOrderingFilter, )
filter_backends = (DistanceToPointOrderingFilter,)
We can then order the results by passing a point in (lon, lat) format in the URL.

Expand Down
2 changes: 1 addition & 1 deletion tests/django_restframework_gis_tests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class LocationAdmin(GeoModelAdmin):
list_display = ('name', 'geometry')


admin.site.register(Location, LocationAdmin)
admin.site.register(Location, LocationAdmin)
33 changes: 22 additions & 11 deletions tests/django_restframework_gis_tests/test_bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ def setUp(self):
self.geojson_location_bbox_list_url = reverse('api_geojson_location_bbox_list')

def _create_locations(self):
self.bl1 = BoxedLocation.objects.create(id=1, name='l1', slug='l1', geometry='POINT (13.007 42.423)',
bbox_geometry='POLYGON((12.997 42.413,12.997 42.433,13.017 42.433,13.017 42.413,12.997 42.413))')
self.bl2 = BoxedLocation.objects.create(id=2, name='l2', slug='l2', geometry='POINT (12.007 43.423)',
bbox_geometry='POLYGON((11.997 43.413,11.997 43.433,12.017 43.433,12.017 43.413,11.997 43.413))')
self.l1 = Location.objects.create(id=1, name='l1', slug='l1',
geometry='POLYGON((12.997 42.413,12.997 42.433,13.017 42.433,13.017 42.413,12.997 42.413))')
self.bl1 = BoxedLocation.objects.create(
id=1, name='l1', slug='l1', geometry='POINT (13.007 42.423)',
bbox_geometry='POLYGON((12.997 42.413,12.997 42.433,13.017 42.433,13.017 42.413,12.997 42.413))'
)
self.bl2 = BoxedLocation.objects.create(
id=2, name='l2', slug='l2', geometry='POINT (12.007 43.423)',
bbox_geometry='POLYGON((11.997 43.413,11.997 43.433,12.017 43.433,12.017 43.413,11.997 43.413))'
)
self.l1 = Location.objects.create(
id=1, name='l1', slug='l1',
geometry='POLYGON((12.997 42.413,12.997 42.433,13.017 42.433,13.017 42.413,12.997 42.413))'
)

def test_list(self):
self._create_locations()
Expand All @@ -37,9 +43,9 @@ def test_list(self):
for feature in response.data['features']:
self.assertIn('bbox', feature)
fid = feature['id']
if fid==1:
if fid == 1:
self.assertEqual(feature['bbox'], self.bl1.bbox_geometry.extent)
elif fid==2:
elif fid == 2:
self.assertEqual(feature['bbox'], self.bl2.bbox_geometry.extent)
else:
self.fail("Unexpected id: {0}".format(fid))
Expand All @@ -60,10 +66,13 @@ def test_post_location_list_geojson(self):
},
"bbox": [11.0, 40.0, 13.0, 42.0]
}
response = self.client.post(self.geojson_boxedlocation_list_url, data=json.dumps(data), content_type='application/json')
response = self.client.post(
self.geojson_boxedlocation_list_url, data=json.dumps(data),
content_type='application/json'
)
self.assertEqual(response.status_code, 201)
self.assertEqual(BoxedLocation.objects.count(), 1)
self.assertEqual(BoxedLocation.objects.all()[0].bbox_geometry.extent, (11.0,40.0,13.0,42.0))
self.assertEqual(BoxedLocation.objects.all()[0].bbox_geometry.extent, (11.0, 40.0, 13.0, 42.0))

def test_get_autogenerated_location_bbox_geojson(self):
self._create_locations()
Expand All @@ -74,11 +83,13 @@ def test_get_autogenerated_location_bbox_geojson(self):

def test_bbox_improperly_configured(self):
self._create_locations()

class LocationGeoFeatureSerializer(gis_serializers.GeoFeatureModelSerializer):
class Meta:
model = Location
geo_field = 'geometry'
bbox_geo_field = 'geometry'
bbox_geo_field = 'geometry'
auto_bbox = True

with self.assertRaises(ImproperlyConfigured):
LocationGeoFeatureSerializer(instance=self.l1)
Loading

0 comments on commit 2146d78

Please sign in to comment.