Changeset 32395 in osm for applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix
- Timestamp:
- 2016-06-24T09:10:57+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/AssociatedStreetFixer.java
r30738 r32395 1 // License: GPL. For details, see LICENSE file. 1 2 package relcontext.relationfix; 2 3 … … 46 47 // check that all street members have same name as relation (???) 47 48 String streetName = rel.get("name"); 48 if (streetName == null) streetName = ""; 49 if (streetName == null) { 50 streetName = ""; 51 } 49 52 for (RelationMember m : rel.getMembers()) { 50 53 if ("street".equals(m.getRole()) && !streetName.equals(m.getWay().get("name"))) { … … 101 104 // fill relation name 102 105 Map<String, Integer> streetNames = new HashMap<>(); 103 for (RelationMember m : rel.getMembers()) 106 for (RelationMember m : rel.getMembers()) { 104 107 if ("street".equals(m.getRole()) && m.isWay()) { 105 108 String name = m.getWay().get("name"); 106 if (name == null || name.isEmpty()) continue; 109 if (name == null || name.isEmpty()) { 110 continue; 111 } 107 112 108 113 Integer count = streetNames.get(name); 109 114 110 streetNames.put(name, count != null? count + 1 : 1); 115 streetNames.put(name, count != null ? count + 1 : 1); 111 116 } 117 } 112 118 String commonName = ""; 113 119 Integer commonCount = 0; … … 146 152 commandList.add(new ChangeCommand(oldWay, newWay)); 147 153 } 148 */ 154 */ 149 155 // return results 150 156 if (commandList.size() == 0) -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/BoundaryFixer.java
r30738 r32395 1 // License: GPL. For details, see LICENSE file. 1 2 package relcontext.relationfix; 2 3 … … 32 33 @Override 33 34 public boolean isRelationGood(Relation rel) { 34 for (RelationMember m : rel.getMembers()35 for (RelationMember m : rel.getMembers()) { 35 36 if (m.getType().equals(OsmPrimitiveType.RELATION) && !"subarea".equals(m.getRole())) { 36 37 setWarningMessage(tr("Relation without ''subarea'' role found")); … … 67 68 } 68 69 69 private Relation fixBoundaryRoles( 70 private Relation fixBoundaryRoles(Relation source) { 70 71 Relation r = new Relation(source); 71 72 boolean fixed = false; 72 for (int i = 0; i < r.getMembersCount(); i++73 for (int i = 0; i < r.getMembersCount(); i++) { 73 74 RelationMember m = r.getMember(i); 74 75 String role = null; 75 if (m.isRelation())76 if (m.isRelation()) { 76 77 role = "subarea"; 77 else if (m.isNode()78 Node n = (Node)m.getMember(); 79 if (!n.isIncomplete()80 if (n.hasKey("place")78 } else if (m.isNode()) { 79 Node n = (Node) m.getMember(); 80 if (!n.isIncomplete()) { 81 if (n.hasKey("place")) { 81 82 String place = n.get("place"); 82 83 if (place.equals("state") || place.equals("country") || … … 86 87 role = "admin_centre"; 87 88 } 88 } else 89 } else { 89 90 role = "label"; 91 } 90 92 } 91 93 } 92 if (role != null && !role.equals(m.getRole())94 if (role != null && !role.equals(m.getRole())) { 93 95 r.setMember(i, new RelationMember(role, m.getMember())); 94 96 fixed = true; -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/MultipolygonFixer.java
r30738 r32395 1 // License: GPL. For details, see LICENSE file. 1 2 package relcontext.relationfix; 2 3 … … 30 31 } 31 32 32 33 33 @Override 34 34 public boolean isRelationGood(Relation rel) { 35 for (RelationMember m : rel.getMembers()) 35 for (RelationMember m : rel.getMembers()) { 36 36 if (m.getType().equals(OsmPrimitiveType.WAY) && !("outer".equals(m.getRole()) || "inner".equals(m.getRole()))) { 37 37 setWarningMessage(tr("Way without ''inner'' or ''outer'' role found")); 38 38 return false; 39 39 } 40 } 40 41 clearWarningMessage(); 41 42 return true; … … 45 46 public Command fixRelation(Relation rel) { 46 47 Relation rr = fixMultipolygonRoles(rel); 47 return rr != null? new ChangeCommand(rel, rr) : null; 48 return rr != null ? new ChangeCommand(rel, rr) : null; 48 49 } 49 50 … … 51 52 * Basically, created multipolygon from scratch, and if successful, replace roles with new ones. 52 53 */ 53 protected Relation fixMultipolygonRoles( 54 protected Relation fixMultipolygonRoles(Relation source) { 54 55 Collection<Way> ways = new ArrayList<>(); 55 for( OsmPrimitive p : source.getMemberPrimitives() ) 56 if( p instanceof Way ) 57 ways.add((Way)p); 56 for (OsmPrimitive p : source.getMemberPrimitives()) { 57 if (p instanceof Way) { 58 ways.add((Way) p); 59 } 60 } 58 61 MultipolygonBuilder mpc = new MultipolygonBuilder(); 59 62 String error = mpc.makeFromWays(ways); 60 if (error != null63 if (error != null) 61 64 return null; 62 65 … … 64 67 boolean fixed = false; 65 68 Set<Way> outerWays = new HashSet<>(); 66 for (MultipolygonBuilder.JoinedPolygon poly : mpc.outerWays)67 for (Way w : poly.ways)69 for (MultipolygonBuilder.JoinedPolygon poly : mpc.outerWays) { 70 for (Way w : poly.ways) { 68 71 outerWays.add(w); 72 } 73 } 69 74 Set<Way> innerWays = new HashSet<>(); 70 for (MultipolygonBuilder.JoinedPolygon poly : mpc.innerWays)71 for (Way w : poly.ways)75 for (MultipolygonBuilder.JoinedPolygon poly : mpc.innerWays) { 76 for (Way w : poly.ways) { 72 77 innerWays.add(w); 73 for( int i = 0; i < r.getMembersCount(); i++ ) { 78 } 79 } 80 for (int i = 0; i < r.getMembersCount(); i++) { 74 81 RelationMember m = r.getMember(i); 75 if (m.isWay()82 if (m.isWay()) { 76 83 String role = null; 77 if (outerWays.contains((Way)m.getMember()))84 if (outerWays.contains(m.getMember())) { 78 85 role = "outer"; 79 else if (innerWays.contains((Way)m.getMember()))86 } else if (innerWays.contains(m.getMember())) { 80 87 role = "inner"; 81 if( role != null && !role.equals(m.getRole()) ) { 88 } 89 if (role != null && !role.equals(m.getRole())) { 82 90 r.setMember(i, new RelationMember(role, m.getMember())); 83 91 fixed = true; -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/NothingFixer.java
r30738 r32395 1 // License: GPL. For details, see LICENSE file. 1 2 package relcontext.relationfix; 2 3 … … 12 13 super(""); 13 14 } 15 14 16 @Override 15 17 public boolean isFixerApplicable(Relation rel) { 16 18 return true; 17 19 } 20 18 21 @Override 19 22 public boolean isRelationGood(Relation rel) { … … 25 28 return null; 26 29 } 27 28 30 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/PublicTransportFixer.java
r30841 r32395 1 // License: GPL. For details, see LICENSE file. 1 2 package relcontext.relationfix; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 2 5 3 6 import org.openstreetmap.josm.command.ChangeCommand; … … 6 9 import org.openstreetmap.josm.data.osm.Relation; 7 10 import org.openstreetmap.josm.data.osm.RelationMember; 8 import static org.openstreetmap.josm.tools.I18n.tr; 11 9 12 import relcontext.actions.PublicTransportHelper; 10 13 … … 18 21 */ 19 22 public class PublicTransportFixer extends RelationFixer { 20 23 21 24 public PublicTransportFixer() { 22 25 super("route", "public_transport"); … … 30 33 public boolean isRelationGood(Relation rel) { 31 34 for (RelationMember m : rel.getMembers()) { 32 if (m.getType().equals(OsmPrimitiveType.NODE) 35 if (m.getType().equals(OsmPrimitiveType.NODE) 33 36 && !(m.getRole().startsWith(PublicTransportHelper.STOP) || m.getRole().startsWith(PublicTransportHelper.PLATFORM))) { 34 37 setWarningMessage(tr("Node without ''stop'' or ''platform'' role found")); … … 62 65 return fixed ? new ChangeCommand(rel, r) : null; 63 66 } 64 67 65 68 private Relation fixStopPlatformRole(Relation source) { 66 69 Relation r = new Relation(source); 67 70 boolean fixed = false; 68 for (int i = 0; i < r.getMembersCount(); i++71 for (int i = 0; i < r.getMembersCount(); i++) { 69 72 RelationMember m = r.getMember(i); 70 73 String role = PublicTransportHelper.getRoleByMember(m); … … 75 78 } 76 79 } 77 return fixed ? r : null; 80 return fixed ? r : null; 78 81 } 79 82 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/RelationFixer.java
r30738 r32395 1 // License: GPL. For details, see LICENSE file. 1 2 package relcontext.relationfix; 2 3 … … 20 21 /** 21 22 * Construct new RelationFixer by a list of applicable types 22 * @param types 23 * @param types types 23 24 */ 24 25 public RelationFixer(String... types) { 25 26 applicableTypes = new ArrayList<>(); 26 for(String type: types) { 27 for (String type: types) { 27 28 applicableTypes.add(type); 28 29 } … … 33 34 * and then check desired relation properties. 34 35 * Note that this only verifies if current RelationFixer can be used to check and fix given relation 35 * Deeper relation checking is at {@link isRelationGood} 36 * Deeper relation checking is at {@link #isRelationGood} 36 37 * 37 38 * @param rel Relation to check … … 45 46 46 47 String type = rel.get("type"); 47 for(String oktype: applicableTypes) 48 for (String oktype: applicableTypes) { 48 49 if (oktype.equals(type)) 49 50 return true; 51 } 50 52 51 53 return false; … … 73 75 this.sortAndFixAction = sortAndFixAction; 74 76 } 77 75 78 protected void setWarningMessage(String text) { 76 79 if (text == null) { … … 80 83 } 81 84 } 85 82 86 protected void clearWarningMessage() { 83 87 sortAndFixAction.putValue(Action.SHORT_DESCRIPTION, tr("Fix roles of the chosen relation members")); 84 88 } 85 86 89 }
Note:
See TracChangeset
for help on using the changeset viewer.