understanding arcGIS python API function arguments

417
3
09-20-2018 09:16 AM
JosephMidura
New Contributor

I'm trying to intersect a point layer with a feature layer in the python API to give me a new point layer with attributes of both layers. I'm following the documentation: arcgis.geometry module — arcgis 1.5.0 documentation but I'm not the best with python and having trouble.

How do I write the arguments to the intersect function? There may be more than one mistake I'm making but for now I have the following:

# Connect
from arcgis.gis import GIS
from arcgis.geocoding import geocode
from arcgis.geometry import filters

gis = GIS("https://www.arcgis.com", "username", "password")

# Need this for geocoding later
map = gis.map("Houston, TX")
map


# get the point and polygon layers (geolocated point and census block)
ptFeatureLayer = gis.content.get('11ed3710e5a54d988d9e4f9d4068ca6f')
polygonFeatureLayer = gis.content.get('e711b54d031244ae9ec6a1ed9bbcb223')

# stuck at this part

# now do the intersection between a point layer and polygon layer:
newPointlayer = geometry.intersect('spatialReference': {'wkid': 4326}},
'geometries' I DONT KNOW WHAT GOES HERE
'geometry': {'geometryType': 'esriGeometryPoint',
gis=None
)

I appreciate any help.

0 Kudos
3 Replies
DanPatterson_Retired
MVP Esteemed Contributor

your point and polygon featurelayers in a list/tuple, I suspect and the output type perhaps "Point"

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

After you intersect these two layers, where do you want the output to live?  As a new layer in AGOL?  Or, are you going to further process it and store the results somewhere else?

Looking at the first place you are running into issues:

ptFeatureLayer = gis.content.get('11ed3710e5a54d988d9e4f9d4068ca6f')‍‍

This line does not return a Feature Layer object, it returns a GIS Item object.  Although the item refers to a feature service that likely has one or more feature layers, it isn't a feature service or feature layer itself.  To get access to one or more feature layers within a feature service, you will need to call the dynamic  Item.layers properties (arcgis.gis module — Item - arcgis 1.5.0 documentation )

Items that have layers (eg FeatureLayerCollection items and ImageryLayer items) and tables have the dynamic layers and tables properties to get to the individual layers/tables in this item.

The same applies to your line getting the polygon feature layer.

I can provide some more suggestions once you answer the question at the beginning of my response.

JosephMidura
New Contributor

Joshua thanks for the question. I want to use the output of the intersect operation in an external place (i.e. outputted to a csv). Here's a rough outline of what I want to accomplish:
1. I have a point (address) in one layer, and a shapefile (counties in a region) in a second layer on my AGOL account. The point is an address I'll geolocate. I only saved it as a layer because it made sense to me to intersect two layers together.

2. I want to intersect the point with the polygon (what county is the address in)

3. I want to put the results of the operation somewhere (csv or database). I don't need a resulting layer.

If that isn't clear let me know. Thank you.

0 Kudos