Osm2city.py: Difference between revisions

Jump to navigation Jump to search
7,887 bytes removed ,  11 September 2016
no edit summary
No edit summary
No edit summary
Line 116: Line 116:
~40MB for the 25x25km LOWI area.
~40MB for the 25x25km LOWI area.


== Install ==
== Installation and Workflow ==
1. dependencies: Install the following packages (names from Debian packages):
Comprehensive documentation can be found on [http://osm2city.readthedocs.io/en/latest/index.html osm2citiy's Read The Docs site].
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx curl
2. get [https://gitlab.com/fg-radi/osm2city osm2city] and [https://gitlab.com/fg-radi/osm2city-data osm2city-data] from gitlab.
 
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH]
You can add
<syntaxhighlight lang="bash">
PYTHONPATH=$PYTHONPATH:/path/of/osm2city
</syntaxhighlight>
or
<syntaxhighlight lang="bash">
PYTHONPATH=$PYTHONPATH:.
</syntaxhighlight>
into your hidden configuration file <b>.bashrc</b> located in your home directory.
 
4. soft link osm2city-data/tex and osm2city-data/tex.src into osm2city/. Typically you will have to "adapt" and execute these commands.
<syntaxhighlight lang="bash">
  cd osm2city
  ln -sf ../osm2city-data/tex.src
  ln -sf ../osm2city-data/tex
</syntaxhighlight>
Then the sub-directory of osm2city will appears like that
<syntaxhighlight lang="bash">
osm2city/
  tex.src/
  tex/
  osm2city.py
  textures.py
  ...
</syntaxhighlight>
 
If you're running FG >= 3.3, or git newer than 10 Oct 2014, and have more than 4 GB RAM, you're done installing now. Otherwise, you will most likely need to set-up and use the old-fashioned way of elevation probing, which requires you to
 
5. copy elev.nas to $FGDATA/Nasal/
 
6. Open elev.nas in a text editor. Change the out variable to a directory with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]
 
== Install on Windows ==
In general, you'll want to follow the above install section. This section lists some additional Windows particularities.
 
Osm2city is pure Python, so install Python if you have not already done so https://www.python.org/downloads/.
 
{{caution|Python 3.5 or later is required. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}}
 
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].
 
* http://www.lfd.uci.edu/~gohlke/pythonlibs/#networkx
* http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
* http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely
* http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack
* https://pypi.python.org/pypi/Pillow/2.5.0#downloads
 
== Workflow ==
There are five main steps:
* get OSM data
* adjust input file
* if neccessary, create elevation grid and run FG to probe elevation data.
* run osm2city
* <del>install the generated scenery</del>installs itself
 
