6

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

AK Joshi
  • 877
  • 6
  • 20
  • You should specify the coordinate System that your Polygon coordinates are! (lat lon decimal degrees( – AlexWien May 24 '13 at 12:51

2 Answers2

2

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.

Community
  • 1
  • 1
Sam R.
  • 16,027
  • 12
  • 69
  • 122
  • 1
    I like your effort that you have put...and i would more like to conversation on this with you, yes in mapsforge there are projection class that convert geopoint to pixcel and I got result as well but here i am confuse with zoom level and panning 1. I dont know in which zoom level its more perferable to calculate area 2. when i pan map with my fingure x,y also change and its effect come with result so how can i prevent from that ? I have also tryed direclty by latitude and longite as X and Y and get the result but dont know what i do to convert it into meter or in inches or in feet – AK Joshi May 24 '13 at 12:30
  • @Mario, Does your polygon get re-sized when you zoom-in or out? – Sam R. May 24 '13 at 12:36
  • @Mario, so the area of your polygon is fixed. Why not getting the current `Zoom Level` and compute `absolute pixel coordinates`? The pixels on screen are changing by panning but the coordinates are fixed and are pointing to the same location on map. Am I understanding you correctly? – Sam R. May 24 '13 at 12:46
2

for area calculation you Need to transform lat, lon to cartesian coordinates with Unit Meters. (Not Pixels) Look into transform Moduls

AlexWien
  • 28,470
  • 6
  • 53
  • 83
  • can you please give some real example for this so i get clear idea for this – AK Joshi May 24 '13 at 13:08
  • 1
    i have apply area calculation based on lat-long but the unit that i got not sure in which form... – AK Joshi May 24 '13 at 13:10
  • If you want to measure the area in square meters, then of course your coordinates must be in units meters. You can define the centere of the polygon as (0,0), this then is your transformation center. You must read more on tranformation from lat/long to cartesian spoace: This topic is called "Map Projections". – AlexWien May 24 '13 at 13:11
  • if your coordinates are in lat, long decimnal degrees then of course this cannot work. – AlexWien May 24 '13 at 13:12