1

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.

1
  • I was able to keep iterating through the rest endpoint to get this query string to work. query endpoint . Now need to code this up in python
    – leeprevost
    Commented Dec 16, 2019 at 18:29

1 Answer 1

0

I was able to get this to work as follows:

1) Iterate through the GIS rest endpoint here: GIS endpoint

2) Was able to get this query string to work: working query string

After that, I developed an arguments dictionary which builds out query string:

radius = 1 #in miles
center = address_geo['location']   #lat/long of address of center of radius
spatial_radius_filter = dict(inSR=4326, 
                             outSR=4326,
                             return_geometry=False, 
                             geometryType="esriGeometryPoint", 
                             spatialRel="esriSpatialRelContains", 
                             geometry=center, 
                             supportsQueryWithDistance=True, 
                             distance=radius, 
                             units='esriSRUnit_StatuteMile')

And this returns the featureset:

features = requests_layer.query(where=sql, **spatial_radius_filter)
features.df

(Dataframe with results)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.