Google displays polygonal optimization

I extracted data from individual countries and was able to successfully convert it to an array of lat-lng coordinates, which I can use for the Google Maps API to draw polylines or polygons.

The problem is that there are about 1200+ points in this form. It is displayed perfectly on Google maps, but I need to reduce the number of points from 1200 to less than 100. I do not need a very smooth outline, I just need to throw out the points where I can live. It takes any algorithm or online tool that can help me reduce points.

+6
algorithm polygon google-maps
source share
5 answers

I think MapShaper can do it online.

Otherwise, implement the algorithm

+4
source share

Found this simple javascript by Bill Chadwick. Just load LatLng into an array and go to the original arguments in the function here. Douglas Peucker Line Simplification Procedure

it will output an array with fewer points for the polygon.

var ArrayforPolygontoUse= GDouglasPeucker(theArrayofLatLng,2000) var polygon=new google.maps.Polygon({ path:ArrayforPolygontoUse, geodesic:true, strokeColor:"#0000FF", strokeOpacity:0.8, strokeWeight:2, fillColor:"#0000FF", fillOpacity:0.4, editable:true }); 

theArrayofLatLng is the latlng array that you compiled using the google maps api. The value 2000 is the bend in meters. My assumption is that the higher the value, the more points will be deleted as an output.

For real beginners: Before using, make sure you declare a js file on your html page. :)

 <script type="text/javascript" src="js/GDouglasPeucker.js"></script> 
+6
source share

If you can install postgis, which in my opinion is simple since they provide an installer, then you can import the data and execute snaptogrid () or st_simplify () , for which I cannot find the equivalent in mysql. If you decide to go with postgis, which I recommend, because it will help you along the way, I can provide you with detailed information.

Now for a simple custom solution, you can reduce the size by reducing or rounding some of the last digits of the lines, and then merge the same lines, which ultimately leads to a simple snaptogrid ().

Hope this helps

+1
source share

Most likely you want to split the glasses into two parts 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 ); } 
0
source share

I agree with someone who is not affiliated with the site, the GeoJson site, I used it on my website and it abbreviated my geoJson, but I think you will also need a world country geo Json

0
source share

All Articles