Changeset 4085 in josm


Ignore:
Timestamp:
2011-05-15T17:30:21+02:00 (8 years ago)
Author:
bastiK
Message:

applied #6308 (patch by Ole Jørgen Brønner) - Filter/search by closed-way area size

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r4018 r4085  
    22package org.openstreetmap.josm.actions.search;
    33
    4 import java.awt.Dimension;
    54import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    65import static org.openstreetmap.josm.tools.I18n.tr;
    76import static org.openstreetmap.josm.tools.I18n.trc;
    87
     8import java.awt.Dimension;
    99import java.awt.Font;
    1010import java.awt.GridBagLayout;
     
    2828import org.openstreetmap.josm.Main;
    2929import org.openstreetmap.josm.actions.ActionParameter;
     30import org.openstreetmap.josm.actions.ActionParameter.SearchSettingsActionParameter;
    3031import org.openstreetmap.josm.actions.JosmAction;
    3132import org.openstreetmap.josm.actions.ParameterizedAction;
    32 import org.openstreetmap.josm.actions.ActionParameter.SearchSettingsActionParameter;
    3333import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
    3434import org.openstreetmap.josm.data.osm.DataSet;
     
    199199                    + "<li>"+tr("<b>role:</b>... - object with given role in a relation")+"</li>"
    200200                    + "<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>"
    201202                    + "<li>"+tr("<b>modified</b> - all changed objects")+"</li>"
    202203                    + "<li>"+tr("<b>selected</b> - all selected objects")+"</li>"
    203204                    + "<li>"+tr("<b>incomplete</b> - all incomplete objects")+"</li>"
    204205                    + "<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>"
    205207                    + "<li>"+tr("<b>child <i>expr</i></b> - all children of objects matching the expression")+"</li>"
    206208                    + "<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  
    2222import org.openstreetmap.josm.data.osm.Way;
    2323import org.openstreetmap.josm.tools.DateUtils;
     24import org.openstreetmap.josm.tools.Geometry;
    2425
    2526/**
     
    629630        }
    630631        @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        }
    631658    }
    632659
     
    701728                    Range range = tokenizer.readRange(tr("Range of numbers expected"));
    702729                    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());
    703733                } else if ("changeset".equals(key))
    704734                    return new ChangesetId(tokenizer.readNumber(tr("Changeset id expected")));
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r3939 r4085  
    458458        return inside;
    459459    }
     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
    460516}
Note: See TracChangeset for help on using the changeset viewer.