Closed phpmaps closed 8 years ago
Hi @achapkowski i see you did a direct checkin today to this repo? Do you know who can help merge this ArcREST API update? Let me know. Cheers!
@achapkowski - yep I can do that.
@achapkowski - ok this is done. can you let me know if you merge? if you do merge, the gain is that people will see pagination as an option. in my own use case I am using pagination when the service supports it and fallback to this helper if it does not.
countResult = self.featureLayer.query(returnCountOnly=True) #Get the count
returnRecordCount = 1000 # fl.maxRecordCount might lead to memory issues, so divide by 1000 to make smaller lists
totalQueried = 0
feautureClasses = []
try:
if(self.featureLayer.advancedQueryCapabilities != None):
if(self.featureLayer.advancedQueryCapabilities['supportsPagination']):
supportsPagination = True
else:
supportsPagination = False
else:
supportsPagination = False
if(supportsPagination == True):
iterations = countResult['count'] / returnRecordCount + 1
print('Total # of features: %i' % countResult['count'])
for chunk in range(0,iterations):
offset = chunk * returnRecordCount
featureSet = self.featureLayer.query(where="1=1",out_fields=outfields,returnGeometry=True,returnFeatureClass=False, resultOffset=offset, resultRecordCount=returnRecordCount)
feautureClasses.append("{}{}".format("temp",chunk))
featureSet.save(temp_fgdb,"{}{}".format("temp",chunk))
totalQueried += len(featureSet.features)
print("{:.0%} Completed: {}/{}".format(totalQueried / float(countResult['count']), totalQueried, countResult['count']))
else:
qRes = self.featureLayer.query(where="1=1", returnIDsOnly=True)
oids = qRes['objectIds']
total = len(oids)
print('Total # of features: %i' % total)
chunkCounter = 0
for chunk in chunklist(l=oids, n=returnRecordCount):
oidsQuery = ",".join(map(str, chunk))
featureSet = self.featureLayer.query(objectIds=oidsQuery,returnGeometry=True,out_fields=outfields)
feautureClasses.append("{}{}".format("temp",chunkCounter))
featureSet.save(temp_fgdb,"{}{}".format("temp",chunkCounter))
totalQueried += len(featureSet.features)
print("{:.0%} Completed: {}/{}".format(totalQueried / float(total), totalQueried, total))
chunkCounter = chunkCounter + 1
except:
line, filename, synerror = trace()
raise ArcRestHelperError({
"function": "random_string_generator",
"line": line,
"filename": filename,
"synerror": synerror,
}
)
finally:
pass
@phpmaps - merged. Thank you
Including resultOffset and resultRecordCount in FeatureLayer query. The advancedQueryCapabilities will need to include supportPagination = true for pagination to work.