CartoDB / observatory-extension

BSD 3-Clause "New" or "Revised" License
6 stars 4 forks source link

Add topology to simplified layers and rebuild it's geometries #310

Open antoniocarlon opened 7 years ago

antoniocarlon commented 7 years ago

The simplification proccess for the geometries in the DO breaks the topology of the input layer (if any). This can lead to other (minor) issues due to overlaps and gaps when augmenting user data.

It would be nice to investigate the possibility of adding topology to a simplified layer to avoid gaps and overlaps.

At this time we are trying to create a topology for a given layer following the steps in https://trac.osgeo.org/postgis/wiki/UsersWikiSimplifyWithTopologyExt

select topology.CreateTopology('mytopology',4326,0);
select topology.ST_CreateTopoGeo('mytopology', ST_Collect(wkb_geometry)) from mylayer;

The problem is that it returns the following error for some geometries:

ERROR: Invalid edge (no two distinct vertices exist)

See this ticket for reference. The code shown there can be used to reproduce the issue.

As stated in the ticket, the problem may be solved in higher version of PostGIS (we need to check this).

Anyway, when using the method proposed here to rebuild the geometries using the created topology (tested with a very small subset of data to avoid the Invalid edge error), the result shows that some geometries have been completely messed up.

We need to investigate the geometry rebuilding algorithm and try to refine it so it gives good results (the expected outcome is the input geometries aligned using the topology and not showing gaps or overlaps).

javitonino commented 7 years ago

I was looking for UK data and run into http://mapshaper.org/ which seems to do a pretty good job of simplification while avoiding overlaps, and it is quite fast. Maybe worth a further look.