Q_school = res['id']
                 print Q_school
                 if type=='node':
                     newSchool = Node(element)
                 elif type=='way':
                     newSchool = Way(element)
                 else:
                     newSchool = Relation(element)
                 dirty =False
                 if newSchool.get('wikidata') != Q_school:
                     newSchool.put('wikidata', Q_school); dirty=True
                 for tag in tagsToSet:
                     if tagsToSet[tag]: newSchool.put(tag, tagsToSet[tag]); dirty=True
                 if dirty:
                     CommandsList=[Command.ChangeCommand( element, newSchool)]
                     Main.main.undoRedo.add(Command.SequenceCommand("Add wikidata and isced:level tags to school", CommandsList))
                 found = True
                 break
         if found: break
     else:
         print 'not found yet'
 if element.isNew(): noNewSchools=False
 if Q_school:
     wbdf = WikibaseDataFetcher.getWikidataDataFetcher()
     wikidataCoords = wbdf.getEntityDocument(Q_school)
     # print dir(wikidataCoords)
     pprint.pprint(wikidataCoords)
     hasCoords = wikidataCoords.hasStatement("P625")
     print('++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
     print(hasCoords)
     # wikidataCoords = wbsea.wbGetEntities(ids=Q_school,props="P625")
                found = False
                for i in range(19, 0, -1):
                    time.sleep(i / 3)
                    params = '?action=wbsearchentities&search=' + URLEncoder.encode(
                        name, "UTF-8") + '&language=en&format=json'
                    url = baseurl + 'api.php' + params
                    r1 = HttpClient.create(URL(url), "GET")
                    r2 = r1.setHeader("Content-Type",
                                      "application/x-www-form-urlencoded"
                                      ).connect().fetchContent()
                    #print dir(r2)
                    print i, r2
                    Q_school = QinJSONRE.search(r2)
                    if Q_school:
                        print Q_school.group('qid')
                        break
                    else:
                        print 'not found yet'

                break
            else:
                print 'already in Wikidata'
        newSchool = Node(element)
        newSchool.put('wikidata', Q_school.group('qid'))
        newSchool.put('isced:level', isced)

        CommandsList = [Command.ChangeCommand(element, newSchool)]
        Main.main.undoRedo.add(
            Command.SequenceCommand(
                "Add wikidata and isced:level tags to school", CommandsList))
                    newRelation.remove('name')
                    relationChanged = True
            else:
                name = ''
            ref = route.get('ref')
            if ref:
                if reNumberDashNumber.match(ref):
                    print 'removing ref when it is of the form ##-##'
                    newRelation.remove('ref')
                    relationChanged = True
            else:
                ref = ''
            if relationChanged:
                commandsList.append(Command.ChangeCommand(route, newRelation))
                
                Main.main.undoRedo.add(Command.SequenceCommand("Removing name and/or ref " + name + '/' + ref, commandsList))
                commandsList = []

            rcn_refs = []; route_relation_names = []; memberslist = []
            endnodes = []; prev_endnodes = []
            continuous_forward = True; continuous_backward = True
            prev_role = None; prev_endnodes_before_forward = None; last_endnodes_before_backward = None
            for member in route.getMembers():
                if member.isWay():
                    role = member.getRole()
                    memberslist.append(member)
                    way = member.getWay()
                    #JOptionPane.showMessageDialog(Main.parent, 'way is selected')
                    endnodes = [way.getNode(0), way.getNode(way.nodesCount-1)]
                    notfoundyet = True
                    for endnode in endnodes:
예제 #4
0
            Main.parent, "Please select some node, way, or relation.")
    else:

        if (selectedNodes):

            for node in selectedNodes:
                nodeChanged = False
                oldname = node.get('name')
                if not (oldname): oldname = ''
                if pattern.match(oldname):
                    newNode = Node(node)
                    newname = oldname
                    newname = re.sub("^E", "e", newname)
                    newname = re.sub("^L", "l", newname)
                    newname = re.sub("^S", "s", newname)
                    newNode.put("name", newname)
                    if (forceNameCA): newNode.put("name:ca", newname)

                    commandsList.append(Command.ChangeCommand(node, newNode))
                    Main.main.undoRedo.add(
                        Command.SequenceCommand("Changed name " + oldname,
                                                commandsList))
                    commandsList = []

        if (selectedWays):
            JOptionPane.showMessageDialog(Main.parent,
                                          "You have selected some way.")
        if (selectedRelations):
            JOptionPane.showMessageDialog(Main.parent,
                                          "You have selected some relation.")
예제 #5
0
    lon2 = lon1 + atan2(
        sin(_bearing) * sindistoverER * cos(lat1),
        cosdistoverER - sin(lat1) * sin(lat2))

    return degrees(lon2), degrees(lat2)


editLayer = MainApplication.getLayerManager().getEditLayer()
print '==== Fresh run ===='
if editLayer and editLayer.data:
    selected_nodes = editLayer.data.getSelectedNodes()
    print selected_nodes

    if not (selected_nodes):
        JOptionPane.showMessageDialog(MainApplication.parent,
                                      "Please select node(s) to displace")
    else:
        for node in selected_nodes:
            b = int(node.get("zone:De_Lijn")) + 90
            if b > 360: b = b - 360
            print b
            lon, lat = displace2(coor=node.getCoor(),
                                 bearing=b,
                                 distance=100.0)
            print node.getCoor().lon(), node.getCoor().lat()
            print lon, lat
            commandsList = []
            commandsList.append(Command.MoveCommand(node, lon, lat))
            MainApplication.undoRedo.add(
                Command.SequenceCommand("Move node", commandsList))