代码之家  ›  专栏  ›  技术社区  ›  leo_bouts

osmnx投影地图的经纬坐标变换

  •  0
  • leo_bouts  · 技术社区  · 4 年前

    我想从osmnx中获取最接近lat-long对的节点。

    下载osmnx图形对象后,我想投影它,这样我就可以按照文档中的指示从道路网络中删除死角。

    我知道我投影了图形和lat,long值需要投影,但我实际上不明白以哪种方式投影。

    例如,我在项目中将lat-long转换为x y z,但我怎么知道这与此图的投影兼容。欧几里德方法似乎没有帮助。

    此外,标志rebuild_graph=True是否会撤消投影并返回未投影的图形obejct?如果是这样,那么lat-long数据就不太接近,无法解释返回的同一节点。

    long = [20.83099222975307, 20.83099222975307, 20.831071057075036, 20.831507821410554, 20.831536549206216, 20.831590645309163, 20.831760926274246, 20.831829734056857, 20.832064826897437, 20.83211892318422, 20.832291232174775, 20.832453521327647, 20.832467537620413, 20.832744680362744, 20.83275203624094, 20.832893649116148, 20.832933033903316, 20.83298713048916, 20.833011166881615, 20.833109340046658, 20.83317212468842, 20.83317212468842, 20.83319216485246, 20.833193496936566, 20.833256281615377, 20.833335746832073, 20.833345766925337, 20.83338451522313, 20.83367104311693, 20.83367104311693, 20.83378456515314, 20.833896118665407, 20.833897450746417, 20.83400095279438, 20.83400095279438, 20.834029044642254, 20.83411517063695, 20.83413121469866, 20.834177955710697, 20.8341879758658, 20.83424074081229, 20.83424074081229, 20.83424074081229, 20.83424809681322, 20.834270801294185, 20.834296169936398, 20.834302193862516, 20.834302193862516, 20.83430485802092, 20.83430485802092, 20.83441438425335, 20.834493213575563, 20.834498541888962, 20.83452391055964, 20.834525938270623, 20.83458669580759, 20.83459405183661, 20.83459405183661, 20.834608068255694, 20.834616756364248, 20.83467288126638, 20.834695585806365, 20.834695585806365, 20.834742326972062, 20.83503887769283, 20.835118343769174, 20.83514840444336, 20.83576757270048, 20.836452193850544, 20.83755761485359, 20.83759706037195, 20.837852203156956, 20.83795570768881, 20.838343145143025, 20.838343145143025, 20.839993748127704, 20.84092763462079, 20.84092763462079, 20.84092763462079, 20.84092763462079, 20.84127702640877, 20.84127702640877, 20.84127702640877, 20.841985137270154, 20.843422866598996, 20.84377429407861, 20.84377429407861, 20.84377429407861, 20.84377429407861, 20.84377429407861, 20.84377429407861, 20.84377429407861, 20.84377429407861, 20.84377429407861, 20.84402151726155, 20.84402151726155, 20.84548742851209, 20.84548742851209, 20.85188606916644, 20.85501616058255, 20.856737430326934, 20.859542430698603, 20.8613760173422, 20.86163714950174, 20.863028413707386, 20.863180155858238, 20.863345567971184, 20.863412802449744, 20.863424615681698, 20.863451670631083, 20.863495295022673, 20.86349756245783, 20.86346547505983, 20.86346547505983, 20.86346547505983, 20.863419542480333, 20.863411941442653, 20.86332960137235, 20.862958153765447, 20.86259449784883, 20.862368831055996, 20.862368831055996, 20.86213427281035, 20.86212634419993, 20.86188638794884, 20.861807035358805, 20.861375561408494, 20.860967669982454, 20.858716012450735, 20.858716012450735, 20.858706051455755, 20.85862909256079, 20.85859787704128, 20.85611899992582, 20.85611899992582, 20.853380676295366, 20.84616157108611, 20.845523814987697, 20.844864025170992, 20.842355069052047, 20.841927997139937, 20.841920696524085, 20.83342199581793, 20.829528649520768, 20.824360163540142, 20.82338364296999, 20.82231856837287]
    
    lat = [39.62319155463754, 39.62319155463754, 39.62320295662305, 39.6232970230751, 39.62329987357564, 39.623311275578985, 39.623345481600296, 39.6233625846173, 39.6234110431884, 39.62341959470448, 39.623456651286325, 39.6234908573795, 39.623496558396674, 39.623553568594225, 39.623553568594225, 39.623584924222904, 39.62359347576046, 39.62360202729907, 39.62361057883875, 39.62362768192127, 39.62364193449326, 39.62364193449326, 39.62364763552287, 39.62364763552287, 39.62365903758352, 39.62367614067801, 39.62368184171045, 39.623687542743355, 39.62374740361722, 39.62374740361722, 39.62377590881346, 39.62379586245781, 39.62379586245781, 39.623824367674004, 39.623824367674004, 39.623827218196276, 39.62384432133233, 39.623850022378626, 39.623858573948944, 39.62386427499641, 39.62387282656849, 39.62387282656849, 39.62387282656849, 39.62387567709275, 39.62388137814163, 39.62388422866624, 39.62388422866624, 39.62388422866624, 39.62388422866624, 39.62388422866624, 39.623912733918836, 39.623929837076034, 39.623929837076034, 39.62393553812936, 39.62393553812936, 39.623946940237445, 39.62395264129219, 39.62395264129219, 39.62395549181974, 39.62395549181974, 39.62396974445926, 39.62397544551588, 39.62397544551588, 39.6239839971017, 39.62404955929475, 39.62406666248575, 39.62407236355037, 39.62421203978002, 39.624368819557304, 39.62462821960523, 39.62463962182745, 39.624696632966725, 39.62472228799472, 39.624816356512106, 39.624816356512106, 39.62522398823179, 39.62546628794432, 39.62546628794432, 39.62546628794432, 39.62546628794432, 39.62556035747312, 39.62556035747312, 39.62556035747312, 39.62574564631297, 39.626144731653206, 39.62624450334792, 39.62624450334792, 39.62624450334792, 39.62624450334792, 39.62624450334792, 39.62624450334792, 39.62624450334792, 39.62624450334792, 39.62624450334792, 39.62631576893222, 39.62631576893222, 39.626754766550185, 39.626754766550185, 39.62903531847423, 39.63050061275056, 39.631469890610106, 39.63349401463708, 39.63539845582614, 39.63574057656538, 39.638423432026336, 39.63893378506902, 39.63967223552374, 39.640079954790295, 39.640191151371056, 39.64042494989323, 39.64123469722554, 39.64159395436001, 39.64219557167739, 39.64219557167739, 39.64219557167739, 39.642680290858735, 39.64276297858772, 39.643316133524635, 39.64490719146398, 39.64600213432235, 39.64658953268899, 39.64658953268899, 39.64713986675438, 39.64715697565563, 39.64768735369431, 39.64785559273931, 39.648711051843534, 39.64946101303195, 39.652951433740164, 39.652951433740164, 39.65296284063269, 39.65307120620556, 39.65311398213635, 39.656285178192974, 39.656285178192974, 39.65940518392453, 39.66665246841233, 39.66725430386289, 39.66786755390862, 39.67016657695176, 39.67055165652977, 39.670560213878105, 39.678005508599924, 39.68132905057261, 39.6857112353726, 39.686538632203565, 39.68744878016951]
    
    bounding_box = (20.814945, 20.876184, 39.612716999999996, 39.685287)
    
    
    # Defining the map boundaries
    west, east, north, south = bounding_box[0], bounding_box[1], bounding_box[2], bounding_box[3]
    
    # Downloading the map as a graph object
    g = ox.graph_from_bbox(north,
                   south,
                   east,
                   west,
                   network_type='all', clean_periphery=True)
    
    G_proj = ox.project_graph(g)
    
    g = ox.consolidate_intersections(G_proj,
                             rebuild_graph=True,
                             tolerance=20,
                             dead_ends=False)
    route = []
    
    for i in range(len(lat)):
    
        point = (lat[i], long[i])
        node = ox.get_nearest_node(g, point)
        print(node)
        route.append(node)
    
    print(route)
    
    0 回复  |  直到 4 年前
        1
  •  3
  •   gboeing    4 年前

    我知道我投影了图形和lat,long值需要投影,但我实际上不明白以哪种方式投影。

    只需将您的点投影到与图形相同的CRS。每 the docs ,OSMnx将您的图投影到本地UTM区域投影,除非您指定了不同的CRS。只需使用投影图的CRS属性将您的lat/lng点投影到相同的位置,然后进行欧几里德最近节点搜索。

    下面是一个带有注释的最小可重复示例:

    import geopandas as gpd
    import osmnx as ox
    from shapely.geometry import Point
    ox.config(use_cache=True, log_console=True)
    
    # create graph, project it, then consolidate intersections
    bbox = (39.612717, 39.685287, 20.876184, 20.814945)
    G = ox.graph_from_bbox(*bbox, network_type='all')
    Gp = ox.project_graph(G)
    Gc = ox.consolidate_intersections(Gp, rebuild_graph=True, tolerance=20, dead_ends=False)
    
    # turn lat/lng lists into list of shapely points
    lats = [39.6654413, 39.6456468, 39.6175496]
    lngs = [20.8586396, 20.8496936, 20.8437053]
    points_list = [Point((lng, lat)) for lat, lng in zip(lats, lngs)]
    
    # then turn list into GeoSeries with original CRS set
    # i'm just guessing that your original CRS is 4326
    points = gpd.GeoSeries(points_list, crs='epsg:4326')
    
    # then project your points to the same CRS as your projected graph
    points_proj = points.to_crs(Gp.graph['crs'])
    
    # find nearest node in projected graph to each projected point
    method = 'euclidean'
    nearest_nodes = [ox.get_nearest_node(Gc, (pt.y, pt.x), method) for pt in points_proj]
    print(nearest_nodes) # prints [1334, 777, 37]
    

    此外,标志rebuild_graph=True是否会撤消投影并返回未投影的图形obejct?

    不。

    推荐文章