We'll now walk through these steps in detail:
=== get OSM data ===
* decide on a region you want to populate. Get its lon/lat coordinates.
* create a project directory. We will use LOWI/ in this example.
* get corresponding OSM data in its native .xml format.
There are several options to get OSM data. You may find the [http://harrywood.co.uk/maps/uixapi/xapi.html XAPI Query Builder] helpful, it will generate a template download URL that you can fetch with wget:
 
wget -O buildings.osm http://www.overpass-api.de/api/xapi?*[key=value][bbox=11.16898,47.20837,11.79108,47.38161]
 
Note that you either need to give a valid ''key=value'' pair, or remove ''[key=value]'' altogether. The alternative
 
wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161
 
will result in a file compatible with JOSM, at the cost of a larger download. If unsure, use the first option.
 
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.
 
Put this data into LOWI/buildings.osm
 
=== Adjust input file ===
* Now adjust the input file. You can generate a commented default parameters file by
<syntaxhighlight lang="bash">
parameters.py -d > LOWI/params.ini
</syntaxhighlight>
 
Edit this file, adjusting (at least) the following:
:* PREFIX = "LOWI" (the project directory)
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST
:* OSM_FILE = "buildings.osm"
:* set PATH_TO_SCENERY to a standard [[$FG_SCENERY]] path. This is the path where we'll get the elevation from. Most likely you'll want to use your TerraSync path here. Suppose the area you want to populate is /home/user/fgfs/scenery/TerraSync/Objects/e010n40/e011n47/, PATH_TO_SCENERY would then be "/home/user/fgfs/scenery/TerraSync" .
:* set PATH_TO_OUTPUT to a ''different'' scenery path, e.g. "/home/user/fgfs/scenery/osm2city" . Osm2city will generate its objects there. First, this avoids TerraSync overwriting the generated scenery. Second, you can easily remove that folder in case you're not happy with the result. Make sure to include that path in your [[$FG_SCENERY]].
:* you might want to set MAX_OBJECTS to a small number (say, 100) for your first try. This will limit the number of buildings parsed, and speed up the whole process.
:* you also need to set up elevation probing in the parameters file, described in the next section.
 
{{note|Python does not recognize environment variables, please use full paths in the parameters file (no $HOME etc).}}
 
=== Probe elevation ===
Probe elevation for your region. Pick one of the three available modes for ELEV_MODE in params.ini. If you have enough memory (4GB should be fine, but YMMV) and run FG git later than 10 Oct 2014, try FgelevCaching. Failing that, try Manual. (portreekid, what's the 3rd mode good for?)
 
{{caution|1=There are a lot of problems reported currently with fgelev. I can't really test for the next month or so. See troubleshooting or use ELEV_MODE = "Manual".}}
 
* ELEV_MODE = "FgelevCaching"
:* Set FG_ELEV to your fgelev executable. For example: FG_ELEV = "/usr/local/fg/bin/fgelev" or just FG_ELEV = "fgelev" if fgelev is already in your OS's path.
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux)
 
* ELEV_MODE = "Manual"
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FG_ROOT/Nasal/
:* Open $FG_ROOT/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = "/path/to/$FG_ROOT/Nasal/elev.in".
:* tools.py will tell you to hide a certain scenery/Objects/... folder, to prevent probing elevation on top of existing objects. Simply rename the folder
:* run FG, open debug->nasal console, enter: elev.get_elevation(), press execute. Might take a long time, depending on the area scanned. This will write elevation data to /tmp/elev.out (which is actually just plain 5 column data: lon,lat,x,y,elevation). Put elev.out into LOWI/
:* unhide, rename the objects folder
 
* ELEV_MODE = "Telnet"
:* Run setup.py
:* Start FG with the properties service on Port 5501
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory
 
=== Run osm2city ===
* Make sure you're in osm2city's directory and run
 
python osm2city.py -f LOWI/params.ini
 
The parsed OSM data is cached to file LOWI/buildings.osm.pkl which is used on next startup if you set USE_PKL = 1.
If all goes well, files like LOWIcity0101.ac and their corresponding .xml, along with .stg files, were created and moved to the correct location in $FG_SCENERY
* copy or link the tex/ folder into the objects folder where these files were created
 
=== Roads ===
* run roads.py in the same fashion for roads
* <del>copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory</del> roads.eff is copied automatically
* Band-aid fix for the roads is to adjust their height in roads.py change AGL_ofs to a higher number e.g. 0.5
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)


== Support and troubleshooting ==
== Support and troubleshooting ==
Line 254: Line 123:


Before you ask a question, make sure you read this wiki page. If your question is not covered here, tell us as much as possible about the problem you're facing. Which steps have you taken to solve it? What is the exact error message? What operating system? Screenshots?  
Before you ask a question, make sure you read this wiki page. If your question is not covered here, tell us as much as possible about the problem you're facing. Which steps have you taken to solve it? What is the exact error message? What operating system? Screenshots?  
We will not cover general questions like "I don't know how to install XY" -- search the Internet.


=== FGElev crashes ===
=== FGElev crashes ===
Line 292: Line 159:


Copy or link the tex/ folder into the objects folder where the .stg files were created, such that you have $FG_SCENERY/Objects/eXXXnXX/eXXXnXX/tex/. Note that buildings might have been created in more than one folder, e.g. in e011n47 and e011n48. You must have a tex/ folder in each of them. On Windows it is sufficient to have one copy in $FG_ROOT.
Copy or link the tex/ folder into the objects folder where the .stg files were created, such that you have $FG_SCENERY/Objects/eXXXnXX/eXXXnXX/tex/. Note that buildings might have been created in more than one folder, e.g. in e011n47 and e011n48. You must have a tex/ folder in each of them. On Windows it is sufficient to have one copy in $FG_ROOT.
===  ImportError: No module named calc_tile ===
Copy calc_tile.py into batch_processing folder


== Improve frame rate ==
== Improve frame rate ==
Line 303: Line 166:


== Contributing ==
== Contributing ==
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.
You know some Python? Or you're keen on writing docs? Contact the team on the FG forum.
None of the above? Take [[Howto:Create_textures_from_photos|pictures]] of buildings where you live and [[Osm2city.py Textures|create textures]]! I'm especially interested in south-east asian style architecture, as I'm planning to populate Hong Kong Kai Tak (VHXX) in the future.
None of the above? Take [[Howto:Create_textures_from_photos|pictures]] of buildings where you live and [[Osm2city.py Textures|create textures]]! I'm especially interested in south-east asian style architecture, as I'm planning to populate Hong Kong Kai Tak (VHXX) in the future.


648

edits

Navigation menu