{"id":1371,"date":"2013-07-04T11:34:11","date_gmt":"2013-07-04T09:34:11","guid":{"rendered":"http:\/\/www.switchbl8.nl\/blog\/?p=1371"},"modified":"2016-08-18T00:22:22","modified_gmt":"2016-08-17T22:22:22","slug":"free-form-drawing-on-google-maps-simplifying-polygons","status":"publish","type":"post","link":"https:\/\/www.switchbl8.nl\/blog\/2013\/07\/free-form-drawing-on-google-maps-simplifying-polygons\/","title":{"rendered":"Free form drawing on Google Maps &#8211; simplifying polygons"},"content":{"rendered":"<p>I found a script to simplify polygons in Google Maps, basically to reduce the number of nodes the polygon is build up from. It does that by some sort of smoothing algorithm, with a distance parameter. Anything under that distance is smoothed out (read: deleted). It&#8217;s a Google Maps V2 script, but I modified it to work with V3.<\/p>\n<p>This is the original: <a href=\"http:\/\/www.bdcc.co.uk\/Gmaps\/GDouglasPeuker.js\" title=\"Stack-based Douglas Peucker line simplification\" target=\"_blank\">Stack-based Douglas Peucker line simplification routine by Dr. Gary J. Robinson<\/a>. Let me know if you need the V3 script, but it shouldn&#8217;t be a problem to do the modifications yourself.<\/p>\n<p>When I set the tolerance (kink as it&#8217;s called in the script) to 10 (meter), my polygons have a node drop from almost 600 to about 30, and still look about the same as what was drawn. I can still optimize the query a little to only use 7 decimal digits on the lats\/longs, but for now that&#8217;s not needed.<\/p>\n<p>Come to think of it, the amount of smoothing should be linked to the zoomlevel the map is at when drawing the polygon.<\/p>\n<p>Update 18-Aug-2016: The V3 file is <a href=\"http:\/\/www.switchbl8.nl\/blog\/wp-content\/uploads\/2013\/07\/GDouglasPeucker.js\">this one<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I found a script to simplify polygons in Google Maps, basically to reduce the number of nodes the polygon is build up from. It does that by some sort of smoothing algorithm, with a distance parameter. Anything under that distance is smoothed out (read: deleted). It&#8217;s a Google Maps V2 script, but I modified it <a href='https:\/\/www.switchbl8.nl\/blog\/2013\/07\/free-form-drawing-on-google-maps-simplifying-polygons\/' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[59,60,98],"class_list":["post-1371","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-gis","tag-google","tag-javascript","category-1-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/www.switchbl8.nl\/blog\/wp-json\/wp\/v2\/posts\/1371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.switchbl8.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.switchbl8.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.switchbl8.nl\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.switchbl8.nl\/blog\/wp-json\/wp\/v2\/comments?post=1371"}],"version-history":[{"count":4,"href":"https:\/\/www.switchbl8.nl\/blog\/wp-json\/wp\/v2\/posts\/1371\/revisions"}],"predecessor-version":[{"id":1373,"href":"https:\/\/www.switchbl8.nl\/blog\/wp-json\/wp\/v2\/posts\/1371\/revisions\/1373"}],"wp:attachment":[{"href":"https:\/\/www.switchbl8.nl\/blog\/wp-json\/wp\/v2\/media?parent=1371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.switchbl8.nl\/blog\/wp-json\/wp\/v2\/categories?post=1371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.switchbl8.nl\/blog\/wp-json\/wp\/v2\/tags?post=1371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}