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


Ignore:
Timestamp:
2018-04-23T23:46:31+02:00 (6 years ago)
Author:
Don-vip
Message:

fix #16188 - Detect crossing of residential areas (patch by marxin, modified)

Location:
trunk/src/org/openstreetmap/josm/data/validation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r12864 r13671  
    347347    }
    348348
     349    /**
     350     * Determines if the specified primitive denotes a residential area.
     351     * @param p The primitive to be tested
     352     * @return True if landuse key is equal to residential
     353     */
     354    protected static final boolean isResidentialArea(OsmPrimitive p) {
     355        return p.hasTag("landuse", "residential");
     356    }
     357
    349358    @Override
    350359    public int hashCode() {
  • trunk/src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java

    r12986 r13671  
    66import java.awt.geom.Point2D;
    77import java.util.ArrayList;
     8import java.util.Arrays;
    89import java.util.HashMap;
    910import java.util.List;
     
    3536    static final String RAILWAY = "railway";
    3637    static final String WATERWAY = "waterway";
     38    static final String LANDUSE = "landuse";
     39
     40    /**
     41     * Type of way. Entries have to be declared in alphabetical order, see sort below.
     42     */
     43    private enum WayType {
     44        BUILDING, HIGHWAY, RESIDENTIAL_AREA, WATERWAY, WAY
     45    }
    3746
    3847    /** All way segments, grouped by cells */
     
    6574                    || isRailway(w)
    6675                    || isCoastline(w)
    67                     || isBuilding(w));
     76                    || isBuilding(w)
     77                    || isResidentialArea(w));
    6878        }
    6979
     
    7888                return true;
    7989            }
     90            if ((w1.hasKey(HIGHWAY) && isResidentialArea(w2))
     91             || (w2.hasKey(HIGHWAY) && isResidentialArea(w1)))
     92                return true;
    8093            if (isSubwayOrTramOrRazed(w2)) {
    8194                return true;
     
    91104        }
    92105
     106        private static WayType getWayType(Way w) {
     107            if (isBuilding(w))
     108                return WayType.BUILDING;
     109            else if (w.hasKey(HIGHWAY))
     110                return WayType.HIGHWAY;
     111            else if (isResidentialArea(w))
     112                return WayType.RESIDENTIAL_AREA;
     113            else if (w.hasKey(WATERWAY))
     114                return WayType.WATERWAY;
     115            else
     116                return WayType.WAY;
     117        }
     118
    93119        @Override
    94120        String createMessage(Way w1, Way w2) {
    95             if (isBuilding(w1)) {
    96                 return tr("Crossing buildings");
    97             } else if (w1.hasKey(WATERWAY) && w2.hasKey(WATERWAY)) {
    98                 return tr("Crossing waterways");
    99             } else if ((w1.hasKey(HIGHWAY) && w2.hasKey(WATERWAY))
    100                     || (w2.hasKey(HIGHWAY) && w1.hasKey(WATERWAY))) {
    101                 return tr("Crossing waterway/highway");
     121            WayType[] types = {getWayType(w1), getWayType(w2)};
     122            Arrays.sort(types);
     123
     124            if (types[0] == types[1]) {
     125                switch(types[0]) {
     126                    case BUILDING:
     127                        return tr("Crossing buildings");
     128                    case HIGHWAY:
     129                        return tr("Crossing highways");
     130                    case RESIDENTIAL_AREA:
     131                        return tr("Crossing residential areas");
     132                    case WATERWAY:
     133                        return tr("Crossing waterways");
     134                    case WAY:
     135                    default:
     136                        return tr("Crossing ways");
     137                }
    102138            } else {
    103                 return tr("Crossing ways");
     139                switch (types[0]) {
     140                    case BUILDING:
     141                        switch (types[1]) {
     142                            case HIGHWAY:
     143                                return tr("Crossing building/highway");
     144                            case RESIDENTIAL_AREA:
     145                                return tr("Crossing building/residential area");
     146                            case WATERWAY:
     147                                return tr("Crossing building/waterway");
     148                            case WAY:
     149                            default:
     150                                return tr("Crossing building/way");
     151                        }
     152                    case HIGHWAY:
     153                        switch (types[1]) {
     154                            case RESIDENTIAL_AREA:
     155                                return tr("Crossing highway/residential area");
     156                            case WATERWAY:
     157                                return tr("Crossing highway/waterway");
     158                            case WAY:
     159                            default:
     160                                return tr("Crossing highway/way");
     161                        }
     162                    case RESIDENTIAL_AREA:
     163                        switch (types[1]) {
     164                            case WATERWAY:
     165                                return tr("Crossing residential area/waterway");
     166                            case WAY:
     167                            default:
     168                                return tr("Crossing residential area/way");
     169                        }
     170                    case WATERWAY:
     171                    default:
     172                        return tr("Crossing waterway/way");
     173                }
    104174            }
    105175        }
     
    236306
    237307    static boolean isCoastline(OsmPrimitive w) {
    238         return w.hasTag("natural", "water", "coastline") || w.hasTag("landuse", "reservoir");
     308        return w.hasTag("natural", "water", "coastline") || w.hasTag(LANDUSE, "reservoir");
    239309    }
    240310
Note: See TracChangeset for help on using the changeset viewer.