File Exchange

## OpenStreetMap Functions

version 1.4.0.0 (49.8 KB) by Ioannis Filippidis

### Ioannis Filippidis (view profile)

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

Updated 15 Nov 2016

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.

Development and releases on GitHub:
https://github.com/johnyf/openstreetmap

PDF documentation, bundled dependencies, and an example file `map.osm` can be found in the releases page on GitHub:

https://github.com/johnyf/openstreetmap/releases

The example file `map.osm` can be used with `usage_example.m`.

### Cite As

Ioannis Filippidis (2020). OpenStreetMap Functions (https://www.github.com/johnyf/openstreetmap), GitHub. Retrieved .

Ebrahim Atya

### Ebrahim Atya (view profile)

Great work.
I wonder if I can get the longitude and latitude as an output when I click on the map?

james flynn

### james flynn (view profile)

Hi there,

First of all, this is a fantastic package which has saved me a lot of time, so thank you!
I was hoping someone would be able to help me with my issue... I need to extract or generate a matrix that contains the coordinates of approximately every 10m across the whole road network, including long straight roads. Is this possible? At the moment I can only retrieve the nodes at intersections and bends in roads which leaves large gaps on the network without coordinate data.

Jay

max max

TG

### TG (view profile)

Hello,
I saw that in your function the distance between nodes is always taken as 1. However this leads to weird shortest routes as nodes are skipped. Is there a way in which the distance between the nodes can be calculated, and can be implemented in the function?

Tim

Philipp Fuchs

Jessica Dilks

### Jessica Dilks (view profile)

Hello,
I am creating an optimal route for a project, and I want to import an entire country (or up to 3 if possible) in to MATLAB. I have the entire countries data as osm.pbf file (https://wiki.openstreetmap.org/wiki/PBF_Format#File_format) from this website: https://download.geofabrik.de/europe.html. Is it possible to use this package with these files? I have used this for much smaller areas (a section of London), and that took a while so even if I could get the .osm.pbf to work, would the area just be too large for it to work?
Thanks,
Jess

Suzanne Crumeyrolle

### Suzanne Crumeyrolle (view profile)

Hi there,
I have pollution data that I want to plot on a map. I used plot google map but the API forced me to move to another solution. So I downloaded 4 light OSM files for the city and the surroundings I'm interested in. These files are still pretty large but that is not the issue here. For each pollution sensor, I'd like to plot a map but I don't need to plot the entire osm file (WAY TOO LONG) just part of it. I'm not sure if I can do that. Could anyone help me ?
Thanks

Suzanne

Miao Dong

### Miao Dong (view profile)

The download package does not include the function "xml2struct". Therefore, it cannot be directly run in Matlab. This is why the Lukas Bergs encounters the error as described below. Users should download the function "xml2struct" from website http://www.mathworks.com/matlabcentral/fileexchange/28518-xml2struct and rename the function as "xml2struct_fex28518".

Lukas Bergs

### Lukas Bergs (view profile)

Hello,
i've got a problem running the usage example and hope someone can help me fix it.
I downloaded the requestet functions (xml2struct, gaimc: graph algorithms, Lat/Lon aspect ratio, plot 2/3d point(s)) and a map from OSM and saved it under the name map.osm. Then I added everything to my Matlab folder.

When I run the example file I get this Error message:

Undefined function or variable 'xml2struct_fex28518'.

Error in parse_openstreetmap (line 36)

Error in usage_example (line 28)
[parsed_osm, osm_xml] = parse_openstreetmap(openstreetmap_filename);

It would be great if someone could help me make the code run.
P.S.: I am new to Matlab so please explain it in a way a neewbie can understand it :)

Thanks,
Lukas

Jan GimpelHenning

### Jan GimpelHenning (view profile)

I Babatunde, I didn't get a full answer, but you get the heights only if there are saved for certain buildings. So it's not fully useful to work with OSM for this. In Google Earth Pro you can estimate the building heights quiet easy but manually building by building, don't know if this helps you.

Babatunde Atolagbe

### Babatunde Atolagbe (view profile)

Hi Jan, did you get an answer to your question? I have a similar issue.

"Hi, thank you a lot for this useful application! I was wondering if it's possible to extract the building heights in Matlab from Openstreetmap? Is that possible?"

Jan Gimpel-Henning

### Jan Gimpel-Henning (view profile)

Hi, thank you a lot for this useful application! I was wondering if it's possible to extract the building heights in Matlab from Openstreetmap? Is that possible?

Carlos Campo

### Carlos Campo (view profile)

Hi Loannis, I've been looking the structure and I'm wondering if any of the information contained in it has data related to the neighbourhood of each of the nodes.

Thank you very much.

Carlos Campo

### Carlos Campo (view profile)

sepehr ghasemi dehkordi

Kais Suleiman

### Kais Suleiman (view profile)

Ioannis Filippidis

### Ioannis Filippidis (view profile)

With the functions currently available in the package, no. But it shouldn't be difficult to find this information (if present) in the data structure loaded from the openstreetmap file.

Thomas Reindl

### Thomas Reindl (view profile)

Is it possible to get the speed limits for the single sections of the route with any funktion?

Ioannis Filippidis

### Ioannis Filippidis (view profile)

@Franco Matzkin: It's been a long time since I've used this package, but I would expect that looking at the nodes in a route, and ways that contain consecutive nodes, you can probably then get the road names from the loaded xml data, using the node or way IDs as references.

Looking inside an OSM file should help with this, for example:

<way id="23162662" user="sbiribizio" uid="354284" visible="true" version="3" changeset="10838386" timestamp="2012-03-01T14:27:28Z">
<nd ref="250342877"/>
<nd ref="1654391914"/>
<nd ref="242684859"/>
<tag k="highway" v="pedestrian"/>
<tag k="name" v="Via delle Grazie"/>

<node id="904353816" lat="44.4156033" lon="8.9460944" user="Ale_Zena_IT" uid="22290" visible="true" version="3" changeset="10051908" timestamp="2011-12-06T17:57:25Z">
<tag k="highway" v="bus_stop"/>
<tag k="name" v="Cabella 2 / Contardo"/>
<tag k="operator" v="AMT"/>
<tag k="route_ref" v="64; 64/; F2/"/>
<tag k="stop_number" v="1121"/>
<tag k="url" v="http://www.amt.genova.it/orari/orari_urbana.asp"/>

Shi Su

Franco Matzkin

### Franco Matzkin (view profile)

Thanks a lot! I have another question. How do you get to the street names from the route? It's that possible? Thanks again

Ioannis Filippidis

### Ioannis Filippidis (view profile)

@Franco Matzkin: Thanks a lot for noting this, it appears that Mathworks has changed the File Exchange website so that it bundles the current contents of the GitHub repository, instead of the archive file that I had uploaded. The PDF file can be found at the releases page on GitHub: https://github.com/johnyf/openstreetmap/releases

I will update the description of the package here to reflect this situation.

Franco Matzkin

### Franco Matzkin (view profile)

I can't find the reference manual or documentation. I've download the zip file but it isn't there.

Ioannis Filippidis

### Ioannis Filippidis (view profile)

@Brandon: I do not know what that message means, other than that the way is lacking annotation [1].

Ioannis Filippidis

### Ioannis Filippidis (view profile)

Ioannis Filippidis

### Ioannis Filippidis (view profile)

@Seb Biass: I knew only the basics of the XML format used by the OpenStreetmap project. Also, I am not aware of any precise definition anywhere for this format (for example, a formal specification using mathematics).

I do not make general assumptions about keys of openstreetmap. This package was an effort to get basic maps loaded, but may not address corner cases.

I do not know whether there is any notion of "main feature type" is OSM. Also, keys are not ordered, e.g., in the XML at [1], so the order that appears in Matlab is likely an artifact of the shortcomings of Matlab's data model, as opposed to dictionaries in Python.

"highway" [2] and "bridge" [3] keys appear to possibly be coexistent.

The information at [4] may be useful as a starting point for a more detailed examination.

Remark: Please consider including the commit hash in references to code.

Seb Biass

### Seb Biass (view profile)

Hey Ioannis,
Such a cool effort! Got a question for you. L48 of extract_connectivity.m, do you always assume that the first key should be the main feature type? Is that something that can be assumed of OSM? For instance, some road segments have the first key=bridge, does that mean that it is a duplicate of the highway key?

Thanks a lot!

S

Brandon

### Brandon (view profile)

When I run the usage_example file, I get a bunch of warnings: "Way has NO tag." Any help would be appreciated!

Ioannis Filippidis

### Ioannis Filippidis (view profile)

Hi Darko,

Thank you for the feedback. Good catch. Currently, I do not recall the XML structure (which may also have evolved in the ensuing years), but the correction sounds reasonable. A pull request on github would be welcome (the change is 2 characters, but in case you would like to provide the commit). If a minimal test or link to documentation is available, please consider including or mentioning it.

Best,
ioannis

Darko Maksimov

### Darko Maksimov (view profile)

Dear Mr Ioannis Filippidis

First i would like to thank you for this files and the great work. I am currently doing my master thesis related with map routing.

While using your functions i noticed a small mistake. In the function "get_unique_node_xy" there is twise the same line:

ids = parsed_osm.node.xy(:,intersection_node_indices);
xys = parsed_osm.node.xy(:,intersection_node_indices);

to get the indices the first line should be changed in to:
ids = parsed_osm.node.id(:,intersection_node_indices);

Kind regards

Ioannis Filippidis

### Ioannis Filippidis (view profile)

@Martin: the axes are scaled to the desired latitude and longitude intervals by calling [1]. The call is at [2], and the bounds originate from [3]. You may want to start by looking at how bounds are obtained, by first looking at [3]. Also, you will need to pass the axes handle (`ax` in [5]) in your calls to plotting functions.

Martin Chudomel

### Martin Chudomel (view profile)

thak you loannis. you are a master.
A have another problem. I need to draw into this map. something likes lines and circle, because a use this script for directing finding and triangulation method. But i do not know how. :( there is nothing like matrix with lat x lon parametres.

THANK YOU

Ioannis Filippidis

### Ioannis Filippidis (view profile)

@Martin: Did you install the dependencies from here: https://github.com/johnyf/openstreetmap/releases ?
The function you are missing is this: https://github.com/johnyf/plot_utils/blob/bd304279ee0e000f72fc936e0ef9f3a690d4e654/hold/takehold.m and should be included in the dependencies. Also, remember to update your matlab path.

Martin Chudomel

### Martin Chudomel (view profile)

Undefined function 'takehold' for input arguments of type 'double'.

Error in plot_nodes (line 37)
held = takehold(ax);

Error in usage_example (line 61)
plot_nodes(ax, parsed_osm, only_nodes)

HSU LITA

### HSU LITA (view profile)

Mahmoud Hassan Eldally

### Mahmoud Hassan Eldally (view profile)

Mahmoud Hassan Eldally

### Mahmoud Hassan Eldally (view profile)

why some of the turn restrictions don't show as a point with index in the final plot and in the connectivity matrix

i added some pedestrian paths and also all the turn restrictions at this paths don't show in the final figure

Hello,
I start using the User Mabual "openstreetmap fuctions for matlab v.0.2". I did the first step which is to download the three dependencies,xml2struct_fex28518,lat_lon_proportions and dijkstra) and i added these files to a path in matlab. When i go to the second step which is parse the openstreetmap file i am writing the code:
1 function parsed_osm = parse_openstreetmap('aarhus_denmark.osm')
2 end
aarhus_denmark.osm is a XML file and it is in the same path whith the above files.
Anyway, when i run the above code it appears an error whith the message:
Error: File: parse_openstreetmap.m Line: 1 Column: 43
Unexpected MATLAB expression.
I also run the codes of mister Filippidis which are online and they also don't work.
Any help?

Arslan Shahid

### Arslan Shahid (view profile)

Hi
I have downloaded .osm files using osm plugin/ XAPI in Arc GIS 10.3. Files are downloaded successfully and i have also opened it in JOSM, BUT i cant able to parse the data in Matlab. Getting error
Reference to non-existent field 'bounds'.

Error in parse_osm (line 35)
parsed_osm.bounds = parse_bounds(osm_xml.bounds);

Error in parse_openstreetmap (line 43)
parsed_osm = parse_osm(osm_xml);

Error in dataBase_preparation (line 17)
[parsed_map, map_xml] = parse_openstreetmap('TUM_arc_test.osm');

Looking for solutions/ suggestions

Gourish

Hong Khai

### Hong Khai (view profile)

Hi,

I downloaded all the dependencies and also the map.osm file from github, and I tried running the usage_example.m
I got an error:
Error using bioinfoprivate.opttf
which is an error with the Bioinformatics_Toolbox

Hence, I commented out line 38,39,40,41 and 55 in the route_planner.m file, to make sure that it only runs the part not for Bioinformatics_Toolbox.

However, when I run the example again, it shows:
Parsed OpenStreetMap given.
Found 370 common nodes.
Connectivity matrix contains 1350 nonzero elements.
Although the unique ones were 226.
Warning: No route found by the route planner. Try without road directions.
> In route_planner at 59
In usage_example at 47
Parsed OpenStreetMap given.
Bounds: xmin = -73.8573, xmax = -73.8337, ymin = 40.7788, ymax = 40.7974
Number of nodes: 2098
Number of ways: 95
way without tag.
way without tag.
way without tag.
way without tag.
way without tag.
way without tag.
way without tag.

and also 2 windows like this:
http://i57.tinypic.com/f4iqlt.png

What did I do wrong? I am supposed to get something like this: http://www.mathworks.com/matlabcentral/fileexchange/screenshots/9670/original.jpg

right?

Matthew

### Matthew (view profile)

Ioannis Filippidis

### Ioannis Filippidis (view profile)

In there you will find the renamed xml2struct_fex28518 function. The rename is to avoid name conflicts with the bioinformatics toolbox (removing that from your installation is not recommended).

The original error that you see did not relate to the bioinformatics toolbox, since it couldn't find xml2struct_fex28518, not xml2struct.

The persistency of xml2struct in matlab's path may be due to caching (e.g., compare `which` with `hash` in a bash shell). Perhaps after restarting matlab it won't find xml2struct any more. In any case, it is not the cause for the error.

kavita

### kavita (view profile)

dear all

i started with usage_example but the follwoing error comes

>> usage_example
Undefined function 'xml2struct_fex28518' for input arguments
of type 'char'.

file

Error in parse_openstreetmap (line 36)

Error in usage_example (line 28)
[parsed_osm, osm_xml] =
parse_openstreetmap(openstreetmap_filename);

1)i extracted the smaller map file from www.openstreetmap.org , even the error is same.

