I am trying to obtain a specific table from a Map Service item, however the table list is empty. The layers list correctly reports back 5 layers.
My code snippet below:
search_result = gis.content.search(mapServiceName,'Map Service')
if len(search_result) == 0:
print ('Map Service: "%s" not found.' % mapServiceName)
return
#take the first return from the list (should only be 1)
item = search_result[0]
if not item is None:
print ('Found map service layer: %s (id=%s)' % (item.title, item.id))
print ('There are %s tables in item : %s' % (len(item.tables), item.title))
print ('There are %s layers in item : %s' % (len(item.layers), item.title))
Found map service layer: xxx (id=2358b6294549491da95820a679304bc0)
There are 0 tables in item : xxx
There are 5 layers in item : xxx
The Map Service itself has 2 tables and 5 layers:
I can access those 5 layers with no problem, but the "ArcGIS API for Python" doesn't list the tables. How to populate that table list?
-
Is using the ArcGIS REST API an option? I haven't populated tables but I assume it works the same way as populating a FeatureLayer, which can be done using both the Python API and the REST API.Marcelo Villa– Marcelo Villa2019年05月22日 15:58:22 +00:00Commented May 22, 2019 at 15:58
-
That's the work-around if I can't resolve this.JC5577– JC55772019年05月23日 14:16:57 +00:00Commented May 23, 2019 at 14:16
1 Answer 1
Just came across the same issue. My workaround was to use a FeatureLayerCollection object like in the code below:
from arcgis.features import FeatureLayerCollection
search_result = gis.content.search(mapServiceName,'Map Service')
if len(search_result) == 0:
print ('Map Service: "%s" not found.' % mapServiceName)
return
#take the first return from the list (should only be 1)
item = search_result[0]
if not item is None:
f_l_coll = FeatureLayerCollection.fromitem(item)
print(f_l_coll.layers) # this prints the layers
print(f_l_coll.tables) # this prints the tables
The caveat of this approach is that it makes a request to the source service in order to instantiate the FeatureLayerCollection object. This means that the service must be live and callable. Apparently, the Item.layers and Item.tables is returning data stored in the Item's properties (no request is made against the source service - Item.url).
The above code can be used with Feature Service item type. For Map Service item type use MapImageLayer (from arcgis.mapping import MapImageLayer)