Iterate all Survey123s in a portal to get FeatureLayer for each

235
1
Jump to solution
2 weeks ago
Dirk_Vandervoort
New Contributor III

Here's the code:

 

 

 

 

from arcgis.gis import GIS
from arcgis.apps.survey123 import SurveyManager
from arcgis.features import FeatureLayer
gis = GIS() 
survey_manager = SurveyManager(gis)
my_S123s = gis.content.search(query="type: Form", max_items=1000) # "Form" guarantees a Survey123

for s123 in my_S123s:
    the_survey = survey_manager.get(s123.itemid)
    aFLay = FeatureLayer(the_survey.parent_fl_url, gis)
    # do something with aFLay
    the_survey = None

 

 

 

 

As you can see, I am looping through all Survey123 Form items in my GIS, creating a Survey123, then creating a FeatureLayer using the parent_fl_id of the Survey123.

Performance is terrible. I expect to be able whip through them. I'm looking for a more efficient way to get from Survey123 to FeatureLayer.

How can I get the Feature Layer from the Survey123 Form without so much pain and suffering.

As always, TIA.

1 Solution

Accepted Solutions
Clubdebambos
Occasional Contributor III

Hi @Dirk_Vandervoort 

I have not got a lot of Forms to test this but here is an option using the related_items() method for an item object.

from arcgis.gis import GIS

## access agol
gis = GIS("home")

## get all forms
my_S123s = gis.content.search(query="type: Form", max_items=1000)

## iterate through all forms
for s123 in my_S123s:
    ## get form as an item object
    sform = gis.content.get(s123.id)
    ## assumes one feature layer per feature service
    ## you could iterate over feature layers instead to access all
    ## https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.related_items
    ## https://developers.arcgis.com/rest/users-groups-and-items/relationship-types.htm
    ## related_items returns a list
    aFLay = sform.related_items("Survey2Service")[0].layers[0]
    print(aFLay.properties)

Cheers

~ learn.finaldraftmapping.com

View solution in original post

0 Kudos
1 Reply
Clubdebambos
Occasional Contributor III

Hi @Dirk_Vandervoort 

I have not got a lot of Forms to test this but here is an option using the related_items() method for an item object.

from arcgis.gis import GIS

## access agol
gis = GIS("home")

## get all forms
my_S123s = gis.content.search(query="type: Form", max_items=1000)

## iterate through all forms
for s123 in my_S123s:
    ## get form as an item object
    sform = gis.content.get(s123.id)
    ## assumes one feature layer per feature service
    ## you could iterate over feature layers instead to access all
    ## https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.related_items
    ## https://developers.arcgis.com/rest/users-groups-and-items/relationship-types.htm
    ## related_items returns a list
    aFLay = sform.related_items("Survey2Service")[0].layers[0]
    print(aFLay.properties)

Cheers

~ learn.finaldraftmapping.com
0 Kudos