English 中文(简体)
How to intelligently degrade or smooth GIS data (simplifying polygons)?
原标题:

I have detailed US county maps, from the TIGER LINE data sets. How might I sample, smooth, or degrade the data so that I get straighter, more boxy, less "noisy" shapes to represent the geographical features -- in this case just county boundaries and state lines, but maybe also in the general case?

The sampling could happen at rendering time if that can be done efficiently, or a parallel data set could be generated and stored. I am using PostGIS, and the lines are multi-polylines generated by shp2pgsql -- but any solution where you take a squiggly line and reduce it to a smoother line of roughly the same significance to a human interpreter would be very useful.

最佳回答

The problem with simply throwing away points is that you can quickly distort the shape of the original polygon. A better approach is to come at it from the other direction; start with a basic approximation of the polygon and then refine it upwards towards your complex shape.

An excellent example of this approach is the Douglas-Puecker algorithm. You start with two vertices drawn from the full polygon. Add a third vertex by selecting the one that lies farthest from an edge drawn between the first two vertices. Continue adding points until you have something that sufficiently resembles your original polygon.

问题回答

Douglas-Peucker is definitely the right approach. There are some simple ways to access implementations of it in PostGIS and QGIS that I thought I would add here for those who come across this post with a similar question. The goal is to start with something like this:

alt text

and end up with something like this:

alt text

In PostGIS Douglas-Peucker is implemented as simplify, the syntax, detailed here at bostongis.org, is some variant of:

SELECT transform(simplify(transform(the_geom, 2249), 500),4326) from the_geo_table

This worked very well even on the full national dataset, with some few errors that seem due to bad underlying data. It also turns out that in QGIS the menu item Tools > Geometry Tools > Simplify Geometries will export a simplified shapefile of any geometry and add it as a layer to your current project.

This is a pretty fundamental tool-set and I asked the question at too low a level, though it was nice to learn the underlying math, there is a good explanation of that here: http://www.mappinghacks.com/code/PolyLineReduction/, along with sample code that turns out not to be too necessary!

Instead of QGIS, I suggest using ogr2ogr because it does not delete polygons!

ogr2ogr output.shp input.shp -simplify 0.0001

Here s a simple iterative smoothing algorithm:

for each three sequential points on any path, if the middle point has no intersections and is within some small threshold angle of the direct path between the two outer points, remove it.

Repeat until satisfied.

You could also try Visvalingam’s algorithm, which iteratively removes the least perceptible part of a line. Here is a great explanation of that algorithm:

You could also use Simplify.js which uses a combination of Douglas-Peucker and Radial Distance algorithms. There are also links to many ports to other languages listed on the github project

Answer by @unmounted is correct, but I would like to add one more suggestion.

Always use function ST_SimplifyPreserveTopology instead of ST_Simplify in PostGIS. Both use the same underlying algorithm (Douglas-Peucker), but the former avoids any simplifications which would result in invalid geometries. For example, ST_Simplify may result in geometry which intersects itself.





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签