2) the i typed the command
>> which xml2struct
C:\Program Files\MATLAB\R2013a\toolbox\bioinfo\biodemos\xml2struct.m

as a solution i removed the bioinfo folder from the follwing path
C:\Program Files\MATLAB\R2013a\toolbox\

even then the same error appears and when i am typing the command ">> which xml2struct
" again it shows the same result. how to resolve this error.kindly suggest and help me plz.

Gummi

### Gummi (view profile)

@shiva I had the same problem, I fixed it with a quick check in the for-loop in parse-osm.m :
for j=1:Nnd
if Nnd == 1
ndtemp(1,j) = str2double(waytemp.nd.Attributes.ref);
else
ndtemp(1, j) = str2double(waytemp.nd{j}.Attributes.ref);
end
end

As you see, the else part is what your line 78 looks like.

shiva

### shiva (view profile)

first of all i have to thank you for your great package.
can you help me about why i get this error:
??? Cell contents reference from a non-cell array object.

Error in ==> parse_osm>parse_way at 78
ndtemp(1, j) = str2double(waytemp.nd{j}.Attributes.ref);

Error in ==> parse_osm at 37
parsed_osm.way = parse_way(osm_xml.way);

Error in ==> parse_openstreetmap at 43
parsed_osm = parse_osm(osm_xml);

