Changeset 4085 in josm
- Timestamp:
- 2011-05-15T17:30:21+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r4018 r4085 2 2 package org.openstreetmap.josm.actions.search; 3 3 4 import java.awt.Dimension;5 4 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 6 5 import static org.openstreetmap.josm.tools.I18n.tr; 7 6 import static org.openstreetmap.josm.tools.I18n.trc; 8 7 8 import java.awt.Dimension; 9 9 import java.awt.Font; 10 10 import java.awt.GridBagLayout; … … 28 28 import org.openstreetmap.josm.Main; 29 29 import org.openstreetmap.josm.actions.ActionParameter; 30 import org.openstreetmap.josm.actions.ActionParameter.SearchSettingsActionParameter; 30 31 import org.openstreetmap.josm.actions.JosmAction; 31 32 import org.openstreetmap.josm.actions.ParameterizedAction; 32 import org.openstreetmap.josm.actions.ActionParameter.SearchSettingsActionParameter;33 33 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError; 34 34 import org.openstreetmap.josm.data.osm.DataSet; … … 199 199 + "<li>"+tr("<b>role:</b>... - object with given role in a relation")+"</li>" 200 200 + "<li>"+tr("<b>timestamp:</b>... - objects with this timestamp (<b>2009-11-12T14:51:09Z</b>, <b>2009-11-12</b> or <b>T14:51</b> ...)")+"</li>" 201 + "<li>"+tr("<b>areaSize:</b>... - closed ways with area between MIN and MAX m\u00b2. (areaSize:MIN-MAX or areaSize:MAX)")+"</li>" 201 202 + "<li>"+tr("<b>modified</b> - all changed objects")+"</li>" 202 203 + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>" 203 204 + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>" 204 205 + "<li>"+tr("<b>untagged</b> - all untagged objects")+"</li>" 206 + "<li>"+tr("<b>closed</b> - all closed ways (a node is not considered closed)")+"</li>" 205 207 + "<li>"+tr("<b>child <i>expr</i></b> - all children of objects matching the expression")+"</li>" 206 208 + "<li>"+tr("<b>parent <i>expr</i></b> - all parents of objects matching the expression")+"</li>" -
trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r3818 r4085 22 22 import org.openstreetmap.josm.data.osm.Way; 23 23 import org.openstreetmap.josm.tools.DateUtils; 24 import org.openstreetmap.josm.tools.Geometry; 24 25 25 26 /** … … 629 630 } 630 631 @Override public String toString() {return "child(" + parent + ")";} 632 } 633 634 /** 635 * Matches on the area of a closed way. 636 * 637 * @author Ole Jørgen Brønner 638 */ 639 private static class Area extends Match { 640 private int min, max; 641 642 public Area(int min, int max) { 643 this.min = min; 644 this.max = max; 645 if (min == max) { 646 this.min = 0; 647 } 648 } 649 650 @Override 651 public boolean match(OsmPrimitive osm) { 652 if(!(osm instanceof Way && ((Way) osm).isClosed())) 653 return false; 654 Way way = (Way)osm; 655 double area = Geometry.closedWayArea(way); 656 return (min <= area && area <= max); 657 } 631 658 } 632 659 … … 701 728 Range range = tokenizer.readRange(tr("Range of numbers expected")); 702 729 return new NodeCountRange((int)range.getStart(), (int)range.getEnd()); 730 } else if ("areaSize".equals(key)) { 731 Range range = tokenizer.readRange(tr("Range of numbers expected")); 732 return new Area((int)range.getStart(), (int)range.getEnd()); 703 733 } else if ("changeset".equals(key)) 704 734 return new ChangesetId(tokenizer.readNumber(tr("Changeset id expected"))); -
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.