Hi all,
I'm trying to create a python script to do the following things:
1- choose objectID=1 of a dataset
2- generate a cluster with all the points within a 80m distance between each others
3- erase these points from the dataset
4- pick the objectID=1 point of the resultant dataset
5- repeat points 2-3-4 until the dataset is empty
6- generate an account of the number of clusters and size of clusters (I haven't tried this yet)
I figured out the clustering thing and the erase (the easy ones!), but I'm having problems with the loop to carry this out till the dataset is empty. I think the problem is how I'm using the temporary file to do this.
I attach the script below. As you will see, I'm a newbie with python, so I'd greatly appreciate any feedback/support/ comments you could give me.
Thanks
Francesco
# Import arcpy module
import arcpy
# Script arguments
# Local variables:
# the map for assumed septic tanks needs to exclude houses in urban-rural sewered areas
housedist = arcpy.GetParameterAsText(0) # in meters
County = arcpy.GetParameterAsText(1)
if (County=='1'): #wexfordcounty
Assumed_Septic_Tanks = "C:\WexfordJune2k13\EPAData.gdb\\Assumed_Septic_Tank"
rivers="C:\WexfordJune2k13\EPAData.gdb\\rivers"
elif (County=='2'): #Leitrim county
Assumed_Septic_Tanks = "C:\WexfordJune2k13\EPAData.gdb\\Leitrim_assumed_septic_tanks"
rivers="C:\WexfordJune2k13\EPAData.gdb\\Leitrim_rivers"
elif (County=='3'):#limrick
Assumed_Septic_Tanks = "C:\WexfordJune2k13\EPAData.gdb\\Limerick_assumed_septic_tanks"
rivers="C:\WexfordJune2k13\EPAData.gdb\\Limerick_rivers"
else: #sligo
Assumed_Septic_Tanks = "C:\WexfordJune2k13\EPAData.gdb\\Sligo_assumed_septic_tanks"
rivers="C:\WexfordJune2k13\EPAData.gdb\\Sligo_rivers"
riverdist = arcpy.GetParameterAsText(2) # in meters
#SpEast=[]
#SpNorth=[]
Assumed_Septic_Tanks_selectionqry ="C:\WexfordJune2k13\EPAData.gdb\\sqlqrySepticktank"
Assumed_septic_tank_Buffered = "C:\\WexfordJune2k13\\EPAData.gdb\\Assumed_septic_tank_Buffernhq"
clipoutput="C:\WexfordJune2k13\EPAData.gdb\\mclipoutput"
buffoutput="C:\WexfordJune2k13\EPAData.gdb\\bufopa"
riverinteresect="C:\WexfordJune2k13\EPAData.gdb\\riverintersect"
clipoutputfinal="C:\WexfordJune2k13\EPAData.gdb\\clipfinal"
workingfilest="C:\WexfordJune2k13\EPAData.gdb\\workingfileST" # total septic tanks minus found clusters
#arcpy.Erase_analysis(Assumed_Septic_Tanks, clipoutputfinal, workingfilest,"")
# start for clustering loop
j=0
Expression = "objectid = 1"
workfilest = (Assumed_Septic_Tanks)
#if (int(arcpy.GetCount_management(clipoutput).getOutput(0))>0):
while (j<3):
j=j+1
arcpy.Select_analysis(workfilest, Assumed_Septic_Tanks_selectionqry, Expression)
# Process: Buffer
arcpy.Buffer_analysis(Assumed_Septic_Tanks_selectionqry, Assumed_septic_tank_Buffered, housedist, "FULL", "ROUND", "ALL", "")
# Process: Clip
arcpy.Clip_analysis(workfilest, Assumed_septic_tank_Buffered, clipoutput, "")
LastRecCount=int(arcpy.GetCount_management(clipoutput).getOutput(0))
#for num in range(1,6):
i=0
clipoutput="C:\WexfordJune2k13\EPAData.gdb\\mclipoutput"
buffoutput="C:\WexfordJune2k13\EPAData.gdb\\bufoutput"
tempor="C:\WexfordJune2k13\EPAData.gdb\\tempor"
while True:
i=i+1
buffoutput=buffoutput+str(i)
arcpy.Buffer_analysis(clipoutput, buffoutput, housedist, "FULL", "ROUND", "ALL", "")
clipoutput=clipoutput+str(i)
arcpy.Clip_analysis(Assumed_Septic_Tanks, buffoutput, clipoutput, "")
if ((i>1) and (int(arcpy.GetCount_management(clipoutput).getOutput(0))
==LastRecCount)):
break
LastRecCount=int(arcpy.GetCount_management(clipoutput).getOutput(0))
inputfeatuesforintersection=[rivers, buffoutput]
arcpy.Intersect_analysis(inputfeatuesforintersection, riverinteresect, "ALL", "", "INPUT")
riverintersectrecord=int(arcpy.GetCount_management(riverinteresect).getOutput(0))
#deleting of clustered septic tanks
arcpy.Erase_analysis(workfilest, clipoutput, tempor,"")
workfilest=tempor+str(j)
workfilest=workfilest+str(j)
I'm trying to create a python script to do the following things:
1- choose objectID=1 of a dataset
2- generate a cluster with all the points within a 80m distance between each others
3- erase these points from the dataset
4- pick the objectID=1 point of the resultant dataset
5- repeat points 2-3-4 until the dataset is empty
6- generate an account of the number of clusters and size of clusters (I haven't tried this yet)
I figured out the clustering thing and the erase (the easy ones!), but I'm having problems with the loop to carry this out till the dataset is empty. I think the problem is how I'm using the temporary file to do this.
I attach the script below. As you will see, I'm a newbie with python, so I'd greatly appreciate any feedback/support/ comments you could give me.
Thanks
Francesco
# Import arcpy module
import arcpy
# Script arguments
# Local variables:
# the map for assumed septic tanks needs to exclude houses in urban-rural sewered areas
housedist = arcpy.GetParameterAsText(0) # in meters
County = arcpy.GetParameterAsText(1)
if (County=='1'): #wexfordcounty
Assumed_Septic_Tanks = "C:\WexfordJune2k13\EPAData.gdb\\Assumed_Septic_Tank"
rivers="C:\WexfordJune2k13\EPAData.gdb\\rivers"
elif (County=='2'): #Leitrim county
Assumed_Septic_Tanks = "C:\WexfordJune2k13\EPAData.gdb\\Leitrim_assumed_septic_tanks"
rivers="C:\WexfordJune2k13\EPAData.gdb\\Leitrim_rivers"
elif (County=='3'):#limrick
Assumed_Septic_Tanks = "C:\WexfordJune2k13\EPAData.gdb\\Limerick_assumed_septic_tanks"
rivers="C:\WexfordJune2k13\EPAData.gdb\\Limerick_rivers"
else: #sligo
Assumed_Septic_Tanks = "C:\WexfordJune2k13\EPAData.gdb\\Sligo_assumed_septic_tanks"
rivers="C:\WexfordJune2k13\EPAData.gdb\\Sligo_rivers"
riverdist = arcpy.GetParameterAsText(2) # in meters
#SpEast=[]
#SpNorth=[]
Assumed_Septic_Tanks_selectionqry ="C:\WexfordJune2k13\EPAData.gdb\\sqlqrySepticktank"
Assumed_septic_tank_Buffered = "C:\\WexfordJune2k13\\EPAData.gdb\\Assumed_septic_tank_Buffernhq"
clipoutput="C:\WexfordJune2k13\EPAData.gdb\\mclipoutput"
buffoutput="C:\WexfordJune2k13\EPAData.gdb\\bufopa"
riverinteresect="C:\WexfordJune2k13\EPAData.gdb\\riverintersect"
clipoutputfinal="C:\WexfordJune2k13\EPAData.gdb\\clipfinal"
workingfilest="C:\WexfordJune2k13\EPAData.gdb\\workingfileST" # total septic tanks minus found clusters
#arcpy.Erase_analysis(Assumed_Septic_Tanks, clipoutputfinal, workingfilest,"")
# start for clustering loop
j=0
Expression = "objectid = 1"
workfilest = (Assumed_Septic_Tanks)
#if (int(arcpy.GetCount_management(clipoutput).getOutput(0))>0):
while (j<3):
j=j+1
arcpy.Select_analysis(workfilest, Assumed_Septic_Tanks_selectionqry, Expression)
# Process: Buffer
arcpy.Buffer_analysis(Assumed_Septic_Tanks_selectionqry, Assumed_septic_tank_Buffered, housedist, "FULL", "ROUND", "ALL", "")
# Process: Clip
arcpy.Clip_analysis(workfilest, Assumed_septic_tank_Buffered, clipoutput, "")
LastRecCount=int(arcpy.GetCount_management(clipoutput).getOutput(0))
#for num in range(1,6):
i=0
clipoutput="C:\WexfordJune2k13\EPAData.gdb\\mclipoutput"
buffoutput="C:\WexfordJune2k13\EPAData.gdb\\bufoutput"
tempor="C:\WexfordJune2k13\EPAData.gdb\\tempor"
while True:
i=i+1
buffoutput=buffoutput+str(i)
arcpy.Buffer_analysis(clipoutput, buffoutput, housedist, "FULL", "ROUND", "ALL", "")
clipoutput=clipoutput+str(i)
arcpy.Clip_analysis(Assumed_Septic_Tanks, buffoutput, clipoutput, "")
if ((i>1) and (int(arcpy.GetCount_management(clipoutput).getOutput(0))
==LastRecCount)):
break
LastRecCount=int(arcpy.GetCount_management(clipoutput).getOutput(0))
inputfeatuesforintersection=[rivers, buffoutput]
arcpy.Intersect_analysis(inputfeatuesforintersection, riverinteresect, "ALL", "", "INPUT")
riverintersectrecord=int(arcpy.GetCount_management(riverinteresect).getOutput(0))
#deleting of clustered septic tanks
arcpy.Erase_analysis(workfilest, clipoutput, tempor,"")
workfilest=tempor+str(j)
workfilest=workfilest+str(j)