source: osm/applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/BoundaryFixer.java@ 28703

Last change on this file since 28703 was 28703, checked in by larry0ua, 12 years ago

'RelToolbox: added warning messages to the warning icon hint'

File size: 3.0 KB
Line 
1package relcontext.relationfix;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import org.openstreetmap.josm.command.ChangeCommand;
6import org.openstreetmap.josm.command.Command;
7import org.openstreetmap.josm.data.osm.Node;
8import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
9import org.openstreetmap.josm.data.osm.Relation;
10import org.openstreetmap.josm.data.osm.RelationMember;
11
12
13/**
14 * @see http://wiki.openstreetmap.org/wiki/Relation:boundary
15 */
16public class BoundaryFixer extends MultipolygonFixer {
17
18 public BoundaryFixer() {
19 super("boundary", "multipolygon");
20 }
21
22 /**
23 * For boundary relations both "boundary" and "multipolygon" types are applicable, but
24 * it should also have key boundary=administrative to be fully boundary.
25 * @see http://wiki.openstreetmap.org/wiki/Relation:boundary
26 */
27 @Override
28 public boolean isFixerApplicable(Relation rel) {
29 return super.isFixerApplicable(rel) && "administrative".equals(rel.get("boundary"));
30 }
31
32 @Override
33 public boolean isRelationGood(Relation rel) {
34 for( RelationMember m : rel.getMembers() ) {
35 if (m.getType().equals(OsmPrimitiveType.RELATION) && !"subarea".equals(m.getRole())) {
36 setWarningMessage(tr("Relation without 'subarea' role found"));
37 return false;
38 }
39 if (m.getType().equals(OsmPrimitiveType.NODE) && !("label".equals(m.getRole()) || "admin_centre".equals(m.getRole()))) {
40 setWarningMessage(tr("Node without 'label' or 'admin_centre' role found"));
41 return false;
42 }
43 if (m.getType().equals(OsmPrimitiveType.WAY) && !("outer".equals(m.getRole()) || "inner".equals(m.getRole()))) {
44 setWarningMessage(tr("Way without 'inner' or 'outer' role found"));
45 return false;
46 }
47 }
48 clearWarningMessage();
49 return true;
50 }
51
52 @Override
53 public Command fixRelation(Relation rel) {
54 Relation r = rel;
55 Relation rr = fixMultipolygonRoles(r);
56 boolean fixed = false;
57 if (rr != null) {
58 fixed = true;
59 r = rr;
60 }
61 rr = fixBoundaryRoles(r);
62 if (rr != null) {
63 fixed = true;
64 r = rr;
65 }
66 return fixed ? new ChangeCommand(rel, r) : null;
67 }
68
69 private Relation fixBoundaryRoles( Relation source ) {
70 Relation r = new Relation(source);
71 boolean fixed = false;
72 for( int i = 0; i < r.getMembersCount(); i++ ) {
73 RelationMember m = r.getMember(i);
74 String role = null;
75 if( m.isRelation() )
76 role = "subarea";
77 else if( m.isNode() ) {
78 Node n = (Node)m.getMember();
79 if( !n.isIncomplete() ) {
80 if( n.hasKey("place") )
81 role = "admin_centre";
82 else
83 role = "label";
84 }
85 }
86 if( role != null && !role.equals(m.getRole()) ) {
87 r.setMember(i, new RelationMember(role, m.getMember()));
88 fixed = true;
89 }
90 }
91 return fixed ? r : null;
92 }
93}
Note: See TracBrowser for help on using the repository browser.