Code covered by the BSD License  

Highlights from
OpenStreetMap Functions

5.0

5.0 | 4 ratings Rate this file 90 Downloads (last 30 days) File Size: 4.57 MB File ID: #35819
image thumbnail

OpenStreetMap Functions

by Ioannis Filippidis

 

22 Mar 2012 (Updated 03 May 2012)

Load map, extract connectivity, plot road network & find shortest paths from OpenStreetMap XML file.

| Watch this File

File Information
Description

This software package includes functions for working with OpenStreetMap XML Data files (extension .osm), as downloaded from http://www.openstreetmap.org, to:

1) Import and parse the XML data file and store the parsed data in a MATLAB structure. This data represents the graph of the transportation network.

2) Plot the MATLAB structure to get a visualization of the transportation network, its nodes and their labels.

3) Extract the adjacency matrix of the directed graph representing the network's connectivity (i.e., road intersections).

4) Find shortest routes between nodes within the network. Note that distance is measured as the number of transitions between intersection nodes, not over the map.

Acknowledgements

Xml2struct, Gaimc : Graph Algorithms In Matlab Code, Correctly Proportion A Lat/Lon Plot, and Plot 2/3 D Point(S) inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File  
Everyone's Tags
automotive(2), data import(2), geography(2), gis, mapping, matrix, modeling, network, openstreetmap, routing, transportation(2)
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (18)
11 May 2013 Ioannis Filippidis

Hi Richard,

It appears that the Java Virtual Machine run out of memory, you can increase that (depending on the limits of your system). Please see here:
http://www.mathworks.com/support/solutions/en/data/1-18I2C/
This can also be the case when plotting a lot of data.

I would suggest trying to instead reduce the piece of the map you attempt to import, based on what is the purpose for further processing.
Otherwise even if it does load after increasing the java heap size, it will still be cumbersome to process.

Another suggestion might be to break into pieces and load those separately, one at a time, extracting the structure of interest and then identifying common nodes between different patches. However this is much more involved, because it involves the global (unique) IDs of the nodes, representing them in the openstreetmap database (and file).

10 May 2013 Richard

I'm trying to get a street map of Beijing, but encountering an out of memory error:

??? Java exception occurred:
java.lang.OutOfMemoryError: Java heap space
.

Error in ==> xmlread at 91
parseResult = p.parse(fileName);

Error in ==> xml2struct at 40
xDoc = xmlread(file);

Error in ==> load_osm_xml at 26
map_osm = xml2struct(filename); % downloaded osm file

Error in ==> parse_openstreetmap at 41
map_osm = load_osm_xml(openstreetmap_filename);

Error in ==> GeoLife_main at 21
[parsed_osm, osm_xml] = parse_openstreetmap('beijing.osm');

Beijing.osm is 75.35 MB

Any suggestions?

15 Feb 2013 Ioannis Filippidis

Some recent feedback I received suggests that the xml loading error might be caused by a name conflict between the function xml2struct included with the openstreetmap functions and a function with the same name in the MATLAB Bioinformatics toolbox.

My version of the bioinformatics toolbox does not have such a function, however it does have some functions for xml handling, so probably there existed xml2struct function in previous versions.

The Bioinformatics toolbox function (when it exists) can shadow the one included with this software package, depending on their relative placement in the MATLAB path.

Please check if this is the case for you by typing:
which xml2struct
This issue might be fixed in some future version by just renaming xml2struct, although in general it is preferable to maintain original names for files from the file exchange to keep better track of code and avoid duplicates.

23 Jan 2013 Ioannis Filippidis

Hi Fabio,

Are you sure that xml2struct is in your path? It appears that the file is not loaded correctly, maybe you could check to see the fields of the structure returned, containing the loaded xml.

A minimal example reproducing the issue would help resolve it.

Best,
Ioannis

08 Nov 2012 Fabio Lopez

Hi Loannis

I have just begun to use the functions package, and as a start a wanted to run the usage example. The following error arises indistinctly of the geographical location of the file or its size:

??? Reference to non-existent field 'osm'.

Error in ==> parse_openstreetmap at 42
osm_xml = map_osm.osm;

Error in ==> usage_example at 29
[parsed_osm, osm_xml] = parse_openstreetmap(openstreetmap_filename);
Could you maybe know the reason for this error?

06 Sep 2012 Paula

Hey Ioannis!
Thanks a lot for your help! Now I’m still working at the details to develop an addition for the run of the power network. I want to find out this run for whole Germany. I got the data directly from the openstreetmap homepage, where I exported them. But I just can get a really small part of Germany, if I export the data from this homepage. Do you know another page, where I can get the whole data base of Germany in once? It would be another great help for me!
Thank you again, Paula

10 Aug 2012 Ioannis Filippidis

Hi Paula,

A connectivity matrix represents the existence of connections between nodes.
In one-way roads the connections are directed, so the connectivity matrix is not symmetric.
In other words, you can go from node a to node b, but not the opposite way.
The route planner just searches within the graph represented by the connectivity matrix, in order to find a path from the initial to the final node.
Sometimes, certain roads are assumed symmetric when extracting the connectivity, but actually they are not.
For this reason, assuming that directions do not matter may work better if the first attempt fails.
This requires that the connectivity matrix be made symmetric.
Both of these two approaches are described in lines 35-48 of the usage_example file.

Since the road network was of interest in this package (at least until now), only roads qualified as valid connections.
So the code searches for road connections only.

