pyrosm icon indicating copy to clipboard operation
pyrosm copied to clipboard

Coordinates of crossings do not match nodes on ways

Open fiftysevendegreesofrad opened this issue 3 years ago • 6 comments

Running the following code produces two shapefiles (one way and one crossing node) in which the crossing node does not fall on the way.

It would seem that they should align as in the underlying data model, ways reference nodes? On the OSM website the node in question is directly referenced by the way:

https://www.openstreetmap.org/api/0.6/way/117042378 https://www.openstreetmap.org/api/0.6/node/7977607954

# -*- coding: utf-8 -*-

import pyrosm

data = pyrosm.get_data("wales")

osm = pyrosm.OSM(data,bounding_box = [-2.718403,51.810258,-2.718202,51.810445])

net = osm.get_data_by_custom_criteria(custom_filter={},filter_type='exclude',osm_keys_to_keep='highway',
                                        keep_nodes=False, 
                                        keep_ways=True 
                                        )

def pretty_print_point(x,y):
    print ("%.30f,%.30f"%(x,y))

print(net)
for part in net.geometry[0]:
    for x,y in zip(*part.coords.xy):
        pretty_print_point(x,y)

net.to_file("net_out.shp")

crossings = osm.get_data_by_custom_criteria(custom_filter={ 'highway': ['crossing'] }, filter_type='keep',
                                        keep_nodes=True, 
                                        keep_ways=False
                                        )
                                        

print(crossings)
for x,y in zip(*crossings.geometry[0].coords.xy):
    pretty_print_point(x,y)

crossings.to_file("crossings_out.shp")

fiftysevendegreesofrad avatar Mar 24 '21 13:03 fiftysevendegreesofrad

Hi @fiftysevendegreesofrad, hmm so have I understood you correctly that in this situation, the node should be part of the way? :

image

HTenkanen avatar Apr 21 '21 07:04 HTenkanen

@fiftysevendegreesofrad : Okay, the reason for this behavior is due to the very narrow bounding box that you use. If you use larger bounding box all the nodes are correctly kept as part of the geometry:

# Adding a larger bounding box ..
box = [-2.7189, 51.78, -2.7182, 51.83]
osm2 = pyrosm.OSM(data,bounding_box = box)
net2 = osm2.get_data_by_custom_criteria(custom_filter={},filter_type='exclude',osm_keys_to_keep='highway',
                                        keep_nodes=False, 
                                        keep_ways=True 
                                        )
# .. will add the missing nodes to the geometry
print(net2.loc[net2["id"]==117042378].geometry.values[0])

The small bounding box dropped all nodes that were outside of it, which is the reason why this happened. I will close this now because it seems that everything works as should. In case you there is still something weird happening, feel free to reopen this issue.

HTenkanen avatar Apr 21 '21 07:04 HTenkanen

Hi, thank you for taking a look at this. Your finding is a bit mystifying as I originally spotted this issue with a much larger bounding box (a few kilometers per side). If you like I'll send that one through when I have a moment?

fiftysevendegreesofrad avatar Apr 21 '21 09:04 fiftysevendegreesofrad

Hmm, okay well in that case, let's keep this open. 👍🏻 If you indeed could provide the bounding box that you used when spotting the issue, I can check if I can reproduce the issue. All the nodes of the way should definitely be included in the geometry if things work normally.

HTenkanen avatar Apr 21 '21 10:04 HTenkanen

Right here goes, I just retested with the wider box, still the same issue. Code as above but:

osm = pyrosm.OSM(data,bounding_box = [-2.7979396516874933, 51.760829607352036, -2.6410739337039164, 51.85148596274141])

image

fiftysevendegreesofrad avatar Apr 21 '21 11:04 fiftysevendegreesofrad

Excellent, thanks! 👍🏻

HTenkanen avatar Apr 21 '21 11:04 HTenkanen