Changeset 29826 in osm for applications/editors/josm/plugins/smed2/src/seamap/SeaMap.java
- Timestamp:
- 2013-08-05T11:15:02+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/src/seamap/SeaMap.java
r29286 r29826 163 163 public AttMap atts; 164 164 public ObjMap objs; 165 public long area; 165 public double area; 166 public double length; 166 167 public Snode centre; 167 168 … … 173 174 objs = new ObjMap(); 174 175 area = 0; 176 length = 0; 175 177 centre = new Snode(); 176 178 } … … 377 379 node.flg = Nflag.ISOL; 378 380 } 381 feature.length = 0; 382 feature.area = 0; 379 383 break; 380 384 case LINE: … … 382 386 nodes.get(edge.first).flg = Nflag.CONN; 383 387 nodes.get(edge.last).flg = Nflag.CONN; 388 Bound ebound = (new Bound(new Side(edge, edge.forward), true)); 389 feature.length = calcLength(ebound); 384 390 if (edge.first == edge.last) { 385 391 feature.flag = Fflag.AREA; 386 392 Area area = new Area(); 387 area.add(new Bound(new Side(edge, edge.forward), true)); 393 area.add(ebound); 394 feature.area = calcArea(ebound); 388 395 areas.put(id, area); 396 } else { 397 feature.area = 0; 389 398 } 390 399 break; 391 400 case AREA: 401 Bound bound = null; 392 402 Area area = new Area(); 393 403 ArrayList<Long> role = outers; … … 397 407 long node1 = edge.first; 398 408 long node2 = edge.last; 399 Boundbound = new Bound(new Side(edge, edge.forward), (role == outers));409 bound = new Bound(new Side(edge, edge.forward), (role == outers)); 400 410 if (node1 != node2) { 401 411 for (ListIterator<Long> it = role.listIterator(0); it.hasNext();) { … … 417 427 } 418 428 if (role == outers) { 429 feature.length = calcLength(bound); 430 feature.area = calcArea(bound); 419 431 role = inners; 420 432 } else { … … 435 447 } 436 448 437 publicdouble signedArea(Bound bound) {449 double signedArea(Bound bound) { 438 450 Snode node; 439 451 double lat, lon, llon, llat; … … 449 461 sigma += (lon * Math.sin(llat)) - (llon * Math.sin(lat)); 450 462 } 451 return sigma; 463 return sigma / 2.0; 452 464 } 453 465 … … 457 469 458 470 public double calcArea(Bound bound) { 459 return Math.abs(signedArea(bound)) * 3444 * 3444 / 2.0; 471 return Math.abs(signedArea(bound)) * 3444 * 3444; 472 } 473 474 public double calcLength(Bound bound) { 475 Snode node; 476 double lat, lon, llon, llat; 477 lat = lon = llon = llat = 0; 478 double sigma = 0; 479 BoundIterator it = new BoundIterator(bound); 480 if (it.hasNext()) { 481 node = it.next(); 482 lat = node.lat; 483 lon = node.lon; 484 while (it.hasNext()) { 485 llon = lon; 486 llat = lat; 487 node = it.next(); 488 lat = node.lat; 489 lon = node.lon; 490 sigma += Math.acos(Math.sin(lat) * Math.sin(llat) + Math.cos(lat) * Math.cos(llat) * Math.cos(llon - lon)); 491 } 492 } 493 return sigma * 3444; 460 494 } 461 495
Note:
See TracChangeset
for help on using the changeset viewer.