Select to view content in your preferred language

How do I generate a polygon SHAPE attribute for a feature layer?

1296
5
Jump to solution
11-16-2018 09:51 AM
HomadsTeam
Emerging Contributor

Is there a way to retrieve or generate the polygon geometries for a feature layer? I can't seem to get the SHAPE attribute that would normally store the geometry type and the polygon geometries, like the example shown here: Geoenrichment: Accepted Forms of Study Areas.

Here's the example from the link above:

arcgis.geometry.Geometry({"rings":[[[-117.185412,34.063170],[-122.81,37.81],[-117.200570,34.057196],[-117.185412,34.063170]]],"spatialReference":{"wkid":4326}})

How can I get that for each of my polygon features to be stored in the SHAPE attribute column? In particular, I am using the ArcGIS online platform and the ArcGIS Python API. Can it be done with either?

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Looking at arcgis.geoenrichment module — arcgis 1.5.1 documentation :

analysis_variablesOptional list. A Data Collection is a preassembled list of attributes that will be used to enrich the input features. With the analysis_variables parameter you can return a subset of variables enrichment attributes can describe various types of information such as demographic characteristics and geographic context of the locations or areas submitted as input features in study_areas.

and your function call:

import arcgis.geometry
enrich(study_areas=Geometry(query.df.loc[0]['SHAPE']), analysis_variables='5yearincrements.MEDAGE_CY')

and your error message:

       raise ValueError("Don't know how to handle study areas of type " + str(type(area)))

ValueError: Lists members must be NamedArea instances

You are passing a string to the analysis_variables parameter, which is expecting a list.  I haven't worked with this module at all, so I am guessing here, but try:

import arcgis.geometry
enrich(study_areas=Geometry(query.df.loc[0]['SHAPE']), analysis_variables=['5yearincrements.MEDAGE_CY'])

View solution in original post

5 Replies
JakeSkinner
Esri Esteemed Contributor

Hey Homads,

Can you provide more context on what you are trying to accomplish?  For example, are you trying to update a feature class from a feature service?

HomadsTeam
Emerging Contributor

Actually, I think it was a difference between looking at table view on the the web viewer and querying via the features module. I can see the SHAPE attribute now when I run a query like the one below:

from arcgis.features import FeatureLayer
query = neighborhoods_layers[0].query()
query.df

What I'm trying to do is geoenrich, just one or a list that contains a subset of polygons from a feature layer. I'm trying to use indexing to get the SHAPE attribute as an input for geoenrichment.enrich(), such as query.df.loc[0]['SHAPE']. I've also tried to run that inside of geometry.Geometry, similar to how the polygon is specified here: GeoEnrichment | ArcGIS for Developers .

Here's the error that I get for the following command:

import arcgis.geometry
enrich(study_areas=Geometry(query.df.loc[0]['SHAPE']), analysis_variables='5yearincrements.MEDAGE_CY')
---------------------------------------------------------------------------ValueError                                Traceback (most recent call last)<ipython-input-29-b2a55c5b1043> in <module>      1 import arcgis.geometry----> 2 enrich(study_areas=Geometry(query.df.loc[0]['SHAPE']), analysis_variables='5yearincrements.MEDAGE_CY')~\Anaconda3\envs\arcgis\lib\site-packages\arcgis\geoenrichment\enrichment.py in enrich(study_areas, data_collections, analysis_variables, comparison_levels, add_derivative_variables, intersecting_geographies, return_geometry, gis)    732                     area_dict = {"sourceCountry": first_area['sourceCountry'], "layer": first_area['layer'], "ids":[ids.join(",")]}    733                 else:--> 734                     raise ValueError('Lists members must be NamedArea instances')    735             else:    736                 raise ValueError("Don't know how to handle study areas of type " + str(type(area)))ValueError: Lists members must be NamedArea instances

When I index, the SHAPE attribute is showing type: arcgis.geometry._types.Polygon, which is the same whether I use Geometry() or not.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Sharing with ArcGIS API for Python

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Looking at arcgis.geoenrichment module — arcgis 1.5.1 documentation :

analysis_variablesOptional list. A Data Collection is a preassembled list of attributes that will be used to enrich the input features. With the analysis_variables parameter you can return a subset of variables enrichment attributes can describe various types of information such as demographic characteristics and geographic context of the locations or areas submitted as input features in study_areas.

and your function call:

import arcgis.geometry
enrich(study_areas=Geometry(query.df.loc[0]['SHAPE']), analysis_variables='5yearincrements.MEDAGE_CY')

and your error message:

       raise ValueError("Don't know how to handle study areas of type " + str(type(area)))

ValueError: Lists members must be NamedArea instances

You are passing a string to the analysis_variables parameter, which is expecting a list.  I haven't worked with this module at all, so I am guessing here, but try:

import arcgis.geometry
enrich(study_areas=Geometry(query.df.loc[0]['SHAPE']), analysis_variables=['5yearincrements.MEDAGE_CY'])
HomadsTeam
Emerging Contributor

Hi Joshua,

Thank you so much for your help and quick replies! I tested it out, and you are right about the function expecting a list; however, it was actually for the "study_areas" parameter, instead of the "analysis_variables". analysis_variables was ok with the string, but needs a list for multiple variables. Both of the following worked for me:

enrich(study_areas=[query.df.loc[0]['SHAPE']], analysis_variables='5yearincrements.MEDAGE_CY')

OR

import arcgis.geometry

enrich(study_areas=[Geometry(query.df.loc[0]['SHAPE'])], analysis_variables='5yearincrements.MEDAGE_CY')

I thought I had tried study_areas as a list before, but apparently not! enrich() is working as expected now.

Thanks again for your help!

0 Kudos