import arcpy
import math
import pythonaddins
class Line(object):
"""Implementation for Projects_addin.Project1_2 (Tool)"""
def __init__(self):
self.enabled = True
self.cursor = 3
self.shape = "Line" # Can set to "Line", "Circle" or "Rectangle" for interactive shape drawing and to activate the onLine/Polygon/Circle event sinks.
def onLine(self, line_geometry):
cur = arcpy.da.InsertCursor("NewL", ["SHAPE@"])
cur.insertRow([line_geometry])
arcpy.RefreshActiveView()
fields = arcpy.ListFields('NewL')
length = False
heightM = False
heightF = False
for field in fields:
if field.name == 'Length':
length = True
elif field.name == 'HeightM':
heightM = True
elif field.name == 'HeightF':
heightF = True
if length == False:
arcpy.AddField_management('NewL', 'Length', 'DOUBLE')
arcpy.RefreshActiveView()
if heightM == False:
arcpy.AddField_management('NewL', 'HeightM', 'DOUBLE')
arcpy.RefreshActiveView()
if heightF == False:
arcpy.AddField_management('NewL', 'HeightF', 'DOUBLE')
arcpy.RefreshActiveView()
arcpy.SelectLayerByAttribute_management('NewL', 'CLEAR_SELECTION')
arcpy.RefreshActiveView()
fid = int(arcpy.GetCount_management('NewL').getOutput(0))-1
arcpy.SelectLayerByAttribute_management('NewL', 'NEW_SELECTION', ''' FID = {} '''.format(fid))
arcpy.RefreshActiveView()
arcpy.CalculateField_management('NewL', 'Length', '!shape.length@meters!', 'PYTHON_9.3')
arcpy.RefreshActiveView()
arcpy.SelectLayerByLocation_management('Source_Package', 'INTERSECT', 'NewL')
with arcpy.da.SearchCursor('Source_Package', ['SunElevati']) as cursor:
for feat in cursor:
new_heightM = math.tan(math.radians(feat[0]))
arcpy.SelectLayerByAttribute_management('Source_Package', 'CLEAR_SELECTION')
arcpy.RefreshActiveView()
arcpy.CalculateField_management('NewL', 'HeightM', '!Length!*{}'.format(new_heightM), 'PYTHON_9.3')
arcpy.RefreshActiveView()
arcpy.CalculateField_management('NewL', 'HeightF', '!HeightM!*3.28089895', 'PYTHON_9.3')
arcpy.RefreshActiveView()
This code generates a line with attribution depending on the polygon it is overlapping. Is it possible to take the first vertex of the line and create a point in another feature class, while simultaneously transferring the attribution?
I was thinking (line_geometry.firstPoint.X, line_geometry.firstPoint.Y) would create the coordinates, but I am still considering other possibilities.
Edit 1:
point = arcpy.Point(line_geometry.firstPoint.X, line_geometry.firstPoint.Y)
pt_cur = arcpy.da.InsertCursor(Point Feature Here, ['SHAPE@'])
pt_cur.insertRow([point])
arcpy.RefreshActiveView()
I added this to the end and I have created the point I desired, now I am working on transferring the attributes.
Edit 2:
I have also successfully added the attribution aspect.