Error in ==> usage_example at 29
[parsed_osm, osm_xml] = parse_openstreetmap(openstreetmap_filename);

pietro

### pietro (view profile)

so I need to zoom in the area and then I can analyze it through matlab, right? I have a huge gpx file and I need to create several papermaps. Can I do it with your functionset?

thanks

Ioannis Filippidis

### Ioannis Filippidis (view profile)

Just select "Export" at the top left and zoom in enough so that it won't complain on the export pane (opens on the left after you click "Export") that the area is too large to be exported. Then hit the blue "Export" button on the left pane, and that will download the ".osm" file that contains the XML data you need.

pietro

### pietro (view profile)

Hi I can't find the OpenStreetMap XML Data file in the openstreet map website. Where can I find it?

thanks

Ioannis Filippidis

### Ioannis Filippidis (view profile)

gist for importing osm graphs as networkx graphs in python:
https://gist.github.com/aflaxman/287370/

Ioannis Filippidis

### Ioannis Filippidis (view profile)

Hi wes, thanks you for the review. If I recollect correctly, the ids should refer to the OSM database, so be global ids over the whole world, rather than indices in the connectivity matrix (which is a sample of the OSM database).

wes

### wes (view profile)

Hi Ioannis,

Great package you have here, working perfectly for what i need! thank you for taking the time to upload.

