0

I am really running into some problems with the Python API, I am trying to query a feature layer and return all results that fall within a certain distance of a supplied point.

According to the docs here: http://esri.github.io/arcgis-python-api/apidoc/html/arcgis.features.toc.html#feature what I am doing should work but instead it is just returning 1,000 results each time. I know that it should only be returning 1.

pt =  Geometry({"x" : -96.95335386999966, "y" : 32.87209363900047, "spatialReference" : {"wkid" : 4326}})

print (pt.is_valid) # True
print (pt.type) # POINT
print (pt) # True

results = policies.query(geometry_filter=pt, distance=10, units="esriSRUnit_Foot")

print(len(results)) # 1000

If someone could point me in the right direction to get that to work that would be amazing.


The query works with the REST API so I know it is not a problem with the layer or anything like that. It's just something with the Python API

1 Answer 1

1

I was able to hack around the problem by wrapping the REST API in python. This is not the ideal solution but it will have to work for now.

def do_buffer_query(url,token,x,y):
    url = "https://www.arcgis.com/sharing/generateToken"
    payload  = {"username" : "username",  "password" :"password",  "referer" : "www.arcgis.com",  "f" : "json" }  

    r = requests.post(url, data=payload)
    j = r.json()
    token = j['token']


    url = url + "/0/query" #url of the feature layer
    id_pin_location = "%s , %s" % (x,y)

    payload = {
        "where": '',
        "geometry" : id_pin_location,
        "geometryType" : "esriGeometryPoint",
        "spatialRel" : "esriSpatialRelIntersects",
        "distance" : "10",
        "units" : "esriSRUnit_StatuteMile",
        "outFields" : "*",
        "returnGeometry" : "true",
        "f" : "json",
        "token": token
    }

    r = requests.post(url, data=payload)
    j = r.json()

    return j

Your Answer

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

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