Example #1
0
def main():
	data=osmcmd.readData()
	fromdata=osmcmd.readData()
	data.mergedata(fromdata)
	todata=osmcmd.readData()
	data.mergedata(todata)
	toid=next(iter(todata.ways))

	nn=0
	nns=0
	for fromid in fromdata.nodes:
		id=sntw(data,fromid,toid)
		if id is None:
			nns+=1
		else:
			nn+=1

	nw=0
	nws=0
	for fromid in fromdata.ways:
		if fromid==toid:
			nws+=1
			continue
		id=swtw(data,fromid,toid)
		if id is None:
			nws+=1
		else:
			nw+=1

	if nw>0 or nn>0:
		data.addcomment(str(nn)+' nodes shot, '+str(nns)+' nodes skipped, '+str(nw)+' ways shot, '+str(nws)+' ways skipped')
		data.write(sys.stdout)
	else:
		osmcmd.fail('WARNING: no nodes/ways shot')
def main():
	data=osmcmd.readData()
	poidata=osmcmd.readData()
	for id,poi in poidata.nodes.items():
		processPoi(poi)
	for id,poi in poidata.ways.items():
		processPoi(poi)
	for id,poi in poidata.relations.items():
		processPoi(poi)
	poidata.write(sys.stdout)
Example #3
0
def main():
    if len(sys.argv) != 1 + 4 * 2:
        return 0

    p0 = osmcmd.Point.fromArgv(1)
    t0 = osmcmd.Point.fromArgv(2)
    p1 = osmcmd.Point.fromArgv(3)
    t1 = osmcmd.Point.fromArgv(4)
    p2 = osmcmd.Point.fromArgv(5)
    t2 = osmcmd.Point.fromArgv(6)
    p3 = osmcmd.Point.fromArgv(7)
    t3 = osmcmd.Point.fromArgv(8)

    data = osmcmd.readData()
    opdata = osmcmd.readData()
    data.mergedata(opdata)

    epsilon = 10e-6
    nIterations = 100

    def transformPoint(p):
        a0 = 0.5
        b0 = 0.5
        # TODO make symmetric eqn
        # (p1-p0)*a+(p3-p0)*b=(p-p0)+(p3-p2)*a*b+(p1-p0)*a*b
        for i in range(nIterations):
            a1, b1 = osmcmd.solveLinEqns([
                [(p1 - p0).x, (p3 - p0).x,
                 (p - p0).x + (p3 - p2).x * a0 * b0 + (p1 - p0).x * a0 * b0],
                [(p1 - p0).y, (p3 - p0).y,
                 (p - p0).y + (p3 - p2).y * a0 * b0 + (p1 - p0).y * a0 * b0],
            ])
            #print('step',i,'coords',a1,b1,'dist2',(a0-a1)**2+(b0-b1)**2,file=sys.stderr) # debug
            if (a0 - a1)**2 + (b0 - b1)**2 < epsilon**2:
                break
            a0 = a1
            b0 = b1
        return t0 + (t1 - t0) * a1 + (t3 - t0) * b1 + (t0 - t1) * a1 * b1 + (
            t2 - t3) * a1 * b1

    for nodeId in data.nodes:
        node = data.nodes[nodeId]
        point = osmcmd.Point.fromNode(node)
        newPoint = transformPoint(point)
        newPoint.setNode(node)

    data.addcomment("Done.")
    data.write(sys.stdout)
Example #4
0
def main():
	data=osmcmd.readData()
	highwayData=osmcmd.readData()
	data.mergedata(highwayData)
	formula=sys.argv[1]
	match=re.match(r'([a-z,]+)(<?)([-+]?)(>?)([a-z,]+)',formula)
	if not match:
		osmcmd.fail('ERROR: invalid syntax')
		return
	outerString,toOuter,newNodeFlag,toInner,innerString=match.groups()
	outers=outerString.split(',')
	inners=innerString.split(',')
	if toOuter and toInner:
		osmcmd.fail('WARNING: ordered not to disconnect')
		return
	if toOuter: outers,inners=inners,outers
	disconnectNodes={}
	for id,way in highwayData.ways.items():
		if not inScope(way,inners): continue
		for nodeId in way[OsmData.REF]:
			disconnectNodes[nodeId]=None
	for id in highwayData.ways:
		way=data.ways[id]
		if not inScope(way,outers): continue
		# assume street is not circular
		i=0
		while i<len(way[OsmData.REF]):
			isEdge=(i==0 or i==len(way[OsmData.REF])-1)
			oldNodeId=way[OsmData.REF][i]
			if oldNodeId in disconnectNodes:
				way[OsmData.ACTION]=OsmData.MODIFY
				if (isEdge and newNodeFlag!='-') or newNodeFlag=='+':
					if disconnectNodes[oldNodeId]:
						way[OsmData.REF][i]=disconnectNodes[oldNodeId]
					else:
						newNodeId=data.addnode()
						data.nodes[newNodeId][OsmData.LON]=data.nodes[oldNodeId][OsmData.LON]
						data.nodes[newNodeId][OsmData.LAT]=data.nodes[oldNodeId][OsmData.LAT]
						way[OsmData.REF][i]=disconnectNodes[oldNodeId]=newNodeId
					i+=1
				else:
					del way[OsmData.REF][i]
			else:
				i+=1
	data.write(sys.stdout)
