Union of polygons, represented as a javascript array of geo-coordinates

I need to find the union of the polygons represented as javascript arrays of geocoordinates, as in the code below:

           var polygon1 = [[51.49151151647854, -0.20633749635419463],
                [51.491517887745886, -0.20663465247037038],
                [51.49125377257769, -0.20707803457401042], 
                [51.49125377257769, -0.20707803457401042],
                [51.49090541057069, -0.2071046417369189],
                [51.490605858341326, -0.20637621141179352],
                [51.49081102624578, -0.20598780005047956],
                [51.490859930095496, -0.20592173450688733]]


            var polygon2 = [[51.492223312188386, -0.20784254067885688],
                [51.49226262897666, -0.20812681455816695],
                [51.49162516066342, -0.2090258514344801],
                [51.491538051645385, -0.2089717941050469],
                [51.49200661100099, -0.20759325088262348]]

I would draw the resulting polygon on a Google map using the Google maps Javascript API v3 so that they can be structured, as in the code below:

   var googleMapPolygon1 = [
        new google.maps.LatLng(51.49151151647854, -0.20633749635419463),
        new google.maps.LatLng(51.491517887745886, -0.20663465247037038),
        new google.maps.LatLng(51.49125377257769, -0.20707803457401042),
        new google.maps.LatLng(51.49090541057069, -0.2071046417369189),
        new google.maps.LatLng(51.490605858341326, -0.20637621141179352),
        new google.maps.LatLng(51.49081102624578, -0.20598780005047956),
        new google.maps.LatLng(51.490859930095496, -0.20592173450688733),
        new google.maps.LatLng(51.49151151647854, -0.20633749635419463)
  ];

  var googleMapPolygon2 = [
        new google.maps.LatLng(51.492223312188386, -0.20784254067885688),
        new google.maps.LatLng(51.49226262897666, -0.20812681455816695),
        new google.maps.LatLng(51.49162516066342, -0.2090258514344801),
        new google.maps.LatLng(51.491538051645385, -0.2089717941050469),
        new google.maps.LatLng(51.49200661100099, -0.20759325088262348),
        new google.maps.LatLng(51.492223312188386, -0.20784254067885688)
  ]

So what could I use to search for the union of polygons? Thanks in advance.

EDIT: This is what I do. I have an array of Voronoi cells structured as polygons (bottom left, bottom). And what I'm trying to get is the border around them (the green polygon to the right of the picture below). enter image description here

So, I think I can get it using the join operation. Can anyone help?

+4
1

:

var polygon1 = [[51.49151151647854, -0.20633749635419463],
                [51.491517887745886, -0.20663465247037038],
                [51.49125377257769, -0.20707803457401042], 
                [51.49125377257769, -0.20707803457401042],
                [51.49090541057069, -0.2071046417369189],
                [51.490605858341326, -0.20637621141179352],
                [51.49081102624578, -0.20598780005047956],
                [51.490859930095496, -0.20592173450688733]];

var polygon2 = [[51.492223312188386, -0.20784254067885688],
                [51.49226262897666, -0.20812681455816695],
                [51.49162516066342, -0.2090258514344801],
                [51.491538051645385, -0.2089717941050469],
                [51.49200661100099, -0.20759325088262348]];

var union = new google.maps.Polygon({
    paths: polygon1.concat(polygon2)
});
-2

All Articles