Bolton-and-Menk-GIS / restapi

Python API designed to work externally with ArcGIS REST Services to query and extract data, and view service properties. Uses arcpy for some functions if available, otherwise uses open source alternatives to interact with the ArcGIS REST API. Also includes a subpackage for administering ArcGIS Server Sites.
GNU General Public License v2.0
93 stars 31 forks source link

How to get more than 1000 features? #12

Closed boesiii closed 6 years ago

boesiii commented 6 years ago

My ArcGIS online feature layer is only returning the first 1000. How can a fetch the next 1000?

boesiii commented 6 years ago

I know that I can set the number of features returned to more than 1000 but wanted to see if another python way is possible.

CalebM1987 commented 6 years ago

When you do a query on the feature layer you need to set the ‘exceed_limit’ parameter to True to fetch all of the features. You can also use the iter_queries() method.

features = lyr.query(exceed_limit=True)

boesiii commented 6 years ago

What if I am not using the query method?

lyr = restapi.FeatureLayer(url,'user', 'pass')

for row in lyr.cursor().rows():
    atts.update({row[0]: folder + str(row[26])})

for oid, att in atts.iteritems():
    lyr.addAttachment(oid, att)
CalebM1987 commented 6 years ago

Ah, ok. Well, the cursor does use the query() method under the hood, so when you define the cursor, just set that same parameter.

lyr = restapi.FeatureLayer(url,'user', 'pass')

for row in lyr.cursor(exceed_limit=True).rows():
    atts.update({row[0]: folder + str(row[26])})

for oid, att in atts.iteritems():
    lyr.addAttachment(oid, att)

Also, I have been terrible about updating the documentation for this package, but I do have a FeatureLayer.updateCursor() as well that works very similar to the arcpy.da.UpdateCursor() and supports attachments as well.

CalebM1987 commented 6 years ago

closing due to lack of feedback from OP.