Comments (8)
Can you please provide a scenario that demonstrates this issue?
from rtree.
@hobu Thanks for the reply, the scenario is the following. First of all, here is the list of the versions that I am using:
- Python 3.8.12
- Django 4.0.2
- GeoPandas 0.10.2
- NumPy 1.22.2
- Shapely 1.8.1.post1
- Rtree 0.9.7
- libspatialindex 1.9.0-1
I am running it on a Bitnami instance on a Debian GNU/Linux 10 (buster) VPS. When I run it locally, on macOS, this error never appears.
I have a view in Django that calls this code:
import geopandas as gpd
from shapely.geometry import Polygon
# ... omitted part ...
# Load a .zip shapefile
shp_data = gpd.GeoDataFrame.from_file(path)
# Set coordinates bounds for test
bounds = [(1.0, 20.0), (1.0, 50.0), (9.0, 50.0), (9.0, 20.0), (1.0, 20.0)]
# Build the Polygon instance
polygon = Polygon(bounds)
# Line that raises the error
subset = shp_data.clip(polygon)
Here there is the last part of the Traceback:
File "/opt/bitnami/projects/demo/api/classes/[omitted]/[omitted]/shapefile/shapefile.py", line 25, in getCoverage
subset = shp_data.clip(polygon)
File "/opt/bitnami/python/lib/python3.8/site-packages/geopandas/geodataframe.py", line 2106, in clip
return geopandas.clip(self, mask=mask, keep_geom_type=keep_geom_type)
File "/opt/bitnami/python/lib/python3.8/site-packages/geopandas/tools/clip.py", line 139, in clip
clipped = _clip_gdf_with_polygon(gdf, poly)
File "/opt/bitnami/python/lib/python3.8/site-packages/geopandas/tools/clip.py", line 36, in _clip_gdf_with_polygon
gdf_sub = gdf.iloc[gdf.sindex.query(poly, predicate="intersects")]
File "/opt/bitnami/python/lib/python3.8/site-packages/geopandas/sindex.py", line 472, in query
tree_idx = list(self.intersection(bounds))
File "/opt/bitnami/python/lib/python3.8/site-packages/geopandas/sindex.py", line 604, in intersection
return super().intersection(coordinates, objects=False)
File "/opt/bitnami/python/lib/python3.8/site-packages/rtree/index.py", line 688, in intersection
core.rt.Index_Intersects_id(self.handle,
Currently, instead of using geopandas.clip()
I am using geopandas.intersection()
that is a viable workaround for my purpose.
from rtree.
Thanks for the example, but you will have to pull geopandas out of it. I would think if the intersection method for Rtree was always passing in the wrong thing, we would have a lot of bugs in the repository. The code that calls that intersection method hasn't changed for 10+ years either.
Maybe @martinfleis or @jorisvandenbossche could work this issue with this scenario and example data that demonstrates it.
from rtree.
@nicolozambon can you try to provide a fully reproducible example?
For example, does running the following using the naturalearth example dataset fail as well for you?
import geopandas
from shapely.geometry import Polygon
df = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))
>>> df.clip(Polygon([(1.0, 20.0), (1.0, 50.0), (9.0, 50.0), (9.0, 20.0), (1.0, 20.0)]))
pop_est continent name iso_a3 gdp_md_est geometry
52 17885245 Africa Mali MLI 38090.0 POLYGON ((1.82323 20.61081, 2.06099 20.14223, ...
55 19245344 Africa Niger NER 20150.0 POLYGON ((8.57289 21.56566, 9.00000 21.80323, ...
82 40969443 Africa Algeria DZA 609400.0 POLYGON ((1.46692 36.60565, 3.16170 36.78390, ...
...
from rtree.
@jorisvandenbossche thank you for your interest. I tried the code you suggested and I confirm that, with the environment described above, the problem arises.
The strangest thing is that the error does not always show up. I tried calling the web page about ten times: the first two returned the correct output while the rest showed the error.
If you want to try simulating my environment you could set up Django on an AWS Lightsail instance.
from rtree.
Can you reproduce this without Django and/or outside of the AWS instance? Or only with this specific situation?
from rtree.
@jorisvandenbossche outside Django it seems working. I tried to run the commands directly from the python shell on AWS and it works.
from rtree.
Closing this issue here as it doesn't seem to be an Rtree thing.
from rtree.
Related Issues (20)
- rtree import still leads to dlsym Attribute Error and crashes geopandas HOT 1
- Python 3.10 wheels HOT 2
- rtree fails to import HOT 1
- typing_extensions now required HOT 1
- Using rtree in Cygwin HOT 1
- import rtree leads to `OSError: Could not load libspatialindex_c library` on aarch64 HOT 6
- Please release a new version with the type hints support HOT 1
- Index is checking write access despite assuming read-only access HOT 3
- why .dat file modified after intersection query?
- Nearest Neighbour Metric
- how to output more information about the constructed Rtree HOT 1
- QUESTION: How can rtree.index.Index properties be used to tweak performance ? HOT 2
- Linux binary wheels have two copies of libspatialindex HOT 1
- Calculating the Height of an R-Tree: Where Did I Go Wrong? HOT 1
- Issue with Python 3.12.0rc1 HOT 5
- "Unable to open file '%s' for index storage" - Write permissions on index should not be required HOT 1
- About RTree Data Structure Persistent Storage HOT 3
- Release publishing automation HOT 1
- Allow string ids in indexes (or at least improve the error messages) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rtree.