OpenStreetMap buildings: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
mNo edit summary
 
(29 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{WIP}}
{{OSM Navigation}}


[[File:Gatewing X100 TU Delft 2.png|thumb|270px|OSM generated buildings and roads.]]
[[File:Gatewing X100 TU Delft 2.png|thumb|270px|OSM generated buildings and roads.]]
[[File:Delft OpenStreetMap buildings with roof textures.png|thumb|270px|Houses with gable roofs.]]
Buildings can be mapped in [[OpenStreetMap]]. Their shapes can be turned into 3D models for use in [[FlightGear]] scenery.
Buildings can be mapped in [[OpenStreetMap]]. Their shapes can be turned into 3D models for use in [[FlightGear]] scenery.


== Note for Windows ==
== Challenges ==
Windows does not contain perl by default. You're advised to install [http://strawberryperl.com/ Strawberry Perl for Windows]. It is a simple installer; no need to dig into your system.
* There are "just" 64 million buildings in OSM<ref>{{cite web |url=http://wiki.openstreetmap.org/wiki/Key:building |title=Key:building |work=OpenStreetMap Wiki |accessdate=15 September 2012 }}</ref>, most cities in the world have no buildings at all or just a few.
* Only 1.04% of the buildings in OSM have a height specified. Ca. 1.4% has a known number of floors (levels).<ref>{{cite web |url=http://taginfo.openstreetmap.org/keys/?key=building#combinations |title=<nowiki>building | Keys | OpenStreetMap Taginfo</nowiki> |accessdate=15 September 2012 }}</ref>
* FlightGear cannot handle thousands of models in a view. Grouping models into bigger files improves performance to a very usable level, but is less practical unless automated.


== A single building ==
== Tools ==
A perl script (bob.pl) is being written to turn the OSM data into 3D models. It is available at {{gitorious url|fgscenery|tools}}.
 
[[osm2city.py]] is another project, under active development as of 06/2014.
 
=== Note for Windows ===
* Windows does not contain perl by default. You're advised to install [http://strawberryperl.com/ Strawberry Perl for Windows]. It is a simple installer; no need to dig into your system.
* [http://www.cygwin.com/ Cygwin] is also advised, so "grep" can be used to get a list of building ids easily.
* When working with shapefiles not coming from OSM you will need ogr2ogr, which is included in [http://fwtools.maptools.org/ FWTools].
 
== From OpenStreetMap ==
=== A single building ===
# Find the building in OpenStreetMap.
# Find the building in OpenStreetMap.
# Enable the "Data" overlay.
# Enable the "Data" overlay.
# Choose a manual area and drag a box around your building.
# Choose a manual area and drag a box around your building.
# Click your building, the way id will be shown. Copy this id.
# Click your building, the way id will be shown. Copy this id.
# Run the following code, replacing 44338398 with your building's id:
# Run the following code, replacing <tt>44338398</tt> with your building's id:
:: <code>perl bob.pl -w 44338398</code>
:: <code>perl bob.pl -w 44338398</code>


Line 19: Line 33:
:::: <code>-lat 52.00141 -lon 4.36966</code>
:::: <code>-lat 52.00141 -lon 4.36966</code>
::* '''Object name''' (not the .ac name!):
::* '''Object name''' (not the .ac name!):
:::: <code>-n "Empite State Building"</code>
:::: <code>-n "Empire State Building"</code>
::* '''Building height''' (in meters):
::* '''Building height''' (in meters):
:::: <code>-h 15</code>
:::: <code>-h 15</code>
:::: '''Note:''' buildings are always sunk 5 m into the ground, in order to account for non-flat terrain.
:::: '''Note:''' buildings are always sunk 5 m into the ground, in order to account for non-flat terrain. These 5 meters are added on top of (or below, if you like) the building height.
::* '''Create a xml file''' with a standard range animation:
:::: <code>-x</code>
::* '''Clean the shape''' by removing nodes that lie within a certain distance from the line that connects its two adjacent nodes. This results in much smaller files and allows more buildings to have a gable roof:
:::: <code>-clean</code>
 
=== All buildings in an area ===
[[File:New York with OSM buildings dawn.png|thumb|270px|Lower Manhattan at dawn.]]
# Download a file with all data from the area, by visiting the following link and save it somewhere on your computer. This will only include buildings (building=yes) within the specified bounding box.
#: <code><nowiki>http://overpass-api.de/api/xapi?way[bbox=left,bottom,right,top][building=*][@meta]</nowiki></code>
#: For example:
#: <code><nowiki>http://overpass-api.de/api/xapi?way[bbox=-74.02037,40.69704,-73.96922,40.73971][building=*][@meta]</nowiki></code>
# Get a list of wayids via <code>grep "<way" map.osm|cut -f2 -d\">wayids.txt</code> change the number after f where appropriate<br />or <code>sed -n 's|<way.*id="\(.*\)" .*>|\1|p' "map.osm" > wayids.txt</code>
# For Windows users: Run <code>for /f %a in (wayids.txt) do perl bob.pl -w %a -f map.osm</code><br />For others: Iterate through wayids.txt and assign each way id to $object and run <code>perl bob.pl -w $object -f map.osm</code> on all the ids.
 
<syntaxhighlight lang="perl">
#!/usr/bin/perl
 
while ($wayid =<STDIN>) {
    system("./bob.pl -v -w $wayid ");
}
</syntaxhighlight>
 
== From another source ==
# Run ogr2ogr with:
#: <code><nowiki>ogr2ogr -t_srs WGS84 -s_srs "ESRI::in_shp.prj" "out_shp.shp" "in_shp.shp"</nowiki></code>
# Run [http://wiki.openstreetmap.org/wiki/Shp2osm shp2osm] with:
#: <code><nowiki>perl shp2osm.pl "out_shp.shp" > "map.osm"</nowiki></code>
# Get a list of wayids via <code>grep "<way" map.osm|cut -f2 -d\">file.txt</code>
# Run <code>perl bob.pl -w $object -f map.osm</code> on all the ids.
 
== Related content ==
* [[Osm2city.py]]
 
== External links ==
* [http://wiki.openstreetmap.org/wiki/Proposed_features/Building_attributes Building attributes] (OSM wiki)
* [http://wiki.openstreetmap.org/wiki/Roof_type_Library Roof type Library] (OSM wiki)


== All buildings in an area ==
{{Appendix}}
# Download a file with all data from the area, by visiting the following link:
#: <code><nowiki>http://api.openstreetmap.org/api/0.6/map?bbox=left,bottom,right,top</nowiki></code>
#: <code><nowiki>http://api.openstreetmap.org/api/0.6/map?bbox=-74.02037,40.69704,-73.96922,40.73971</nowiki></code>
# Filter out the buildings, by filtering for <code><tag k="building" v="yes"/></code>.


[[Category:Scenery enhancement]]
[[Category:Scenery enhancement]]

Latest revision as of 20:21, 13 November 2016

Autogen Scenery
Started in 11/2013
Description Improved autogen support for FlightGear using OSM data
Contributor(s) radi, vanosten, Soitanen, portreekid
Status Under active development as of 02/2016
Topic branches:
$FG_SRC https://gitlab.com/osm2city/osm2city/
fgdata https://gitlab.com/osm2city/osm2city-data/


OSM generated buildings and roads.
Houses with gable roofs.

Buildings can be mapped in OpenStreetMap. Their shapes can be turned into 3D models for use in FlightGear scenery.

Challenges

  • There are "just" 64 million buildings in OSM[1], most cities in the world have no buildings at all or just a few.
  • Only 1.04% of the buildings in OSM have a height specified. Ca. 1.4% has a known number of floors (levels).[2]
  • FlightGear cannot handle thousands of models in a view. Grouping models into bigger files improves performance to a very usable level, but is less practical unless automated.

Tools

A perl script (bob.pl) is being written to turn the OSM data into 3D models. It is available at https://gitorious.org/fgscenery/tools?p=fgscenery:tools.git;a=summary.

osm2city.py is another project, under active development as of 06/2014.

Note for Windows

  • Windows does not contain perl by default. You're advised to install Strawberry Perl for Windows. It is a simple installer; no need to dig into your system.
  • Cygwin is also advised, so "grep" can be used to get a list of building ids easily.
  • When working with shapefiles not coming from OSM you will need ogr2ogr, which is included in FWTools.

From OpenStreetMap

A single building

  1. Find the building in OpenStreetMap.
  2. Enable the "Data" overlay.
  3. Choose a manual area and drag a box around your building.
  4. Click your building, the way id will be shown. Copy this id.
  5. Run the following code, replacing 44338398 with your building's id:
perl bob.pl -w 44338398
Next to this basic code, there are several options, to be added behind the basic code.
  • Lat/lon location of the model's origin:
-lat 52.00141 -lon 4.36966
  • Object name (not the .ac name!):
-n "Empire State Building"
  • Building height (in meters):
-h 15
Note: buildings are always sunk 5 m into the ground, in order to account for non-flat terrain. These 5 meters are added on top of (or below, if you like) the building height.
  • Create a xml file with a standard range animation:
-x
  • Clean the shape by removing nodes that lie within a certain distance from the line that connects its two adjacent nodes. This results in much smaller files and allows more buildings to have a gable roof:
-clean

All buildings in an area

Lower Manhattan at dawn.
  1. Download a file with all data from the area, by visiting the following link and save it somewhere on your computer. This will only include buildings (building=yes) within the specified bounding box.
    http://overpass-api.de/api/xapi?way[bbox=left,bottom,right,top][building=*][@meta]
    For example:
    http://overpass-api.de/api/xapi?way[bbox=-74.02037,40.69704,-73.96922,40.73971][building=*][@meta]
  2. Get a list of wayids via grep "<way" map.osm|cut -f2 -d\">wayids.txt change the number after f where appropriate
    or sed -n 's|<way.*id="\(.*\)" .*>|\1|p' "map.osm" > wayids.txt
  3. For Windows users: Run for /f %a in (wayids.txt) do perl bob.pl -w %a -f map.osm
    For others: Iterate through wayids.txt and assign each way id to $object and run perl bob.pl -w $object -f map.osm on all the ids.
#!/usr/bin/perl

while ($wayid =<STDIN>) {
    system("./bob.pl -v -w $wayid ");
}

From another source

  1. Run ogr2ogr with:
    ogr2ogr -t_srs WGS84 -s_srs "ESRI::in_shp.prj" "out_shp.shp" "in_shp.shp"
  2. Run shp2osm with:
    perl shp2osm.pl "out_shp.shp" > "map.osm"
  3. Get a list of wayids via grep "<way" map.osm|cut -f2 -d\">file.txt
  4. Run perl bob.pl -w $object -f map.osm on all the ids.

Related content

External links

References
  1. "OpenStreetMap Wiki". Retrieved 15 September 2012.
  2. building | Keys | OpenStreetMap Taginfo. Retrieved 15 September 2012.