POST
|
Thanks Hornbydd My code is as follows: >>> import arcpy
... import os
... fc = "DubaiRoads_Extent"
... sr = arcpy.Describe(fc).spatialReference
... radius = 3
... out_fc = r'J:\research\MapLiteracyStudy\Dubai.gdb\points'
... int_pt = r'J:\research\MapLiteracyStudy\Dubai.gdb\int_pt'
... arcpy.Intersect_analysis(fc,int_pt,output_type='POINT')
... diss_int_pt = r'J:\research\MapLiteracyStudy\Dubai.gdb\diss_int_pt'
... arcpy.Dissolve_management(int_pt,diss_int_pt,'#',[["OBJECTID","MIN"]],"SINGLE_PART")
... buff = r'J:\research\MapLiteracyStudy\Dubai.gdb\buff'
... arcpy.Buffer_analysis(diss_int_pt,buff,str(radius) + ' METERS')
... buff_line_int = r'J:\research\MapLiteracyStudy\Dubai.gdb\buff_line_int'
... arcpy.Intersect_analysis([buff,fc],buff_line_int,output_type='POINT')
... sing_buff_line_int = r'J:\research\MapLiteracyStudy\Dubai.gdb\sing_buff_line_int'
... arcpy.MultipartToSinglepart_management(buff_line_int,sing_buff_line_int)
... new_points = {}
... with arcpy.da.SearchCursor(diss_int_pt,['OID@','SHAPE@'],spatial_reference=sr) as cursor1:
... for row1 in cursor1:
... cent_pt = row1[1].centroid
... angs = []
... with arcpy.da.SearchCursor(sing_buff_line_int,'SHAPE@','\"FID_buff\" = ' + str(row1[0]),spatial_reference=sr) as cursor2:
... for row2 in cursor2:
... buff_pt = row2[0].centroid
... dx = cent_pt.X - buff_pt.X
... dy = cent_pt.Y - buff_pt.Y
... if dx < 0 and dy <= 0:
... ang = math.degrees(math.atan(abs(dy/dx)))
... if dx <= 0 and dy > 0:
... ang = math.degrees(math.atan(abs(dx/dy))) + 270
... if dx > 0 and dy >= 0:
... ang = math.degrees(math.atan(abs(dy/dx))) + 180
... if dx >= 0 and dy < 0:
... ang = math.degrees(math.atan(abs(dx/dy))) + 90
... angs.append(ang)
... angs.sort()
... for i in range(1,len(angs)):
... mid_ang = ((angs[i] + angs[i-1])/2)
... ang_diff = angs[i] - angs[i-1]
... new_x = cent_pt.X + (radius * math.cos(math.radians(mid_ang)))
... new_y = cent_pt.Y + (radius * math.sin(math.radians(mid_ang)))
... new_point = arcpy.PointGeometry(arcpy.Point(new_x, new_y),sr)
... new_points[str(row1[0]) + '_' + str(i)] = [ang_diff,new_point]
... mid_ang = (((360-angs[-1]) + angs[0])/2) - (360-angs[-1])
... ang_diff = (360-angs[-1]) + angs[0]
... new_x = cent_pt.X + (radius * math.cos(math.radians(mid_ang)))
... new_y = cent_pt.Y + (radius * math.sin(math.radians(mid_ang)))
... new_point = arcpy.PointGeometry(arcpy.Point(new_x, new_y),sr)
... new_points[str(row1[0]) + '_0'] = [ang_diff,new_point]
... arcpy.CreateFeatureclass_management(os.path.dirname(out_fc),os.path.basename(out_fc),'POINT',spatial_reference=sr)
... arcpy.AddField_management(out_fc,'FID_buff',"LONG")
... arcpy.AddField_management(out_fc,'ANGLE',"DOUBLE")
... iCursor = arcpy.da.InsertCursor(out_fc,['SHAPE@','FID_buff','ANGLE'])
... for k,v in new_points.iteritems():
... row = [v[1],k.split('_')[0],v[0]]
... iCursor.insertRow(row)
... The script runs, with the resulting image: And the buffers look like: However, in the example provided by Darren Wiens, it the result should be: I can't figure out why all of my calculated points seem to be in a circle around my study area, as opposed to on the buffers between the intersecting lines. Any help would be greatly appreciated. Erin
... View more
10-15-2017
05:02 PM
|
0
|
4
|
607
|
POST
|
I'm trying to compute the angles between intersecting roads using dkwiens script found at: https://community.esri.com/message/582193?q=calculate%20angle%20of but am receiving the following error: Runtime error Traceback (most recent call last): File "<string>", line 53, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 3246, in AddField raise e ExecuteError: ERROR 000732: Input Table: Dataset in_memory\points does not exist or is not supported My code is: >>> import arcpy ... import os ... fc = "NYC_Roads_Extent50" ... sr = arcpy.Describe(fc).spatialReference ... radius = 3 ... out_fc = r'in_memory\points' ... int_pt = r'in_memory\int_pt' ... diss_fc = 'NYC_Roads_Extent50' ... arcpy.Dissolve_management(fc,diss_fc,["name"],"","SINGLE_PART") ... arcpy.Intersect_analysis(diss_fc,int_pt,output_type='POINT') ... diss_int_pt = r'in_memory\diss_int_pt' ... arcpy.Dissolve_management(int_pt,diss_int_pt,'#',[["OBJECTID","MIN"]],"SINGLE_PART") ... buff = r'in_memory\buff' ... arcpy.Buffer_analysis(diss_int_pt,buff,str(radius) + ' METERS') ... buff_line_int = r'in_memory\buff_line_int' ... arcpy.Intersect_analysis([buff,fc],buff_line_int,output_type='POINT') ... sing_buff_line_int = r'in_memory\sing_buff_line_int' ... arcpy.MultipartToSinglepart_management(buff_line_int,sing_buff_line_int) ... new_points = {} ... with arcpy.da.SearchCursor(diss_int_pt,['OID@','SHAPE@'],spatial_reference=sr) as cursor1: ... for row1 in cursor1: ... cent_pt = row1[1].centroid ... angs = [] ... with arcpy.da.SearchCursor(sing_buff_line_int,'SHAPE@','\"FID_buff\" = ' + str(row1[0]),spatial_reference=sr) as cursor2: ... for row2 in cursor2: ... buff_pt = row2[0].centroid ... dx = cent_pt.X - buff_pt.X ... dy = cent_pt.Y - buff_pt.Y ... if dx < 0 and dy <= 0: ... ang = math.degrees(math.atan(abs(dy/dx))) ... if dx <= 0 and dy > 0: ... ang = math.degrees(math.atan(abs(dx/dy))) + 270 ... if dx > 0 and dy >= 0: ... ang = math.degrees(math.atan(abs(dy/dx))) + 180 ... if dx >= 0 and dy < 0: ... ang = math.degrees(math.atan(abs(dx/dy))) + 90 ... angs.append(ang) ... angs.sort() ... for i in range(1,len(angs)): ... mid_ang = ((angs + angs[i-1])/2) ... ang_diff = angs - angs[i-1] ... new_x = cent_pt.X + (radius * math.cos(math.radians(mid_ang))) ... new_y = cent_pt.Y + (radius * math.sin(math.radians(mid_ang))) ... new_point = arcpy.PointGeometry(arcpy.Point(new_x, new_y),sr) ... new_points[str(row1[0]) + '_' + str(i)] = [ang_diff,new_point] ... mid_ang = (((360-angs[-1]) + angs[0])/2) - (360-angs[-1]) ... ang_diff = (360-angs[-1]) + angs[0] ... new_x = cent_pt.X + (radius * math.cos(math.radians(mid_ang))) ... new_y = cent_pt.Y + (radius * math.sin(math.radians(mid_ang))) ... new_point = arcpy.PointGeometry(arcpy.Point(new_x, new_y),sr) ... new_points[str(row1[0]) + '_0'] = [ang_diff,new_point] ... arcpy.CreateFeatureclass_management(os.path.dirname(out_fc),os.path.basename(out_fc),'POINT',spatial_reference=sr) ... arcpy.AddField_management(out_fc,'FID_buff',"LONG") ... arcpy.AddField_management(out_fc,'ANGLE',"DOUBLE") ... iCursor = arcpy.da.InsertCursor(out_fc,['SHAPE@','FID_buff','ANGLE']) ... for k,v in new_points.iteritems(): ... row = [v[1],k.split('_')[0],v[0]] ... iCursor.insertRow(row) Can someone please help? Apologies, I am a novice Python user.
... View more
08-14-2017
06:38 PM
|
0
|
8
|
1048
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:25 AM
|