Skip to content

Commit

Permalink
Minor improvements related to style
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Sep 7, 2014
1 parent c62bd0f commit b6ace56
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rest_framework_gis/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def from_native(self, value):

try:
return GEOSGeometry(value)
except (ValueError, GEOSException, OGRException, TypeError) as e:
except (ValueError, GEOSException, OGRException, TypeError):
raise ValidationError(_('Invalid format: string or unicode input unrecognized as WKT EWKT, and HEXEWKB.'))

return value
Expand Down
4 changes: 1 addition & 3 deletions rest_framework_gis/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def get_filter_point(self, request):
p = Point(x,y)
return p


def dist_to_deg(self, distance, latitude):
"""
distance = distance in meters
Expand Down Expand Up @@ -146,8 +145,7 @@ def dist_to_deg(self, distance, latitude):
earthRadius = 6378160.0
latitudeCorrection = 0.5 * (1 + cos(lat * pi / 180))
return (distance / (earthRadius * latitudeCorrection) * rad2deg)



def filter_queryset(self, request, queryset, view):
filter_field = getattr(view, 'distance_filter_field', None)
convert_distance_input = getattr(view, 'distance_filter_convert_meters', False)
Expand Down
9 changes: 5 additions & 4 deletions rest_framework_gis/tilenames.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/usr/bin/env python
#-------------------------------------------------------
# -------------------------------------------------------
# Translates between lat/long and the slippy-map tile
# numbering scheme
#
# http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames
#
# Written by Oliver White, 2007
# This file is public-domain
#-------------------------------------------------------
from math import pi, atan, sinh, degrees, pow
# -------------------------------------------------------
from math import pi, atan, sinh, degrees, pow as math_pow


def num_tiles(z):
return(pow(2,z))
return(math_pow(2,z))


def lat_edges(y,z):
Expand Down
16 changes: 7 additions & 9 deletions tests/django_restframework_gis_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,11 @@ def test_DistanceToPointFilter_filtering(self):

# Filter parameters
distance = 5000 #meters
point_inside_ggpark = [ -122.49034881591797, 37.76949349270407 ]
point_on_golden_gate_bridge = [ -122.47894, 37.8199 ]
point_on_alcatraz = [-122.4222, 37.82667 ]
point_on_treasure_island = [ -122.3692, 37.8244 ]
point_on_angel_island = [ -122.4326, 37.86091 ]
point_inside_ggpark = [-122.49034881591797, 37.76949349270407]
point_on_golden_gate_bridge = [-122.47894, 37.8199]
point_on_alcatraz = [-122.4222, 37.82667]
point_on_treasure_island = [-122.3692, 37.8244]
point_on_angel_island = [-122.4326, 37.86091]

url_params = '?dist=%0.4f&point=%0.4f,%0.4f&format=json' % (distance, point_on_alcatraz[0], point_on_alcatraz[1])

Expand Down Expand Up @@ -634,20 +634,18 @@ def test_DistanceToPointFilter_filtering(self):
ggpark.save()

# Make sure we only get back the ones within the distance
response = self.client.get(self.location_within_distance_of_point_list_url + url_params)
response = self.client.get('%s%s' % (self.location_within_distance_of_point_list_url, url_params))
self.assertEqual(len(response.data['features']), 1)
for result in response.data['features']:
self.assertEqual(result['properties']['name'] in (treasure_island.name), True)

# Make sure we get back all the ones within the distance
distance = 7000
url_params = '?dist=%0.4f&point=%0.4f,%0.4f&format=json' % (distance, point_on_alcatraz[0], point_on_alcatraz[1])
response = self.client.get(self.location_within_distance_of_point_list_url + url_params)
response = self.client.get('%s%s' % (self.location_within_distance_of_point_list_url, url_params))
self.assertEqual(len(response.data['features']), 2)
for result in response.data['features']:
self.assertEqual(result['properties']['name'] in (ggpark.name, treasure_island.name), True)



# Make sure we only get back the ones within the distance
degrees = .05
Expand Down
2 changes: 2 additions & 0 deletions tests/django_restframework_gis_tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class GeojsonLocationOverlapsTileList(GeojsonLocationContainedInTileList):

geojson_location_overlaps_tile_list = GeojsonLocationOverlapsTileList.as_view()


class GeojsonLocationWithinDistanceOfPointList(generics.ListAPIView):
model = Location
serializer_class = LocationGeoFeatureSerializer
Expand All @@ -74,6 +75,7 @@ class GeojsonLocationWithinDistanceOfPointList(generics.ListAPIView):

geojson_location_within_distance_of_point_list = GeojsonLocationWithinDistanceOfPointList.as_view()


class GeojsonLocationWithinDegreesOfPointList(GeojsonLocationWithinDistanceOfPointList):
distance_filter_convert_meters = False #Default setting

Expand Down

0 comments on commit b6ace56

Please sign in to comment.