How to get intersection area coordinates of two polygons on General Polygon Clipper(GPC)?

363 Views Asked by At

I'm using nutiteq library to draw polygons and getting the coordinates of the polygons with .getVertexList() command. Then I cast these coordinates to an array list . Then I cast these coordinates to another polygon list. GPC is calculating the intersection, union, XOR and difference areas integer values. Then I need to highlight the process area so I need processed areas coordinates but I can't get these coordinates directly from GPC.

The code I'm using for the area calculation is below. What should I do to get the coordinates of result polygon?. (I can't cast the coordinates directly by the way as you can see here...)

Thanks in advance.

public void IntersectionButton(View view) {
VectorElement selectedElement = mapView.getSelectedElement();
List<?> VisibleElements = selectedElement.getLayer().getVisibleElements();
ArrayList<Poly> polyList = new ArrayList<Poly>();
for (Object obj : VisibleElements) {
if (obj instanceof Polygon) {
            Polygon poly = (Polygon) obj;
            List<MapPos> geoList = poly.getVertexList();
 Poly p = new PolyDefault();
            for (MapPos pos : geoList) {
                p.add(pos.x, pos.y);
                }
             polyList.add(p);
         }

    }
 PolyDefault result = (PolyDefault) Clip.intersection(polyList.get(0), polyList.get(1));
 int area = (int) (((int) result.getArea()) * (0.57417));
1

There are 1 best solutions below

0
On

The result polygon seems to have all the methods you need:

  1. getNumPoints() to get number of outer polygon points.
  2. getX(i) to get X of specific outer polygon point, and getY(i) for Y.
  3. getNumInnerPoly() to get number of holes in the polygon
  4. getInnerPoly(i) to get specific hole. You iterate through hole similar way like outer polygon

You can construct new Nutiteq Polygon from this data, create list of MapPos for outer and list of list of MapPos for inner polygons (holes). What are values of X and Y, do they need further processing, is another question what you can investigate.