Hi everyone,
I'm trying to find intersection of two polylines with a set of polygons to determine the segment of each polyline that intersects with the polygons.
below is my sample code, I want to get the length of the polyline's segments that intersecte with the polygons but I continuously get one of the following error messages:
1-Eceptions.TypeError:Invalid geometry type for method- : I get this error when I use (GEODESIC,PLANAR, GREAT_ELLIPTIC)as a type measurement in "getLength"method.
2- Access violation at address 5C5B11E8 in module 'GeometryXLib.dll'. Read of address 00000000: I get this error when I use (PRESERVE_SHAPE) as a type measurment in "getLength"method.
I don't Know How to solve it. Any help and suggestion are greatly appreciated.
The Code is :
import arcpy
path="E:\Code_Python\Data_trial.gdb"
arcpy.env.workspace=path
infc="CandidateStations_clipped"
fc="PopulationDensity_poly_del"
OBJ_field="OBJECTID"
#--------------------------------------------------------------------------
def get_station_shape(station_id):
with arcpy.da.SearchCursor(infc,"shape@",'%s = %s'%(OBJ_field,station_id)) as cursor:
t1=cursor.next()[0].lastPoint
return t1
#------------------------------------------------------------------------------
def get_population_shape(pop_stns):
for i in range (len(pop_stns)):
pop_list.append(get_station_shape(pop_stns))
return pop_list
#-----------------------------------------------------------------------------
def determine_line_length(pop_list_line):
pop_line=arcpy.Polyline(arcpy.Array([get_population_shape(pop_list_line)]))
return pop_line
#------------------------------------------------------------------------
# Enter for loop for each feature
def get_polygon_shape(fc):
pd_poly=[]
for row in arcpy.da.SearchCursor(fc, ["OBJECTID", "SHAPE@"]):
# Print the current multipoint's ID
print("Feature {0}:".format(row[0]))
partnum = 0
# Step through each part of the feature
for part in row[1]:
# Print the part number
print("Part {0}:".format(partnum))
# Step through each vertex in the feature
for pnt in part:
poly=[]
if pnt:
poly.append(pnt)
# Print x,y coordinates of current point
#
print("{0}, {1}".format(pnt.X, pnt.Y))
else:
# If pnt is None, this represents an interior ring
#
print("Interior Ring:")
tmp_poly=arcpy.Polygon(arcpy.Array(poly))
pd_poly.append(tmp_poly)
print tmp_poly
partnum += 1
print pd_poly
return(tmp_poly)
#---------------------------------------------------------------------------
pop_list_line=[[2,9],[1,7]]
for i in range(len(pop_list_line)):
pop_list=[]
pop_line=determine_line_length(pop_list_line)
intersect=pop_line.intersect((get_polygon_shape(fc)),2)
print intersect
pop_list.append(intersect.getLength("GEODESIC"))
print "pop_list=",pop_list