# Add Feature Class to Map in ArcGIS Pro

4551
9
01-29-2019 09:42 AM
MVP Regular Contributor

How do I add a feature class from an SDE to a Map in Pro? This is where most of our data is stored.

Here's what I've tried:

import arcpy
p = arcpy.mp.ArcGISProject("CURRENT")
map = p.listMaps()[0]

#this returned a ValueError

#this returned a RuntimeError

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

All the methods for using classes seem to be referencing layer files, and nowhere do I see a reference to feature classes.

EDIT:

The confusing thing is that when feature classes from the SDE are in the Map they're referred to as layers. The CURRENT project I'm testing on already has two feature classes from an SDE in it. You can list them with the following:

for lyrname in map.listLayers():
print(lyrname.name)‍‍
Tags (2)
1 Solution

Accepted Solutions
MVP Esteemed Contributor

In your original post, it looked like you are using the 'Database Connections' ArcGIS application alias.  Have you tried specifying the full Windows file system path to the SDE connection file and feature class?

9 Replies
MVP Esteemed Contributor

From the interactive Python window in ArcGIS Pro, the following code works for me, i.e., adds a feature class as a new layer in an open map window:

import arcpy

fc = # path to feature class

p = arcpy.mp.ArcGISProject("CURRENT")
map = p.listMaps()[0]
<arcpy._mp.Layer object at 0x000002549A35FF28>‍‍‍‍‍‍‍‍

Are you getting errors?  What version of Pro are you using?

MVP Regular Contributor

I'm using Pro 2.0.

If you look at line 9 above that's what I did pretty much (also noted the errors above)

Is your feature class coming from a FGDB? Because I'm able to add a feature class from a FGDB. The thing is I'm trying to bring in a feature class from an SDE.

MVP Esteemed Contributor

Yes, FGDB feature class.  Regarding your error, it is helpful to provide the full error with traceback.

MVP Regular Contributor

Ok, Thanks. I'll have to get back to this on Thursday. Our building is being closed because of the cold weather.

MVP Regular Contributor

Joshua,

I ran the same few lines of code that you have, but instead I'm directing the path to a Feature Class in an .SDE.

Here's the full error:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\_mp.py", line 1248, in addDataFromPath
RuntimeError‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
MVP Esteemed Contributor

In your original post, it looked like you are using the 'Database Connections' ArcGIS application alias.  Have you tried specifying the full Windows file system path to the SDE connection file and feature class?

MVP Regular Contributor

Yes, that's correct. I copied the path from ArcCatalog. This path is what I used in ArcGIS for Desktop Arcpy scripts and it always worked fine. I'm not sure how to specify the full Windows file system path?

MVP Esteemed Contributor

Will it matter, possibly not it could.  Since the effort to specify the full path is trivial, it is good to test it to make sure the issue isn't related. 'Database Connections' is an application-level alias, and ArcGIS Pro doesn't have a similar construct.

Have you tried using a newer version of Pro?  Pro 2.0 is very old by Pro standards, and Esri has been addressing issues in 2.2.x and 2.3 with Oracle enterprise geodatabases.

by Anonymous User
Not applicable

I was working on the same problem with a SQL enterprise geodatabase. I had to use the fully qualified feature class name for it to be added to the map:  DatabaseName.SchemaName.FeatureClassName.