Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    and-viceversa
    @and-viceversa
    Hello all, the github contact section pointed me here. I'd like to open a feature request to build oriented minimum bounding boxes from polygons, like you can do in QGIS. Having trouble implementing it on my own. This this an appropriate issue to open?
    Martin Fleischmann
    @martinfleis
    Hi, the built-in method will likely come soon, we have just recently implemented it in pygeos. At the moment, you can get it via oriented_box = gdf.geometry.apply(lambda geom: geom.minimum_rotated_rectangle)
    and-viceversa
    @and-viceversa
    Excellent! Much appreciated.
    and-viceversa
    @and-viceversa

    Still got some testing to do, but I ended up using https://github.com/dbworth/minimum-area-bounding-rectangle/blob/master/python/min_bounding_rect.py to make follow on operations easier.

    It looks like geom.minimum_rotated_rectangle doesn't guarantee right angles? They might be trying to accomplish different things.

    Martin Fleischmann
    @martinfleis
    @and-viceversa that doesn't sound right. Can you show an example when it doesn't return right angles?
    and-viceversa
    @and-viceversa

    Short answer everything works as intended - thank you again. FWIW the github link to min_bounding_rect.py returns identical return as geom.minimum_rotated_rectangle.

    Long answer is that the KML writer enforces geographic coordinates, which I did not know. So QGIS' project on the fly visually was not showing a true rectangle versus the underlying (in my case) local UTM. I had done quick tests with min_bounding_rect.py at large scales only, and tests with minimum_rotated_rectangle at small scale only. Obviously at large scale the difference in the projection were not as noticeable so the two calls appeared to have different results. Using the same projections for minimum rectangle and the underlying in a non-KML format works as intended.

    Shirzart Enwer
    @Aniwax
    Hello everyone :) As a completely freshman to pygeos, I just have simple question on data input format when constructing a geometry in pygeos: is there other input data format possible other than string?
    I want to construct polygon, whose boundary points are returned from a list of numbers....it's quite cumbersome to convert it in the desired string format.
    Martin Fleischmann
    @martinfleis
    @Aniwax you can pass arrays of coordinates, see the docs here https://pygeos.readthedocs.io/en/latest/creation.html (for linearrings and polygons)
    Shirzart Enwer
    @Aniwax
    Thanks! @martinfleis , another dummy question: what's the difference between linearrings and polygon? If I don't need any hole in a within the boundary of my geometry, do I just need linearrings and not polygon?
    Martin Fleischmann
    @martinfleis
    Linearring is linear geometry (just that exterior line) while polygon covers an area it encloses.
    Shirzart Enwer
    @Aniwax
    Alright, got it, thanks!
    Alex Yule
    @yuletide
    Hey folks, working on a project and ran into a bunch of "illegalArgumentException: Geometry must be a Point or LineString" when exporting a dataframe to json (or passing it into rasterstats). Any idea what could cause this? The geometry seems valid and plots fine. I'm using Shapely 1.8a1 but unable to reproduce with sample data. This data is a large set of isochrones created using the Mapbox API.
    Happy to create a ticket but didn't want to clutter things up if there's something I should try first
    The project is analyzing internet connectivity in Kazakhstan for Unicef GIGA
    Martin Fleischmann
    @martinfleis
    I think we’ll need more info, code and ideally reproducible example or a some way to reproduce it. Best to file it as a bug or question on GitHub
    Alex Yule
    @yuletide
    Sounds good, I'll try to put together a smaller dataset that produces the same errors!
    Thanks Martin
    Shirzart Enwer
    @Aniwax
    Hey Guys, I have the issue of not the same version of GEOS used, when I try to install Shapely and Pygeos in the same environment on Github Actions to run my automated tests. I could resolved this problem on my machine by replacing the geos_c.dill file inside the Shapely package, but I don't know how to resolve it on the cloud. I am using Windows both on the cloud and local environment.
    Any suggestions? Appreciated :)
    Martin Fleischmann
    @martinfleis
    @Aniwax how are you installing shapely and pygeos? Try to use conda and conda-forge channel, which should resolve this. Check geopandas CI how we do it on GHA if you need an example.
    Shirzart Enwer
    @Aniwax
    I am using pip install @martinfleis but will try conda channel
    Martin Fleischmann
    @martinfleis
    pip install is not recommended for geopandas and its dependencies as it is not able to ensure compatibility of C libraries (like in this case)
    Shirzart Enwer
    @Aniwax
    Damn, alright. I usually prefer pip for my python environment management. But anyway, I will try this on the cloud. Thanks for your lightening-speed reply as always :)
    Shirzart Enwer
    @Aniwax
    Hi Community, I am wondering if there is any general guide on how to exploit the vectorized-operation the best to improve the runtime of code using pygeos?
    Appreciate any suggestions :)
    Martin Fleischmann
    @martinfleis
    I am not aware of a ready-made guide for geopandas (apart from the one on my long to-do list). Generally speaking, avoid for loops, avoid apply and try to rely as much as you can on built-in GeoSeries methods. If needed use the underlying array of pygeos geometries directly with pygeos functions. You can access it as gdf.geometry.values.data. When you can use numpy functions instead of for loops, use them. Look up some vectorization guide for pandas, the rules are fairly similar. And when using spatial index, use query_bulk.
    Shirzart Enwer
    @Aniwax
    Thanks ! As I am only using pygeos, not Geopandas, then it's quite straight forward in my case then I guess: use pygeos directly as much as possible, without breaking the design?
    Brendan Ward
    @brendan-ward
    @Aniwax correct: you can use the pygeos functions directly to leverage the speedups (they are already vectorized in most cases). There are a few cases where the pygeos functions operate on singular geometries where you may need to do a bit more to vectorize them (e.g., get_geometry), but we've been adding more functions to vectorize the most common operations where you would get these back as ragged arrays (e.g., get_parts), where there are varying numbers of geometries within arrays of multi / geometry collections.
    If you run into a case where trying to use pygeos to get what you need isn't obvious, certainly feel free to ask here.
    Shirzart Enwer
    @Aniwax
    @brendan-ward Thanks a lot :)
    Alex Yule
    @yuletide
    @martinfleis Ticket filed! #1943
    I created a minimal test dataset with one feature
    robertbozsik
    @robertbozsik
    Hi there,
    I've seen you have already talked about this warning in January.
    UserWarning: The Shapely GEOS version (3.8.0-CAPI-1.13.1 ) is incompatible with the GEOS version PyGEOS was compiled with (3.9.0-CAPI-1.16.2). Conversions between both will be slow.
    Is there any "pip install" solution to get rid of the warning besides installing geopandas with conda/conda forge?
    I would like to integrate a new geopandas spatial join feature into a package created by poetry and I cannot use a conda.
    Joris Van den Bossche
    @jorisvandenbossche
    I don't think there is an easy way with the current built wheels (except by installing from source). It might be that an older version of PyGEOS' wheels are built with GEOS 3.8.0, but not fully sure.
    (it might also be that you can ignore the warning, depending on your use case)
    robertbozsik
    @robertbozsik
    I could ignore the warning but this package is a command-line tool used by non-programmer colleagues to run some reports. It would be confusing for them to see a warning that they cannot understand.
    Can you please recommend any resource (link, video, blog post, ...) where I can check how to install from source?
    I also tried to use rtree instead of pygeos. Although the warning disappeared, the spatial join was much slower with rtree.
    Joris Van den Bossche
    @jorisvandenbossche
    The shapely readme (https://github.com/Toblerity/Shapely/) has some info about how to install from source. I think the main thing is to get an install of GEOS. Once that is available, installing shapely/pygeos from source is not that hard
    If it's just for the warning being visible, you could also suppress the warning with the warnings python package, you can filter that specific UserWarning
    Martin Fleischmann
    @martinfleis
    Just heads up that we'll be working on centralised XYZ services package (geopandas/contextily#153) today. I am going to create a new repo for that under geopandas org.
    robertbozsik
    @robertbozsik
    Thank you for your recommendation, @jorisvandenbossche!
    I managed to suppress the UserWarning with this small code snippet at the top of the main file of the package:
    import warnings warnings.filterwarnings("ignore", message="The Shapely GEOS version")
    and-viceversa
    @and-viceversa
    Hello all! What is the best way to plot each individual feature from a GeoDataFrame? I'm trying to quickly make many simple plots at once. I've tried variations on the following, but it feels a bit hacky.
    for feature in gdf.iterfeatures():
        temp = gpd.GeoSeries(Point(*feat['geometry']['coordinates'][0]), crs=gdf.crs)
        ax = temp.plot(figsize=(20, 20), color='red', marker='o', alpha=0.9)
        ctx.add_basemap(ax=ax)
        fig = ax.get_figure()
        fig.savefig('.../out/path/...')
    Martin Fleischmann
    @martinfleis
    Hi all, the link for the meeting is here https://meet.google.com/bfa-crgm-cbn
    Levi John Wolf
    @ljwolf
    I won’t be able to attend this one! My apologies
    Shirzart Enwer
    @Aniwax

    Hey guys,

    A question here about constructing polygons with 3 points using pygeos.polygons. I got Invalid number of points in LinearRing found 3. Is there a way to get around this?

    Shirzart Enwer
    @Aniwax
    I see a similar discussion here pygeos/pygeos#150. But before any progress there, is there any quick fix to detect and remove the invalid points?
    Martin Fleischmann
    @martinfleis
    x_coords = np.array([[1, 2, 3], [4, 5, 6]])
    y_coords = np.array([[1, 2, 3], [4, 5, 6]])
    pygeos.polygons(pygeos.linearrings(x_coords, y=y_coords))
    array([<pygeos.Geometry POLYGON ((1 1, 2 2, 3 3, 1 1))>,
           <pygeos.Geometry POLYGON ((4 4, 5 5, 6 6, 4 4))>], dtype=object)
    try to get your coordinates in a structure like this
    Shirzart Enwer
    @Aniwax
    Great! It works out of the box. Thanks @martinfleis
    Shirzart Enwer
    @Aniwax
    Hey guys,
    I encountered 'divided by zero' error, while using union. The error message is RuntimeWarning: divide by zero encountered in unary_union result = lib.unary_union(collections, **kwargs). What would have caused this error? And is there a quick fix?
    Martin Fleischmann
    @martinfleis
    are all your polygons valid? never seen this error in union
    Shirzart Enwer
    @Aniwax
    I didn't get polygon invalid error...I use pygeos.make_valid() if I found any invalid polygons during the process.
    Martin Fleischmann
    @martinfleis
    if you are able to figure out which geometries are causing this, you may want to report it to pygeos repo. This error message makes a little sense in this context.