3

In How Create Fishnet works from the ArcGIS Help it says:

Calculating a value for the y-axis coordinate
If you know the angle of rotation, you can compute a value for the Y-Axis Coordinate parameter as follows:

Tangent of angle = x-coordinate / y-coordinate

Fishnet Y-Axis point calculation
For example, the angle is 60 degrees. Assuming the y-coordinate to be 10, then

x-coordinate = tan(60) * 10 = 1.732 * 10 = 17.32

The y-axis coordinate point is (17.32,10).

In Python.

x-coordinate = (math.tan(math.radians(60) * 10) * 10)
print x-coordinate
>>>17.32

Perfect that's correct!

Now lets try using a real coordinate

Lat = 51.003757 Long, -114.09341083433694
or in NAD83 UTM Zone 11
x, y = 703919.581359, 5654264.1538 in UTM Zone 11

Using the same formula replacing 10 with the y-coordinate of the lat/long, and x,y of UTM as above none of the results make sense. What am I missing?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Tristan Forward
  • 2,199
  • 3
  • 23
  • 43

3 Answers3

3

Here is the answer I ended up using:

    def rotate_point(input_point, center_point, angle=0):
        angle = math.radians(angle)
        x = float(input_point.X) - float(center_point.X)
        y = float(input_point.Y) - float(center_point.Y)
        xr = (x * math.cos(angle)) - (y * math.sin(angle)) + float(center_point.X)
        yr = (x * math.sin(angle)) + (y * math.cos(angle)) + float(center_point.Y)
        return arcpy.Point(xr, yr)
Tristan Forward
  • 2,199
  • 3
  • 23
  • 43
3
import arcpy, traceback, os, sys, math
from math import radians,sin,cos
from arcpy import env
env.overwriteOutput = True
inFC=arcpy.GetParameterAsText(0)
outFolder=arcpy.GetParameterAsText(1)
nRows,nCols=4,3
env.workspace = outFolder
rectangle=r'in_memory\rectangle'
tempf=r'in_memory\many'
outFile="fnet.shp"
## ERROR HANDLING
def showPyMessage():
    arcpy.AddMessage(str(time.ctime()) + " - " + message)
def ShapeMake(pGon,angle):
    ar=arcpy.Array()
    a=radians(angle)
    part=pGon.getPart(0)
    for p in part:
        x,y=p.X,p.Y
        xN=cos(a)*x+sin(a)*y
        yN=-sin(a)*x+cos(a)*y
        pN=arcpy.Point(xN,yN)
        s='%s %s' %(xN,yN)
        ar.add(pN)
    pgonRotated=arcpy.Polygon(ar)
    return pgonRotated
try:
    arcpy.MinimumBoundingGeometry_management(inFC,rectangle,
                                             "RECTANGLE_BY_WIDTH", "ALL", "", "MBG_FIELDS")
    with arcpy.da.SearchCursor(rectangle, ("SHAPE@","MBG_Orientation")) as rows:
        for row in rows:
            shp,angle = row
        del row,rows
    onside=ShapeMake(shp,-angle)
    extent=onside.extent
    origPoint='%s %s' %(extent.XMin,extent.YMin)
    yPoint='%s %s' %(extent.XMin,extent.YMax)
    endPoint='%s %s' %(extent.XMax,extent.YMax)
    arcpy.CreateFishnet_management(tempf, origPoint,yPoint,
                                   "0", "0", nRows, nCols,endPoint,
                                   "NO_LABELS", "", "POLYGON")
    with arcpy.da.UpdateCursor(tempf, "SHAPE@") as rows:
        for row in rows:
            shp = row[0]
            rollBack=ShapeMake(shp,angle)
            row[0]=rollBack
            rows.updateRow(row)
        del row,rows
    arcpy.CopyFeatures_management(tempf, outFolder+os.sep+outFile)
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()

this is example of output enter image description here

Yes it is more than 2 lines of code

FelixIP
  • 22,922
  • 3
  • 29
  • 61
0

You are rotating around origin point(0,0). The correct way to find a couple of points to specify rotation is this http://www.mathematics-online.org/inhalt/aussage/aussage444/

FelixIP
  • 22,922
  • 3
  • 29
  • 61
  • Are you able to translate the maths at that link into Python code for the question's asker? If so, that is something I would be keen to upvote, and I bet you would get accepted. – PolyGeo Nov 11 '14 at 00:43
  • 1
    I would upvote most def. I am trying to do it put getting this angle = 60 x_new = math.cos(angle)x - math.sin(angle)y print x_new>>>124.210532308 Which is not correct – Tristan Forward Nov 11 '14 at 00:47
  • I think the answer is in here: http://www.arcgis.com/home/item.html?id=9398bd2232cb4c8490b0b05015364d28 and https://geonet.esri.com/thread/48226 but will need to look at more tomorrow to figure it all out. – Tristan Forward Nov 11 '14 at 01:23
  • @TForward I think both those links seek to meet requirements considerably more complex than the one described in your question. – PolyGeo Nov 11 '14 at 01:39
  • @PolyGeo I apologize, I realize that and it did in fact have the answer to what I was looking for rotating a point which I posted. The rest I used as well but is part of a much bigger problem as you mentioned. – Tristan Forward Nov 11 '14 at 17:05