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?

3
  • 2
    You're not going to get projected units at the same angle of rotation as Cartesian degrees.
    – Vince
    Nov 11, 2014 at 0:12
  • 2
    Is your problem that print math.tan(math.radians(60) * -114.09341083433694) * -114.09341083433694 returns 11.1963055307 when you would expect it be much closer to -114?
    – PolyGeo
    Nov 11, 2014 at 0:18
  • 1
    @PolyGeo Yes that's the problem Nov 11, 2014 at 0:33

3 Answers 3

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

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)
3
  • Isn't it the answer I gave?
    – FelixIP
    Nov 11, 2014 at 20:25
  • 1
    @Felix If you mean your first post, sort of... If you mean your second post then yes. Nov 11, 2014 at 22:19
  • thanks. Doesn't matter where the green thing is.
    – FelixIP
    Nov 12, 2014 at 0:32
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/

5
  • 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, 2014 at 0: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 Nov 11, 2014 at 0:47
  • I think the answer is in here: arcgis.com/home/item.html?id=9398bd2232cb4c8490b0b05015364d28 and geonet.esri.com/thread/48226 but will need to look at more tomorrow to figure it all out. Nov 11, 2014 at 1:23
  • @TForward I think both those links seek to meet requirements considerably more complex than the one described in your question.
    – PolyGeo
    Nov 11, 2014 at 1: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. Nov 11, 2014 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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