I am having a few problems with the route planner though. when i take the node id out of the parsed osm file i get a big number such as 1151088456 but i get an eorror message saying source node index invalid. if i randomly pick one of the small numbers out of the connectivity matrix i can get it working but i have no idea how to relate to these locations to there real world position untill i run it and see where they appear.

any advice on where i'm going wrong?

ghufran

### ghufran (view profile)

Ioannis Filippidis

### Ioannis Filippidis (view profile)

Ioannis Filippidis

### Ioannis Filippidis (view profile)

Please consider switching to Python. There are numerous OpenStreetMap facilities there and excellent visualization capabilities:

https://pypi.python.org/pypi?%3Aaction=search&term=openstreetmap&submit=search

Ioannis Filippidis

### Ioannis Filippidis (view profile)

Hi Gaurav,

I've updated the submission on github (and here, waits review) to fix the name shadowing conflict that presumably causes the "no osm field" error.

@Matthew:
the restorehold function is now included (rename was needed) and an example map.osm as well.

What was your reason for commenting that the "chosen XML parser is not appropriate for anything but the extremely simple example." ?

gaurav

### gaurav (view profile)

hey,
I have been trying to use this distribution to convert the region Dharavi,Mumbai, India to data set. However, I am not able to understand how to use the package and which is the main file which would call the matlab files given.
Also, I tried using the usage_example.m, however it shows error :
"Reference to non-existent field 'osm'.

