0

I have a point dataset with 3 useful columns. Those are width, height and direction (degrees from 1 to 360). I would like to create rectangles using the width and height, and with the specific direction (orientation), either using ArcGIS or R code. Any ideas?

4
  • 1
    Please pick one software stack, as per the One question per Question policy. Note that 365 is 5 degrees too many for a proper degree range.
    – Vince
    Mar 26, 2020 at 21:22
  • Yes it's 1 to 360! (I believe I was thinking on days) Mar 26, 2020 at 23:58
  • What are the units of width? Are the rectangles large? Because a rectangle on a sphere is going to be very different to a rectangle in an X-Y coordinate system.
    – Spacedman
    Mar 27, 2020 at 8:01
  • Units are meters (the result would change but the process is the same). Mar 27, 2020 at 15:05

1 Answer 1

1
import arcpy

def rotateXY(x,y,xc=0,yc=0,angle=0,units = "DEGREES"):
    import math
    x = x - xc
    y = y - yc
    if units=="DEGREES":
        angle = math.radians(angle)
    xr = (x*math.cos(angle))-(y*math.sin(angle)) + xc 
    yr = (y*math.sin(angle))+(y*math.cos(angle)) + yc
    return xr,yr


def createIndexPoly(X,Y,h=5,w=5,sr=None):
    angle = 20
    if not h is None and not w is None:
        ### set up editor

        arrPnts = arcpy.Array()  
        # point 1  
        pnt = arcpy.Point(X-w/2,Y-h/2)  
        pnt = arcpy.Point(rotateXY(pnt.X,pnt.Y,X,Y,angle)[0],rotateXY(pnt.X,pnt.Y,X,Y,angle)[1])
        arrPnts.add(pnt)  
        # point 2  
        pnt = arcpy.Point(X-w/2,Y+h/2)  
        pnt = arcpy.Point(rotateXY(pnt.X,pnt.Y,X,Y,angle)[0],rotateXY(pnt.X,pnt.Y,X,Y,angle)[1])
        arrPnts.add(pnt)  
        # point 3  
        pnt = arcpy.Point(X+w/2,Y+h/2)  
        pnt = arcpy.Point(rotateXY(pnt.X,pnt.Y,X,Y,angle)[0],rotateXY(pnt.X,pnt.Y,X,Y,angle)[1])
        arrPnts.add(pnt)  
        # point 4  
        pnt = arcpy.Point(X+w/2,Y-h/2)  
        pnt = arcpy.Point(rotateXY(pnt.X,pnt.Y,X,Y,angle)[0],rotateXY(pnt.X,pnt.Y,X,Y,angle)[1])
        arrPnts.add(pnt)  
        # point 5 (close diamond)  
        pnt = arcpy.Point(X-w/2,Y-h/2)  
        pnt = arcpy.Point(rotateXY(pnt.X,pnt.Y,X,Y,angle)[0],rotateXY(pnt.X,pnt.Y,X,Y,angle)[1])
        arrPnts.add(pnt)  
        pol = arcpy.Polygon(arrPnts,sr,True,True)

        return pol



print(createIndexPoly(3000000,1000000))

The rotateXY function was taken from this thread https://community.esri.com/thread/48226

Not the answer you're looking for? Browse other questions tagged or ask your own question.