He escrito un guión con el objetivo de producir un buffer rectangular de dos sistemas de coordenadas que indican los extremos de una línea. El objetivo es crear una matriz de puntos de los extremos de la línea y crear un polígono de ellos.
Mi herramienta es informar como trabajo pero no está creando un ouput (he revisado la carpeta de salida):
import arcpy
import math
import sys
def getBearing(x0,y0,x1,y1):
deltaX = x1 - x0
deltaY = y1 - y0
return ((math.atan2(deltaY, deltaX)/math.pi*180)+360) % 360
def createRectpoints(x0,y0,x1,y1,displacement,bearing):
#Bottom left corner.
xr_1 = x0 - (displacement*math.cos(math.radians(90-bearing)))
yr_1 = y0 + (displacement*math.cos(math.radians(bearing)))
#Bottom right corner.
xr_2 = x0 + (displacement*math.cos(math.radians(90-bearing)))
yr_2 = y0 - (displacement*math.cos(math.radians(bearing)))
#Top left corner.
xr_3 = x1 - (displacement*math.cos(math.radians(90-bearing)))
yr_3 = y1 + (displacement*math.cos(math.radians(bearing)))
#Top right corner.
xr_4 = x1 + (displacement*math.cos(math.radians(90-bearing)))
yr_4 = y1 - (displacement*math.cos(math.radians(bearing)))
bl_corner = (xr_1, yr_1)
br_corner = (xr_2, yr_2)
tl_corner = (xr_3, yr_3)
tr_corner = (xr_4, yr_4)
rectangle_points = [bl_corner, br_corner, tl_corner, tr_corner]
return rectangle_points
if __name__ == '__main__':
# Take in Arguments
# Arguments are optional
outFC_location = arcpy.GetParameterAsText(0)
end1_Easting = float(arcpy.GetParameterAsText(1))
end1_Northing = float(arcpy.GetParameterAsText(2))
end2_Easting = float(arcpy.GetParameterAsText(3))
end2_Northing = float(arcpy.GetParameterAsText(4))
fcName = (arcpy.GetParameterAsText(5))
fcPath = outFC_location.rpartition("\\")[0]
outFC = arcpy.CreateFeatureclass_management(fcPath, fcName)
x0 = 500138
y0 = 348941
x1 = 502291
y1 = 349303
thickness = 180
displacement = thickness/2
bearing = getBearing(x0,y0,x1,y1)
ext_r_points = createRectpoints(x0,y0,x1,y1, displacement, bearing)
polygon_array = arcpy.Array([arcpy.Point(ext_r_points[0][0], ext_r_points[0][1]),arcpy.Point(ext_r_points[1][0], ext_r_points[1][1]), arcpy.Point(ext_r_points[2][0], ext_r_points[2][1]),arcpy.Point(ext_r_points[3][0], ext_r_points[3][1])])
mypolygon = arcpy.Polygon(polygon_array)
cursor = arcpy.da.InsertCursor(outFC, ['SHAPE@'])
cursor.insertRow([mypolygon])
¿Cuál es el error en mi codigo o mi enfoque?