3

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:

enter image description here

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?

asked May 21, 2019 at 20:52
2
  • 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. Commented May 22, 2019 at 15:58
  • That's the work-around if I can't resolve this. Commented May 23, 2019 at 14:16

1 Answer 1

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)

answered Jul 7, 2021 at 10:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.