Changeset 4085 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2011-05-15T17:30:21+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r3939 r4085 458 458 return inside; 459 459 } 460 461 /** 462 * returns area of a closed way in square meters 463 * (approximate(?), but should be OK for small areas) 464 */ 465 public static double closedWayArea(Way way) { 466 467 //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/ 468 double area = 0; 469 Node lastN = null; 470 for (Node n : way.getNodes()) { 471 if (lastN != null) { 472 n.getEastNorth().getX(); 473 474 area += (calcX(n) * calcY(lastN)) - (calcY(n) * calcX(lastN)); 475 } 476 lastN = n; 477 } 478 return Math.abs(area/2); 479 } 480 481 protected static double calcX(Node p1){ 482 double lat1, lon1, lat2, lon2; 483 double dlon, dlat; 484 485 lat1 = p1.getCoor().lat() * Math.PI / 180.0; 486 lon1 = p1.getCoor().lon() * Math.PI / 180.0; 487 lat2 = lat1; 488 lon2 = 0; 489 490 dlon = lon2 - lon1; 491 dlat = lat2 - lat1; 492 493 double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2)); 494 double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 495 return 6367000 * c; 496 } 497 498 protected static double calcY(Node p1){ 499 double lat1, lon1, lat2, lon2; 500 double dlon, dlat; 501 502 lat1 = p1.getCoor().lat() * Math.PI / 180.0; 503 lon1 = p1.getCoor().lon() * Math.PI / 180.0; 504 lat2 = 0; 505 lon2 = lon1; 506 507 dlon = lon2 - lon1; 508 dlat = lat2 - lat1; 509 510 double a = (Math.pow(Math.sin(dlat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2), 2)); 511 double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 512 return 6367000 * c; 513 } 514 515 460 516 }
Note:
See TracChangeset
for help on using the changeset viewer.