Error in parse_openstreetmap (line 42)
osm_xml = map_osm.osm;

Error in usage_example (line 29)
[parsed_osm, osm_xml] = parse_openstreetmap(openstreetmap_filename);"

my input file was with name same as in example - map.osm and saved in the same directory as all other files in the distribution.
Your help would be highly valued as I am in urgent need for this thing to work

Reham

### Reham (view profile)

Ioannis Filippidis

### Ioannis Filippidis (view profile)

The osm is loaded in MATLAB as a directed graph represented by an adjacency matrix. Assuming constant speed, travel time is proportional to distance. So for them to be different, different speeds need to be assumed for different types of roads. I would suggest assigning weights to roads (edges) depending on their size by storing the weights in the adjacency matrix. Then you can run Dijkstra's shortest path algorithm on the weighted graph.

Recommended reading the wikipedia article on Dijkstra's algorithm, which you can find implemented e.g. in http://www.mathworks.com/matlabcentral/fileexchange/10922-matlabbgl, as a starting point to learn more about the connectivity matrix you can look at the help text of extract_connectivity.m .

Reham

### Reham (view profile)

Okay, Problem resolved. I could change the start and target nodes based in the (index) values generated from my map and it worked!

Now I need your suggestions if I want to get the fastest route (based on travel time not distance). What should I do? should I add these data into the map osm file? so I have to search for such info/tags. or should this be modified into the algorithms weights? I see it's mainly based on the distance. I'm really confused what to do next!

