Community Conundrum 25: Feature Visualization is now live! Read More

Matching geopoints with areas

Level 1
Matching geopoints with areas

Hello Guys,

I was wondering if there is an easy solution to match areas (polygons) on geopoints.

 

0 Kudos
2 Replies
Dataiker
Dataiker

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

Level 2
Level 2

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:

  1. Install libspatialindex into the DSS node
    1. If you are running DSS locally, you probably have root permission to install it.
    2. If you are running in Docker (what I did)
      1. log on as root user:  docker exec -it --user root <container> bash 
      2. install libspatialinddex: yum install -y spatialindex-devel
  2. Create new Code Environment (managed by DSS) Python = 3.6
  3. Add to "Packages to Install":
    1. geopandas==0.7.0
    2. rtree==0.9.4 (when I tried to create the env before installing libspatiaindex, I did get an error trying to install rtree)
  4. 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.

 

 

0 Kudos