Changeset 11264 in josm
- Timestamp:
- 2016-11-16T17:07:03+01:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/GeoPropertyIndex.java
r11259 r11264 19 19 */ 20 20 public class GeoPropertyIndex<T> { 21 22 /**23 * A method to look up a property of the earth surface.24 * (User input for the index.)25 * @param <T> the property26 */27 public interface GeoProperty<T> {28 /**29 * Look up the property for a point.30 * @param ll the point coordinates31 * @return property value at that point. Must not be null.32 */33 T get(LatLon ll);34 35 /**36 * Look up the property for a coordinate rectangle.37 * @param box the rectangle38 * @return the property, if it is the same in the entire rectangle;39 * null otherwise40 */41 T get(BBox box);42 }43 21 44 22 private final int maxLevel; -
trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java
r11259 r11264 2 2 package org.openstreetmap.josm.tools; 3 3 4 import java.awt.geom.Area;5 4 import java.io.File; 6 5 import java.io.FileInputStream; … … 24 23 import org.openstreetmap.josm.actions.PurgeAction; 25 24 import org.openstreetmap.josm.data.coor.LatLon; 26 import org.openstreetmap.josm.data.osm.BBox;27 25 import org.openstreetmap.josm.data.osm.DataSet; 28 26 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 34 32 import org.openstreetmap.josm.io.OsmWriter; 35 33 import org.openstreetmap.josm.io.OsmWriterFactory; 36 import org.openstreetmap.josm.tools.GeoPropertyIndex.GeoProperty;37 import org.openstreetmap.josm.tools.Geometry.PolygonIntersection;38 34 39 35 /** … … 46 42 private static final String RIGHT = "right"; 47 43 48 private static class RLTrafficGeoProperty implements GeoProperty<Boolean> { 49 50 @Override 51 public Boolean get(LatLon ll) { 52 for (Area a : leftHandTrafficPolygons) { 53 if (a.contains(ll.lon(), ll.lat())) 54 return Boolean.TRUE; 55 } 56 return Boolean.FALSE; 57 } 58 59 @Override 60 public Boolean get(BBox box) { 61 Area abox = new Area(box.toRectangle()); 62 for (Area a : leftHandTrafficPolygons) { 63 PolygonIntersection is = Geometry.polygonIntersection(abox, a, 1e-10 /* using deg and not meters */); 64 if (is == PolygonIntersection.FIRST_INSIDE_SECOND) 65 return Boolean.TRUE; 66 if (is != PolygonIntersection.OUTSIDE) 67 return null; 68 } 69 return Boolean.FALSE; 70 } 71 } 72 73 static volatile Collection<Area> leftHandTrafficPolygons; 74 static volatile GeoPropertyIndex<Boolean> rlCache; 44 private static volatile GeoPropertyIndex<Boolean> rlCache; 75 45 76 46 private RightAndLefthandTraffic() { … … 93 63 */ 94 64 public static synchronized void initialize() { 95 leftHandTrafficPolygons = new ArrayList<>();96 65 Collection<Way> optimizedWays = loadOptimizedBoundaries(); 97 66 if (optimizedWays.isEmpty()) { … … 99 68 saveOptimizedBoundaries(optimizedWays); 100 69 } 101 for (Way w : optimizedWays) { 102 leftHandTrafficPolygons.add(Geometry.getAreaLatLon(w.getNodes())); 103 } 104 rlCache = new GeoPropertyIndex<>(new RLTrafficGeoProperty(), 24); 70 rlCache = new GeoPropertyIndex<>(new DefaultGeoProperty(optimizedWays), 24); 105 71 } 106 72
Note:
See TracChangeset
for help on using the changeset viewer.