[GIS] Editing PostGIS topology in web browser

javascriptleafletopenlayers-2postgis

I am trying to conceptualize the best process for editing topology from PostGIS in a web browser. Ideally what I would like to accomplish is the loading of a topology (imagine the lower 48 states of the US), adjusting the borders, and updating a PostGIS table with the changes. I am fairly comfortable with the delivery, representation, and uploading of the geometry, but I am a bit stuck on the editing part.

Although it seems like OpenLayers 3 supports topology editing (despite this answer), it does not seem to enforce any rules (for example, it allows the user to drag a boundary to overlap another polygon), nor does it seem like OpenLayers supports exporting vector layers as a GeoJSON, though I'm sure it's possible to write that functionality. Likewise, Leaflet offers the excellent Leaflet.draw plugin along with GeoJSON export functionality, but does not offer the ability to edit a topology.

Unless I'm missing something, it seems like my best bet at this point is to write a tool that allows for the topological editing of polygons, most likely for Leaflet because I am more comfortable with it. I imagine the process would be something like:

  • Click on a boundary
  • Find all features that have a geometry at this location
  • Create a vertex at this location in all found feature geometries
  • While dragging, update all features that share this vertex
  • When done dragging, make sure that no segments of the altered geometries intersect other features

Ideally it would function very similarly to the OpenLayers example above, but would also enforce some rules and make exporting easy.

Does this sound like a reasonable process?

Am I missing anything?

Do you have any specific suggestions for any part of the process, i.e. any existing tools that accomplish these pieces of functionality?

Best Answer

I ended up writing a Leaflet plugin, Leaflet.draw.topology, to accomplish this task. The only thing not implemented in the plugin is geometry validation, though in the future it certainly could be. It is currently handled server side with PostGIS.