Changeset 8220 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2015-04-18T15:58:51+02:00 (9 years ago)
Author:
simon04
Message:

fix #11351 - Search: add ways: to search for nodes with specified number of referring ways, or relations containing specified number of ways; modify nodes: to search also for relations containing specified number of nodes

Location:
trunk/src/org/openstreetmap/josm/actions/search
Files:
2 edited

Legend:

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

    r8208 r8220  
    349349                .addKeyword("<i>key</i>=", null, tr("matches if ''key'' exists"))
    350350                .addKeyword("<i>key</i>><i>value</i>", null, tr("matches if ''key'' is greater than ''value'' (analogously, less than)"))
     351                .addKeyword("\"key\"=\"value\"", "\"\"=\"\"", tr("to quote operators.<br>Within quoted strings the <b>\"</b> and <b>\\</b> characters need to be escaped by a preceding <b>\\</b> (e.g. <b>\\\"</b> and <b>\\\\</b>)."), "\"addr:street\"")
    351352                , GBC.eol());
    352353        right.add(new SearchKeywordRow(hcbSearchString)
     
    357358                .addKeyword("-<i>expr</i>", null, tr("logical not"))
    358359                .addKeyword("(<i>expr</i>)", "()", tr("use parenthesis to group expressions"))
    359                 .addKeyword("\"key\"=\"value\"", "\"\"=\"\"", tr("to quote operators.<br>Within quoted strings the <b>\"</b> and <b>\\</b> characters need to be escaped by a preceding <b>\\</b> (e.g. <b>\\\"</b> and <b>\\\\</b>)."), "\"addr:street\"")
    360360                , GBC.eol());
    361361
     
    379379            right.add(new SearchKeywordRow(hcbSearchString)
    380380                .addTitle(tr("properties"))
    381                 .addKeyword("nodes:<i>20-</i>", "nodes:", tr("objects with at least 20 nodes"))
     381                .addKeyword("nodes:<i>20-</i>", "nodes:", tr("ways with at least 20 nodes, or relations containing at least 20 nodes"))
     382                .addKeyword("ways:<i>3-</i>", "ways:", tr("nodes with at least 3 referring ways, or relations containing at least 3 ways"))
    382383                .addKeyword("tags:<i>5-10</i>", "tags:", tr("objects having 5 to 10 tags"))
    383384                .addKeyword("role:", "role:", tr("objects with given role in a relation"))
  • trunk/src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r8198 r8220  
    2929import org.openstreetmap.josm.tools.Geometry;
    3030import org.openstreetmap.josm.tools.Predicate;
     31import org.openstreetmap.josm.tools.Utils;
    3132import org.openstreetmap.josm.tools.date.DateUtils;
    3233
     
    99100    public class CoreSimpleMatchFactory implements SimpleMatchFactory {
    100101        private Collection<String> keywords = Arrays.asList("id", "version",
    101                 "changeset", "nodes", "tags", "areasize", "waylength", "modified", "selected",
     102                "changeset", "nodes", "ways", "tags", "areasize", "waylength", "modified", "selected",
    102103                "incomplete", "untagged", "closed", "new", "indownloadedarea",
    103104                "allindownloadedarea", "inview", "allinview", "timestamp", "nth", "nth%");
     
    137138                    case "nodes":
    138139                        return new NodeCountRange(tokenizer);
     140                    case "ways":
     141                        return new WayCountRange(tokenizer);
    139142                    case "tags":
    140143                        return new TagCountRange(tokenizer);
     
    922925        @Override
    923926        protected Long getNumber(OsmPrimitive osm) {
    924             if (!(osm instanceof Way))
     927            if (osm instanceof Way) {
     928                return (long) ((Way) osm).getRealNodesCount();
     929            } else if (osm instanceof Relation) {
     930                return (long) ((Relation) osm).getMemberPrimitives(Node.class).size();
     931            } else {
    925932                return null;
    926             else
    927                 return (long) ((Way) osm).getRealNodesCount();
     933            }
    928934        }
    929935
     
    931937        protected String getString() {
    932938            return "nodes";
     939        }
     940    }
     941
     942    /**
     943     * Matches objects with the number of referring/contained ways in the given range
     944     */
     945    private static class WayCountRange extends RangeMatch {
     946        public WayCountRange(Range range) {
     947            super(range);
     948        }
     949
     950        public WayCountRange(PushbackTokenizer tokenizer) throws ParseError {
     951            this(tokenizer.readRange(tr("Range of numbers expected")));
     952        }
     953
     954        @Override
     955        protected Long getNumber(OsmPrimitive osm) {
     956            if (osm instanceof Way) {
     957                return (long) Utils.filteredCollection(osm.getReferrers(), Way.class).size();
     958            } else if (osm instanceof Relation) {
     959                return (long) ((Relation) osm).getMemberPrimitives(Way.class).size();
     960            } else {
     961                return null;
     962            }
     963        }
     964
     965        @Override
     966        protected String getString() {
     967            return "ways";
    933968        }
    934969    }
Note: See TracChangeset for help on using the changeset viewer.