def main(): if len(sys.argv) != 3: return 0 coords = (sys.argv[1].split(',')) A = projections.from4326((float(coords[0]),float(coords[1])), "EPSG:3857") B = projections.from4326((float(coords[2]),float(coords[3])), "EPSG:3857") C = projections.from4326((float(coords[4]),float(coords[5])), "EPSG:3857") segments = int(sys.argv[2]) AM = ((B[0] - A[0])/2, (B[1] - A[1])/2) BN = ((C[0] - B[0])/2, (C[1] - B[1])/2) M = (A[0] + AM[0], A[1] + AM[1]) N = (B[0] + BN[0], B[1] + BN[1]) MM = (AM[1], -AM[0]) NN = (BN[1], -BN[0]) O = intersect(MM, M, NN, N) OA = (O[0] - A[0], O[1] - A[1]) r = math.sqrt(OA[0]*OA[0] + OA[1]*OA[1]) arc = createarc(O, A, C, r, segments) tData = OsmData() wayid = tData.addway() for point in arc: p = projections.to4326(point, "EPSG:3857") newid = tData.addnode() tData.nodes[newid][LON] = p[0] tData.nodes[newid][LAT] = p[1] tData.nodes[newid][TAG] = {} tData.ways[wayid][REF].append(newid) tData.addcomment("Done.") tData.write(sys.stdout) #f = open("out.txt", "w") #tData.write(f) #f.close() return 0
def main(): if len(sys.argv) != 4: return 0 rdata = OsmData() data = OsmData() rdata.read(sys.stdin) data.read(sys.stdin) codeset = locale.getdefaultlocale()[1] search = re.compile(unicode(sys.argv[1], codeset)) replace = unicode(sys.argv[2], codeset) prtags = False prvalues = False if sys.argv[3] == 'Tags': prtags = True elif sys.argv[3] == 'Values': prvalues = True elif sys.argv[3] == 'Both': prtags = True prvalues = True else: data.addcomment("Processing data (tags, values or both) isn't selected.") data.write(sys.stdout) return 0 nodes = process(data.nodes, search, replace, prtags, prvalues) ways = process(data.ways, search, replace, prtags, prvalues) relations = process(data.relations, search, replace, prtags, prvalues) data.addcomment("Done. " + str(nodes) + " nodes, " + str(ways) + " ways and " + str(relations) + " relations changed.") data.write(sys.stdout) return 0
def main(): if len(sys.argv) != 3: return 0 segments = int(sys.argv[2]) pointlist = (sys.argv[1].split(';')) coordlist = [] for point in pointlist: coords = point.split(',') coordlist.append( projections.from4326((float(coords[0]), float(coords[1])), "EPSG:3857")) if len(coordlist) < 3: sys.stdout.write("<!--Too few control points-->") return 0 if segments == 0: # optimal number of segments for i in range(0, len(coordlist) - 2): P1 = coordlist[i] P2 = coordlist[i + 1] P1P2 = (P2[0] - P1[0], P2[1] - P1[1]) P1P2abs = math.sqrt(P1P2[0] * P1P2[0] + P1P2[1] * P1P2[1]) segments += math.ceil(math.log(P1P2abs, 4)) # cat's magic formula segments = int(segments) tData = OsmData() wayid = tData.addway() step = 1.0 / segments for i in range(segments + 1): t = step * i node = projections.to4326(getpoint(coordlist, t), "EPSG:3857") nodeid = tData.addnode() tData.nodes[nodeid][LON] = node[0] tData.nodes[nodeid][LAT] = node[1] tData.ways[wayid][REF].append(nodeid) tData.addcomment("Done.") tData.write(sys.stdout) return 0
def main(): if len(sys.argv) != 2: return 0 params = int(sys.argv[1]) nData = OsmData() # Nodes rData = OsmData() # Reference way tData = OsmData() # Target ways nData.read(sys.stdin) rData.read(sys.stdin) tData.read(sys.stdin) tangle = 0 rangle = 0 if params == 1: rangle = getangle( FOREL(createtable(rData, nData, list(rData.ways.keys())[0]), 15)) #get main angle of reference object rcenter = getbboxcenter(getbbox(rData, nData, list(rData.ways.keys())[0])) targets = {} for key in tData.ways.keys(): if params == 1: tangle = getangle(FOREL(createtable(tData, nData, key), 15)) #get target object main angle tcenter = getbboxcenter(getbbox(tData, nData, key)) targets[key] = (tangle, tcenter) for key in targets.keys(): treplace(nData, rData, list(rData.ways.keys())[0], tData, key, (rangle, rcenter), targets[key]) tData.mergedata(nData) tData.addcomment('Done.') tData.write(sys.stdout)
def main(): if len(sys.argv) != 3: return 0 segments = int(sys.argv[2]) pointlist = (sys.argv[1].split(';')) coordlist = [] for point in pointlist: coords = point.split(',') coordlist.append(projections.from4326((float(coords[0]), float(coords[1])), "EPSG:3857")) if len(coordlist) < 3: sys.stdout.write("<!--Too few control points-->") return 0 if segments == 0: # optimal number of segments for i in range(0, len(coordlist) - 2): P1 = coordlist[i] P2 = coordlist[i+1] P1P2 = (P2[0]-P1[0], P2[1]-P1[1]) P1P2abs = math.sqrt(P1P2[0]*P1P2[0] + P1P2[1]*P1P2[1]) segments += math.ceil(math.log(P1P2abs, 4)) # cat's magic formula segments=int(segments) tData = OsmData() wayid = tData.addway() step = 1.0 / segments for i in range(segments + 1): t = step * i node = projections.to4326(getpoint(coordlist, t), "EPSG:3857") nodeid = tData.addnode() tData.nodes[nodeid][LON] = node[0] tData.nodes[nodeid][LAT] = node[1] tData.ways[wayid][REF].append(nodeid) tData.addcomment("Done.") tData.write(sys.stdout) return 0
def main(): if len(sys.argv) != 2: return 0 params = int(sys.argv[1]) nData = OsmData() # Nodes rData = OsmData() # Reference way tData = OsmData() # Target ways nData.read(sys.stdin) rData.read(sys.stdin) tData.read(sys.stdin) tangle = 0 rangle = 0 if params == 1: rangle = getangle( FOREL(createtable(rData, nData, list(rData.ways.keys())[0]), 15) ) # get main angle of reference object rcenter = getbboxcenter(getbbox(rData, nData, list(rData.ways.keys())[0])) targets = {} for key in tData.ways.keys(): if params == 1: tangle = getangle(FOREL(createtable(tData, nData, key), 15)) # get target object main angle tcenter = getbboxcenter(getbbox(tData, nData, key)) targets[key] = (tangle, tcenter) for key in targets.keys(): treplace(nData, rData, list(rData.ways.keys())[0], tData, key, (rangle, rcenter), targets[key]) tData.mergedata(nData) tData.addcomment("Done.") tData.write(sys.stdout)
def main(): if len(sys.argv) != 6: return 0 sides = int(sys.argv[5]) if sides < 3: return 0 coords = (sys.argv[1].split(',')) lon = float(coords[0].replace(',', '.')) lat = float(coords[1].replace(',', '.')) radius1 = float(sys.argv[2].replace(',', '.'))/math.cos(math.radians(lat)) radius2 = float(sys.argv[3].replace(',', '.'))/math.cos(math.radians(lat)) rot_angle = math.radians(float(sys.argv[4].replace(',', '.'))) if radius1 <= 0: return 0 if radius2 <= 0: return 0 startangle = 0 coords_m = projections.from4326((lon,lat), "EPSG:3857") tData = OsmData() wayid = tData.addway() for i in range(sides): angle = startangle + 2*math.pi*i/sides x = coords_m[0] + radius1 * math.cos(angle) * math.cos(rot_angle) - radius2 * math.sin(angle) * math.sin(rot_angle) y = coords_m[1] + radius1 * math.cos(angle) * math.sin(rot_angle) + radius2 * math.sin(angle) * math.cos(rot_angle) node = projections.to4326((x, y), "EPSG:3857") nodeid = tData.addnode() tData.nodes[nodeid][LON] = node[0] tData.nodes[nodeid][LAT] = node[1] tData.ways[wayid][REF].append(nodeid) tData.ways[wayid][REF].append(tData.ways[wayid][REF][0]) tData.addcomment("Done.") tData.write(sys.stdout) return 0
def main(): data1 = OsmData() # Dependencies data2 = OsmData() # Selected objects data1.read(sys.stdin) data2.read(sys.stdin) if len(data2.ways)==0: data1.addcomment("No geometry for orthogonalization") else: path_ortho(data1, data2) #data.addcomment("Done.") data1.write(sys.stdout) #only nodes in dependencies could be modified return 0
def main(): if len(sys.argv) != 1: return 0 wData = OsmData() # Way nData = OsmData() # Nodes wData.read(sys.stdin) wData.read(sys.stdin) nData.read(sys.stdin) nData.read(sys.stdin) ids = nData.nodes.keys() if sys.version_info[0] >= 3: ids = list(ids) if len(ids) != 2: return 0 way = wData.ways.popitem() way1 = (way[0], way[1].copy()) way2 = (-1 - abs(way[0]), {}) way2[1][TAG] = way1[1][TAG].copy() way1[1][REF] = [] way2[1][REF] = [] way1[1][ACTION] = MODIFY way2[1][ACTION] = CREATE isNewWay = False isNewWayClosed = False cutStart = 0 for nd in way[1][REF]: if nd == ids[0] or nd == ids[1]: if isNewWay == False: way1[1][REF].append(nd) cutStart = nd else: way2[1][REF].append(nd) way2[1][REF].append(cutStart) isNewWayClosed = True isNewWay = not isNewWay if isNewWay: if not isNewWayClosed: way2[1][REF].append(nd) else: way1[1][REF].append(nd) wData.ways[way1[0]] = way1[1] wData.ways[way2[0]] = way2[1] wData.addcomment("Done.") wData.write(sys.stdout) return 0
def main(): if len(sys.argv) != 3: return 0 rdata = OsmData() data = OsmData() rdata.read(sys.stdin) data.read(sys.stdin) codeset = locale.getdefaultlocale()[1] newtag = unicode(sys.argv[1], codeset) formula = unicode(sys.argv[2], codeset) nodes = process(data.nodes, newtag, formula,1) ways = process(data.ways, newtag, formula,2) relations = process(data.relations, newtag, formula,3) data.addcomment("Done. " + str(nodes) + " nodes, " + str(ways) + " ways and " + str(relations) + " relations changed.") data.write(sys.stdout) return 0
def main(): if len(sys.argv) != 4: return 0 offset = float(sys.argv[1]) nMap = Map() wMap = Map() both = False copye = False if sys.argv[2] == "Left": offset *= (-1) elif sys.argv[2] == "Both": both = True if sys.argv[3] == "Yes": copye = True data = OsmData() ndata = OsmData() data.read(sys.stdin) data.read(sys.stdin) if both: if copye: nwaydata1 = calcoffset(data, offset, True, nMap, wMap) nwaydata2 = calcoffset(data, -offset, True, nMap, wMap) else: nwaydata1 = calcoffset(data, offset, True, nMap, wMap) nwaydata2 = calcoffset(data, -offset, False, nMap, wMap) ndata.nodes.update(nwaydata1.nodes) ndata.nodes.update(nwaydata2.nodes) ndata.ways.update(nwaydata1.ways) ndata.ways.update(nwaydata2.ways) else: if copye: nwaydata = calcoffset(data, offset, True, nMap, wMap) else: nwaydata = calcoffset(data, offset, False, nMap, wMap) ndata.nodes.update(nwaydata.nodes) ndata.ways.update(nwaydata.ways) ndata.addcomment("Done.") ndata.write(sys.stdout) return 0
def main(): nData = OsmData() # Nodes rData = OsmData() # Reference way tData = OsmData() # Target ways nData.read(sys.stdin) rData.read(sys.stdin) tData.read(sys.stdin) rangle = getangle(FOREL(createtable(rData, nData, list(rData.ways.keys())[0]), 15)) rcenter = getbboxcenter(getbbox(rData, nData, list(rData.ways.keys())[0])) targets = {} for key in tData.ways.keys(): tangle = getangle(FOREL(createtable(tData, nData, key), 15)) tcenter = getbboxcenter(getbbox(tData, nData, key)) targets[key] = (tangle, tcenter) for key in targets.keys(): treplace(nData, rData, list(rData.ways.keys())[0], tData, key, (rangle, rcenter), targets[key]) tData.mergedata(nData) tData.addcomment('Done.') tData.write(sys.stdout)
def main(): if len(sys.argv) != 3: return 0 segments = int(sys.argv[2]) pointlist = (sys.argv[1].split(';')) coordlist = [] for point in pointlist: coords = point.split(',') coordlist.append(projections.from4326((float(coords[0]), float(coords[1])), "EPSG:3857")) if len(coordlist) < 4: sys.stdout.write("<!--Too few control points-->") return 0 if segments < 0: sys.stdout.write("<!--Segments must be greater than zero-->"); tData = OsmData() wayid = tData.addway() step = 1.0 / segments for j in range (1, len(coordlist)-2): # for segments other than the first, skip the first point since it's the # last point of the previous segment - otherwise you'll get overlapping points # at the segment ends. if j > 1: segs = range(1,segments+1) else: segs = range(segments+1) for i in segs: t = step * i node = projections.to4326(spline_4p(t, coordlist[j-1], coordlist[j], coordlist[j+1], coordlist[j+2]), "EPSG:3857") nodeid = tData.addnode() tData.nodes[nodeid][LON] = node[0] tData.nodes[nodeid][LAT] = node[1] tData.ways[wayid][REF].append(nodeid) tData.addcomment("Done.") tData.write(sys.stdout) return 0
def main(): if len(sys.argv) != 2: return 0 coords = (sys.argv[1].split(',')) # lon = float(coords[0]) # lat = float(coords[1]) # coords_m = projections.from4326((lon,lat), "EPSG:3857") tData = OsmData() httpc = client() # text = httpc.request('http://pkk5.rosreestr.ru/arcgis/rest/services/Cadastre/CadastreSelected/MapServer/1/query?text=&geometry='+str(coords_m[0])+','+str(coords_m[1])+'&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=&time=&returnCountOnly=false&returnIdsOnly=false&returnGeometry=false&maxAllowableOffset=&outSR=&outFields=*&f=pjson') text = httpc.request('https://pkk.rosreestr.ru/api/features/1?text=' + coords[1] + '%20' + coords[0] + '&tolerance=4&limit=11') data = json.loads(text) if 'features' in data: ids = [] for result in data['features']: #if len(result['value']) >= 11: try: ids.append(result['attrs']['id']) except KeyError: continue if len(ids) > 0: addresses = [] for id in ids: #text = httpc.request('http://maps.rosreestr.ru/arcgis/rest/services/Cadastre/CadastreInfo/MapServer/2/query?f=json&where=PARCELID%20IN%20(%27'+id+'%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=FULLADDRESS,CATEGORY,UTIL_BY_DOC'); text = httpc.request( 'https://pkk.rosreestr.ru/api/features/1/' + id) data = json.loads(text) if 'feature' in data: address = {} try: s = data['feature']['attrs']['address'].split(',') address['addr:housenumber'] = s.pop().strip() address['addr:street'] = s.pop().strip() address['addr:full'] = data['feature']['attrs'][ 'address'] address['fixme'] = 'yes' except KeyError: continue try: # address['category'] = feature['attributes']['CATEGORY'] address['utilization'] = data['feature']['attrs'][ 'util_by_doc'] except KeyError: pass addresses.append(address) else: tData.addcomment('Feature is empty') continue count = len(addresses) if count == 1: nodeid = tData.addnode() tData.nodes[nodeid][LON] = coords[0] tData.nodes[nodeid][LAT] = coords[1] tData.nodes[nodeid][TAG] = addresses[0] comment = addresses[0]['addr:street'] + ', ' + addresses[0][ 'addr:housenumber'] if addresses[0]['utilization'] <> None: comment += ' - ' + addresses[0]['utilization'] tData.addcomment(comment) else: for i in range(count): angle = 2 * math.pi * i / count x = float(coords[0]) + 0.00001 * math.cos(angle) y = float(coords[1]) + 0.00001 * math.sin(angle) #node = projections.to4326((x, y), "EPSG:3857") nodeid = tData.addnode() tData.nodes[nodeid][LON] = x tData.nodes[nodeid][LAT] = y tData.nodes[nodeid][TAG] = addresses[i] comment = addresses[i]['addr:street'] + ', ' + addresses[ i]['addr:housenumber'] if addresses[i]['utilization'] <> None: comment += ' - ' + addresses[i]['utilization'] tData.addcomment(comment) else: tData.addcomment('Unknown error') else: tData.addcomment('Features is empty') tData.write(sys.stdout) return 0
def main(): if len(sys.argv) != 4: return 0 coords = (sys.argv[1].split(',')) A = projections.from4326((float(coords[0]), float(coords[1])), "EPSG:3857") B = projections.from4326((float(coords[2]), float(coords[3])), "EPSG:3857") C = projections.from4326((float(coords[4]), float(coords[5])), "EPSG:3857") segments = int(sys.argv[2]) params = int(sys.argv[3]) AM = ((B[0] - A[0]) / 2, (B[1] - A[1]) / 2) BN = ((C[0] - B[0]) / 2, (C[1] - B[1]) / 2) M = (A[0] + AM[0], A[1] + AM[1]) N = (B[0] + BN[0], B[1] + BN[1]) MM = (AM[1], -AM[0]) NN = (BN[1], -BN[0]) O = intersect(MM, M, NN, N) # circle center OA = (O[0] - A[0], O[1] - A[1]) r = math.sqrt(OA[0] * OA[0] + OA[1] * OA[1]) # radius arc = createarc(O, A, C, r, segments) tData = OsmData() wayid = tData.addway() for point in arc: p = projections.to4326(point, "EPSG:3857") newid = tData.addnode() tData.nodes[newid][LON] = p[0] tData.nodes[newid][LAT] = p[1] tData.nodes[newid][TAG] = {} tData.ways[wayid][REF].append(newid) if params == 1: p2 = projections.to4326(O, "EPSG:3857") # center p1 = projections.to4326((O[0] - r * 1.05, O[1]), "EPSG:3857") # axes points p3 = projections.to4326((O[0] + r * 1.05, O[1]), "EPSG:3857") p4 = projections.to4326((O[0], O[1] - r * 1.05), "EPSG:3857") p5 = projections.to4326((O[0], O[1] + r * 1.05), "EPSG:3857") wayid = tData.addway() newid = tData.addnode() tData.nodes[newid][LON] = p1[0] tData.nodes[newid][LAT] = p1[1] tData.nodes[newid][TAG] = {} tData.ways[wayid][REF].append(newid) newid2 = tData.addnode() tData.nodes[newid2][LON] = p2[0] tData.nodes[newid2][LAT] = p2[1] tData.nodes[newid2][TAG] = {} tData.ways[wayid][REF].append(newid2) newid = tData.addnode() tData.nodes[newid][LON] = p3[0] tData.nodes[newid][LAT] = p3[1] tData.nodes[newid][TAG] = {} tData.ways[wayid][REF].append(newid) wayid = tData.addway() newid = tData.addnode() tData.nodes[newid][LON] = p4[0] tData.nodes[newid][LAT] = p4[1] tData.nodes[newid][TAG] = {} tData.ways[wayid][REF].append(newid) tData.ways[wayid][REF].append(newid2) newid = tData.addnode() tData.nodes[newid][LON] = p5[0] tData.nodes[newid][LAT] = p5[1] tData.nodes[newid][TAG] = {} tData.ways[wayid][REF].append(newid) tData.addcomment("Done.") tData.write(sys.stdout) #f = open("out.txt", "w") #tData.write(f) #f.close() return 0
def main(): if len(sys.argv) != 3: return 0 wData = OsmData() # Way nData = OsmData() # Nodes wData.read(sys.stdin) wData.read(sys.stdin) nData.read(sys.stdin) radius = float(sys.argv[1]) segments = int(sys.argv[2]) nodes = [] usednodes = set() for way in wData.ways.items(): for key in nData.nodes.keys(): if key in usednodes: continue try: index = way[1][REF].index(key) except ValueError: pass else: lastindex = len(way[1][REF]) - 1 if way[1][REF][0] == way[1][REF][lastindex]: # polygon if index == 0: nodes.append([way[1][REF][lastindex-1], key, way[1][REF][index+1], way[0], index]) # previous node, node for fillet, next node, way usednodes.add(key) else: nodes.append([way[1][REF][index-1], key, way[1][REF][index+1], way[0], index]) usednodes.add(key) else: # way if index > 0 and index < lastindex: nodes.append([way[1][REF][index-1], key, way[1][REF][index+1], way[0], index]) usednodes.add(key) tData = OsmData() tData.mergedata(nData) tData.mergedata(wData) for pack in nodes: M = projections.from4326( (wData.nodes[pack[0]][LON], wData.nodes[pack[0]][LAT]), "EPSG:3857") # previous node O = projections.from4326( (wData.nodes[pack[1]][LON], wData.nodes[pack[1]][LAT]), "EPSG:3857") # center node N = projections.from4326( (wData.nodes[pack[2]][LON], wData.nodes[pack[2]][LAT]), "EPSG:3857") # next node r = radius / math.cos(math.radians(wData.nodes[pack[1]][LAT])) OM = (M[0] - O[0], M[1] - O[1]) ON = (N[0] - O[0], N[1] - O[1]) OMabs = math.sqrt(OM[0]*OM[0] + OM[1]*OM[1]) ONabs = math.sqrt(ON[0]*ON[0] + ON[1]*ON[1]) cosa = (OM[0]*ON[0] + OM[1]*ON[1]) / (OMabs * ONabs) OCabs = r / (math.sqrt((1 - cosa) / 2)) OMnorm = (OM[0]/OMabs, OM[1]/OMabs) ONnorm = (ON[0]/ONabs, ON[1]/ONabs) bisectrix = (OMnorm[0] + ONnorm[0], OMnorm[1] + ONnorm[1]) bisectrixabs = math.sqrt(bisectrix[0]*bisectrix[0] + bisectrix[1]*bisectrix[1]) bisectrixnorm = (bisectrix[0]/bisectrixabs, bisectrix[1]/bisectrixabs) OC = (bisectrixnorm[0]*OCabs, bisectrixnorm[1]*OCabs) C = (O[0]+OC[0], O[1]+OC[1]) P1 = project(OM, O, C) P2 = project(ON, O, C) arc = createarc(C, P1, P2, r, segments) arcref = [] exists = int(segments/2) for point in range(len(arc)): p = projections.to4326(arc[point], "EPSG:3857") if point == exists: tData.nodes[pack[1]][ACTION] = MODIFY tData.nodes[pack[1]][LON] = p[0] tData.nodes[pack[1]][LAT] = p[1] arcref.append(pack[1]) else: newid = tData.addnode() tData.nodes[newid][LON] = p[0] tData.nodes[newid][LAT] = p[1] tData.nodes[newid][TAG] = {} arcref.append(newid) way = tData.ways[pack[3]] way[ACTION] = MODIFY lastindex = len(way[REF]) - 1 index = way[REF].index(pack[1]) ref = way[REF][:] if way[REF][0] == way[REF][lastindex] and index == 0: # polygon way[REF] = arcref[:] way[REF] += (ref[1:lastindex]) way[REF] += [(arcref[0])] else: # way way[REF] = ref[:index] + arcref + ref[index+1:] tData.ways[pack[3]] = way tData.addcomment("Done.") tData.write(sys.stdout) #f = open("out.txt", "w") #tData.write(f) #f.close() return 0
def main(): if len(sys.argv) != 4: return 0 rData = OsmData() # References mData = OsmData() # Objects for moving rData.read(sys.stdin) mData.read(sys.stdin) coords = (sys.argv[1].split(',')) p1 = projections.from4326((float(coords[0]), float(coords[1])), "EPSG:3857") coords = (sys.argv[2].split(',')) p2 = projections.from4326((float(coords[0]), float(coords[1])), "EPSG:3857") if sys.argv[3] == "Yes": nData = OsmData() # New objects nMap = Map() wMap = Map() rMap = Map() for key in rData.nodes.keys(): p = projections.from4326( (rData.nodes[key][LON], rData.nodes[key][LAT]), "EPSG:3857") p = mirror(p, p1, p2) p = projections.to4326(p, "EPSG:3857") nData.nodes[nMap[key]] = {} nData.nodes[nMap[key]][TAG] = rData.nodes[key][TAG] nData.nodes[nMap[key]][LON] = p[0] nData.nodes[nMap[key]][LAT] = p[1] nData.nodes[nMap[key]][ACTION] = CREATE for key in mData.nodes.keys(): p = projections.from4326( (mData.nodes[key][LON], mData.nodes[key][LAT]), "EPSG:3857") p = mirror(p, p1, p2) p = projections.to4326(p, "EPSG:3857") nData.nodes[nMap[key]] = {} nData.nodes[nMap[key]][TAG] = mData.nodes[key][TAG] nData.nodes[nMap[key]][LON] = p[0] nData.nodes[nMap[key]][LAT] = p[1] nData.nodes[nMap[key]][ACTION] = CREATE for key in rData.ways.keys(): nData.ways[wMap[key]] = {} nData.ways[wMap[key]][TAG] = rData.ways[key][TAG] nData.ways[wMap[key]][REF] = [] for nd in rData.ways[key][REF]: nData.ways[wMap[key]][REF].append(nMap[nd]) nData.ways[wMap[key]][ACTION] = CREATE for key in mData.ways.keys(): nData.ways[wMap[key]] = {} nData.ways[wMap[key]][TAG] = mData.ways[key][TAG] nData.ways[wMap[key]][REF] = [] for nd in mData.ways[key][REF]: nData.ways[wMap[key]][REF].append(nMap[nd]) nData.ways[wMap[key]][ACTION] = CREATE for key in rData.relations.keys(): nData.relations[rMap[key]] = {} nData.relations[rMap[key]][TAG] = rData.relations[key][TAG] nData.relations[rMap[key]][REF] = [[], [], []] for nd in rData.relations[key][REF][NODES]: if nData.nodes.get(nMap[nd]) != None: nData.relations[rMap[key]][REF][NODES].append( (nMap[nd[0]], nd[1])) for way in rData.relations[key][REF][WAYS]: if nData.ways.get(wMap[way]) != None: nData.relations[rMap[key]][REF][WAYS].append( (wMap[way[0]], way[1])) for relation in rData.relations[key][REF][RELATIONS]: if rData.relations.get( relation) != None or mData.relations.get( relation) != None: nData.relations[rMap[key]][REF][RELATIONS].append( (rMap[relation[0]], relation[1])) nData.relations[rMap[key]][ACTION] = CREATE for key in mData.relations.keys(): nData.relations[rMap[key]] = {} nData.relations[rMap[key]][TAG] = mData.relations[key][TAG] nData.relations[rMap[key]][REF] = [[], [], []] for nd in mData.relations[key][REF][NODES]: if nData.nodes.get(nMap[nd[0]]) != None: nData.relations[rMap[key]][REF][NODES].append( (nMap[nd[0]], nd[1])) for way in mData.relations[key][REF][WAYS]: if nData.ways.get(wMap[way[0]]) != None: nData.relations[rMap[key]][REF][WAYS].append( (wMap[way[0]], way[1])) for relation in mData.relations[key][REF][RELATIONS]: if rData.relations.get( relation[0]) != None or mData.relations.get( relation) != None: nData.relations[rMap[key]][REF][RELATIONS].append( (rMap[relation[0]], relation[1])) nData.relations[rMap[key]][ACTION] = CREATE nData.addcomment("Done.") nData.write(sys.stdout) elif sys.argv[3] == "No": rData.nodes.update(mData.nodes) for nkey in rData.nodes.keys(): p = projections.from4326( (rData.nodes[nkey][LON], rData.nodes[nkey][LAT]), "EPSG:3857") p = mirror(p, p1, p2) p = projections.to4326(p, "EPSG:3857") rData.nodes[nkey][LON] = p[0] rData.nodes[nkey][LAT] = p[1] rData.nodes[nkey][ACTION] = MODIFY rData.write(sys.stdout) return 0
def main(): if len(sys.argv) != 4: return 0 rData = OsmData() # References mData = OsmData() # Objects for moving rData.read(sys.stdin) mData.read(sys.stdin) coords = (sys.argv[1].split(',')) p1 = projections.from4326((float(coords[0]),float(coords[1])), "EPSG:3857") coords = (sys.argv[2].split(',')) p2 = projections.from4326((float(coords[0]),float(coords[1])), "EPSG:3857") if sys.argv[3] == "Yes": nData = OsmData() # New objects nMap = Map() wMap = Map() rMap = Map() for key in rData.nodes.keys(): p = projections.from4326((rData.nodes[key][LON],rData.nodes[key][LAT]), "EPSG:3857") p = mirror(p, p1, p2) p = projections.to4326(p, "EPSG:3857") nData.nodes[nMap[key]] = {} nData.nodes[nMap[key]][TAG] = rData.nodes[key][TAG] nData.nodes[nMap[key]][LON] = p[0] nData.nodes[nMap[key]][LAT] = p[1] nData.nodes[nMap[key]][ACTION] = CREATE for key in mData.nodes.keys(): p = projections.from4326((mData.nodes[key][LON],mData.nodes[key][LAT]), "EPSG:3857") p = mirror(p, p1, p2) p = projections.to4326(p, "EPSG:3857") nData.nodes[nMap[key]] = {} nData.nodes[nMap[key]][TAG] = mData.nodes[key][TAG] nData.nodes[nMap[key]][LON] = p[0] nData.nodes[nMap[key]][LAT] = p[1] nData.nodes[nMap[key]][ACTION] = CREATE for key in rData.ways.keys(): nData.ways[wMap[key]] = {} nData.ways[wMap[key]][TAG] = rData.ways[key][TAG] nData.ways[wMap[key]][REF] = [] for nd in rData.ways[key][REF]: nData.ways[wMap[key]][REF].append(nMap[nd]) nData.ways[wMap[key]][ACTION] = CREATE for key in mData.ways.keys(): nData.ways[wMap[key]] = {} nData.ways[wMap[key]][TAG] = mData.ways[key][TAG] nData.ways[wMap[key]][REF] = [] for nd in mData.ways[key][REF]: nData.ways[wMap[key]][REF].append(nMap[nd]) nData.ways[wMap[key]][ACTION] = CREATE for key in rData.relations.keys(): nData.relations[rMap[key]] = {} nData.relations[rMap[key]][TAG] = rData.relations[key][TAG] nData.relations[rMap[key]][REF] = [[], [], []] for nd in rData.relations[key][REF][NODES]: if nData.nodes.get(nMap[nd]) != None: nData.relations[rMap[key]][REF][NODES].append((nMap[nd[0]], nd[1])) for way in rData.relations[key][REF][WAYS]: if nData.ways.get(wMap[way]) != None: nData.relations[rMap[key]][REF][WAYS].append((wMap[way[0]], way[1])) for relation in rData.relations[key][REF][RELATIONS]: if rData.relations.get(relation) != None or mData.relations.get(relation) != None: nData.relations[rMap[key]][REF][RELATIONS].append((rMap[relation[0]], relation[1])) nData.relations[rMap[key]][ACTION] = CREATE for key in mData.relations.keys(): nData.relations[rMap[key]] = {} nData.relations[rMap[key]][TAG] = mData.relations[key][TAG] nData.relations[rMap[key]][REF] = [[], [], []] for nd in mData.relations[key][REF][NODES]: if nData.nodes.get(nMap[nd[0]]) != None: nData.relations[rMap[key]][REF][NODES].append((nMap[nd[0]], nd[1])) for way in mData.relations[key][REF][WAYS]: if nData.ways.get(wMap[way[0]]) != None: nData.relations[rMap[key]][REF][WAYS].append((wMap[way[0]], way[1])) for relation in mData.relations[key][REF][RELATIONS]: if rData.relations.get(relation[0]) != None or mData.relations.get(relation) != None: nData.relations[rMap[key]][REF][RELATIONS].append((rMap[relation[0]], relation[1])) nData.relations[rMap[key]][ACTION] = CREATE nData.addcomment("Done.") nData.write(sys.stdout) elif sys.argv[3] == "No": rData.nodes.update(mData.nodes) for nkey in rData.nodes.keys(): p = projections.from4326((rData.nodes[nkey][LON],rData.nodes[nkey][LAT]), "EPSG:3857") p = mirror(p, p1, p2) p = projections.to4326(p, "EPSG:3857") rData.nodes[nkey][LON] = p[0] rData.nodes[nkey][LAT] = p[1] rData.nodes[nkey][ACTION] = MODIFY rData.write(sys.stdout) return 0
def main(): if len(sys.argv) != 4: return 0 rData = OsmData() # References mData = OsmData() # Objects for moving rData.read(sys.stdin) mData.read(sys.stdin) coords = sys.argv[1].split(',') p1 = (float(coords[0]), float(coords[1])) if sys.argv[3] == "No": coords = (sys.argv[2].split(',')) p2 = (float(coords[0]), float(coords[1])) vector = (p2[0] - p1[0], p2[1] - p1[1]) rData.nodes.update(mData.nodes) for nkey in rData.nodes.keys(): rData.nodes[nkey][LON] += vector[0] rData.nodes[nkey][LAT] += vector[1] rData.nodes[nkey][ACTION] = MODIFY rData.write(sys.stdout) elif sys.argv[3] == "Yes": nData = OsmData() nMap = Map() wMap = Map() rMap = Map() no = wo = ro = 0 # Offsets rData.nodes.update(mData.nodes) rData.ways.update(mData.ways) rData.relations.update(mData.relations) pointlist = (sys.argv[2].split(';')) for point in pointlist: cData = OsmData() coords = point.split(',') p2 = (float(coords[0]), float(coords[1])) vector = (p2[0] - p1[0], p2[1] - p1[1]) for key in rData.nodes.keys(): cData.nodes[nMap[key]] = {} cData.nodes[nMap[key]][TAG] = rData.nodes[key][TAG] cData.nodes[nMap[key]][LON] = rData.nodes[key][LON] + vector[0] cData.nodes[nMap[key]][LAT] = rData.nodes[key][LAT] + vector[1] cData.nodes[nMap[key]][ACTION] = CREATE for key in rData.ways.keys(): cData.ways[wMap[key]] = {} cData.ways[wMap[key]][TAG] = rData.ways[key][TAG] cData.ways[wMap[key]][REF] = [] for nd in rData.ways[key][REF]: cData.ways[wMap[key]][REF].append(nMap[nd + no]) cData.ways[wMap[key]][ACTION] = CREATE for key in rData.relations.keys(): cData.relations[rMap[key]] = {} cData.relations[rMap[key]][TAG] = rData.relations[key][TAG] cData.relations[rMap[key]][REF] = [[], [], []] for nd in rData.relations[key][REF][NODES]: if cData.nodes.get(nMap[nd[0] + no]) != None: cData.relations[rMap[key]][REF][NODES].append( (nMap[nd[0] + no], nd[1])) for way in rData.relations[key][REF][WAYS]: if cData.ways.get(wMap[way[0] + wo]) != None: cData.relations[rMap[key]][REF][WAYS].append( (wMap[way[0] + wo], way[1])) for relation in rData.relations[key][REF][RELATIONS]: if rData.relations.get( relation) != None or mData.relations.get( relation) != None: cData.relations[rMap[key]][REF][RELATIONS].append( (rMap[relation[0] + ro], relation[1])) cData.relations[rMap[key]][ACTION] = CREATE nMap.omap.clear() wMap.omap.clear() rMap.omap.clear() nData.nodes.update(cData.nodes) nData.ways.update(cData.ways) nData.relations.update(cData.relations) nData.addcomment("Done.") nData.write(sys.stdout) return 0
def main(): if len(sys.argv) != 3: return 0 wData = OsmData() # Way nData = OsmData() # Nodes wData.read(sys.stdin) wData.read(sys.stdin) nData.read(sys.stdin) radius = float(sys.argv[1]) segments = int(sys.argv[2]) nodes = [] usednodes = set() for way in wData.ways.items(): for key in nData.nodes.keys(): if key in usednodes: continue try: index = way[1][REF].index(key) except ValueError: pass else: lastindex = len(way[1][REF]) - 1 if way[1][REF][0] == way[1][REF][lastindex]: # polygon if index == 0: nodes.append([ way[1][REF][lastindex - 1], key, way[1][REF][index + 1], way[0], index ]) # previous node, node for fillet, next node, way usednodes.add(key) else: nodes.append([ way[1][REF][index - 1], key, way[1][REF][index + 1], way[0], index ]) usednodes.add(key) else: # way if index > 0 and index < lastindex: nodes.append([ way[1][REF][index - 1], key, way[1][REF][index + 1], way[0], index ]) usednodes.add(key) tData = OsmData() tData.mergedata(nData) tData.mergedata(wData) for pack in nodes: M = projections.from4326( (wData.nodes[pack[0]][LON], wData.nodes[pack[0]][LAT]), "EPSG:3857") # previous node O = projections.from4326( (wData.nodes[pack[1]][LON], wData.nodes[pack[1]][LAT]), "EPSG:3857") # center node N = projections.from4326( (wData.nodes[pack[2]][LON], wData.nodes[pack[2]][LAT]), "EPSG:3857") # next node r = radius / math.cos(math.radians(wData.nodes[pack[1]][LAT])) OM = (M[0] - O[0], M[1] - O[1]) ON = (N[0] - O[0], N[1] - O[1]) OMabs = math.sqrt(OM[0] * OM[0] + OM[1] * OM[1]) ONabs = math.sqrt(ON[0] * ON[0] + ON[1] * ON[1]) cosa = (OM[0] * ON[0] + OM[1] * ON[1]) / (OMabs * ONabs) OCabs = r / (math.sqrt((1 - cosa) / 2)) OMnorm = (OM[0] / OMabs, OM[1] / OMabs) ONnorm = (ON[0] / ONabs, ON[1] / ONabs) bisectrix = (OMnorm[0] + ONnorm[0], OMnorm[1] + ONnorm[1]) bisectrixabs = math.sqrt(bisectrix[0] * bisectrix[0] + bisectrix[1] * bisectrix[1]) bisectrixnorm = (bisectrix[0] / bisectrixabs, bisectrix[1] / bisectrixabs) OC = (bisectrixnorm[0] * OCabs, bisectrixnorm[1] * OCabs) C = (O[0] + OC[0], O[1] + OC[1]) P1 = project(OM, O, C) P2 = project(ON, O, C) arc = createarc(C, P1, P2, r, segments) arcref = [] exists = int(segments / 2) for point in range(len(arc)): p = projections.to4326(arc[point], "EPSG:3857") if point == exists: tData.nodes[pack[1]][ACTION] = MODIFY tData.nodes[pack[1]][LON] = p[0] tData.nodes[pack[1]][LAT] = p[1] arcref.append(pack[1]) else: newid = tData.addnode() tData.nodes[newid][LON] = p[0] tData.nodes[newid][LAT] = p[1] tData.nodes[newid][TAG] = {} arcref.append(newid) way = tData.ways[pack[3]] way[ACTION] = MODIFY lastindex = len(way[REF]) - 1 index = way[REF].index(pack[1]) ref = way[REF][:] if way[REF][0] == way[REF][lastindex] and index == 0: # polygon way[REF] = arcref[:] way[REF] += (ref[1:lastindex]) way[REF] += [(arcref[0])] else: # way way[REF] = ref[:index] + arcref + ref[index + 1:] tData.ways[pack[3]] = way tData.addcomment("Done.") tData.write(sys.stdout) #f = open("out.txt", "w") #tData.write(f) #f.close() return 0
def main(): if len(sys.argv) != 4: return 0 rData = OsmData() # References mData = OsmData() # Objects for moving rData.read(sys.stdin) mData.read(sys.stdin) coords = sys.argv[1].split(',') p1 = (float(coords[0]), float(coords[1])) if sys.argv[3] == "No": coords = (sys.argv[2].split(',')) p2 = (float(coords[0]), float(coords[1])) vector = (p2[0] - p1[0], p2[1] - p1[1]) rData.nodes.update(mData.nodes) for nkey in rData.nodes.keys(): rData.nodes[nkey][LON] += vector[0] rData.nodes[nkey][LAT] += vector[1] rData.nodes[nkey][ACTION] = MODIFY rData.write(sys.stdout) elif sys.argv[3] == "Yes": nData = OsmData() nMap = Map() wMap = Map() rMap = Map() no = wo = ro = 0 # Offsets rData.nodes.update(mData.nodes) rData.ways.update(mData.ways) rData.relations.update(mData.relations) pointlist = (sys.argv[2].split(';')) for point in pointlist: cData = OsmData() coords = point.split(',') p2 = (float(coords[0]), float(coords[1])) vector = (p2[0] - p1[0], p2[1] - p1[1]) for key in rData.nodes.keys(): cData.nodes[nMap[key]] = {} cData.nodes[nMap[key]][TAG] = rData.nodes[key][TAG] cData.nodes[nMap[key]][LON] = rData.nodes[key][LON] + vector[0] cData.nodes[nMap[key]][LAT] = rData.nodes[key][LAT] + vector[1] cData.nodes[nMap[key]][ACTION] = CREATE for key in rData.ways.keys(): cData.ways[wMap[key]] = {} cData.ways[wMap[key]][TAG] = rData.ways[key][TAG] cData.ways[wMap[key]][REF] = [] for nd in rData.ways[key][REF]: cData.ways[wMap[key]][REF].append(nMap[nd + no]) cData.ways[wMap[key]][ACTION] = CREATE for key in rData.relations.keys(): cData.relations[rMap[key]] = {} cData.relations[rMap[key]][TAG] = rData.relations[key][TAG] cData.relations[rMap[key]][REF] = [[], [], []] for nd in rData.relations[key][REF][NODES]: if cData.nodes.get(nMap[nd[0] + no]) != None: cData.relations[rMap[key]][REF][NODES].append((nMap[nd[0] + no], nd[1])) for way in rData.relations[key][REF][WAYS]: if cData.ways.get(wMap[way[0] + wo]) != None: cData.relations[rMap[key]][REF][WAYS].append((wMap[way[0] + wo], way[1])) for relation in rData.relations[key][REF][RELATIONS]: if rData.relations.get(relation) != None or mData.relations.get(relation) != None: cData.relations[rMap[key]][REF][RELATIONS].append((rMap[relation[0] + ro], relation[1])) cData.relations[rMap[key]][ACTION] = CREATE nMap.omap.clear() wMap.omap.clear() rMap.omap.clear() nData.nodes.update(cData.nodes) nData.ways.update(cData.ways) nData.relations.update(cData.relations) nData.addcomment("Done.") nData.write(sys.stdout) return 0