new layer will not display in map

583
2
Jump to solution
12-13-2012 10:23 AM
AndrewMaracini
New Contributor
I'm sure this very easy but as a progamming nitwit I cannot figure it out. When I run the script in the Python Shell in ArcGIS it runs and displays every layer (I only want to display the output of the intersect operation). When I try running the script from my toolbox it runs successfully but the desired intersect layer isn't added.

My other issue is that everytime I run the script I have to create a new "ProjectLocation_Intersect" layer. I don't want to do that, I just want one layer, how do I tell arcgis that its OK to overwrite that layer?

I'm running ArcGIS 10.1, Python 2.7.

sript follows:

# Import arcpy module import arcpy   # Local variables: mxd= arcpy.mapping.MapDocument(r"R:\lwcd\_land\GIS\SpecialProjects\Cultural_Resource_Map\Cultural_Map_template2.mxd") ProjectLocation = "R:\\lwcd\\_land\\GIS\\SpecialProjects\\Cultural_Resource_Map\\Cultural.gdb\\ProjectArea\\ProjectLocation" gm_seq_shp = "R:\\lwcd\\_land\\GIS\\Data\\Control\\gm_seq.shp" gm_par_shp = "R:\\lwcd\\_land\\GIS\\Data\\Landbase\\gm_par.shp" topbound_shp = "R:\\lwcd\\_land\\GIS\\Data\\USGSBoundaries\\topbound.shp" ProjectLocation_Layer = "ProjectLocation_Layer" topbound_Layer = "topbound_Layer" gm_seq_Layer = "gm_seq_Layer" gm_par_Layer = "gm_par_Layer" ProjectLocation_Intersect4 = "R:\\lwcd\\_land\\GIS\\SpecialProjects\\Cultural_Resource_Map\\Cultural.gdb\\ProjectArea\\ProjectLocation_Intersect4"  # Process: Make Feature Layer arcpy.MakeFeatureLayer_management(ProjectLocation, ProjectLocation_Layer, "", "", "OBJECTID OBJECTID VISIBLE NONE;SHAPE SHAPE VISIBLE NONE;ParcelID ParcelID VISIBLE NONE;ProjectName ProjectName VISIBLE NONE")  # Process: Make Feature Layer (2) arcpy.MakeFeatureLayer_management(topbound_shp, topbound_Layer, "", "", "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;USGS_QD_ID USGS_QD_ID VISIBLE NONE;QUAD_NAME QUAD_NAME VISIBLE NONE;MAP_EDIT MAP_EDIT VISIBLE NONE;ST_NAME1 ST_NAME1 VISIBLE NONE;ST_NAME2 ST_NAME2 VISIBLE NONE;ST_NAME3 ST_NAME3 VISIBLE NONE;ST_NAME4 ST_NAME4 VISIBLE NONE;DATE_REV DATE_REV VISIBLE NONE;DATE_PUB DATE_PUB VISIBLE NONE;PHOTO_R_DT PHOTO_R_DT VISIBLE NONE")  # Process: Make Feature Layer (3) arcpy.MakeFeatureLayer_management(gm_seq_shp, gm_seq_Layer, "", "", "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;TAG TAG VISIBLE NONE")  # Process: Make Feature Layer (4) arcpy.MakeFeatureLayer_management(gm_par_shp, gm_par_Layer, "", "", "FID FID VISIBLE NONE;Shape Shape VISIBLE NONE;parno parno VISIBLE NONE;owner1 owner1 VISIBLE NONE;owner2 owner2 VISIBLE NONE;tax_addr tax_addr VISIBLE NONE;tax_add2 tax_add2 VISIBLE NONE;csz csz VISIBLE NONE;revised revised VISIBLE NONE;s_t_r s_t_r VISIBLE NONE;sch_dist sch_dist VISIBLE NONE;assmt_yr assmt_yr VISIBLE NONE;lvalue lvalue VISIBLE NONE;ivalue ivalue VISIBLE NONE;avalue avalue VISIBLE NONE;doc_no doc_no VISIBLE NONE;deed_ac deed_ac VISIBLE NONE;legal1 legal1 VISIBLE NONE;legal2 legal2 VISIBLE NONE;legal3 legal3 VISIBLE NONE;legal4 legal4 VISIBLE NONE;legal5 legal5 VISIBLE NONE;legal6 legal6 VISIBLE NONE;c_sqft c_sqft VISIBLE NONE;c_acres c_acres VISIBLE NONE;prop_csz prop_csz VISIBLE NONE;prop_add prop_add VISIBLE NONE")  # Process: Intersect arcpy.Intersect_analysis("ProjectLocation_Layer #;topbound_Layer #;gm_seq_Layer #;gm_par_Layer #", ProjectLocation_Intersect4, "ALL", "", "INPUT")  # get the data frame df = arcpy.mapping.ListDataFrames(mxd,"Main Map")[0]  # add the layer to the map at the bottom of the TOC in data frame 0 addLayer = arcpy.mapping.Layer("ProjectLocation_Intersect4") arcpy.mapping.AddLayer(df, addLayer,"TOP")
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MikeHunter
Occasional Contributor
To allow overwriting of the featureclass, add this to the top of the script:

arcpy.env.overwriteOutput = True


And your layer is getting added to the mxd file on the disk, not to the current version that's displayed. Maybe I'm misunderstanding what you want, but if you want the layer added to the current display, then you'll have reference the current mxd:

mxd = arcpy.mapping.MapDocument('Current')


To keep all the other layers out of a map, do this:

arcpy.gp.AddOutputsToMap = False


This may or may not help, but hopefully it will get you started in the right direction.

Mike

View solution in original post

0 Kudos
2 Replies
MikeHunter
Occasional Contributor
To allow overwriting of the featureclass, add this to the top of the script:

arcpy.env.overwriteOutput = True


And your layer is getting added to the mxd file on the disk, not to the current version that's displayed. Maybe I'm misunderstanding what you want, but if you want the layer added to the current display, then you'll have reference the current mxd:

mxd = arcpy.mapping.MapDocument('Current')


To keep all the other layers out of a map, do this:

arcpy.gp.AddOutputsToMap = False


This may or may not help, but hopefully it will get you started in the right direction.

Mike
0 Kudos
AndrewMaracini
New Contributor
Mike,

Thank you! Each line did exactly what you said it would do! I may actually get this thing to work after all.
0 Kudos