Matching geopoints with areas
![VanDeSurk](https://us.v-cdn.net/6038231/uploads/Dataiku/nAvatar4.png)
Hello Guys,
I was wondering if there is an easy solution to match areas (polygons) on geopoints.
Answers
-
Hi,
This can be done in a python recipe (with geopandas) for example, or better, if you have a Postgres sql database, the postgis extension is very useful to handle geo data.
Cheers,
Du
-
tim-wright Partner, L2 Designer, Snowflake Advanced, Neuron 2020, Registered, Neuron 2021, Neuron 2022 Posts: 77 Partner
I realize I'm a bit late to the game, but I thought I would chime in for others needing similar help doing geospatial queries. Having never used geopandas before I thought I would just add it as a package to a custom code environment. It was not quite that simple. (I realize that this workload would generally be better offloaded to a database if possible, but I am running DSS 7 locally in a docker container - without access to a DB right now).
This will require a custom Python environment. I was unable to do spatial joins (using the "intersects" operation) without geopandas only. First I got some errors relating to missing package "rtree" and then after installing that package got another error related to "libspatialindex_c". Turns out that rtree is a python package that wraps libstpatialindex. libspatial index is a library that allows for robust spatial indexing and spatial querying - but is not installable through pip. So geopandas depends on rtree and rtree on libspatial index (for some things).
How I resolved my issue:
- Install libspatialindex into the DSS node
- If you are running DSS locally, you probably have root permission to install it.
- If you are running in Docker (what I did)
- log on as root user: docker exec -it --user root <container> bash
- install libspatialinddex: yum install -y spatialindex-devel
- Create new Code Environment (managed by DSS) Python = 3.6
- Add to "Packages to Install":
- geopandas==0.7.0
- rtree==0.9.4 (when I tried to create the env before installing libspatiaindex, I did get an error trying to install rtree)
- Happy Geocoding!
Other Notes: During my googling, it does appear that there are pre-built binaries on Conda Forge for libspatialindex. So you probably wouldn't need to go through the hassle of all the steps above if you create a code-env that is managed by conda - disclaimer: I did not test this.
- Install libspatialindex into the DSS node