Changeset 28703 in osm for applications/editors/josm/plugins/reltoolbox/src/relcontext
- Timestamp:
- 2012-09-11T09:55:54+02:00 (12 years ago)
- Location:
- applications/editors/josm/plugins/reltoolbox/src/relcontext
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/SortAndFixAction.java
r28693 r28703 37 37 rel.addChosenRelationListener(this); 38 38 setEnabled(false); 39 39 40 40 // construct all available fixers 41 41 fixers = new ArrayList<RelationFixer>(); 42 fixers.add(new BoundaryFixer()); // should be before multipolygon as takes special case of multipolygon relation - boundary 43 fixers.add(new MultipolygonFixer()); 44 fixers.add(new AssociatedStreetFixer()); 45 42 //should be before multipolygon as takes special case of multipolygon relation - boundary 43 fixers.add(new BoundaryFixer()); // boundary, multipolygon, boundary=administrative 44 fixers.add(new MultipolygonFixer()); // multipolygon 45 fixers.add(new AssociatedStreetFixer()); //associatedStreet 46 47 for(RelationFixer fix : fixers) { 48 fix.setFixAction(this); 49 } 46 50 } 47 51 52 @Override 48 53 public void actionPerformed( ActionEvent e ) { 49 54 Command c = fixRelation(rel.get()); … … 52 57 } 53 58 59 @Override 54 60 public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) { 55 61 setEnabled(newRelation != null && needsFixing( newRelation)); … … 59 65 return !isIncomplete(rel) && !getFixer(rel).isRelationGood(rel); 60 66 } 61 67 62 68 private RelationFixer getFixer( Relation rel ) { 63 69 for(RelationFixer fixer : fixers) -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/AssociatedStreetFixer.java
r28693 r28703 1 1 package relcontext.relationfix; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 2 4 3 5 import java.util.ArrayList; … … 15 17 import org.openstreetmap.josm.data.osm.Way; 16 18 17 import static org.openstreetmap.josm.tools.I18n.tr;18 19 19 public class AssociatedStreetFixer extends RelationFixer { 20 20 … … 26 26 public boolean isRelationGood(Relation rel) { 27 27 for (RelationMember m : rel.getMembers()) { 28 if (m.getType().equals(OsmPrimitiveType.NODE) && !"house".equals(m.getRole())) 28 if (m.getType().equals(OsmPrimitiveType.NODE) && !"house".equals(m.getRole())) { 29 setWarningMessage(tr("Node without 'house' role found")); 29 30 return false; 30 if (m.getType().equals(OsmPrimitiveType.WAY) && !("house".equals(m.getRole()) || "street".equals(m.getRole()))) 31 } 32 if (m.getType().equals(OsmPrimitiveType.WAY) && !("house".equals(m.getRole()) || "street".equals(m.getRole()))) { 33 setWarningMessage(tr("Way without 'house' or 'street' role found")); 34 return false; 35 } 36 if (m.getType().equals(OsmPrimitiveType.RELATION) && !"house".equals(m.getRole())) { 37 setWarningMessage(tr("Relation without 'house' role found")); 31 38 return false; 32 if (m.getType().equals(OsmPrimitiveType.RELATION) && !"house".equals(m.getRole())) 33 return false; 39 } 34 40 } 35 41 // relation should have name 36 42 if (!rel.hasKey("name")) { 43 setWarningMessage(tr("Relation does not have name")); 37 44 return false; 38 45 } … … 40 47 String streetName = rel.get("name"); 41 48 for (RelationMember m : rel.getMembers()) { 42 if (m.getRole().equals("street") && !m.getWay().get("name").equals(streetName)) 43 return false; 49 if (m.getRole().equals("street") && !m.getWay().get("name").equals(streetName)) { 50 setWarningMessage(tr("Relation has streets with different names")); 51 return false; 52 } 44 53 } 54 clearWarningMessage(); 45 55 return true; 46 56 } 47 57 48 58 @Override 49 59 public Command fixRelation(Relation source) { 50 60 // any way with highway tag -> street … … 54 64 Relation rel = new Relation(source); 55 65 boolean fixed = false; 56 66 57 67 for (int i = 0; i < rel.getMembersCount(); i++) { 58 68 RelationMember m = rel.getMember(i); 59 69 60 70 if (m.isNode()) { 61 71 Node node = m.getNode(); 62 if (!"house".equals(m.getRole()) && 72 if (!"house".equals(m.getRole()) && 63 73 (node.hasKey("building") || node.hasKey("addr:housenumber"))) { 64 74 fixed = true; … … 70 80 fixed = true; 71 81 rel.setMember(i, new RelationMember("street", way)); 72 } else if (!"house".equals(m.getRole()) && 82 } else if (!"house".equals(m.getRole()) && 73 83 (way.hasKey("building") || way.hasKey("addr:housenumber"))) { 74 84 fixed = true; … … 77 87 } else if (m.isRelation()) { 78 88 Relation relation = m.getRelation(); 79 if (!"house".equals(m.getRole()) && 89 if (!"house".equals(m.getRole()) && 80 90 (relation.hasKey("building") || relation.hasKey("addr:housenumber") || "multipolygon".equals(relation.get("type")))) { 81 91 fixed = true; … … 84 94 } 85 95 } 86 96 87 97 // fill relation name 88 98 Map<String, Integer> streetNames = new HashMap<String, Integer>(); 89 for (RelationMember m : rel.getMembers()) 99 for (RelationMember m : rel.getMembers()) 90 100 if ("street".equals(m.getRole()) && m.isWay()) { 91 101 String name = m.getWay().get("name"); 92 102 if (name == null || name.isEmpty()) continue; 93 103 94 104 Integer count = streetNames.get(name); 95 105 96 106 streetNames.put(name, count != null? count + 1 : 1); 97 107 } … … 104 114 } 105 115 } 106 107 if (!rel.hasKey("name") ) {116 117 if (!rel.hasKey("name") && !commonName.isEmpty()) { 108 118 fixed = true; 109 119 rel.put("name", commonName); … … 111 121 commonName = ""; // set empty common name - if we already have name on relation, do not overwrite it 112 122 } 113 123 114 124 List<Command> commandList = new ArrayList<Command>(); 115 125 if (fixed) { 116 126 commandList.add(new ChangeCommand(source, rel)); 117 127 } 118 128 119 129 /*if (!commonName.isEmpty()) 120 130 // fill common name to streets 121 for (RelationMember m : rel.getMembers()) 131 for (RelationMember m : rel.getMembers()) 122 132 if ("street".equals(m.getRole()) && m.isWay()) { 123 133 String name = m.getWay().get("name"); 124 134 if (commonName.equals(name)) continue; 125 135 126 136 // TODO: ask user if he really wants to overwrite street name?? 127 137 128 138 Way oldWay = m.getWay(); 129 139 Way newWay = new Way(oldWay); 130 140 newWay.put("name", commonName); 131 141 132 142 commandList.add(new ChangeCommand(oldWay, newWay)); 133 143 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/BoundaryFixer.java
r28693 r28703 1 1 package relcontext.relationfix; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 2 4 3 5 import org.openstreetmap.josm.command.ChangeCommand; … … 15 17 16 18 public BoundaryFixer() { 17 super( new String[]{"boundary", "multipolygon"});19 super("boundary", "multipolygon"); 18 20 } 19 21 20 22 /** 21 * For boundary relations both "boundary" and "multipolygon" types are applicable, but 23 * For boundary relations both "boundary" and "multipolygon" types are applicable, but 22 24 * it should also have key boundary=administrative to be fully boundary. 23 25 * @see http://wiki.openstreetmap.org/wiki/Relation:boundary … … 27 29 return super.isFixerApplicable(rel) && "administrative".equals(rel.get("boundary")); 28 30 } 29 31 30 32 @Override 31 33 public boolean isRelationGood(Relation rel) { 32 34 for( RelationMember m : rel.getMembers() ) { 33 if (m.getType().equals(OsmPrimitiveType.RELATION) && !"subarea".equals(m.getRole())) 35 if (m.getType().equals(OsmPrimitiveType.RELATION) && !"subarea".equals(m.getRole())) { 36 setWarningMessage(tr("Relation without 'subarea' role found")); 34 37 return false; 35 if (m.getType().equals(OsmPrimitiveType.NODE) && !("label".equals(m.getRole()) || "admin_centre".equals(m.getRole()))) 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")); 36 41 return false; 37 if (m.getType().equals(OsmPrimitiveType.WAY) && !("outer".equals(m.getRole()) || "inner".equals(m.getRole()))) 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")); 38 45 return false; 46 } 39 47 } 48 clearWarningMessage(); 40 49 return true; 41 50 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/MultipolygonFixer.java
r28693 r28703 1 1 package relcontext.relationfix; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 2 4 3 5 import java.util.ArrayList; … … 23 25 super("multipolygon"); 24 26 } 25 26 protected MultipolygonFixer(String []types) {27 28 protected MultipolygonFixer(String...types) { 27 29 super(types); 28 30 } … … 32 34 public boolean isRelationGood(Relation rel) { 33 35 for (RelationMember m : rel.getMembers()) 34 if (m.getType().equals(OsmPrimitiveType.WAY) && !("outer".equals(m.getRole()) || "inner".equals(m.getRole()))) 35 return false; 36 if (m.getType().equals(OsmPrimitiveType.WAY) && !("outer".equals(m.getRole()) || "inner".equals(m.getRole()))) { 37 setWarningMessage(tr("Way without 'inner' or 'outer' role found")); 38 return false; 39 } 40 clearWarningMessage(); 36 41 return true; 37 42 } -
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/RelationFixer.java
r28693 r28703 1 1 package relcontext.relationfix; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 2 4 3 5 import java.util.ArrayList; 4 6 import java.util.List; 5 7 8 import javax.swing.Action; 9 6 10 import org.openstreetmap.josm.command.Command; 7 11 import org.openstreetmap.josm.data.osm.Relation; 8 12 13 import relcontext.actions.SortAndFixAction; 14 9 15 public abstract class RelationFixer { 10 16 11 17 private List<String> applicableTypes; 12 13 { 14 applicableTypes = new ArrayList<String>(); 15 } 18 private SortAndFixAction sortAndFixAction; 19 16 20 /** 17 * Construct new RelationFixer by only one applicable relation type 18 * @param type 19 */ 20 public RelationFixer(String type) { 21 applicableTypes.add(type); 22 } 23 24 /** 25 * Construct new RelationFixer by an array of applicable types 21 * Construct new RelationFixer by a list of applicable types 26 22 * @param types 27 23 */ 28 public RelationFixer(String[] types) { 24 public RelationFixer(String... types) { 25 applicableTypes = new ArrayList<String>(); 29 26 for(String type: types) { 30 27 applicableTypes.add(type); 31 28 } 32 29 } 33 30 34 31 /** 35 32 * Check if given relation is of needed type. You may override this method to check first type 36 33 * and then check desired relation properties. 37 34 * Note that this only verifies if current RelationFixer can be used to check and fix given relation 38 * Deeper relation checking is at {@link isRelationGood} 39 * 35 * Deeper relation checking is at {@link isRelationGood} 36 * 40 37 * @param rel Relation to check 41 38 * @return true if relation can be verified by current RelationFixer … … 46 43 if (!rel.hasKey("type")) 47 44 return false; 48 45 49 46 String type = rel.get("type"); 50 47 for(String oktype: applicableTypes) 51 if (oktype.equals(type)) 48 if (oktype.equals(type)) 52 49 return true; 53 50 54 51 return false; 55 52 } 56 53 57 54 /** 58 55 * Check if given relation is OK. That means if all roles are given properly, all tags exist as expected etc. 59 56 * Should be written in children classes. 60 * 57 * 61 58 * @param rel Relation to verify 62 59 * @return true if given relation is OK 63 60 */ 64 61 public abstract boolean isRelationGood(Relation rel); 65 62 66 63 /** 67 64 * Fix relation and return new relation with fixed tags, roles etc. 68 65 * Note that is not obligatory to return true for isRelationGood for new relation 69 * 66 * 70 67 * @param rel Relation to fix 71 68 * @return command that fixes the relation {@code null} if it cannot be fixed or is already OK 72 69 */ 73 70 public abstract Command fixRelation(Relation rel); 71 72 public void setFixAction(SortAndFixAction sortAndFixAction) { 73 this.sortAndFixAction = sortAndFixAction; 74 } 75 protected void setWarningMessage(String text) { 76 if (text == null) { 77 clearWarningMessage(); 78 } else { 79 sortAndFixAction.putValue(Action.SHORT_DESCRIPTION, text); 80 } 81 } 82 protected void clearWarningMessage() { 83 sortAndFixAction.putValue(Action.SHORT_DESCRIPTION, tr("Fix roles of the chosen relation members")); 84 } 85 74 86 }
Note:
See TracChangeset
for help on using the changeset viewer.