How does matlab construct 3d buildings in siteviewer?
Show older comments
I'm trying to utilize the ray tracing/propagation models in Matlab and would like to be able to make use of the geometries (footprints and heights) of the buildings that are rendered in siteviewer. Right now I'm using an external tool (osmium and pyrosm) to parse the .osm file I provide to the siteviewer 'buildings' parameter to extract this data. As far as I can tell, in the .osm file the only "height" information comes in the form of <height> and <building:levels> tags. The number of <ways> with these tags is not equal to the number of buildings that are generated in the siteviewer window. Is there any way to access the 3d geometries siteviewer creates?
Answers (1)
Eswaramoorthy
on 7 Jun 2023
In MATLAB's Site Viewer, the 3D geometries of buildings are generated based on the data provided in the OpenStreetMap (OSM) file, but the geometries themselves are not directly accessible through the Site Viewer interface. However, you can extract the 3D geometries of buildings using the Mapping Toolbox in MATLAB. Here's a general approach:
1. Import the OSM file: Use the `shaperead` function from the Mapping Toolbox to import the OSM file and convert it into a geographic data structure.
data = shaperead('your_osm_file.osm');
2. Filter buildings: Iterate over the imported data and filter out the buildings based on the available attributes such as `<building>` or `<building:levels>`.
buildings = data(strcmp({data.highway},'building'));
3. Extract building footprints: Extract the 2D footprints of the buildings by accessing the coordinates of the building polygons.
footprints = vertcat(buildings(:).Lat, buildings(:).Lon);
4. Extract building heights: Extract the heights of the buildings from the available attributes such as `<height>` or `<building:levels>`.
heights = [buildings(:).height];
5. Generate 3D geometries: Use the footprints and heights to generate 3D geometries of the buildings using the extrusion operation.
extrudedGeometries = extrude(buildings(:).Lon, buildings(:).Lat, heights);
Now you have access to the 3D geometries of the buildings in MATLAB, which you can further utilize for ray tracing or propagation modeling purposes.
Note that the `extrude` function mentioned above is not a built-in function in MATLAB, but you can implement it using various approaches such as creating a custom function or utilizing existing functions/libraries like the Extrude Polygons from the MATLAB File Exchange.
Keep in mind that the accuracy and availability of the building heights may vary depending on the information provided in the OSM file. It's recommended to inspect and validate the data to ensure its suitability for your specific use case.
Hope this helps!
7 Comments
Mostafa
on 18 Jul 2023
shaperead() doesn't read OSM files.
I get this error (Myfile.osm has an invalid extension. If included must be .shp, .shx, or .dbf).
Brian LaRocca
on 21 Sep 2023
Very cool. I have a similar need, but would like to add 3D structures to the OSM files (like busses and cars). I want to then use raytrace to solve for my edited environment. Is this possible with using the Mapping Toolbox? Thanks, Brian L
Walter Roberson
on 21 Sep 2023
https://www.mathworks.com/matlabcentral/fileexchange/35819-openstreetmap-functions is a contribution to read OSM files; and see also https://www.mathworks.com/matlabcentral/fileexchange/108539-open-street-maps-osm-for-machine-learning
It appears that Mapping Toolbox can read OSM files these days; see readgeotable and https://www.mathworks.com/help/map/read-data-from-openstreetmap-files.html
Walter Roberson
on 21 Sep 2023
I do not believe that the Mapping Toolbox has any raytracing facilities.
Brian LaRocca
on 21 Sep 2023
Hi Walter. I am using the Communications and Antenna Toolboxes. Both of these have a very nice raytrace that handles 10 reflections. That is what I am using. Currently I am using raytrace to examine urban multipath with OSM files that include stationary buildings. I need to add traffic into the OSM models to study that behavior. That is why I want to use MATLAB for perhaps adding 3D vehicle models to the standard OSM. Thanks.
Walter Roberson
on 21 Sep 2023
Sorry, that is a topic I have never worked with.
Jacob Halbrooks
on 13 Oct 2023
This capability is available as of R2023b. In particular, Mapping Toolbox can read OSM files using readgeotable, and you just read in buildings data by specifying the Layer name-value argument as "buildings" or "buildingparts". You can inspect and edit the buildings data, including changing geometries or setting per-building materials. The data can be passed to Site Viewer for 3-D visualization and ray tracing analysis. The material names in the buildings data will be matched to the RF Propagation materials and used in the ray tracing analysis.
A complete example of the workflow is available here:
Categories
Find more on Propagation and Channel Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!