Giter Club home page Giter Club logo

pygeoif's Issues

Initial Update

The bot created this issue to inform you that pyup.io has been set up on this repo.
Once you have closed it, the bot will open pull requests for updates as soon as they are available.

Can't run test_factories.py

Trying to run test_factories.py throws an error:
"cannot import name 'factories' from 'pygeoif'"

Running factories.py in turn throws:
"ImportError: cannot import name 'GenericAlias' from partially initialized module 'types' (most likely due to a circular import)"

Properties, CRS and other optional geo_interface items

I might have overlooked it but it seems like the as_shape function and geometry classes don't take advantage of any of the optional geo_interface keys (and that the geo_interface specification itself omits the crs key in the GeoJSON standard). Could you provide some detail on why these were omitted? Are these things that you felt that pygeoif users should implement themselves?

Would pull requests that implemented them be looked upon favorably or at least be something you would be interested in reviewing and discussing?

Thanks for your work on pygeoif!

Wrong Multipolygon

Hi there, I am reading a shapefile with pyshp:

sf = shapefile.Reader(os.path.join(cwd, shapefile_name))

for i in range(3):
    print(pygeoif.as_shape(sf.shape(i)).wkt)

The print result is the following one, with three single Polygon:

POLYGON((10.225265936197262 52.55248772818054, 10.2245 52.5526, 10.239898977006918 52.587244203792714, 10.257158479683646 52.626074168135474, 10.852814795836748 53.96616570784997, 10.869259391910935 54.00316231726286, 10.8855 54.0397, 10.886403440289543 54.0395673568947, 13.6072 53.6401, 13.588449967690627 53.603121815044084, 12.878710662659484 52.20339775809922, 12.8599 52.1663, 10.225265936197262 52.55248772818054))
POLYGON((4.994589472083415 51.136294699609905, 4.99387 51.1364, 5.009205610686967 51.17282464256336, 5.024854148511461 51.20999253946237, 5.590074308333594 52.552485036916316, 5.605067138274774 52.58809551782692, 5.62111 52.6262, 5.621949238159022 52.626076986136376, 8.26066 52.2393, 8.24233115618 52.20101287449061, 7.570667393061582 50.79797430581851, 7.55335 50.7618, 4.994589472083415 51.136294699609905))
POLYGON((11.174866239143656 51.13628785575964, 11.1741 51.1364, 11.1904078402353 51.175130145676, 11.205089843196898 51.20999902501951, 11.770362674077559 52.55248820634584, 11.7850061463172 52.58726557752808, 11.8014 52.6262, 11.802253839101338 52.62607484358844, 14.4409 52.2393, 14.422065104984824 52.19995522778889, 13.751660545626997 50.79952721075059, 13.7336 50.7618, 11.174866239143656 51.13628785575964))

Now, I am using pygeoif to create a Multipolygon with these given Polygon:

m = pygeoif.MultiPolygon(sf.shapes())
print(m.wkt)

and the result is broken (missing comma separation).

MULTIPOLYGON(((10.225265936197262 52.55248772818054, 10.2245 52.5526, 10.239898977006918 52.587244203792714, 10.257158479683646 52.626074168135474, 10.852814795836748 53.96616570784997, 10.869259391910935 54.00316231726286, 10.8855 54.0397, 10.886403440289543 54.0395673568947, 13.6072 53.6401, 13.588449967690627 53.603121815044084, 12.878710662659484 52.20339775809922, 12.8599 52.1663, 10.225265936197262 52.55248772818054))((4.994589472083415 51.136294699609905, 4.99387 51.1364, 5.009205610686967 51.17282464256336, 5.024854148511461 51.20999253946237, 5.590074308333594 52.552485036916316, 5.605067138274774 52.58809551782692, 5.62111 52.6262, 5.621949238159022 52.626076986136376, 8.26066 52.2393, 8.24233115618 52.20101287449061, 7.570667393061582 50.79797430581851, 7.55335 50.7618, 4.994589472083415 51.136294699609905))((11.174866239143656 51.13628785575964, 11.1741 51.1364, 11.1904078402353 51.175130145676, 11.205089843196898 51.20999902501951, 11.770362674077559 52.55248820634584, 11.7850061463172 52.58726557752808, 11.8014 52.6262, 11.802253839101338 52.62607484358844, 14.4409 52.2393, 14.422065104984824 52.19995522778889, 13.751660545626997 50.79952721075059, 13.7336 50.7618, 11.174866239143656 51.13628785575964)))

