Si tu peux installer le plugin scripting et Jython, j'ai un script qui fait cela. Il fait un peu plus, donc tu devras enlever ce dont tu n'as pas besoin.
Jo Ce qui t'intéresse commence à la ligne 122. #!/bin/jython ''' CheckRouteOrNetworkOrCollectionOfRoutes.jy - Validation of a rXn route relation This code is released under the GNU General Public License v2 or later. The GPL v3 is accessible here: http://www.gnu.org/licenses/gpl.html The GPL v2 is accessible here: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html It comes with no warranty whatsoever. This code illustrates how to use Jython (Python in the scripting plugin of JOSM) to: * loop over all members of a route relation * find out whether the member is a node, a way or a relation * add/change properties of a relation * remove properties of a relation * add members to a relation * remove members from a relation * sort all members backwards * How to set an element selected ''' from javax.swing import JOptionPane from org.openstreetmap.josm import Main import org.openstreetmap.josm.command as Command import org.openstreetmap.josm.data.osm.Node as Node import org.openstreetmap.josm.data.osm.Way as Way import org.openstreetmap.josm.data.osm.Relation as Relation import org.openstreetmap.josm.data.Bounds as Bounds import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor as BoundingXYVisitor import org.openstreetmap.josm.data.osm.TagCollection as TagCollection import org.openstreetmap.josm.data.osm.DataSet as DataSet import org.openstreetmap.josm.data.osm.RelationMember as RelationMember import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask as DownloadRelationMemberTask import org.openstreetmap.josm.actions.DownloadReferrersAction as DownloadReferrersAction import org.openstreetmap.josm.actions.AutoScaleAction as AutoScaleAction import org.openstreetmap.josm.plugins.utilsplugin2.replacegeometry.ReplaceGeometryUtils as ReplaceGeometryUtils #import org.openstreetmap.josm.plugins.utilsplugin2.selection.SelectAllInsideAction.java as SelectAllInsideAction import org.openstreetmap.josm.plugins.todo as Todo import org.openstreetmap.josm.plugins.todo.TodoListModel as TodoListModel import org.openstreetmap.josm.plugins.todo.TodoDialog as TodoDialog print dir(TodoDialog) import javax.swing.DefaultListSelectionModel as DefaultListSelectionModel # the file name where the report for the wiki goes, needs to be configurable wikiReportFN = 'C:/data/wikiReport.txt' # comment to disable side effect sideEffects = {} logVerbosity = 30 ''' 10: only report problems that require attention 20: report on collection 30: report on network nodes 40: report on which routes are being checked 50: report everything ''' def getMapView(): if Main.main and Main.main.map: return Main.main.map.mapView else: return None def findSuitableBuilding(node, ignorelist, zoomOutThisManyTimes=2, houseNumber=None, street=None): bboxCalculator = BoundingXYVisitor() bboxCalculator.computeBoundingBox([node]) bboxCalculator.enlargeBoundingBox() if bboxCalculator.getBounds(): mv.recalculateCenterScale(bboxCalculator) mv.zoomTo(node.getEastNorth()) stopPosition = Node() found = False for i in range(1,zoomOutThisManyTimes): candidates = mv.getAllNearest(mv.getPoint(node),ignorelist,Node().nodePredicate) if candidates: for candidate in candidates: if candidate in ignorelist: break for foundway in candidate.getReferrers(): if houseNumber and \ 'addr:housenumber' in foundway.getKeys() and \ foundway.get('addr:housenumber').upper() == houseNumber.upper(): if 'addr:street' in foundway.getKeys() and street and \ foundway.get('addr:street').upper() == street.upper(): continue # if we find a building with the housenumber we were looking for, stop searching print 'Building with same housenumber' found = True; break if 'addr:housenumber' in foundway.getKeys(): # If we find a building with another housenumber, add its nodes to the ignorelist print foundway.get('addr:housenumber') + " not a good candidate" for node in foundway.getNodes(): ignorelist.append(node) continue if 'building' in foundway.getKeys(): # If we get here, this means we found a building, without housenumber information, which may be a good candidate print 'found a good candidate building without a housenumber' found = True; break else: ignorelist.append(candidate) print 'Ignoring ', candidate if found: break else: bboxCalculator.enlargeBoundingBox() # zoom out a bit and try again if bboxCalculator.getBounds(): mv.recalculateCenterScale(bboxCalculator) if not(found): print 'Found no suitable candidate building' return None else: print 'Returning ' + repr(foundway) + ' as the best candidate' return foundway dummy_way = Way() dummy_relation = Relation() mv = getMapView() if mv and mv.editLayer and mv.editLayer.data: selectedRelations = mv.editLayer.data.getSelectedRelations() selectedWays = mv.editLayer.data.getSelectedWays() selectedNodes = mv.editLayer.data.getSelectedNodes() #todoList = TodoListModel(DefaultListSelectionModel()) #print type(todoList) #print dir(todoList) if not(selectedRelations or selectedWays or selectedNodes): JOptionPane.showMessageDialog(Main.parent, "Please select an address node, a building or an associatedStreet relation") else: asrelations = [] for node in selectedNodes: for parent in node.getReferrers(): #print dir(parent) if parent.getType() == dummy_relation.getType() and parent.get('type') == 'associatedStreet': asrelations.append(parent) for way in selectedWays: for parent in way.getReferrers(): if parent.getType() == dummy_relation.getType() and parent.get('type') == 'associatedStreet': asrelations.append(parent) for relation in selectedRelations: for parentrelation in relation.getReferrers(): if parentrelation.get('type') == 'associatedStreet': asrelations.append(parent) #print asrelations ignorelist = [] for zoomTries in range(2,5): #for relation in asrelations: #for member in relation.getMembers(): # if member.isWay(): # for node in member.getWay().getNodes(): # ignorelist.append(node) # if member.isNode(): # ignorelist.append(member.getNode()) for relation in asrelations: memberCounter = -1 for member in relation.getMembers(): memberCounter += 1 if member.isWay() and not(member.getWay().get('addr:housenumber')): pass if member.isNode(): node = member.getNode() if 'addr:housenumber' in node.getKeys(): hn = node.get('addr:housenumber') print hn candidateBuilding = findSuitableBuilding(node, ignorelist, zoomOutThisManyTimes=zoomTries, houseNumber=hn, street=node.get('addr:street')) if candidateBuilding: candidateBuilding.get("addr:housenumber") buildingtype = candidateBuilding.get('building') street = candidateBuilding.get('addr:street') print buildingtype, street, node.get('addr:street'), candidateBuilding.get("addr:housenumber") candaddrhn=candidateBuilding.get("addr:housenumber") if buildingtype and not(buildingtype in ['garage','garages']): if street and street != node.get('addr:street'): break Main.main.getEditLayer().data.setSelected([candidateBuilding, node]) AutoScaleAction.autoScale("selection") if not(street): street = 'No street' if not(candaddrhn): candaddrhn = 'No number' rc=JOptionPane.showInputDialog('(' + str(zoomTries) + ') Found ' + street + ' ' + candaddrhn + ' for:', node.get('addr:street') + ' ' + node.get("addr:housenumber")) print 'rc', rc if rc == None: continue #print dir(candidateBuilding.getBBox()) #print member newBuilding = Way(candidateBuilding) memberNode = member.getNode() for key in memberNode.getKeys(): newBuilding.put(key, memberNode.get(key)) for key in ['addr:city', 'addr:country', 'addr:postcode']: newBuilding.remove(key) if candidateBuilding.get('building') == 'yes': newBuilding.put('building', 'house') CommandsList=[Command.ChangeCommand( candidateBuilding, newBuilding)] #Main.main.undoRedo.add(Command.SequenceCommand("Add tags to building", CommandsList)) newRelation = Relation(relation) newRelation.removeMember(memberCounter) newMember = RelationMember('house', candidateBuilding) newRelation.addMember(memberCounter, newMember) CommandsList.append(Command.ChangeCommand(relation, newRelation)) #Main.main.undoRedo.add(Command.SequenceCommand("Replace node with building in aS Relation", CommandsList)) #print dir(memberNode) print 'memberNode is undeleted ', memberNode.isDeleted() if not(memberNode.isDeleted()): print 'deleting ' + memberNode.get("addr:housenumber") CommandsList.append(Command.DeleteCommand(memberNode)) Main.main.undoRedo.add(Command.SequenceCommand("Teplace temp node with building in aS relation", CommandsList)) #todoList.add([candidateBuilding]) 2014-11-05 11:37 GMT+01:00 Tony Emery <tony.em...@yahoo.fr>: > On travaille actuellement dans les communes de la CCPRO dans lesquelles > nous > n'avons pas qualifier les adresses. > > Donc, sauf quelques adresses isolées, ça doit pour être jouable. > > Le problème est qu'on doit être sûr que la relation qui est créée dans OSM > récupère aussi les tronçons de voies correspondant et qui, eux, sont déjà > dans OSM. > > > > ----- > Tony EMERY > Administrateur OpenStreetMap.fr > Mandataire Grand Sud-Est > Géomaticien & chef de projets > -- > View this message in context: > http://gis.19327.n5.nabble.com/Creation-automatique-de-relations-associated-street-tp5823180p5823208.html > Sent from the France mailing list archive at Nabble.com. > > _______________________________________________ > Talk-fr mailing list > Talk-fr@openstreetmap.org > https://lists.openstreetmap.org/listinfo/talk-fr >
_______________________________________________ Talk-fr mailing list Talk-fr@openstreetmap.org https://lists.openstreetmap.org/listinfo/talk-fr