Changeset 7193 in josm for trunk


Ignore:
Timestamp:
2014-05-30T10:27:18+02:00 (10 years ago)
Author:
bastiK
Message:

added right- and left-hand traffic database
(new mapcss pseudo-class-condition :righthandtraffic)

Data file (data/left-right-hand-traffic.osm) license: CC0.
Loosely based on boundary lines data from naturalearthdata.com.
Traffic law info from wikipedia.
Boundaries generalized, especially in areas where there seem to be no roads.
Should be mostly correct, but some remote islands and atolls may be assigned wrongly.
Alway check before you start driving. :)

Added fast lookup index similar to QuadBuckets.

Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/BBox.java

    r6890 r7193  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.awt.geom.Rectangle2D;
    45import java.util.Arrays;
    56
     
    259260        return idx1;
    260261    }
     262   
     263    public Rectangle2D toRectangle() {
     264        return new Rectangle2D.Double(xmin, ymin, xmax - xmin, ymax - ymin);
     265    }
    261266
    262267    @Override
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r7167 r7193  
    403403            case "unconnected":
    404404                return e.osm instanceof Node && OsmPrimitive.getFilteredList(e.osm.getReferrers(), Way.class).isEmpty();
     405            case "righthandtraffic":
     406                return ExpressionFactory.Functions.is_right_hand_traffic(e);
    405407            }
    406408            return false;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r7170 r7193  
    2626import org.openstreetmap.josm.actions.search.SearchCompiler.Match;
    2727import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
     28import org.openstreetmap.josm.data.osm.Node;
    2829import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2930import org.openstreetmap.josm.gui.mappaint.Cascade;
     
    3233import org.openstreetmap.josm.tools.ColorHelper;
    3334import org.openstreetmap.josm.tools.Predicates;
     35import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
    3436import org.openstreetmap.josm.tools.Utils;
    3537
     
    621623            return cs.getValue();
    622624        }
     625       
     626        public static boolean is_right_hand_traffic(Environment env) {
     627            if (env.osm instanceof Node)
     628                return RightAndLefthandTraffic.isRightHandTraffic(((Node) env.osm).getCoor());
     629            return RightAndLefthandTraffic.isRightHandTraffic(env.osm.getBBox().getCenter());
     630        }
    623631    }
    624632
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r7145 r7193  
    444444    /**
    445445     * Returns the Area of a polygon, from its list of nodes.
    446      * @param polygon List of nodes forming polygon
     446     * @param polygon List of nodes forming polygon (EastNorth coordinates)
    447447     * @return Area for the given list of nodes
    448448     * @since 6841
     
    469469        return new Area(path);
    470470    }
     471   
     472    /**
     473     * Returns the Area of a polygon, from its list of nodes.
     474     * @param polygon List of nodes forming polygon (LatLon coordinates)
     475     * @return Area for the given list of nodes
     476     * @since 6841
     477     */
     478    public static Area getAreaLatLon(List<Node> polygon) {
     479        Path2D path = new Path2D.Double();
     480
     481        boolean begin = true;
     482        for (Node n : polygon) {
     483            if (begin) {
     484                path.moveTo(n.getCoor().lon(), n.getCoor().lat());
     485                begin = false;
     486            } else {
     487                path.lineTo(n.getCoor().lon(), n.getCoor().lat());
     488            }
     489        }
     490        if (!begin) {
     491            path.closePath();
     492        }
     493
     494        return new Area(path);
     495    }
    471496
    472497    /**
     
    490515     */
    491516    public static PolygonIntersection polygonIntersection(Area a1, Area a2) {
     517        return polygonIntersection(a1, a2, 1.0);
     518    }
     519
     520    /**
     521     * Tests if two polygons intersect.
     522     * @param a1 Area of first polygon
     523     * @param a2 Area of second polygon
     524     * @param eps an area threshold, everything below is considered an empty intersection
     525     * @return intersection kind
     526     */
     527    public static PolygonIntersection polygonIntersection(Area a1, Area a2, double eps) {
    492528
    493529        Area inter = new Area(a1);
     
    496532        Rectangle bounds = inter.getBounds();
    497533
    498         if (inter.isEmpty() || bounds.getHeight()*bounds.getWidth() <= 1.0) {
     534        if (inter.isEmpty() || bounds.getHeight()*bounds.getWidth() <= eps) {
    499535            return PolygonIntersection.OUTSIDE;
    500536        } else if (inter.equals(a1)) {
Note: See TracChangeset for help on using the changeset viewer.