Reham

### Reham (view profile)

Hello Ioannis,

I'm sorry for my previous comment, I wasn't setting the path correctly inside Matlab. Now the file runs but I have this:
Warning: path is empty. This means that the planner found no path.
> In plot_route at 24
In my_example at 37

the ways are plotted but the shortest route is not! Should I change the start and target nodes values?

and based on what? should I copy/paste nodes IDs from the XML file? knowing that I've already tried this but I get an error that the node ID is invalid.

Please I need your help since I have to modify all of the code to work on fastest route instead of the shortest as a part of my thesis, and I need to resolve all these errors and warnings first and start thinking on modifying the algorithm and add traffic or travel time info and start working on the map and algorithm to produce the fastest route. I still have no clue how to implement this, since I'm totally new to Matlab. But if you could at least help with the file you provided I'd be grateful.

Thanks,

Best,

Reham

### Reham (view profile)

Hello,
I'd like to thank you for this submission, it's really helpful in my masters thesis, but I really need your help in this error I get when I run the usage_example:

Reference to non-existent field 'osm'.

Error in parse_openstreetmap (line 42)
osm_xml = map_osm.osm;

Error in usage_example (line 29)
[parsed_osm, osm_xml] = parse_openstreetmap(openstreetmap_filename);

knowing that I copied the map.osm file in the home directory of openstreetmap and I've traced the code line by line and referred to each function to see how it works and try to solve the problem but nothing, and found no similar errors in the comments below. I can't even see the output of your code in the end. So could you please help?

Matthew

### Matthew (view profile)

I wanted to give this 5 stars. May I suggest the following issues are addressed:
1. The usage_example throws an error: there is no restorehold() function within the distribution.
2. The chosen XML parser is not appropriate for anything but the extremely simple example.
3. The example does not work out of the box. Why not included a example map.osm file?

Ioannis Filippidis

### Ioannis Filippidis (view profile)

Hi Nermeen,

Thank you, I would suggest against parsing 30GB files in any context, MATLAB certainly cannot handle that, but neither does any other tool. The issue is that your RAM and virtual memory won't support this, unless you have a very unusual hardware or software setup.

So what I would suggest is file-based operations, where you gradually process your input, while at the same time dumping the results into a (possibly big) output file. Then you can access them from that file.

You may also consider if your task really requires brute-force parsing of whole countries, vs somehow pre-filtering the information at the source from where you get it (I don't know if that's possible in this case, but it's an option worth considering, if you don't need all that data).

