Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Cannot Add FeatureClass from GeoDatabase

$
0
0
Greetings,

I'm still fairly new to using the arcpy.mapping functions. I want to add a FeatureClass to my map document which is open.

In looking at other forum threads and reading help, I tried the following code:

Code:

import arcpy
import arcpy.mapping
import os

GeoDatabaseName = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurementsDeep_GroundwaterElevation_Daily_Contours_20130625_20120731.gdb"

##Reference the map document in memory.
mxd = arcpy.mapping.MapDocument(r"G:\Documents\GIS\HydstraData\Contours_20131223.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
print df

FeatureClassToAdd = os.path.join(GeoDatabaseName,"AllPoints")
print FeatureClassToAdd
tempLayer = "layer"
## Make a layer from the feature class
arcpy.MakeFeatureLayer_management(FeatureClassToAdd,tempLayer)
addLayer = arcpy.Layer(tempLayer)
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
arcpy.RefreshTOC()

This is the result I get back in my Python Shell windowing when I run the script in IDLE:

<geoprocessing Data Frame object object at 0x02C57368>
G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurementsDeep_GroundwaterElevation_Daily_Contours_20130625_20120731.gdb\AllPoints

Traceback (most recent call last):
File "G:/Documents/GIS/HydstraData/UpdateMxd.py", line 24, in <module>
addLayer = arcpy.Layer(tempLayer)
AttributeError: 'module' object has no attribute 'Layer'

Any suggestions? Thanks for any help!

Jon Mulder

Viewing all articles
Browse latest Browse all 2485

Trending Articles