cleder / pygeoif Goto Github PK
View Code? Open in Web Editor NEWBasic implementation of the __geo_interface__ ๐๏ธ
Home Page: https://pygeoif.readthedocs.io
Basic implementation of the __geo_interface__ ๐๏ธ
Home Page: https://pygeoif.readthedocs.io
Add documentation similar to django-transitions
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.
https://inventwithpython.com/blog/2019/02/01/hashable-objects-must-be-immutable/
__slots__ = ("_geoms",)
def __init__(self, ...):
....
super.__setattr__(self, "_geoms", geoms)
def __setattr__(self, *args) -> NoReturn:
raise AttributeError(f"Attributes of {self.__class__.__name__} cannot be changed")
def __delattr__(self, *args) -> NoReturn:
raise AttributeError(f"Attributes of {self.__class__.__name__} cannot be deleted")
Ramer-Douglas-Peucker or Visvalingam-Whyatt algorithm.
https://github.com/omarestrella/simplify.py
https://github.com/jraedler/Polygon3/blob/master/Polygon/Utils.py
https://www.djangosnippets.org/snippets/1559/
https://github.com/CUUATS/geojson-vt-py/blob/master/geojsonvt/simplify.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)"
Instead of setup.py
the packaging configuration should be done with pyproject.toml
https://github.com/gvalkov/setuptools-py2cfg to convert setup.py to a config file and https://github.com/abravalheri/ini2toml to convert the setup.cfg
file into pyproject.toml
check the results with https://github.com/abravalheri/validate-pyproject https://github.com/tox-dev/pyproject-fmt and https://github.com/kieran-ryan/pyprojectsort
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!
Hi there,
I was wondering what version of LGPL license is pygeoif release under?
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)))
Add pre-commit and configuration .pre-commit-config.yaml
to run the static tests.
Run the static tests on pre-commit.ci
Use the Lark hypothesis extension to generate WKT from EBNF to improve hypothesis test cases.
It is possible to add GeometryCollection
s to a GeometryCollection
. Reflect this in the strategy to create recursive data
Test pygeoif
against these strategies, repr
and geometry.wkt
are Encode/Decode invariant
The strategies should be similar to hypothesis-geojson, but one should be able to create coordinates for any given CRS (SRS) with EPSG 4326 as a predefined shortcut
GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 0), MULTIPOINT (0 0, 1 1, 1 2, 2 2)), LINESTRING (0 0, 3 1)), POLYGON ((0 0, 1 1, 1 0, 0 0)))
cannot be parsed sucessfully
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.
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!
Move contents out of README into the sphinx documentation similar to django-transitions
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.