1

I am new to iOS, Currently i am working on to calculate the area of polygon in the mapview. I have only lengths for the sides of an irregular polygon, can anyone tell me how I can measure the area of the polygon? Remember only lengths of all the sides , no angles or coordinates.

Few forums mention about trangulation of the polygon etc But I only have side lengths.

Does anybody has any feedback?

Thanks.

user1482232
  • 17
  • 1
  • 6
  • You can this link, it may help you a bit http://www.wikihow.com/Sample/Area-of-an-Irregular-Polygon. But you have to find a logic to get the coordinates. – Exploring Aug 19 '13 at 13:46
  • This is a math question, not a programming question. Consider asking it on http://math.stackexchange.com/. – Hot Licks Aug 19 '13 at 14:54
  • 4
    This question appears to be off-topic because it is about math, not programming. – Hot Licks Aug 19 '13 at 14:56
  • +1 Hey user1482232 did get solution for this. If yes put that here. If no then tell which way you used for this. – python Aug 22 '13 at 07:04
  • This link may help someone http://stackoverflow.com/a/36090029/3918500 – dev_binod Mar 22 '16 at 06:43

3 Answers3

3

I think you cannot do that from that information as it might be convex or concave as well: enter image description here

You need more information to do that.

gen
  • 9,528
  • 14
  • 35
  • 64
  • 1
    Even for convex shapes you cannot determine the area from the side lengths (imagine a rectangle vs a parallelogram with the same side lengths). – Martin R Aug 19 '13 at 13:14
  • 1
    Actually, I am unable to convert from latitude and longitude to cartesian coordinates (x,y) that's the reason I find the distance between two coordinates(latitude,longitude). I have gone through the below link but I didn't get exact values http://stackoverflow.com/questions/1185408/converting-from-longitude-latitude-to-cartesian-coordinates Can you please help me Is there any other way to calculate the area of irregular polygon which was written in the mapview. Thanks!! – user1482232 Aug 19 '13 at 13:26
  • Same problem I am facing please answer here http://stackoverflow.com/questions/18311091/how-to-calculate-irregular-shape-polygon-area-draw-on-map-in-ios if anyone knows – python Aug 22 '13 at 06:57
1

If you can get the points of each corner in the polygon you can use this:

float area = 0;
int N = pointArray.count;

for (int a = 0; a < N-1; a++) {
    float term = ([pointArray[a] CGPointValue].x * [pointArray[a+1 % N] CGPointValue].y -
                      [pointArray[a+1 % N] CGPointValue].x * [pointArray[a] CGPointValue].y)/2.0;
    area += term;
}
Arbitur
  • 38,684
  • 22
  • 91
  • 128
  • Well, OP explicitly said "no angles or coordinates". - In any case, there are parentheses missing in `[a+1 % N]` ... – Martin R Aug 19 '13 at 13:29
  • Thank you for the prompt response, but I am unable to get exact cartesian values from the latitude and longitude so that's the reason I have chosen this option. Is there any other way to calculate the area of irregular polygon (map). Thank you once again. – user1482232 Aug 19 '13 at 13:40
0

Hope you can convert CLLocationCoordinate2D to CGPoint by the following way, then you may have the coordinates of all points.

//CGPoint myPoint = CGPointMake(coordinate.longitude, coordinate.latitude);

CGPoint Point = [self.mapView convertCoordinate:self.mapCoordinate toPointToView:self.mapView]; 

Then you can try the way as per the link

http://www.wikihow.com/Sample/Area-of-an-Irregular-Polygon

CLLocationCoordinate2D overflowLotCoords[15]={
    CLLocationCoordinate2DMake(39.04864351611461,-76.8513227245313),
    CLLocationCoordinate2DMake(39.04851710015167,-76.8517540587399),
    CLLocationCoordinate2DMake(39.04868674731313,-76.85192728689483),
    CLLocationCoordinate2DMake(39.04850095882104,-76.85230365946416),
    CLLocationCoordinate2DMake(39.04819087100218,-76.85265260435219),
    CLLocationCoordinate2DMake(39.0477370134458,-76.85286078490296),
    CLLocationCoordinate2DMake(39.04692851484644,-76.85283202926037),
    CLLocationCoordinate2DMake(39.04695987529381,-76.85235192135768),
    CLLocationCoordinate2DMake(39.04734847050665,-76.85236298239703),
    CLLocationCoordinate2DMake(39.04779491740192,-76.85232236959109),
    CLLocationCoordinate2DMake(39.04814366462639,-76.85208905182692),
    CLLocationCoordinate2DMake(39.04838024069194,-76.85164072166863),
    CLLocationCoordinate2DMake(39.04843331131504,-76.85085998781742),
    CLLocationCoordinate2DMake(39.04857547181026,-76.8507923535788),
    CLLocationCoordinate2DMake(39.04864351611461,-76.8513227245313)
};

NSMutableArray *marrPointsList = [NSMutableArray array];

for (int i = 0; i < 15; i++)
{
    CLLocationCoordinate2D coordinate = overflowLotCoords[i];

    CGPoint point = [self.myMapView convertCoordinate:overflowLotCoords[i] toPointToView:self.myMapView];

    NSLog(@"convert %@", NSStringFromCGPoint(point));

    [marrPointsList addObject:[NSValue valueWithCGPoint:point]];        
}

hope this code snippet may help you.

Exploring
  • 925
  • 6
  • 18
  • I am using the below method to convert the coordinate to CGPoint, but I am unable to get exact cartesian point. CGPoint Point = [self.mapView convertCoordinate:self.mapCoordinate toPointToView:self.mapView]; Thanks!! – user1482232 Aug 19 '13 at 14:12
  • I used CGPoint myPoint = CGPointMake(coordinate.longitude, coordinate.latitude); this method but I didn't get the exact value. Please assist me, is there any other way to convert coordinates into cgpoints. Thanks!1 – user1482232 Aug 19 '13 at 14:23
  • I have gone through what ever mentioned in the above but, if we zoom the mapview and then calculate the area, the result is getting wrong. – user1482232 Aug 20 '13 at 11:02