I am working on a little task, where I create some points, based on coordinates. Every point is then used to create a couple of polylines, where each point is supposed to be the start point for a set of polylines. The endpoints for the polylines are determined by angle and distance.
So, the outcome should be a point, in the center of some polylines, looking like sunrays.
I create the points and use the created points thereafter as point of origin for my polylines. Only problem, the created point is not where the polylines 'meet' and the polylines do not meet at the same point either.
I wonder how that can be, if the point of origin does not change!
import arcpy
import arcgis
from arcgis.gis import GIS
from arcgis.geometry import Point, Polyline, Geometry
bearing_list = [(345,165),(315,135),(285,105),(255,75),(225,45),(195,15)]
distance_2 = 2000
in_sr = 4326
out_sr = 3006
# create featureclass and populate with points from coordinates
points_fc = arcpy.CreateFeatureclass_management(out_name='Sites', geometry_type='POINT', spatial_reference=out_sr)
arcpy.AddField_management(points_fc, 'SiteName', 'TEXT')
point_insert_cursor = arcpy.da.InsertCursor(points_fc, ('SiteName', 'SHAPE@XY'))
pnt_list = []
for item in point_dict:
y, x = point_dict[item]
pnt = Point({
'x': x,
'y': y,
'spatialReference':{
'wkid': in_sr,
'latestWkid': in_sr
}
})
out_pnt = pnt.project_as(out_sr)
pnt_list.append([item, out_pnt])
row_point = (item, out_pnt.centroid)
point_insert_cursor.insertRow(row_point)
del point_insert_cursor
# iterate over points, create temporary line featureclass,
temp_lines = arcpy.CreateFeatureclass_management(out_name='temp_lines', geometry_type='POLYLINE', spatial_reference=out_sr)
arcpy.AddField_management(temp_lines, 'SiteName', 'TEXT')
line_insert_cursor = arcpy.InsertCursor(temp_lines)
line_length = distance_2 + 5
for pnt in pnt_list:
for bearing_set in bearing_list:
pnt_array = arcpy.Array()
x = pnt[1].first_point.x
y = pnt[1].first_point.y
pg = arcpy.PointGeometry(arcpy.Point(x, y), arcpy.SpatialReference(out_sr))
start = pg.pointFromAngleAndDistance(bearing_set[0], line_length)
start_pnt = arcpy.Point(start.firstPoint.X, start.firstPoint.Y)
end = pg.pointFromAngleAndDistance(bearing_set[1], line_length)
end_pnt = arcpy.Point(end.firstPoint.X, end.firstPoint.Y)
pnt_array.append(start_pnt)
pnt_array.append(end_pnt)
line_feature = line_insert_cursor.newRow()
line_feature.shape = arcpy.Polyline(pnt_array)
line_feature.setValue("SiteName", pnt[0])
line_insert_cursor.insertRow(line_feature)
del line_insert_cursor
The result for one of the points: the point is 10 centimeters away from where the lines 'meet'.

And it looks like this at the 'center' of the polylines