Example #5
0
def main():
    data = osmcmd.readData()
    nodedata = osmcmd.readData()
    data.mergedata(nodedata)

    while data.relations.get(data.currrelationid) != None:
        data.currrelationid -= 1
    rel = data.relations[data.currrelationid] = {
        OsmData.ACTION: OsmData.CREATE,
        OsmData.REF: {
            OsmData.NODES: [],
            OsmData.WAYS: [],
            OsmData.RELATIONS: [],
        },
        OsmData.TAG: {
            'type': 'public_transport',
            'public_transport': 'stop_area',
        }
    }
    name = None
    for id, node in nodedata.nodes.items():
        if 'name' in node[OsmData.TAG]:
            name = node[OsmData.TAG]['name']
    if name is not None:
        rel[OsmData.TAG]['name'] = name
    for id in nodedata.nodes:
        node = data.nodes[id]
        if node[OsmData.TAG].get('public_transport') == 'stop_position':
            rel[OsmData.REF][OsmData.NODES].append((id, 'stop'))
        elif node[OsmData.TAG].get('public_transport') == 'platform':
            rel[OsmData.REF][OsmData.NODES].append((id, 'platform'))
        else:
            continue
        if name is not None and 'name' not in node[OsmData.TAG]:
            node[OsmData.ACTION] = OsmData.MODIFY
            node[OsmData.TAG]['name'] = name

    if len(rel[OsmData.REF][OsmData.NODES]) <= 0:
        osmcmd.fail('No stops/platforms provided')
    else:
        data.addcomment('Done')
        data.write(sys.stdout)
def main():
    data = osmcmd.readData()
    rewiredata = osmcmd.readData()
    data.mergedata(rewiredata)
    fromdata = osmcmd.readData()
    data.mergedata(fromdata)
    todata = osmcmd.readData()
    data.mergedata(todata)

    fromid = next(iter(fromdata.ways))

    toroadid = tosidewalkid = None
    for toid, toway in todata.ways.items():
        if toway[OsmData.TAG].get('highway') == 'footway':
            tosidewalkid = toid
        else:
            toroadid = toid
    if toroadid is None and tosidewalkid is not None:
        toroadid = tosidewalkid
        tosidewalkid = None
    if toroadid is None:
        osmcmd.fail('ERROR: no way to rewire to')
        return

    nn = nm = 0
    for rewireid in rewiredata.ways:
        nn += rewireWay(data, rewireid, fromid, toroadid, tosidewalkid)
    for rewireid, rewirerel in rewiredata.relations.items():
        if rewirerel[OsmData.TAG].get('type') == 'restriction':
            nm += rewireRestriction(data, rewireid, fromid, toroadid)
    if nn == 0 and nm == 0:
        osmcmd.fail('WARNING: nothing changed')
    else:
        data.addcomment(
            str(nn) + ' nodes rewired, ' + str(nm) +
            ' relation members changed')
        data.write(sys.stdout)
def main():
    data = osmcmd.readData()
    nwdata = osmcmd.readData()
    data.mergedata(nwdata)
    wayid = next(iter(nwdata.ways))
    n = 0
    for platformid in nwdata.nodes:
        stopid = shoot.sntw(data, platformid, wayid)
        if stopid is None:
            continue
        n += 1
        plnode = data.nodes[platformid]
        stnode = data.nodes[stopid]
        plnode[OsmData.ACTION] = OsmData.MODIFY
        plnode[OsmData.TAG].update({'public_transport': 'platform'})
        stnode[OsmData.TAG].update({'public_transport': 'stop_position'})
        if 'name' not in stnode[OsmData.TAG] and 'name' in plnode[OsmData.TAG]:
            stnode[OsmData.TAG]['name'] = plnode[OsmData.TAG]['name']

    if n > 0:
        data.addcomment(str(n) + ' stops created')
        data.write(sys.stdout)
    else:
        osmcmd.fail('WARNING: no stops created')
