Skip to content

Instantly share code, notes, and snippets.

@higs4281
Last active August 29, 2015 14:04
Show Gist options
  • Save higs4281/db0042538f968ac07268 to your computer and use it in GitHub Desktop.
Save higs4281/db0042538f968ac07268 to your computer and use it in GitHub Desktop.
arrest geo query
from arrestee.models import Arrestee
from geopy.distance import distance as geo_distance
from geopy import Point
hildrugs = Arrestee.objects.filter(
booking_county__name='Hillsborough',
arrest_date__gte=datetime.datetime(2014, 2, 1),
arrest_date__lt=datetime.datetime(2014, 4, 1),
charge__code__category='Narcotics').distinct()#1,210 arrests
hits=[]# we'll use this list to collect arrests
# define the points -- i used google maps to get the lat/lon values
pt1 = Point(28.025304, -82.477551)
pt2 = Point(28.025304, -82.466307)
for arrestee in hildrugs:
if arrestee.arrestx:# check to see if our arrestee was geocoded; all of them were
arpoint = Point(arrestee.arresty, arrestee.arrestx)
if geo_distance(pt1, arpoint).miles <= 1 or geo_distance(pt2, arpoint).miles <= 1:
hits.append(arrestee)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment