Last active
August 29, 2015 14:04
-
-
Save higs4281/db0042538f968ac07268 to your computer and use it in GitHub Desktop.
arrest geo query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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