I'm using python's requests and arcgis libraries for to query an open data endpoint for my county GIS data. I'm trying to query the recent sales data within a 2 mile radius of an address. I've worked out the sql "where" logic to get the "recent" results but can't seem to find a way to do the radius filter. Here is what I've tried:
from arcgis.gis import GIS
from arcgis.geocoding import geocode, reverse_geocode
from arcgis.geometry import Point
from arcgis.features import *
gis=GIS()
address = "2526 westmoreland dr raleigh nc"
wake_url = 'https://maps.wakegov.com/arcgis/rest/services/Property/Parcels/MapServer/0/'
address_geo = geocode(address = address, out_sr=102100)[0]
address_geo
{'address': 'Westmoreland Dr, Raleigh, North Carolina, 27612', 'location': {'x': -8758500.574766971, 'y': 4276897.574964388}, 'score': 94.81, 'attributes': {'Loc_name': 'World', 'Status': 'M', ......
This gets me a geocoded address. Next, I try to query the feature layer:
requests_layer = FeatureLayer(wake_url)
Setup my SQL statemetn for my where clause:
from_date = dt.datetime.strptime('1/1/2016', '%m/%d/%Y')
sql = "SALE_DATE >= DATE '{}'".format(from_date.strftime('%Y-%m-%d'))
sql
"SALE_DATE >= DATE '2016-01-01'"
Then perform my queries:
#how many total records are there?
requests_layer.query(return_count_only=True)
393540
Now, how many parcels have sold in last 4 years:
requests_layer.query(where=sql, return_count_only=True)
95117
All good so far as I now have filtered this down to just the parcels that sold recently across the whole county. But I then get lost when I try to further reduce this to just the parcels within a radius of an address... I have tried buffers, geometry_filter, etc. Can't seem to find the right combo. Example:
requests_layer.query(where=sql, return_count_only=True, geometry_filter=address_geo, distance=1, units='miles')
95117
This is a small subset of the county and the count should be much less. What am I missing?
I've also played around with the endpoint REST API. I"m not sure I understand what the geometry_filter is doing for me.