POST
|
import arcpy
import sys
import os
# Script to create Shapefiles of WP Infrastructure within a specified boundary
# Define variables
UserName = "n041871"
Shapefile = r"S:\SupportServices\Meet\Arc Gis\Planning Refs\Canning\20150107_CTLE.shp"
Suffix = "CTLE"
#Build Path name for workspace
SDEPre = "C:\Users"
SDEPost = "\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde"
SDE= os.path.join(SDEPre,UserName+SDEPost)
print "Using "+SDE+" as Geodatabase"
arcpy.AddMessage("Using " + str(SDE)+ " as Geodatabase")
arcpy.env.workspace = SDE
arcpy.env.overwriteOutput = True
#Define Layers to Clip
#1. Transmission feature classes
T330OH = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_330kV_OH_Carrier")
T330UG = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_330kV_UG_Cable")
T220OV = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_220kV_OH_Carrier")
T132OH = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_132kV_OH_Carrier")
T132UG = os.path.join ("GISTRAN.Transmission" , "GISTRAN.Trans_132kV_UG_Cable")
T66OV = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_66kV_OH_Carrier")
T66UG = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_66kV_UG_Cable")
T33OH = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_33kV_OH_Carrier")
T33UG = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_33kV_UG_Cable")
TransStruc = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_Structure")
Substation = os.path.join ("GISTRAN.Transmission", "GISTRAN.Substation")
#Group Transmission Values:
Transmission = (T330OH, T330UG, T220OV, T132OH, T132UG, T66OV, T66UG, T33OH, T33UG, TransStruc, Substation)
#2. Distrubution feature classes
POLES = os.path.join("ARCFM.Structure", "ARCFM.Pole")
HVOH = os.path.join("ARCFM.Distribution_HV", "ARCFM.Conductor_HV")
HVUG = os.path.join("ARCFM.Distribution_HV", "ARCFM.Cable_HV")
LVOH = os.path.join("ARCFM.Distribution_LV", "ARCFM.Conductor_LV")
LVUG = os.path.join("ARCFM.Distribution_LV", "ARCFM.Cable_LV")
#Group Distribution Values
Distribution = (POLES, HVOH, HVUG, LVOH, LVUG)
#Future Infrastructure Shapefiles
ISubstation = r"S:\SupportServices\SPIDA Projects\Transmission\Sub-Regional Structure Planning\WP Future Infrastructure\Version 1\WP_New_Sub_stations_20130807.shp"
ILine = r"S:\SupportServices\SPIDA Projects\Transmission\Sub-Regional Structure Planning\WP Future Infrastructure\Version 1\WP_New_Power_Lines_20130807.shp"
#Group New Infrastructure
NewI = (ISubstation, ILine)
#Select Required LOCALITY
arcpy.MakeFeatureLayer_management(Shapefile, "lyr")
#Set Ouput Directory
outputPath = "S:\\SupportServices\\SPIDA Projects\\Infrastructure Shapefiles\\Custom\\"+ str(Suffix)
# Clip Transmission Feature Classes with LOCALITY Layer
for StrucT in Transmission:
basefileName = arcpy.Describe(StrucT).baseName.replace('.','_') + Suffix
fileFormat= '.shp'
finalDest = os.path.join(outputPath,basefileName+fileFormat)
arcpy.Clip_analysis(StrucT,Shapefile,finalDest)
print StrucT + "Shapefile Created"
arcpy.AddMessage(str(StrucT)+" Shapefile Created")
# Clip Distriution Feature Classes with LOCALITY Layer
for StrucD in Distribution:
basefileName = arcpy.Describe(StrucD).baseName.replace('.','_') + Suffix
fileFormat= '.shp'
finalDest = os.path.join(outputPath,basefileName+fileFormat)
arcpy.Clip_analysis(StrucD,Shapefile,finalDest)
print StrucD + " Shapefile created"
arcpy.AddMessage(str(StrucD)+" Shapefile Created")
#Clip New Infrastructure
for Struc in NewI:
if not os.path.exists(outputPath):os.makedirs(outputPath)
basefileName = arcpy.Describe(Struc).baseName.replace('.','_') + Suffix
fileFormat= '.shp'
finalDest = os.path.join(outputPath,basefileName+fileFormat)
arcpy.Clip_analysis(Struc,Shapefile,finalDest)
print Struc + " Shapefile created"
arcpy.AddMessage(str(Struc)+" Shapefile Created")
#Find empty shapefiles and delete them
arcpy.env.workspace = outputPath
shapefiles = arcpy.ListFeatureClasses()
for shapefile in shapefiles:
layerName = arcpy.Describe(shapefile).baseName
arcpy.AddMessage(layerName)
arcpy.MakeFeatureLayer_management (shapefile, layerName)
arcpy.AddMessage(arcpy.GetCount_management(layerName).getOutput(0))
if int(arcpy.GetCount_management(layerName).getOutput(0)) == 0:
arcpy.Delete_management(shapefile)
print shapefile + " deleted"
arcpy.AddMessage(str(shapefile)+" Deleted")
print "All empty shapefiles have been deleted"
arcpy.AddMessage("All empty shapefiles have been deleted")
print "process complete" I am getting the following error: Traceback (most recent call last): File "S:\SupportServices\Meet\Arc Gis\Scripts\WP_Infrastructure_Shapefile_Cut.py", line 71, in <module> arcpy.Clip_analysis(StrucT,"lyr",finalDest) File "c:\Program Files (x86)\ArcGIS\Desktop10.0\ArcPy\arcpy\analysis.py", line 55, in Clip raise e ExecuteError: ERROR 000210: Cannot create output S:\SupportServices\SPIDA Projects\Infrastructure Shapefiles\Custom\CTLE\GISTRAN_Trans_330kV_OH_CarrierCTLE.shp Failed to execute (Clip).
... View more
01-06-2015
11:37 PM
|
0
|
1
|
4352
|
POST
|
def ResZones(Layer, Buffer): try: arcpy.Buffer_analysis(Layer, "S:/Support Services/LGA Maps/buffer.shp" "Buffer", "FULL", "ROUND", "LIST", "Distance") except arcpy.ExecuteError: print arcpy.GetMessages(0) arcpy.AddError(arcpy.GetMessages(0)) if __name__ == '__main__': ResZones(T330, "35 meters") I want to define a new function to do a batch buffer but with different buffer size for each feature class. For example, line one with a buffer of 35m and line 2 with a buffer of 10m and line 3 with a buffer of 6m. After all the buffers are created, I would like to combine them into one. I started with the above but already failing. Please help.
... View more
11-04-2014
11:46 PM
|
0
|
0
|
2326
|
POST
|
Hi, I want to define a list of values for a Parameter as all the values for a particular field in a Feature Class. How do I do that?
... View more
09-25-2014
08:38 PM
|
0
|
2
|
3539
|
POST
|
Hi Riyas, Now there is this ExecuteError: ERROR 000210: Cannot create output S:\SupportServices\LGAShapefiles\GISTRAN_Trans_330kV_OH_CarrierKONDININ, SHIRE OF.shp ERROR 000354: The name contains invalid characters Failed to execute (Clip).
... View more
09-25-2014
06:40 PM
|
0
|
2
|
2040
|
POST
|
import arcpy
import sys
import os
# Script to create LGA Map with WP Infrastructure
# Define variables
arcpy.env.workspace = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde"
arcpy.env.overwriteOutput = True
#LGA = arcpy.GetParameterAsText(0) # Input Required Local Government Area
LGA ="COOROW, SHIRE OF"
#Define Layers to Intersect
#1. Transmission Layers
T330OH = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_330kV_OH_Carrier"
T330UG = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_330kV_UG_Cable"
T220OV = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_220kV_OH_Carrier"
T132OH = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_132kV_OH_Carrier"
T132UG = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_132kV_UG_Cable"
T66OV = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_66kV_OH_Carrier"
T66UG = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_66kV_UG_Cable"
T33OH = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_33kV_OH_Carrier"
T33UG = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_33kV_UG_Cable"
TransStruc = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_Structure"
Substation = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Substation"
#Group Transmission Values:
Transmission = (T330OH, T330UG, T220OV, T132OH, T132UG, T66OV, T66UG, T33OH, T33UG, TransStruc, Substation)
#2. Distrubution Layers
POLES = os.path.join("ARCFM.Structure", "ARCFM.Pole")
HVOH = os.path.join("ARCFM.Distribution_HV", "ARCFM.Conductor_HV")
HVUG = os.path.join("ARCFM.Distribution_HV", "ARCFM.Cable_HV")
LVOH = os.path.join("ARCFM.Distribution_LV", "ARCFM.Conductor_LV")
LVUG = os.path.join("ARCFM.Distribution_LV", "ARCFM.Cable_LV")
#Group Distribution Values
Distribution = (POLES, HVOH, HVUG, LVOH, LVUG)
#Select Required LGA
arcpy.MakeFeatureLayer_management("GISEXT.Local_Government_Authority", "LGAlyr")
fieldName = "NAME"
Query = "\""+fieldName+"\"='"+LGA+"'"
arcpy.SelectLayerByAttribute_management ("LGAlyr", "NEW_SELECTION", Query)
###arcpy.SelectLayerByAttribute_management ("LGAlyr", "NEW_SELECTION", """ "NAME" = 'ALBANY, CITY OF' """) - working code
for Struc in Transmission:
outputPath = r"S:\SupportServices\LGAShapefiles"
basefileName = arcpy.Describe(Struc).baseName + LGA
fileFormat= '.shp'
finalDest = os.path.join(outputPath,basefileName+fileFormat)
arcpy.Clip_analysis(Struc, "LGAlyr",finalDest)
#arcpy.Clip_analysis(Struc,"LGAlyr", finalDest)
print "Transmission Shapefile Created"
##for Struc in Distribution:
## outputPath = r"S:\SupportServices\LGAShapefiles"
## basefileName = arcpy.Describe(Struc).baseName + LGA
## fileFormat= '.shp'
## finalDest = os.path.join(outputPath,basefileName+fileFormat)
## arcpy.Clip_analysis(Struc, "LGAlyr",finalDest)
#Find empty shapefiles and delete them
arcpy.env.workspace = r"S:\SupportServices\LGAShapefiles"
shapefiles = arcpy.ListFeatureClasses()
for shapefile in shapefiles:
layerName = arcpy.Describe(shapefile).baseName
arcpy.AddMessage(layerName)
arcpy.MakeFeatureLayer_management (shapefile, layerName)
arcpy.AddMessage(arcpy.GetCount_management(layerName).getOutput(0))
if int(arcpy.GetCount_management(layerName).getOutput(0)) == 0:
arcpy.Delete_management(shapefile)
... View more
09-25-2014
05:39 PM
|
0
|
4
|
2040
|
POST
|
Hi Riyas, This time it gets stuck at the MakeFeatureLayer ERROR 000732: Input Features: Dataset GISTRAN.SubstationCOOROW, SHIRE OF.shp does not exist or is not supported Failed to execute (MakeFeatureLayer).
... View more
09-25-2014
05:38 PM
|
0
|
5
|
2040
|
POST
|
Still not working. ERROR 000732: Input Rows: Dataset GISTRAN.SubstationCOOROW, SHIRE OF.shp does not exist or is not supported Failed to execute (GetCount).
... View more
09-25-2014
05:00 PM
|
0
|
1
|
744
|
POST
|
Hi Riyas, Thank you for your input. I am now getting the following error: ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Rows: Dataset GISTRAN.SubstationCOOROW, SHIRE OF.shp does not exist or is not supported Failed to execute (GetCount). What is going on?
... View more
09-25-2014
04:57 PM
|
0
|
7
|
2040
|
POST
|
I want to delete all empty shapefiles in a folder. The following is not working: #Find empty shapefiles and delete them arcpy.env.workspace = r"S:\SupportServices\LGAShapefiles" shapefiles = arcpy.ListFeatureClasses() for shapefile in shapefiles: if arcpy.management.GetCount(shapefile)[0]=="0": arcpy.Delete_management(shapefile) print shapefile + "Deleted"
... View more
09-25-2014
02:06 AM
|
0
|
11
|
5882
|
POST
|
I have another issue. I want to delete all empty shapefiles in a folder. The following is not working:
#Find empty shapefiles and delete them
arcpy.env.workspace = r"S:\SupportServices\LGAShapefiles"
shapefiles = arcpy.ListFeatureClasses()
for shapefile in shapefiles:
if arcpy.management.GetCount(shapefile)[0]=="0":
arcpy.Delete_management(shapefile)
print shapefile + "Deleted"
... View more
09-25-2014
02:03 AM
|
0
|
3
|
744
|
POST
|
Thank you Curtis. That worked and yes if did figure the path thing.
... View more
09-25-2014
01:58 AM
|
0
|
4
|
744
|
POST
|
import arcpy import sys import os # Script to create LGA Map with WP Infrastructure # Define variables arcpy.env.workspace = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde" arcpy.env.overwriteOutput = True #LGA = arcpy.GetParameterAsText(0) # Input Required Local Government Area LGA ="COOROW, SHIRE OF" LGA2 = "COOROW" #Define Layers to Intersect #1. Transmission Layers T330OH = arcpy.ListFeatureClasses("GISTRAN.Trans_330kV_OH_Carrier","All","GISTRAN.Transmission") T330UG = arcpy.ListFeatureClasses("GISTRAN.Trans_330kV_UG_Cable","All","GISTRAN.Transmission") T220OV = arcpy.ListFeatureClasses("GISTRAN.Trans_220kV_OH_Carrier","All","GISTRAN.Transmission") T132OH = r"C:\Users\N041871\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde\GISTRAN.Transmission\GISTRAN.Trans_132kV_OH_Carrier" T132UG = arcpy.ListFeatureClasses("GISTRAN.Trans_132kV_UG_Cable","All","GISTRAN.Transmission") T66OV = arcpy.ListFeatureClasses("GISTRAN.Trans_66kV_OH_Carrier","All","GISTRAN.Transmission") T66UG = arcpy.ListFeatureClasses("GISTRAN.Trans_66kV_UG_Cable","All","GISTRAN.Transmission") T33OH = arcpy.ListFeatureClasses("GISTRAN.Trans_33kV_OH_Carrier","All","GISTRAN.Transmission") T33UG = arcpy.ListFeatureClasses("GISTRAN.Trans_33kV_UG_Cable","All","GISTRAN.Transmission") TransStruc = arcpy.ListFeatureClasses("GISTRAN.Trans_Structure","All","GISTRAN.Transmission") Substation = arcpy.ListFeatureClasses("GISTRAN.Substation","All","GISTRAN.Transmission") #Group Transmission Values: Transmission = (T330OH, T330UG, T220OV, T132OH, T132UG, T66OV, T66UG, T33OH, T33UG, TransStruc, Substation) #Select Required LGA arcpy.MakeFeatureLayer_management("GISEXT.Local_Government_Authority", "LGAlyr") fieldName = "NAME" Query = "\""+fieldName+"\"='"+LGA+"'" arcpy.SelectLayerByAttribute_management ("LGAlyr", "NEW_SELECTION", Query) ###arcpy.SelectLayerByAttribute_management ("LGAlyr", "NEW_SELECTION", """ "NAME" = 'ALBANY, CITY OF' """) - working code for Struc in Transmission: outputPath = r"S:\SupportServices\LGAShapefiles" basefileName = str(LGA2)+str(Struc)) fileFormat= '.shp' finalDest = os.path.join(outputPath,basefileName+fileFormat) #print Struc arcpy.Clip_analysis(T132OH, "LGAlyr",finalDest) #arcpy.Clip_analysis(Struc,"LGAlyr", finalDest) print "Process ended" That is my code. In the last loop I want to use the variable name to name the output file and the variable content for geoprocessing.... Is that possible?
... View more
09-25-2014
12:49 AM
|
0
|
6
|
744
|
POST
|
I want to loop through P and then return T R S, not 1 2 3 e.g for x in P filename = " XYZ " + T The desired output is XYZT not XYZ1 Is that possible?
... View more
09-25-2014
12:33 AM
|
0
|
8
|
744
|
POST
|
Hi, Is there a function that returns the name of the variable rather than its contents. For example. T = 1 R= 2 S= 3 P = (T, R, S) Is there a fucntion that if I do function(T) it will return T?
... View more
09-24-2014
11:54 PM
|
0
|
10
|
4454
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|