Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

measure area of irregular polygon in android

Tags:

java

android

I am developing one application in which i have draw the polygon on map and map that I have used is not google,Its Mapsforge opensource offline map library.i have easily draw polygon on map by converting geopoint into pixcel point.but here i want to find are of that irregular polygon,and for that i have make lots of try but its getting me unsuccess.. I have tried with calculate area with basic Math but its not working in this case be case pixcel are change accodingly while change zoom level. Here is Math logic : Math calculation

 for(int miAreainc = 0;miAreainc  < x.length-1; miAreainc++)
                 {
                     sumX += x[miAreainc] * y[miAreainc + 1];
                     sumY += y[miAreainc] * x[miAreainc + 1];
                 }
                 int unit = ((sumX - (sumY)) / 2);
                 AppLog.showLogE(TAG,"UNIT >> " + unit);

I found that funcation stay at server side which get area from geopoint array,but here I want to make it offline. I have tried so far but not getting any clue or result .. Please help me out this.. Thanks

like image 952
AK Joshi Avatar asked May 24 '13 10:05

AK Joshi


1 Answers

Note: I don't really know how stupid my answer is. So please let me know if it doesn't make sense and I'll delete it.

Since the map is not in Cartesian Coordinate System, your calculation will not yield accurate result. You need Spherical Trigonometry for Spherical Polygon which is not trivial.

There is a good discussion at Calculating area enclosed by arbitrary polygon on Earth's surface. Take a look.

But apart from all of these, I have found Projection.java in mapsforge which has a method to find the absolute pixel coordinates on the world map from GeoPoint at a specific zoom level:

Translates the given {@link GeoPoint} to absolute pixel coordinates on the world map.

Point toPoint(GeoPoint in, Point out, byte zoomLevel);

I'm not really knowledgeable, but I think it will give you the absolute coordinate of GeoPoint on a projected map so you can use Cartesian calculation.

like image 84
Sam R. Avatar answered Oct 16 '22 12:10

Sam R.