Queried feature layers as analysis input?

94
0
12-09-2019 08:42 AM
ZacharyHart
Regular Contributor

In this particular case I'm trying to use the arcgis.features.analysis module's join_features function using two feature layers I've applied queries to.

I'm using Jupyter Labs to work on this and I've not included the outputs/responses which the code does return successfully and the queried layers appear as expected in the ipython display.

from arcgis.gis import GIS
from arcgis.features import FeatureLayer #Not needed here
from IPython.display import display #Not needed here
from arcgis import features
gis = GIS("https://amazingportal.com/portal", "me", "m3LoG!!N")
print("Logged in as: " + gis.properties.user.username)

#Access feature layers
cruiseFeatureLayer = gis.content.search('title: NortheastCruisePoints', 'Feature Layer')
cruisePoints = cruiseFeatureLayer[0].layers[0]
print("Item ID:{0}".format(cruiseFeatureLayer[0].id))
print("Input Layer:{0}".format(cruisePoints.properties.name))
cruisePoints

clientsFeatureLayer = gis.content.search('title: NortheastClientsCollector', item_type='Feature Layer')
clients = clientsFeatureLayer[0].layers[2]
print("Item ID:{0}".format(clientsFeatureLayer[0].id))
print("Input Layer:{0}".format(clients.properties.name))
clients

#Query based on ClientID
clientQuery = clients.query(where="LVI_CODE ='7282'")
cruiseQuery = cruisePoints.query(where="LVI_CODE ='7282'")
print("{0} stands selected".format(len(clientQuery.features)))
print("{0} cruise points selected".format(len(cruiseQuery.features)))

#Review queried feature layers in ipython display [need to modify so queried layers are zoomed-to]
queryMap = gis.map()
queryMap.extent = clientsFeatureLayer[0].extent
queryMap.add_layer(clientQuery)
queryMap.add_layer(cruiseQuery)
queryMap

features.analysis.join_features(target_layer=clientQuery,join_layer=cruiseQuery, spatial_relationship='intersects')

Here is the error I get:

Exception: Invalid format of input layer. url string, feature service Item, feature service instance or dict supported

So does the analysis module only work for feature layers, not feature sets? Is there a way to supply a queried/filtered input to the analysis w/o having to create an entirely new item in your portal?

0 Kudos
0 Replies