Select to view content in your preferred language

understanding arcGIS python API function arguments

09-20-2018 09:16 AM
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("", "username", "password")

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

# 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}},
'geometry': {'geometryType': 'esriGeometryPoint',

I appreciate any help.

0 Kudos
3 Replies
MVP Emeritus

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

0 Kudos
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.

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