GithubHelp home page GithubHelp logo

Comments (3)

JessicaS11 avatar JessicaS11 commented on August 18, 2024 1

Turns out shapely polygons have an orient method (thanks to @asteiker for sharing that!)

from icepyx.

ShashankBice avatar ShashankBice commented on August 18, 2024

Points reordering should be simple to implement with some math like this: https://stackoverflow.com/questions/51074984/sorting-according-to-clockwise-point-coordinates/51075469. I can try tonight and see if it works..

from icepyx.

ShashankBice avatar ShashankBice commented on August 18, 2024

I did a quick hack today,

from shapely.geometry import Point,Polygon
import numpy as np
def sort_cord_clockwise(reg_a_poly):
    # this assumes that the first and last coordinate tuples are the same..
    poly = Polygon(reg_a_poly)
    cx,cy = [poly.centroid.xy[0][0],poly.centroid.xy[1][0]]
    xy_sort = (sorted(reg_a_poly[:-1], key = lambda x: np.arctan2((x[1]-cy),(x[0]-cx))))
    #this returns counterclockwise 
    xy_sorted = list(reversed(xy_sort[1:]))
    xy_sorted.append(reg_a_poly[-1])
    out_xy = [reg_a_poly[-1]]+xy_sorted
    return list(out_xy)

Input: sort_cord_clockwise([(-64, 66),(-55, 72),(-55, 66),(-64, 72),(-64, 66)])
Out: [(-64, 66), (-64, 72), (-55, 72), (-55, 66), (-64, 66)]
Input: sort_cord_clockwise([(-64, 66),(-55, 66),(-64, 72),(-55, 72),(-64, 66)])
Out: (-64, 66), (-64, 72), (-55, 72), (-55, 66), (-64, 66)]

@JessicaS11, Can you check with other problematic inputs, specifically for which you got this error. You can also pass those inputs to me and I can check and refine..

from icepyx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.