If I add comma as separator, I get this:

MULTIPOLYGON(((10.225265936197262 52.55248772818054, 10.2245 52.5526, 10.239898977006918 52.587244203792714, 10.257158479683646 52.626074168135474, 10.852814795836748 53.96616570784997, 10.869259391910935 54.00316231726286, 10.8855 54.0397, 10.886403440289543 54.0395673568947, 13.6072 53.6401, 13.588449967690627 53.603121815044084, 12.878710662659484 52.20339775809922, 12.8599 52.1663, 10.225265936197262 52.55248772818054)),((4.994589472083415 51.136294699609905, 4.99387 51.1364, 5.009205610686967 51.17282464256336, 5.024854148511461 51.20999253946237, 5.590074308333594 52.552485036916316, 5.605067138274774 52.58809551782692, 5.62111 52.6262, 5.621949238159022 52.626076986136376, 8.26066 52.2393, 8.24233115618 52.20101287449061, 7.570667393061582 50.79797430581851, 7.55335 50.7618, 4.994589472083415 51.136294699609905)),((11.174866239143656 51.13628785575964, 11.1741 51.1364, 11.1904078402353 51.175130145676, 11.205089843196898 51.20999902501951, 11.770362674077559 52.55248820634584, 11.7850061463172 52.58726557752808, 11.8014 52.6262, 11.802253839101338 52.62607484358844, 14.4409 52.2393, 14.422065104984824 52.19995522778889, 13.751660545626997 50.79952721075059, 13.7336 50.7618, 11.174866239143656 51.13628785575964)))

Graham Scan as an alternative convex hull algorithm.

def orientation(p, q, r):
    """
    Calculate orientation of three points (p, q, r).
    Returns:
    -1 if counterclockwise
    0 if colinear
    1 if clockwise
    """
    val = (q[1] - p[1]) * (r[0] - q[0]) - (q[0] - p[0]) * (r[1] - q[1])
    if val == 0:
        return 0
    return 1 if val > 0 else -1

def graham_scan(points):
    """
    Graham's scan algorithm to find the convex hull of a set of points.
    Returns the sorted points forming the convex hull.
    """
    n = len(points)
    if n < 3:
        return points

    # Find the point with the lowest y-coordinate (and leftmost if ties)
    pivot = min(points, key=lambda p: (p[1], p[0]))

    # Sort the points based on polar angle with respect to the pivot
    sorted_points = sorted(points, key=lambda p: (math.atan2(p[1]-pivot[1], p[0]-pivot[0]), p))

    # Initialize the stack
    stack = [pivot, sorted_points[0], sorted_points[1]]

    # Iterate over the sorted points
    for i in range(2, n):
        while len(stack) > 1 and orientation(stack[-2], stack[-1], sorted_points[i]) != -1:
            stack.pop()
        stack.append(sorted_points[i])

    return stack

# Example: Collection of arbitrary points
points = [(0, 0), (3, 1), (1, 2), (2, 3), (4, 4), (3, 0), (2, 1)]

# Sort the points to form a closed linear ring
sorted_ring = graham_scan(points)

print("Original Points:", points)
print("Sorted Linear Ring Points:", sorted_ring)

This implementation uses the Graham's scan algorithm to find the convex hull of the points, and the resulting sorted_ring contains the points forming a closed linear ring without self-intersections.

Pip 23.1 deprecation warning

Hello,

Thanks for all your work on this package.

I've noticed that that when installing in a fresh virtual environment I get the following warning:

DEPRECATION: fxpmath is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559

It looks like pip 23.1 is going to be released in the near future, so I thought I'd bring it to your attention.

Thanks again!

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.