Hello all,
Does anyone know
I have been trying to write a script that will create duplicate polygons based on the number of points that intersect each polygon.
The catch is that I want the output polygon feature class to include the "name" of the point layer intersecting it.
So if I have three points: ID1, ID1 and ID3 intersecting polygon A I would like a polygon feature class with an attribute table showing:
FID, PolygonName, PointName
0, A, ID1
1, A, ID2
2, A, ID3
3, B, etc, etc, etc
Is this possible in python? I have been struggling with getting this to work with the following code....
Any help would be appreciated!
Regards,
Kevin
import arcgisscripting
gp = arcgisscripting.create(9.3)
print "Step1"
# Load required toolboxes...
gp.AddToolbox(r"C:\Program Files\ArcGIS\ArcToolbox\Toolboxes\Data Management Tools.tbx")
Output_Layer_Name = "Polygons_Layer"
Polygons_shp = r"C:\Temp\ES106506\Polygons.shp"
Polygons_Layer = "Polygons_Layer"
Output_Feature_Class = "C:\\Temp\\ES106506\\Polygons_CopyFeatures.shp"
gp.Workspace = r"C:\Temp\ES106506\output.gdb"
gp.OverWriteOutput = 1
try:
#Define the points layer
gp.MakeFeatureLayer(r"C:\Temp\ES106506\Points.shp", "Points_Layer")
#Define the polygons layer
gp.MakeFeatureLayer(Polygons_shp, Polygons_Layer)
print "Step5"
#create search cursor to loop through points
points = gp.searchCursor("Points_Layer")
print "Step6"
#For each point select the polygon intersecting it
point = points.next()
while points:
gp.selectLayerByLocation(Polygons_Layer, "INTERSECT", point.shape)
#Create a new Polygon feature class based on the original Point
#feature class and named based on a field within the the polygon field
name = Polygons_Layer.TempID
gp.CopyFeatures(Polygons_Layer, Polygons_Layer.name)
#move on to next point
point = points.next()
print "Finished"
del gp, points, point
except:
print gp.getmessages()
print "Errored"
del gp