Alex Rivera | Logout

Google maps polygon optimization

Asked 2011-03-14T13:05:59.840
11

I extracted country outline data from somewhere and successfully managed to convert it into an array of lat-lng coordinates that I can feed to Google maps API to draw polyline or polygons.

The problem is that that there are about 1200+ points in that shape. It renders perfectly in Google maps but I need to reduce the number of points from 1200 to less than 100. I don't need a very smooth outline, i just need to throw away the points that I can live without. Any algorithm or an online tool that can help me reduce the number of points is needed.

Edit
Report

1 Answer

0

Mostly likely what you want to divide the points into 2 half and want to try my Javascript function:

function shortenAndShow ( polyline, color ) {
  var dist = 0, copyPoints = Array ( );
  for ( var n = 0, var end = polyline.getVertexCount ( ) - 1; n < end ; n++ ) {
    dist += polyline.getVertex ( n ).distanceFrom ( polyline.getVertex ( n +1 ) );
    copyPoints.push ( polyline.getVertex (n) );
   }
   var lastPoint = copyPoints [copyPoints.length-1];
   var newLine = new GPolyline (copyPoints, color, 2, 1);
   gmap2.addOverlay ( newLine );
} 
answered 2011-03-14T13:33:38.220

Your Answer