Arcgis将圆任意等分思路(附python实现代码)

 

整体需求:根据给定的一个坐标点(x,y),一个圆半径distance以及圆的任意等分数n,将一个圆等分成n个扇形Polygon。

总体思路:1.根据点坐标创建要素生成一个点图层

                  2.对点图层进行缓冲区分析生成一个圆

                  3.新建一个表(如下图,6等分)用于生成线

Arcgis将圆任意等分思路(附python实现代码)

                 4.用原点夹角距离定义线工具生成线

Arcgis将圆任意等分思路(附python实现代码)

                5.将生成的线和面作为输入参数进行要素转面操作,就得到了多个扇形面

Arcgis将圆任意等分思路(附python实现代码)

代码实现:

# -*- coding: utf-8 -*-
import arcpy
import os

# --------------- 自定义参数 -------------------
# 圆的等分个数
n = 6
# 中心点坐标
x = 833408.618
y = 3390153.422
# 圆形半径的距离,单位:km 
distances = [8]
# 工作目录
env = arcpy.env.workspace = "D:/data/"
# tif遥感图路径
tif = r"D:\data\q.tif"
# ---------------------------------------------

# 读取tif空间参考信息
tifsr = arcpy.Describe(tif).spatialReference

fc = "point.shp"
if os.path.exists(env + fc):
    arcpy.Delete_management(fc)
arcpy.AddField_management(fc, "NAME", "TEXT", "", "", "", "", "", "", "")

xy_values = [('point1', (x, y))]
cursor = arcpy.da.InsertCursor(fc, ("NAME", "[email protected]"))
for row in xy_values:
    cursor.insertRow(row)
del cursor

inFeatures = fc
outFeatureClass = "circle.shp"
bufferUnit = "Kilometers"
if os.path.exists(env + outFeatureClass):
    arcpy.Delete_management(outFeatureClass)
arcpy.MultipleRingBuffer_analysis(inFeatures, outFeatureClass, distances, bufferUnit, "", "ALL")

degrees = [(j + 1) * 360 / n for j in range(n)]
tablefc = arcpy.CreateTable_management(env, "table")
arcpy.AddField_management(tablefc, "distance", "DOUBLE", "", "", "", "", "", "", "")
arcpy.AddField_management(tablefc, "x", "DOUBLE", "", "", "", "", "", "", "")
arcpy.AddField_management(tablefc, "y", "DOUBLE", "", "", "", "", "", "", "")
arcpy.AddField_management(tablefc, "degrees", "FLOAT", "", "", "", "", "", "", "")

cursor = arcpy.InsertCursor(tablefc)
i = 0
while i < len(degrees):
    row = cursor.newRow()
    row.distance = distances[0]
    row.x = x
    row.y = y
    row.degrees = degrees[i]
    cursor.insertRow(row)
    i += 1
del cursor

arcpy.BearingDistanceToLine_management("table", "lines", "x", "y", "distance", bufferUnit, "degrees",
                                       "DEGREES", "", "", tifsr)

if os.path.exists(env + "sector.shp"):
    arcpy.Delete_management("sector.shp")
arcpy.FeatureToPolygon_management(["lines.shp", "circle.shp"], "sector.shp")

# ----------------删除中间数据------------------
if os.path.exists(env + fc):
    arcpy.Delete_management(fc)
if os.path.exists(env + outFeatureClass):
    arcpy.Delete_management(outFeatureClass)
if os.path.exists(env + "lines.shp"):
    arcpy.Delete_management("lines.shp")
if os.path.exists(env + "info"):
    arcpy.Delete_management("info")
# ---------------------------------------------