spatial.to_featurelayer fails with 'maximum number of records allowed has been exceeded'

1220
4
06-16-2021 09:14 AM
PhilLarkin1
Occasional Contributor III

The Spatial DataFrame is unable to export to a Hosted Feature Layer at API version 1.8.5. It seems the to_featurelayer function should handle batching. The feature layer I am exporting from has 219k records. 

 

from arcgis.gis import GIS
import pandas as pd
gis = GIS(url, username, password)

premiseLayer = gis.content.get(fsItemId)
fLyr = premiseLayer.layers[0]
df = pd.DataFrame.spatial.from_layer(fLyr)

df[columnList].spatial.to_featurelayer('NewName',folder='folderName')

...

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\geo\_accessor.py, in to_featurelayer:
Line 2182:  return content.import_data(self._data, folder=folder, title=title, tags=tags)

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py, in import_data:
Line 5361:  res = self._portal.con.post(path, postdata)#, use_ordered_dict=True) - OrderedDict >36< PropertyMap

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in post:
Line 720:   force_bytes=kwargs.pop('force_bytes', False))

File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in _handle_response:
Line 502:   raise Exception(data['error'])

Exception: {'code': 400, 'message': 'The maximum number of records allowed (1000) has been exceeded.', 'requestId': '', 'traceId': 'f7ed4d8d8f6b6647b195319ca2c420a8'}

 

Tags (1)
0 Kudos
4 Replies
StuartMoore
Occasional Contributor III

@PhilLarkin1 did you ever get this to work? i am having the same issue

0 Kudos
PhilLarkin1
Occasional Contributor III

The details are a little foggy, but I was able to use this. The trick might have been generating the dataframe from the GeoAssessor class vs creating a dataframe from the pandas library. Here is what I have now:

from arcgis.features import FeatureLayer
from arcgis.features import GeoAccessor

serviceUrl = "https://services<x>.arcgis.com/<orgId>/arcgis/rest/services/<ServiceName>/FeatureServer/0"
FL = FeatureLayer(serviceUrl)
DF = GeoAccessor.from_layer(FL)
globalIDLookupTempSDEF = DF.spatial.to_featurelayer(title='GlobalIDLookupTemp',tags='<tag>',folder='<folder>')

 

PhilLarkin1
Occasional Contributor III

By the way, what is fantastic about the dataframe created from GeoAssessor is that the GlobalID of the source feature layer is retained.

0 Kudos
StuartMoore
Occasional Contributor III

thanks @PhilLarkin1 i'll give it a go

0 Kudos