Changeset 35288 in osm for applications/editors


Ignore:
Timestamp:
2020-01-13T21:45:26+01:00 (5 years ago)
Author:
simon04
Message:

JOSM/comfort0: parse relations

Location:
applications/editors/josm/plugins/comfort0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/comfort0/src/net/simon04/comfort0/level0l/Level0LParser.jj

    r35287 r35288  
    9090}
    9191
     92RelationData relation():
     93{
     94    RelationData r;
     95    Token id;
     96}
     97{
     98    <RELATION>
     99    { r = new RelationData(); }
     100    id=<H_ID>
     101    { r.setId(Long.parseLong(id.image)); }
     102    ( <COMMENT_START> <C_EOL> | <H_EOL> )
     103    relation_data(r)
     104    { return r; }
     105}
     106
    92107void way_data(WayData r):
    93108{}
     
    112127}
    113128
     129void relation_data(RelationData r):
     130{}
     131{
     132    (
     133        <D_SPACE> <D_SPACE>
     134        ( relation_member(r) | tag(r) )
     135    )*
     136}
     137
     138void relation_member(RelationData r):
     139{
     140    OsmPrimitiveType type;
     141    Token id;
     142    Token role = null;
     143}
     144{
     145    (
     146        <ND> { type = OsmPrimitiveType.NODE; }
     147    |
     148        <WY> { type = OsmPrimitiveType.WAY; }
     149    |
     150        <REL> { type = OsmPrimitiveType.RELATION; }
     151    )
     152    <D_SPACE>
     153    id=<D_ID>
     154    (
     155        <D_SPACE>
     156        (
     157            role=<IDENT> ( <D_SPACE> )*
     158        |
     159            ( <D_SPACE> )*
     160        )
     161    )?
     162    { r.getMembers().add(new RelationMemberData(role != null ? role.image : "", type, Long.parseLong(id.image))); }
     163    ( <D_COMMENT_START> <C_EOL> | <D_EOL> )
     164}
     165
    114166void tag(PrimitiveData r):
    115167{
  • applications/editors/josm/plugins/comfort0/test/unit/net/simon04/comfort0/level0l/parsergen/Level0LParserTest.java

    r35285 r35288  
    88import org.junit.Test;
    99import org.openstreetmap.josm.data.osm.NodeData;
     10import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     11import org.openstreetmap.josm.data.osm.RelationData;
    1012import org.openstreetmap.josm.data.osm.WayData;
    1113
     
    4547        assertThat(way.getKeys().get("name"), is("Pastower Straße"));
    4648    }
     49
     50    @Test
     51    public void testRelation() throws Exception {
     52        final String level0l = "" +
     53                "relation 56688 # member types: nd, wy, rel; roles are put after ids\n" +
     54                "  nd 294942404\n" +
     55                "  nd 364933006 # the second node\n" +
     56                "  wy 4579143 forward\n" +
     57                "  nd 249673494 stop # the end\n" +
     58                "  name = Küstenbus Linie 123\n" +
     59                "  network = VVW\n" +
     60                "  operator = Regionalverkehr Küste\n" +
     61                "  ref = 123\n" +
     62                "  route = bus\n" +
     63                "  type = route\n";
     64        final RelationData relation = new Level0LParser(new StringReader(level0l)).relation();
     65        assertThat(relation.getId(), is(56688L));
     66        assertThat(relation.getMembersCount(), is(4));
     67        assertThat(relation.getMembers().get(0).getMemberId(), is(294942404L));
     68        assertThat(relation.getMembers().get(0).getMemberType(), is(OsmPrimitiveType.NODE));
     69        assertThat(relation.getMembers().get(0).getRole(), is(""));
     70        assertThat(relation.getMembers().get(2).getMemberId(), is(4579143L));
     71        assertThat(relation.getMembers().get(2).getMemberType(), is(OsmPrimitiveType.WAY));
     72        assertThat(relation.getMembers().get(2).getRole(), is("forward"));
     73        assertThat(relation.getKeys().size(), is(6));
     74    }
    4775}
Note: See TracChangeset for help on using the changeset viewer.