Changeset 32822 in osm for applications/editors


Ignore:
Timestamp:
2016-08-16T14:03:50+02:00 (8 years ago)
Author:
xamanu
Message:

Allowing multiple stop positions and platforms in stop area checks

Location:
applications/editors/josm/plugins/pt_assistant
Files:
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/NodeChecker.java

    r32797 r32822  
    55import java.lang.reflect.InvocationTargetException;
    66import java.util.ArrayList;
    7 import java.util.HashMap;
    87import java.util.List;
    98
     
    9998                        TestError e = new TestError(this.test, Severity.WARNING,
    10099                                        tr("PT: Stop position or platform is not part of a stop area relation"),
    101                                         PTAssistantValidatorTest.ERROR_CODE_NODE_PART_OF_STOP_AREA, primitives);
     100                                        PTAssistantValidatorTest.ERROR_CODE_NOT_PART_OF_STOP_AREA, primitives);
    102101                        errors.add(e);
    103102                }
    104103        }
    105104
    106         /**
    107          * Checks if the given stop_position belongs to the same route relations as
    108          * its related platform(s). *
    109          *
    110          * @param n
    111          */
    112         protected void performStopPositionComparePlatformRelations() {
    113 
    114                 HashMap<Long, Long> stopPositionRelationIds = new HashMap<>();
    115                 HashMap<Long, Long> platformRelationIds = new HashMap<>();
    116 
    117                 // Loop through all referrer relations
    118                 for (Relation referrer : OsmPrimitive.getFilteredList(node.getReferrers(), Relation.class)) {
    119 
    120                         // Create list of relations the stop position belongs to
    121                         if (referrer.get("type") == "route") {
    122                                 stopPositionRelationIds.put(referrer.getId(), referrer.getId());
    123                         }
    124 
    125                         // Create list of relations the related platform(s) belongs to
    126                         else if (referrer.get("public_transport") == "stop_area") {
    127                                 for (RelationMember stopAreaMember : referrer.getMembers()) {
    128                                         OsmPrimitive stopAreaMemberFoo = stopAreaMember.getMember();
    129                                         if (stopAreaMemberFoo.get("public_transport") == "platform") {
    130                                                 for (Relation stopAreaMemberReferrer : OsmPrimitive
    131                                                                 .getFilteredList(stopAreaMemberFoo.getReferrers(), Relation.class)) {
    132                                                         if (stopAreaMemberReferrer.get("type") == "route") {
    133                                                                 platformRelationIds.put(stopAreaMemberReferrer.getId(), stopAreaMemberReferrer.getId());
    134                                                         }
    135                                                 }
    136                                         }
    137                                 }
    138                         }
    139                 }
    140 
    141                 // Check if the stop_position has no referrers at all. If it has no
    142                 // referrers, then no error should be reported (changed on 11.08.2016 by
    143                 // darya):
    144                 if (stopPositionRelationIds.isEmpty()) {
    145                         return;
    146                 }
    147 
    148                 // Check if route relation lists are identical
    149                 if (stopPositionRelationIds.equals(platformRelationIds)) {
    150                         return;
    151                 }
    152 
    153                 List<OsmPrimitive> primitives = new ArrayList<>(1);
    154                 primitives.add(node);
    155                 TestError e = new TestError(this.test, Severity.WARNING,
    156                                 tr("PT: Stop position and its related platform(s) have different route relations"),
    157                                 PTAssistantValidatorTest.ERROR_CODE_STOP_POSITION_COMPARE_RELATIONS, primitives);
    158                 errors.add(e);
    159         }
    160105
    161106        /**
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssistantValidatorTest.java

    r32804 r32822  
    4646        public static final int ERROR_CODE_STOP_NOT_SERVED = 3753;
    4747        public static final int ERROR_CODE_STOP_BY_STOP = 3754;
    48         public static final int ERROR_CODE_STOP_POSITION_COMPARE_RELATIONS = 3755;
    49         public static final int ERROR_CODE_NODE_PART_OF_STOP_AREA = 3761;
    50         public static final int ERROR_CODE_STOP_AREA_MEMBERS_EXCESS = 3762;
    51         public static final int ERROR_CODE_STOP_AREA_STOP_POSITION = 3763;
    52         public static final int ERROR_CODE_STOP_AREA_PLATFORM = 3764;
    53         public static final int ERROR_CODE_STOP_AREA_NO_STOPS = 3765;
    54         public static final int ERROR_CODE_STOP_AREA_MANY_STOPS = 3765;
    55         public static final int ERROR_CODE_STOP_AREA_NO_PLATFORM = 3766;
    56         public static final int ERROR_CODE_STOP_AREA_MANY_PLATFORMS = 3767;
    57         public static final int ERROR_CODE_STOP_AREA_MEMBERS_RELATIONS = 3768;
     48        public static final int ERROR_CODE_NOT_PART_OF_STOP_AREA = 3761;
     49        public static final int ERROR_CODE_STOP_AREA_NO_STOPS = 3762;
     50        public static final int ERROR_CODE_STOP_AREA_NO_PLATFORM = 3763;
     51        public static final int ERROR_CODE_STOP_AREA_COMPARE_RELATIONS = 3764;
     52
    5853
    5954
     
    8681                        // check if stop positions are in any stop_area relation:
    8782                        nodeChecker.performNodePartOfStopAreaTest();
    88                        
    89                         // Check if stop positions belong the same route relation as related platform(s)
    90                         nodeChecker.performStopPositionComparePlatformRelations();
     83
    9184                }
    9285
     
    115108                        // Check if stop area relation has one stop position.
    116109                        stopChecker.performStopAreaStopPositionTest();
    117                        
    118                         // Check if stop area relation has more than one stop position.
    119                         stopChecker.performStopAreaMultiStopPositionTest();
    120110
    121111                        // Check if stop area relation has one platform.
    122112                        stopChecker.performStopAreaPlatformTest();
    123 
    124                         // Check if stop area relation has more than one platform.
    125                         stopChecker.performStopAreaMultiPlatformTest();
     113                       
     114                        // Check if stop position(s) belong the same route relation as related platform(s)
     115                        stopChecker.performStopAreaRelationsTest();
    126116
    127117                        // Attach thrown errors
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/StopChecker.java

    r32791 r32822  
    66import java.util.List;
    77import java.util.Set;
     8import java.util.HashMap;
    89
    910import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1011import org.openstreetmap.josm.data.osm.Relation;
     12import org.openstreetmap.josm.data.osm.RelationMember;
    1113import org.openstreetmap.josm.data.validation.Severity;
    1214import org.openstreetmap.josm.data.validation.Test;
     
    5052        }
    5153
    52         /**
    53          * Checks if the given stop area relation has more than one stop position.
    54          */
    55         protected void performStopAreaMultiStopPositionTest() {
    56                
    57                 // Count members tagged as stop position.
    58                 int countStopPosition = 0;
    59                 for (OsmPrimitive member : members) {
    60                         if (StopUtils.verifyStopAreaStopPosition(member)) {
    61                                 countStopPosition++;
    62 
    63                         }
    64                 }
    65 
    66                 // No errors if there are more than one stop position.
    67                 if (countStopPosition <= 1) {
    68                         return;
    69                 }
    70                
    71                 // Throw error message
    72                 List<OsmPrimitive> primitives = new ArrayList<>(1);
    73                 primitives.add(relation);
    74                 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Stop area relation has several stop positions"),
    75                                 PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_MANY_STOPS, primitives);
    76                 errors.add(e);
    77                
    78         }
    7954       
    8055        /**
     
    10176
    10277        /**
    103          * Checks if the given stop area relation has more than one platform.
     78         * Checks if the stop_position(s) of an stop area belong to the same route relations as
     79         * its related platform(s).
     80         *
     81         * @param n
    10482         */
    105         protected void performStopAreaMultiPlatformTest() {
    106                
    107                 // Count members tagged as platformn.
    108                 int countPlatform = 0;
     83        protected void performStopAreaRelationsTest() {
     84
     85                HashMap<Long, Long> stopPositionRelationIds = new HashMap<>();
     86                HashMap<Long, Long> platformRelationIds = new HashMap<>();
     87
     88
     89                // Loop through all members
    10990                for (OsmPrimitive member : members) {
    110                         if (StopUtils.verifyStopAreaPlatform(member)) {
    111                                 countPlatform++;
     91                       
     92                        // For stop positions...
     93                        if (StopUtils.verifyStopAreaStopPosition(member)) {
     94                               
     95                                // Create a list of assigned route relations
     96                                for (Relation referrer : OsmPrimitive.getFilteredList(member.getReferrers(), Relation.class)) {
     97                                        if (referrer.get("type") == "route") {
     98                                                stopPositionRelationIds.put(referrer.getId(), referrer.getId());
     99                                        }
     100                                }
     101                        }
     102                       
     103                        // For platforms...
     104                        else if (StopUtils.verifyStopAreaPlatform(member)) {
    112105
    113                         }
     106                                // Create a list of assigned route relations
     107                                for (Relation referrer : OsmPrimitive.getFilteredList(member.getReferrers(), Relation.class)) {
     108                                        if (referrer.get("type") == "route") {
     109                                                platformRelationIds.put(referrer.getId(), referrer.getId());
     110                                        }
     111                                }
     112                        }       
    114113                }
    115114               
    116                 // No errors if there are more than one platformnn.
    117                 if (countPlatform <= 1) {
     115                // Check if the stop_position has no referrers at all. If it has no
     116                // referrers, then no error should be reported (changed on 11.08.2016 by
     117                // darya):
     118                if (stopPositionRelationIds.isEmpty()) {
    118119                        return;
    119120                }
    120                                
     121
     122                // Check if route relation lists are identical
     123                if (stopPositionRelationIds.equals(platformRelationIds)) {
     124                        return;
     125                }
     126               
    121127                // Throw error message
    122128                List<OsmPrimitive> primitives = new ArrayList<>(1);
    123129                primitives.add(relation);
    124                 TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Stop area relation has several platforms"),
    125                                 PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_MANY_PLATFORMS, primitives);
     130                TestError e = new TestError(this.test, Severity.WARNING,
     131                                tr("PT: Route relations of stop position(s) and platform(s) of stop area memebrs diverge"),
     132                                PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_COMPARE_RELATIONS, primitives);
    126133                errors.add(e);
    127                
    128134        }
    129135       
  • applications/editors/josm/plugins/pt_assistant/test/data/stop-area-relations.osm

    r32783 r32822  
    11<?xml version='1.0' encoding='UTF-8'?>
    22<osm version='0.6' upload='true' generator='JOSM'>
    3   <node id='-60958' action='modify' visible='true' lat='12.12569675765' lon='-86.28455907163'>
     3  <node id='-55' action='modify' visible='true' lat='12.12569675765' lon='-86.28455907163'>
    44    <tag k='bus' v='yes' />
    55    <tag k='public_transport' v='stop_position' />
    66  </node>
    7   <node id='-60960' action='modify' visible='true' lat='12.12574315765' lon='-86.28459437163'>
     7  <node id='-57' action='modify' visible='true' lat='12.12574315765' lon='-86.28459437163'>
    88    <tag k='bus' v='yes' />
    99    <tag k='public_transport' v='platform' />
    1010  </node>
    11   <node id='-60966' action='modify' visible='true' lat='12.12586275765' lon='-86.28635997163' />
    12   <node id='-60968' action='modify' visible='true' lat='12.12586605765' lon='-86.28641487163' />
    13   <node id='-60970' action='modify' visible='true' lat='12.12592805765' lon='-86.28729767163' />
    14   <node id='-60972' action='modify' visible='true' lat='12.12598865765' lon='-86.28844557163' />
    15   <node id='-60974' action='modify' visible='true' lat='12.12599975765' lon='-86.28875027163'>
     11  <node id='-59' action='modify' visible='true' lat='12.12586275765' lon='-86.28635997163' />
     12  <node id='-61' action='modify' visible='true' lat='12.12586605765' lon='-86.28641487163' />
     13  <node id='-63' action='modify' visible='true' lat='12.12592805765' lon='-86.28729767163' />
     14  <node id='-65' action='modify' visible='true' lat='12.12598865765' lon='-86.28844557163' />
     15  <node id='-67' action='modify' visible='true' lat='12.12599975765' lon='-86.28875027163'>
    1616    <tag k='highway' v='traffic_signals' />
    1717  </node>
    18   <node id='-60976' action='modify' visible='true' lat='12.12602745765' lon='-86.29081977163' />
    19   <node id='-60978' action='modify' visible='true' lat='12.12603135765' lon='-86.29160537163' />
    20   <node id='-60980' action='modify' visible='true' lat='12.12603245765' lon='-86.29184287163'>
     18  <node id='-69' action='modify' visible='true' lat='12.12602745765' lon='-86.29081977163' />
     19  <node id='-71' action='modify' visible='true' lat='12.12603135765' lon='-86.29160537163' />
     20  <node id='-73' action='modify' visible='true' lat='12.12603245765' lon='-86.29184287163'>
    2121    <tag k='highway' v='traffic_signals' />
    2222  </node>
    23   <node id='-60997' action='modify' visible='true' lat='12.12605336295' lon='-86.29221374917'>
     23  <node id='-75' action='modify' visible='true' lat='12.12605336295' lon='-86.29221374917'>
    2424    <tag k='bus' v='yes' />
    2525    <tag k='public_transport' v='stop_position' />
    2626  </node>
    27   <node id='-61002' visible='true' lat='12.1261061435' lon='-86.2922353432'>
     27  <node id='-77' visible='true' lat='12.1261061435' lon='-86.2922353432'>
    2828    <tag k='bus' v='yes' />
    2929    <tag k='public_transport' v='platform' />
    3030  </node>
    31   <way id='-60982' action='modify' visible='true'>
    32     <nd ref='-60958' />
    33     <nd ref='-60966' />
    34     <nd ref='-60968' />
    35     <nd ref='-60970' />
    36     <nd ref='-60972' />
    37     <nd ref='-60974' />
     31  <way id='-79' action='modify' visible='true'>
     32    <nd ref='-55' />
     33    <nd ref='-59' />
     34    <nd ref='-61' />
     35    <nd ref='-63' />
     36    <nd ref='-65' />
     37    <nd ref='-67' />
    3838    <tag k='highway' v='primary' />
    3939    <tag k='lanes' v='2' />
     
    4343    <tag k='surface' v='asphalt' />
    4444  </way>
    45   <way id='-63380' action='modify' visible='true'>
    46     <nd ref='-60974' />
    47     <nd ref='-60976' />
    48     <nd ref='-60978' />
    49     <nd ref='-60980' />
    50     <nd ref='-60997' />
     45  <way id='-81' action='modify' visible='true'>
     46    <nd ref='-67' />
     47    <nd ref='-69' />
     48    <nd ref='-71' />
     49    <nd ref='-73' />
     50    <nd ref='-75' />
    5151    <tag k='highway' v='primary' />
    5252    <tag k='lanes' v='2' />
     
    5656    <tag k='surface' v='asphalt' />
    5757  </way>
    58   <relation id='-60984' action='modify' visible='true'>
    59     <member type='node' ref='-60958' role='stop' />
    60     <member type='node' ref='-60960' role='platform' />
     58  <relation id='-83' action='modify' visible='true'>
     59    <member type='node' ref='-55' role='stop' />
     60    <member type='node' ref='-57' role='platform' />
    6161    <tag k='name' v='Rotonda El Periodista' />
    6262    <tag k='public_transport' v='stop_area' />
     
    6464    <tag k='type' v='public_transport' />
    6565  </relation>
    66   <relation id='-60986' action='modify' visible='true'>
    67     <member type='node' ref='-60958' role='stop' />
    68     <member type='node' ref='-61002' role='platform' />
    69     <member type='way' ref='-60982' role='' />
    70     <member type='way' ref='-63380' role='' />
     66  <relation id='-85' action='modify' visible='true'>
     67    <member type='node' ref='-55' role='stop' />
     68    <member type='way' ref='-79' role='' />
     69    <member type='way' ref='-81' role='' />
     70    <member type='node' ref='-75' role='stop' />
    7171    <tag k='bus' v='yes' />
    7272    <tag k='from' v='Cuesta el Plomo' />
     
    7878    <tag k='type' v='route' />
    7979  </relation>
    80   <relation id='-61332' action='modify' visible='true'>
    81     <member type='node' ref='-60997' role='stop' />
    82     <member type='node' ref='-61002' role='platform' />
     80  <relation id='-87' action='modify' visible='true'>
     81    <member type='node' ref='-75' role='stop' />
     82    <member type='node' ref='-77' role='platform' />
    8383    <tag k='name' v='Mercado Oriental' />
    8484    <tag k='public_transport' v='stop_area' />
  • applications/editors/josm/plugins/pt_assistant/test/unit/org/openstreetmap/josm/plugins/pt_assistant/validation/StopCheckerTest.java

    r32783 r32822  
    3333                Assert.assertEquals(nodeChecker.getErrors().size(), 1);
    3434                Assert.assertEquals(nodeChecker.getErrors().get(0).getCode(),
    35                                 PTAssistantValidatorTest.ERROR_CODE_NODE_PART_OF_STOP_AREA);
     35                                PTAssistantValidatorTest.ERROR_CODE_NOT_PART_OF_STOP_AREA);
    3636        }
    3737       
     
    3939
    4040        @Test
    41         public void stopPositionComparePlatformRelations() {
     41        public void stopAreaRelationsTest() {
    4242               
    4343                // Check if stop positions belong the same routes as related platform(s)
     
    4646                DataSet ds = ImportUtils.importOsmFile(file, "testLayer");
    4747                PTAssistantValidatorTest test = new PTAssistantValidatorTest();
    48                 Node node = null;
     48                Relation stopArea = null;
    4949               
    50                 for (Node n : ds.getNodes()) {
    51                         if (n.hasTag("public_transport", "stop_position")) {
    52                                 node = n;
     50                for (Relation r : ds.getRelations()) {
     51                        if (r.hasTag("public_transport", "stop_area")) {
     52                                stopArea = r;
    5353                        }
    5454                }
    5555               
    56                 NodeChecker nodeChecker = new NodeChecker(node, test);
    57                 nodeChecker.performStopPositionComparePlatformRelations();
    58                 Assert.assertEquals(nodeChecker.getErrors().size(), 1);
    59                 Assert.assertEquals(nodeChecker.getErrors().get(0).getCode(),
    60                                 PTAssistantValidatorTest.ERROR_CODE_STOP_POSITION_COMPARE_RELATIONS);
    61                        
     56                StopChecker stopChecker = new StopChecker(stopArea, test);
     57                stopChecker.performStopAreaRelationsTest();
     58                Assert.assertEquals(stopChecker.getErrors().size(), 1);
     59                Assert.assertEquals(stopChecker.getErrors().get(0).getCode(),
     60                                PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_COMPARE_RELATIONS);               
    6261        }
    6362       
     
    6665        public void stopAreaStopPositionTest() {
    6766               
    68                 // Check if stop area relation has one stop position.
     67                // Check if stop area relation has at least one stop position.
    6968               
    7069                File file = new File(AbstractTest.PATH_TO_STOP_AREA_NO_STOPS);
     
    8786        }
    8887       
    89         @Test
    90         public void stopAreaMultiStopPositionTest() {
    91                
    92                 // Check if stop area relation has more than one stop position.
    93                
    94                 File file = new File(AbstractTest.PATH_TO_STOP_AREA_MANY_STOPS);
    95                 DataSet ds = ImportUtils.importOsmFile(file, "testLayer");
    96                 PTAssistantValidatorTest test = new PTAssistantValidatorTest();
    97                 Relation stopArea = null;
    98 
    99                 for (Relation r : ds.getRelations()) {
    100                         if (r.hasTag("public_transport", "stop_area")) {
    101                                 stopArea = r;
    102                         }
    103                 }
    104 
    105                 StopChecker stopChecker = new StopChecker(stopArea, test);
    106                 stopChecker.performStopAreaMultiStopPositionTest();
    107                 Assert.assertEquals(stopChecker.getErrors().size(), 1);
    108                 Assert.assertEquals(stopChecker.getErrors().get(0).getCode(),
    109                                 PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_MANY_STOPS);
    110 
    111         }
    112        
    11388
    11489        @Test
    11590        public void stopAreaPlatformTest() {
    11691               
    117                 // Check if stop area relation has one platform.
     92                // Check if stop area relation has at least one platform.
    11893               
    11994                File file = new File(AbstractTest.PATH_TO_STOP_AREA_NO_PLATFORMS);
     
    135110
    136111        }
    137        
    138         @Test
    139         public void stopAreaMultiPlatformTest() {
    140                
    141                 // Check if stop area relation has more than one stop position.
    142                
    143                 File file = new File(AbstractTest.PATH_TO_STOP_AREA_MANY_PLATFORMS);
    144                 DataSet ds = ImportUtils.importOsmFile(file, "testLayer");
    145                 PTAssistantValidatorTest test = new PTAssistantValidatorTest();
    146                 Relation stopArea = null;
    147 
    148                 for (Relation r : ds.getRelations()) {
    149                         if (r.hasTag("public_transport", "stop_area")) {
    150                                 stopArea = r;
    151                         }
    152                 }
    153 
    154                 StopChecker stopChecker = new StopChecker(stopArea, test);
    155                 stopChecker.performStopAreaMultiPlatformTest();
    156                 Assert.assertEquals(stopChecker.getErrors().size(), 1);
    157                 Assert.assertEquals(stopChecker.getErrors().get(0).getCode(),
    158                                 PTAssistantValidatorTest.ERROR_CODE_STOP_AREA_MANY_PLATFORMS);
    159 
    160         }
    161112
    162113}
Note: See TracChangeset for help on using the changeset viewer.