Hello,
I have 2 lists of gps coordinates (lat / long). The points in the lists are all unique, i.e. none of the points in one of the lists can be found in the other list. That being said, if I draw a bounding box around each list of points, the boxes will overlap. I am trying to determine the percent overlap. This is my approach:
- Create Polygon1, and add all the coordinates of list 1 to the ExteriorRing of Ploygon1 (which is a LinearRing)
- Create Polygon2, and add all the coordinates of list 2 to the ExteriorRing of Ploygon2 (which is a LinearRing)
- Create DiffPolygon = Polygon1.Difference(Polygon2)
- Overlap percent = DiffPolygon.GetArea() / Polygon1.GetArea()
Does that seem like the best approach?
Thanks
@zgreenberg
This request needs investigation. Aspose.PSD team will text you back after this. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): GISNET-1662
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Good day.
Here is how you can calculate the percentage of overlap for polygon A:
var pointSetA = Geometry.FromText("GEOMETRYCOLLECTION(POINT (30.645676 52.54734), POINT (30.631256 52.533558), POINT (30.661125 52.533558))",
SpatialReferenceSystem.Wgs84);
var pointSetB = Geometry.FromText("GEOMETRYCOLLECTION(POINT (30.653915 52.540867), POINT (30.677261 52.546713), POINT (30.683784 52.532096))",
SpatialReferenceSystem.Wgs84);
IGeometry poligonA = pointSetA.GetExtent().ToPolygon();
IGeometry poligonB = pointSetB.GetExtent().ToPolygon();
IGeometry intersection = poligonA.Intersection(poligonB);
var transformation = SpatialReferenceSystem.Wgs84.CreateTransformationTo(SpatialReferenceSystem.CreateFromEpsg(102013));
poligonA = transformation.Transform(poligonA);
intersection = transformation.Transform(intersection);
var intersectionArea = intersection.GetArea();
var poligonAArea = poligonA.GetArea();
Console.WriteLine(intersectionArea / poligonAArea * 100);
GetExtent() is the same as a bounded box, as you asked.
Thanks for the reply.
I see you are using pointSetA.GetExtent(). Would a better approach be to use GetConvexHull instead?
Hello @zgreenberg,
Yes indeed, the bounding box is a way to optimise performance and is more suitable for search and indexing algorithms. But in your case it really makes sense to use GetConvexHull to get a more accurate result. Of course it all depends on your goals and objectives.
But there is one thing to note when using GetConvexHull. Since GetConvexHull returns LinearRing, the result of their intersections will be a few points. But we need a polygon, luckily we can easily get a polygon from LinearRing:
IGeometry poligonA = new Polygon((LinearRing)pointSetA.GetConvexHull());
IGeometry poligonB = new Polygon((LinearRing)pointSetB.GetConvexHull());
and then it’s just like it was before.