The PBF format is currently not supported by this toolbox. There is already a Python solution here:
http://blog.lifeeth.in/2011/02/extract-pois-from-osm-pbf.html
(pointed to by this: http://wiki.openstreetmap.org/wiki/PBF_Format)
and I'm suggesting switching to Python anyway (see below).

Please feel free to contribute towards that, btw motivated by people's interest, it will probably migrate to github not far in the future.

Finally I would advise switching to Python for heavy GIS tasks as the one you describe, as it is more suited for system-oriented operations and you will find a much wider set of tools already available, though it takes more searching. Starting points (though haven't tried them):
http://wiki.openstreetmap.org/wiki/PythonOsmApi
http://stackoverflow.com/questions/11321718/how-can-i-display-osm-tiles-using-python/11325174#11325174
https://ep2013.europython.eu/media/conference/slides/making-use-of-openstreetmap-data-with-python.pdf
http://nzjrs.github.io/osm-gps-map/

Nermeen Ahmed

### Nermeen Ahmed (view profile)

Hi,

The tool has been magically helpful in my environment classification project. I was just wondering about the osm file size limitation that can be parsed. As i need to parse files of complete countries; osm files that can reach up to 30 GB. Also is there a way to parse PBF files instead of XML using this tool? Thanks in advance

Ioannis Filippidis

### Ioannis Filippidis (view profile)

Happy that it proves useful. No, I haven't considered processing administrative boundaries. If you write some enhancement, please consider sending it in.

Also, when I find some time this project will probably appear in github for people to contribute.

Seb Biass

### Seb Biass (view profile)

Hi there,

This toolbox is brilliant. I was wondering if you saw a way to extract and perform connectivity analysis on a road network that is within an administrative boundary of a given level. I am looking at the API, but fairly new, so still struggling...
Please do let me know if you do, and again, a bunch of thanks!

Preeti Goel

### Preeti Goel (view profile)

I get an error when I try to load and parse an osm file, I have tried with different file sizes:

Cell contents reference from a non-cell array object.

Error in parse_osm>parse_way (line 61)
ndtemp(1, j) = str2double(waytemp.nd{j}.Attributes.ref);

Error in parse_osm (line 20)
parsed_osm.way = parse_way(osm_xml.way);

Error in parse_openstreetmap (line 43)
parsed_osm = parse_osm(osm_xml);

Error in OSMExample (line 29)
[parsed_osm, osm_xml] = parse_openstreetmap(openstreetmap_filename);

Any suggestions?

Rinat

### Rinat (view profile)

I have error ??? Reference to non-existent field 'osm'. osm_xml = map_osm.osm;?

matlab file xml2struct.m
tree =
[#document: null]
theStruct =
Name: 'osm'
Attributes: [1x5 struct]
Data: ''
Children: [1x439 struct]

parse_openstreetmap.m
map_osm =
Name: 'osm'
Attributes: [1x5 struct]
Data: ''
Children: [1x439 struct]

name file
openstreetmap_filename = 'map.osm';

I do not understand where the error, using Matlab 2013a and 2009a?

Ioannis Filippidis

### Ioannis Filippidis (view profile)

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).

Richard

### Richard (view profile)

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

Error in ==> load_osm_xml at 26

Error in ==> parse_openstreetmap at 41

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

Beijing.osm is 75.35 MB

Any suggestions?

Ioannis Filippidis

### Ioannis Filippidis (view profile)

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.

Ioannis Filippidis

### Ioannis Filippidis (view profile)

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

Fabio Lopez

### Fabio Lopez (view profile)

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?

Paula

### Paula (view profile)

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

Ioannis Filippidis

### Ioannis Filippidis (view profile)

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

Paula

### Paula (view profile)

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!

Catherine Holloway

Jingjing Wang

### Jingjing Wang (view profile)

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

Jingjing Wang

### Jingjing Wang (view profile)

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

Mate

### Mate (view profile)

Ioannis Filippidis

### Ioannis Filippidis (view profile)

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

Catherine Holloway

### Catherine Holloway (view profile)

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

Ioannis Filippidis

### Ioannis Filippidis (view profile)

continued:

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).

Ioannis Filippidis

### Ioannis Filippidis (view profile)

Hi David,

Thanks for noting this behavior.
parse_osm>parse_way, line 59

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

RED STONE

David

### David (view profile)

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