How to calculate position in a clockwise manner?

387
3
Jump to solution
12-01-2023 08:31 AM
Davec43
Occasional Contributor

I have data with X/Y data that plots and I'm trying to get it to look like so:

Sort.png

I've tried near analysis, and it gets me close but doesn't label them in a clockwise manner. Is there any geoprocessing tool or arcpy process that I'm overlooking that will accomplish this?

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

slow week

aoi  # a square
array([[  0.00,   5.00],
       [  5.00,  10.00],
       [ 10.00,   5.00],
       [  5.00,   0.00],
       [  0.00,   5.00]])

def geom_angles(a, fromNorth=False):
    """Polyline/segment angles.

    Parameters
    ----------
    a : array-like
        A Geo array or a list of arrays representing the polyline shapes.
    """
    out = []
    dxy = a[1:] - a[:-1]
    ang = np.degrees(np.arctan2(dxy[:, 1], dxy[:, 0]))
    if fromNorth:
        ang = np.mod((450.0 - ang), 360.)
    return ang
    

geom_angles(aoi, fromNorth=False)  # -- option 1
array([ 45.00, -45.00, -135.00,  135.00])

geom_angles(aoi, fromNorth=True)  # -- option 2
array([ 45.00,  135.00,  225.00,  315.00])

cent = np.mean(aoi[:-1])  # -- now from the center of the points
vals = aoi - cent  # -- angles from the center

vals 
array([[ -5.00,   0.00],
       [  0.00,   5.00],
       [  5.00,   0.00],
       [  0.00,  -5.00],
       [ -5.00,   0.00]])

geom_angles(vals, fromNorth=False)
array([ 45.00, -45.00, -135.00,  135.00])

geom_angles(vals, fromNorth=True)
array([ 45.00,  135.00,  225.00,  315.00])

... sort of retired...

View solution in original post

0 Kudos
3 Replies
VinceAngelo
Esri Esteemed Contributor

You can write your own, but I doubt there's any general purpose tool for this.

The atan2 function takes dy & dx parameters, but that's counter-clockwise from 3-o'clock,
so you'd need to reverse the sign and rotate.

- V

0 Kudos
DanPatterson
MVP Esteemed Contributor

slow week

aoi  # a square
array([[  0.00,   5.00],
       [  5.00,  10.00],
       [ 10.00,   5.00],
       [  5.00,   0.00],
       [  0.00,   5.00]])

def geom_angles(a, fromNorth=False):
    """Polyline/segment angles.

    Parameters
    ----------
    a : array-like
        A Geo array or a list of arrays representing the polyline shapes.
    """
    out = []
    dxy = a[1:] - a[:-1]
    ang = np.degrees(np.arctan2(dxy[:, 1], dxy[:, 0]))
    if fromNorth:
        ang = np.mod((450.0 - ang), 360.)
    return ang
    

geom_angles(aoi, fromNorth=False)  # -- option 1
array([ 45.00, -45.00, -135.00,  135.00])

geom_angles(aoi, fromNorth=True)  # -- option 2
array([ 45.00,  135.00,  225.00,  315.00])

cent = np.mean(aoi[:-1])  # -- now from the center of the points
vals = aoi - cent  # -- angles from the center

vals 
array([[ -5.00,   0.00],
       [  0.00,   5.00],
       [  5.00,   0.00],
       [  0.00,  -5.00],
       [ -5.00,   0.00]])

geom_angles(vals, fromNorth=False)
array([ 45.00, -45.00, -135.00,  135.00])

geom_angles(vals, fromNorth=True)
array([ 45.00,  135.00,  225.00,  315.00])

... sort of retired...
0 Kudos
Davec43
Occasional Contributor

Thanks Dan!

0 Kudos