Check if polygon is inside a polygon

后端 未结 5 1120
鱼传尺愫
鱼传尺愫 2020-12-01 06:35

Yesterday I was looking to check if a point was inside a polygon and found this great script: https://github.com/tparkin/Google-Maps-Point-in-Polygon

But today at wo

5条回答
  •  没有蜡笔的小新
    2020-12-01 07:16

    I had to find a similar solution. Here is what i have so far :

    1. First i fetched all the level 1 polygon coordinates in an array[pol1cords[cord1,cord2...],pol2cords[cord1,cord2...],..]
    2. Then fetched all the level 3 polygons and plotted them
    3. Then for each level 1 polygon, i checked if each of the polygon coordinates was inside the plotted level 3 coordinate with google.maps.geometry.poly.containsLocation(latLng, pol)
    4. If it returned true counter would go up
    5. At last if the counter was equal to the length of that array, the result would be true(the level 1 polygon is inside the level3 polygon).

    My algorithm looks something like this:

    ""Zone(level 3)->District(level 2)->VDC(level 1)"" vdcs = getVDCs(); -> gives vdcs in an array which has name, id and polygon coordinates zones = getZones(); ->gives zones in an array which has name, id and polygon coordinates

    foreach(zones as zone){
        drawPolygon(zone[coordinates]);
        foreach(vdcs as vdc){
            foreach(vdc[coordinates] as coordinate){
                result = checkLocation(zone, coordinate);
                if(result) counter++;
            }
            if(counter = vdc[coordinates].length){writeConsole(vdc_id+"true in"+zone_id)}
        }
    }
    

提交回复
热议问题