在 arcpy 中围绕点创建矩形时如何定义单位?

问题描述 投票:0回答:1

因此,我尝试在地图上的点周围创建 50 米宽和 500 米宽的矩形。我使用了以下代码,该代码有效,但单位已关闭,因此矩形很大(参见照片)。

地图投影为WGS 1984,因此单位为十进制度。所以,我认为比例尺不正确的原因是长度和宽度的单位是米,而不是十进制度。因此,我计算了某点以东 50 米和以南 500 米的经纬度差,并将其用作长度和宽度。代码通过了,但输出没有显示任何功能(即使有属性表)。我想也许它不喜欢小数,但它适用于 w=0.1 和 h=1,直到我关闭图层然后再次打开。现在该图层不再显示。

我很茫然,我不知道我做错了什么。这是我使用的代码。

inFeatures = "potentialpoint.shp"
outFeatureClass = "rectanglestest.shp"
rectangleWidth= 50
rectangleHeight = 500

# create a new feature class to hold the rectangles
arcpy.CreateFeatureclass_management("D:\OceanWind2023\DepletionExperiments", outFeatureClass, "POLYGON")

# loop through each point and create a rectangle around it
with arcpy.da.SearchCursor(inFeatures, ["SHAPE@XY"]) as cursor:
    for row in cursor:
        x, y = row[0]
        array = arcpy.Array([arcpy.Point(x - rectangleWidth / 2.0, y - rectangleHeight / 2.0),
                             arcpy.Point(x - rectangleWidth / 2.0, y + rectangleHeight / 2.0),
                             arcpy.Point(x + rectangleWidth / 2.0, y + rectangleHeight / 2.0),
                             arcpy.Point(x + rectangleWidth / 2.0, y - rectangleHeight / 2.0)])
        polygon = arcpy.Polygon(array)
        with arcpy.da.InsertCursor(outFeatureClass, ["SHAPE@"]) as insertCursor:
            insertCursor.insertRow([polygon])
arcgis arcpy
1个回答
0
投票

pointFromAngleAndDistance 将为您提供以空间参考测量单位表示的距离。 作用于 XY 坐标在您的情况下的坐标系中为十进制度,因此您将 X 更改 25 度,Y 更改 250 度。

pnt = row[0]
array = arcpy.Array(
pnt.pointFromAngleAndDistance(, 251.247)...

我需要计算三角函数,但这就是你想要的

© www.soinside.com 2019 - 2024. All rights reserved.