Roads can be identified by their special tag, which has a key and a value, see
http://wiki.openstreetmap.org/wiki/Key:highway
http://wiki.openstreetmap.org/wiki/Highway_tag_usage
http://wiki.openstreetmap.org/wiki/Highways
for the related documentation on highways.
If the object has a tag, then the function get_way_tag_key gets the key and its value.

The tag's key is called "highway" and can take on many values (those of the possible values which were of interest are defined in the "road_vals" cell array in line 39 of extract_connectivity).

However, objects which are not highways do not have a tag with key named "highway".
This is checked in line 54 of extract_connectivity.
In this case, they are ignored, as far as connectivity is concerned.

Further, even if they do have the "highway" key, they may not be of interest (i.e., have a value included in "road_vals").
In this case, they are again ignored, see line 59 of extract_connectivity.

So the first warning means that the object is not a highway.
Taking the previous into consideration, it follows that this object does not contribute to the road connectivity (since it is not a road).

This is probably the reason that no route has been found.
The connectivity matrix produced from the current version of this code does not incorporate any information about the power lines or cables.

The second warning is just a suggestion by the route planner to use a symmetric network assumption, for the reasons described previously. (i.e., in case the one-way assumption does not hold exactly. For example, this could happen when we are interested in walking only and not cars. One would need to change "road_vals" as well in this case.)

To work with power networks, you would need to extract their connectivity from the loaded openstreetmap xml data.
You can do this by altering the function extract_connectivity to identify key="power" and the appropriate values, please see
http://wiki.openstreetmap.org/wiki/WikiProject_Power_networks

Extracting various networks is a good idea, I may add this capability when I have time.
If you develop an addition towards that direction, I would be happy to add it to the current distribution.

Best regards,
Ioannis

10 Aug 2012 Paula

Hey Ioannis,
I want to create a connectivity matrix for th run of cables and powerlines. Right now I'm trying to understand the function of the connectivity matrix and the rout planner, but I'm not even able to create one simple route. It always says:
"Warning: Way has NO tag.
> In get_way_tag_key at 20
In extract_connectivity at 53"
and:
"Warning: No route found by the route planner. Try without road directions."

What does it mean exactly and what can I do now?

Thanks a lot!

31 Jul 2012 Catherine Holloway  
06 Jul 2012 Jingjing Wang

One more comments.
For the route planner, it differentiates one-way roads from normal roads only by not making the directed graph symmetric. However, it does not take into account the tag "oneway=yes" which can be extracted from the original osm file. I think maybe using that info. will make more sense.

Thanks,
Jingjing

06 Jul 2012 Jingjing Wang

Hi Loannis,

I'm using your functions to get the connectivity matrix of Shanghai road network. It seems that there are several things to be modified.
1. the tag "highway" may not be always the first tag in each <way> element so in the function 'get_way_tag_key', it should traverse all the tags to see whether there is a "highway" tag.
2. In terms of the connectivity matrix, it seems to me that you are trying to get the directed graph only containing the intersection nodes. If so, 'node1_index' should not be initiated to be the first node but an empty set '[]' since the first node not necessarily belongs to the intersection nodes.

Could you help me check it?

Thanks,
Jingjing

29 May 2012 Mate  
03 May 2012 Ioannis Filippidis

Hi Catherine,

Thank you for providing feedback on these functions. I have released an updated version which fixes this bug and adds more functionality.

Best regards,
Ioannis

17 Apr 2012 Catherine Holloway

Hi Ioannis,

Thanks for taking the time to post this. I am trying to use your functions to plot the area of Genoa, Italy but I am getting the following errors:

??? Cell contents reference from a non-cell array object.

Error in ==> get_way_tag_key at 16
key = tag{1}.Attributes.k;

Error in ==> plot_way>show_ways at 43
[key, val] = get_way_tag_key(way.tag{1,i} );

Error in ==> plot_way at 34
show_ways(ax, bounds, node, way, map_img_filename);

Error in ==> genoa at 34
plot_way(ax, parsed_osm)

Do you have any suggestions?

Thanks,
Catherine

14 Apr 2012 Ioannis Filippidis

continued:

Please consider replacing:

parse_osm>parse_way line 59
tag{1,i} = waytemp.tag;

with:

if isfield(waytemp, 'tag')
tag{1, i} = waytemp.tag;
else
tag{1, i} = [];
end

I am going to post an update, fixing this bug. It would be helpful if you can post the geographical region you exported from OpenStreetmap which caused this issue. (Particularly if you can e-mail me the .osm file).

14 Apr 2012 Ioannis Filippidis

Hi David,

Thanks for noting this behavior.
Please consider replacing:
parse_osm>parse_way, line 59

if isfield(waytemp, 'tag')
tag{1, i} = waytemp.tag;
else
tag{1, i} = [];
end

11 Apr 2012 RED STONE  
27 Mar 2012 David

Hi Ioannis

I like your OpenStreetMap Matlab functions a lot. However, for some osm files I get the following error:

[parsed_osm] = parse_openstreetmap('openstreetmap/map.osm');
??? Reference to non-existent field 'tag'.

Error in ==> parse_osm>parse_way at 59
tag{1,i} = waytemp.tag;

Error in ==> parse_osm at 14
parsed_osm.way = parse_way(osm.way);

Error in ==> parse_openstreetmap at 40
parsed_osm = parse_osm(map_osm.osm);

Do you have an idea how this can be resolved?

Regards,
David

Updates
03 May 2012

Bug fixes associated with some ways having no tags.
Included routing functionality.
Added more plotting functions.
Updated manual.

Contact us