WGS84

Handling WGS84 (longitude, latitude, used by GPS, etc) coordinates is a pretty common requirement under concave hull use cases.

Give you an example, this is the boundary of Songjiang district, Shanghai, China(中国上海市松江区): (click image to view in geojson.io)

If you directly pass [[lon, lat], ...] to concave_hull algorithm, you get something like this:

It's waaay tooo rough. Because wgs84 are degrees in lon~(-180,+180), lat~(-90,+90), they are small numbers!!!

And it's hard to tweat the length_threshold under this metric system (CRS/SRS as you may know).

You may know that 1.0 degree in lon/lat is about 100km, then use 0.01 (~1km) as threshold. But it's very tricky to get it right. And the ratio (1 degree -> 100km) varies in lon/lat direction, and varies at different latitude.

concave_hull with help of mapbox/cheap-ruler

We use mapbox/cheap-ruler to quickly convert WGS84 data (we use [lon, lat] order) to local coordinates (in direction east/north, in meters, ENU as you may have know), so you can have better control over lenght_threshold parameter.

Just add is_wgs84=True to concave_hull or concave_hull_indexes:

hull = concave_hull(lon_lats, length_threshold=thresh, is_wgs84=True)
length_threshold Screenshot View in geojson.io
10m link
100m link
1,000m link
5,000m link
10,000m link

Interactive demo

And there is a jupyter notebook:

other CRS/SRS?

For other CRS/SRS, you need to manually convert it to some cartesian coordinates with know metric (e.g. unit 1 is 1 meter in reality), then:

  • use concave_hull_indexes(cartesian_coords, ...) to get indexes, then
  • use original_coords[indexes] to get desired concave hull