Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an array of Lines and I am using it to draw vectors in my map. I want to replace two superposed Lines (or have short distance between them) with one Line. Here is a picture that helps you to understand this problem:

The Input Lines :

The input Lines

The Output


PS: A Line is an ArrayList of points.

share|improve this question
What software are you using? Some of it (such as much GIS software) has this capability built in, but if you are on a non-GIS platform, you might need a detailed algorithm. – whuber Dec 14 '12 at 17:31

Possibly take a look at the topojson project, which includes a simplification option for geometry.

If you wanted to do this yourself one algoritm would be as follows:

  1. Break each line into segments (pairs of points)
  2. Order these segments in a clockwise direction (sort vertices by x ascending, then y descending)
  3. Calculate whether the segments are the same within some threshold
  4. If the segments are the same, determine how you will calculate the true value (average, priorities a over b etc).
  5. Replace updated segments in original shapes

Note this is a very simple algorithm - it doesn't take into account that you may wish to "snap" lines based on slope - to do that you'd have to calculate the line functions, compare them (the standard two-point function of a line is (x2 - x1)(y - y1) = (y2 - y1)(x - x1) for two points x1,y1 and x2,y2 - see Wikipedia for a more detailed explanation), and then decide on your rules for snapping them to the original line.

The author of the topojson projet, Mike Bostock, has also written a good article on line simplification which would certainly be worth a read.

share|improve this answer
Program options are using PostGIS ST_SnaptoGrid and topology tools, FME networktopology + transformer or MRFtools, GRASS – simplexio May 21 '13 at 12:43

Edit the vertices and merge it.

But it all depends on what you are doing and what you want out of it.

Topology and logical consistencies, come to mind as well.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.