Friday, 6 July 2018

arcmap - Cutting rectangle set (not squares) into triangles using ArcGIS for Desktop?


I have some large features that I need to split into smaller pieces for terrain alignment through vertices in another program. I figured triangles would be the best solution.


So basically I want to turn this:


enter image description here


into this:


enter image description here


Sadly the latter image is a mockup. I had some success with the fishnet tool and intersecting to create rectangles, but I can't get triangles out of it. Rotating the net doesn't work because the rectangles aren't square. Any ideas that don't involve manual cutting?



Answer



One of multiple solutions. Create points inside polygon, fishnet will do. Add vertices of polygons to this set. Create TIN. Export tin triangles and clip them: enter image description here



Updated answer on points creation. Script below works from ArcGIS and takes 3 parameters:



  1. Layer in TOC. Used to define extent.

  2. Distance between points, type double

  3. Points layer (empty)


import arcpy, traceback, os, sys extentLayer = arcpy.GetParameterAsText(0) xStep = float(arcpy.GetParameterAsText(1)) destLayer = arcpy.GetParameterAsText(2)


try:
def showPyMessage():
arcpy.AddMessage(str(time.ctime()) + " - " + message)

def isLayerExist(lName):
layer = arcpy.mapping.ListLayers(mxd,lName)[0]
ext=layer.getSelectedExtent()
return (layer,ext)
mxd = arcpy.mapping.MapDocument("CURRENT")
destLayer, anExt=isLayerExist(destLayer)
extentLayer, anExt=isLayerExist(extentLayer)
yMin,yMax,xS,xE=anExt.YMin,anExt.YMax,anExt.XMin,anExt.XMax
yStep=xStep/2*math.pow(3.0,0.5)
curT = arcpy.da.InsertCursor(destLayer,"SHAPE@")

p=arcpy.Point()
iMax=int((yMax-yMin)/yStep)+2
jMax=int((xE-xS)/xStep)+2
for i in range(iMax):
Y=yMin+i*yStep
xStart=xS+i%2*xStep/2
xEnd = xE +i%2*xStep/2
for j in range(jMax):
X=xStart+j*xStep
p.X,p.Y=X,Y

theRow=(p,)
curT.insertRow(theRow)
except:
message = "\n*** PYTHON ERRORS *** "; showPyMessage()
message = "Python Traceback Info: " + traceback.format_tb(sys.exc_info()[2])[0]; showPyMessage()
message = "Python Error Info: " + str(sys.exc_type)+ ": " + str(sys.exc_value) + "\n"; showPyMessage()

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...