Example #8
0
def main():
    data = osmcmd.readData()
    opdata = osmcmd.readData()
    data.mergedata(opdata)
    buildingWayId = None
    connectorWayIds = []
    for wid in opdata.ways:
        way = opdata.ways[wid]
        if way[OsmData.TAG].get('highway') is None:
            if buildingWayId is None:
                buildingWayId = wid
            else:
                osmcmd.fail('ERROR: too many building ways')
        else:
            connectorWayIds.append(wid)
    if buildingWayId is None:
        osmcmd.fail('ERROR: no building ways')
    buildingWay = data.ways[buildingWayId]

    def makeEntranceAndConnect(poiNodeId, entranceNodeId):
        entranceNode = data.nodes[entranceNodeId]
        if entranceNode[OsmData.TAG].get('entrance') is None:
            if entranceNode.get(OsmData.ACTION) != OsmData.CREATE:
                entranceNode[OsmData.ACTION] = OsmData.MODIFY
            entranceNode[OsmData.TAG]['entrance'] = poiNode[
                OsmData.TAG]['entrance']
        corridorWayId = data.addway()
        corridorWay = data.ways[corridorWayId]
        corridorWay[OsmData.REF] = [entranceNodeId, poiNodeId]
        corridorWay[OsmData.TAG]['highway'] = 'corridor'

    for poiNodeId in opdata.nodes:
        poiNode = data.nodes[poiNodeId]
        poiPoint = osmcmd.Point.fromNode(poiNode)
        offsetLength = poiPoint.lengthFromMeters(2)
        buildingChain = osmcmd.Chain.fromWay(
            buildingWay, data)  # get points again in case the way was altered
        buildingWayNodeIds = buildingWay[OsmData.REF]
        isBuildingWayClosed = buildingWayNodeIds[0] == buildingWayNodeIds[-1]

        def getBuildingChainAroundIndex(j):
            pts = []
            if 0 < j < len(buildingWayNodeIds) - 1:
                pts = buildingChain.points[j - 1:j + 2]
            elif isBuildingWayClosed:
                pts = [
                    buildingChain.points[-2], buildingChain.points[0],
                    buildingChain.points[1]
                ]
            elif j == 0:
                pts = buildingChain.points[:2]
            else:
                pts = buildingChain.points[-2:]
            return osmcmd.Chain(pts)

        connectedToBuildingIndices = set()

        def getPossibleBuildingConnections():
            for cwid in connectorWayIds:
                connectorWayNodeIds = data.ways[cwid][OsmData.REF]
                for i, cwid in enumerate(connectorWayNodeIds):
                    if cwid == poiNodeId:
                        for j, bwid in enumerate(buildingWayNodeIds):
                            if (not isBuildingWayClosed or j > 0) and (
                                (i > 0 and bwid == connectorWayNodeIds[i - 1])
                                    or
                                (i < len(connectorWayNodeIds) - 1
                                 and bwid == connectorWayNodeIds[i + 1])):
                                connectedToBuildingIndices.add(j)

        getPossibleBuildingConnections()
        if len(
                connectedToBuildingIndices
        ) == 1:  # if poi is connected to the building, look only at segments adjacent to connection point
            for j in connectedToBuildingIndices:
                connectionPoint = osmcmd.Point.fromNode(
                    data.nodes[buildingWayNodeIds[j]])
                poiPoint = connectionPoint + (poiPoint - connectionPoint).dir(
                    offsetLength * delta)
                buildingChain = getBuildingChainAroundIndex(j)
        newPoiPoint, entrancePoint, buildingWayIndices = getPoiAndEntranceLocations(
            poiPoint, buildingChain, offsetLength)
        newPoiPoint.setNode(poiNode)
        if poiNode[OsmData.TAG].get(
                'entrance') is not None and entrancePoint is not None:
            if len(buildingWayIndices) == 1:
                entranceNodeId = buildingWay[OsmData.REF][
                    buildingWayIndices[0]]
                makeEntranceAndConnect(poiNodeId, entranceNodeId)
            elif len(buildingWayIndices) == 2:
                entranceNodeId, _ = entrancePoint.makeNode(data)
                buildingWay[OsmData.ACTION] = OsmData.MODIFY
                buildingWay[OsmData.REF].insert(buildingWayIndices[1],
                                                entranceNodeId)
                makeEntranceAndConnect(poiNodeId, entranceNodeId)
            del poiNode[OsmData.TAG]['entrance']
    data.write(sys.stdout)