larshei
Merging and minifiying geo polygon data in elixir?
I am looking for an option to merge multiple geojson polygons to a single polygon, but could not find a library to do that with. I understand that merging minified shapes might lead to all kinds of artifacts (except if the polygons can be inflated a bit).
Checked out GitHub - felt/geo: A collection of GIS functions for Elixir, but could not find a function to merge shapes and GitHub - pkinney/topo: A Geometry library for Elixir that calculates spatial relationships between two geometries, which is more about finding relations between shapes.
Does a library to merge/minify polygons exists or is there a gap I am having in understanding the current libraries?
Marked As Solved
joddm
Would probably then just export it as WKT from Elixir then, and fire up PostGIS and import the WKT and do the merging, export from PostGIS to WKT and to Elixir again
Also Liked
entone
I haven’t found one that does it, but if you are utilizing PostGIS, there are some functions there that can do it. ST_Union for example, ST_Union
There is the elixir library geo_postgis that wraps up quite a few of the functions into Ecto, Geo.PostGIS — GeoPostGIS v3.7.1
D4no0
Good point!
In addition to this, if the GeoPostGIS library is missing a function from a newer postgis version, creating it on your own is very trivial, example from the library itself:
defmacro st_transform(wkt, srid) do
quote do: fragment("ST_Transform(?, ?)", unquote(wkt), unquote(srid))
end
D4no0
Postgis is the best overall option, this is the better supported library out there for dealing with geo data.
If you want to simplify the process so that you can run livebooks without having a pg + postgis installed on each dev machine, you can deploy a dev instance and have everybody connect to it remotely, in this way you will have to setup it only once.
axelson
I’m not aware of a library to merge polygons together, but there is GitHub - pkinney/simplify_ex that will simplify a polygon using Ramer–Douglas–Peucker.
tme_317
I haven’t looked at this stuff since 2019 but in the past when not having PostGIS to help I’ve shelled out to GDAL/OGR (ogr2ogr) command line utilities from Elixir apps to do a wide variety of vector and raster geo manipulation on files. It’s amazing what these OSS tools can do and I’d be shocked if they wouldn’t work for your use case.
I don’t have time to research now but I believe ogr2ogr may be able to do this for you:
Or you can use the tools to convert your GeoJSON to Spatialite or another format which may help also if you don’t want to bring PostGIS in. Enjoy the rabbit hole! ![]()







