TransWikia.com

Modifying parameters in Subdivide Polygon to obtain value from attribute table

Geographic Information Systems Asked by user186831 on June 28, 2021

I want to split polygons in half, like if a building were split by its roof ridge. I’ve somehow managed to obtain this in model builder by doing calculations on geometry statistics but as the input data might consist of 50,000+ polygons it’s clunky and slow.

There’s a tool in ArcGIS Pro, Subdivide Polygons, which is far more faster and would have given the desirable output. If it would only have allowed to use attribute values as an input for Split angle but instead you have to define a fixed value, which would be 0 in the snippet below.

I’m really a beginner at python, but would there be a way to modify the parameter so that it obtains the value from the attribute table rather than using a fixed value?

import arcpy

arcpy.env.workspace = r"C:/data/project.gdb"
arcpy.SubdividePolygon_management(
    "studyarea", "subdivisions", "NUMBER_OF_EQUAL_PARTS", 10, "", "", 0, 
    "STRIPS")

One Answer

I am running ArcGIS 10.8, but I cannot find subdivide polygon tool. Anyway, the idea is to rotate original polygons around centroid (so you can use same rotation angle in subdivide tool) and un-rotate results after. So, I used 2 tools, - add geometry attributes to compute centroid coordinates and minimum bounding geometry to calculate polygon orientation:

enter image description here enter image description here

I ran this on field Shape of the copy(!) of originals:

from math import sin, cos
def RotateLine(x0,y0, shp,a):
  a=  math.radians(a)
  part=shp.getPart(0)
  ar=arcpy.Array()
  for i in range(len(part)):
    p=part.getObject(i)
    x,y = p.X-x0, p.Y-y0
    xN=cos(a)*x+sin(a)*y
    yN=-sin(a)*x+cos(a)*y
    pN=arcpy.Point(xN+x0,yN+y0)
    ar.add(pN)
  lineRotated=arcpy.Polygon(ar)
  return lineRotated

#-----------------------

RotateLine( !INSIDE_X!, !INSIDE_Y!, !Shape!, !MBG_Orientation! )

I used my own procedure, to split polygon and un-rotated results:

RotateLine( !INSIDE_X!, !INSIDE_Y!, !Shape!, -!MBG_Orientation! )

Note minus in above!

Output:

enter image description here

Answered by FelixIP on June 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP