<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.flightgear.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Radi</id>
	<title>FlightGear wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.flightgear.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Radi"/>
	<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/Special:Contributions/Radi"/>
	<updated>2026-06-10T02:01:23Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=137268</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=137268"/>
		<updated>2023-01-31T10:34:51Z</updated>

		<summary type="html">&lt;p&gt;Radi: make wingflexer run as &amp;lt;autopilot&amp;gt; instead of &amp;lt;property-rule&amp;gt;, and remove comment about instability (which suggests just that).&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:787 wing flex hard landing.gif|thumb|Wingflex after a touchdown at 9 ft/s on a 787-8.]]&lt;br /&gt;
&lt;br /&gt;
The '''Wingflexer''' module aims at animating the 3-D model of a wing in a somewhat realistic fashion. Wings of large aspect ratio tend to behave similar to a spring. They bend under load and oscillate for a while when the load changes, for example when entering a turn, during turbulence, or on touchdown. The method used is a significant improvement over what has been described [[Howto:Implement_wing_flex|here]]. However, the actual model animation part is identical and will not be covered.&lt;br /&gt;
&lt;br /&gt;
Including this in your aircraft is fairly straightforward, but obtaining plausible parameters can require some research and trial-and-error. We will give an example (for the 787) below.&lt;br /&gt;
&lt;br /&gt;
Introduced in FG 3.5, there are two implementations available. The first, which this article is focused on, uses autopilot/property rules. It is therefore very optimized and should be your first choice. The second implementation uses Nasal. It is a bit more flexible in the sense that it could also be applied to AI aircraft.&lt;br /&gt;
&lt;br /&gt;
== Physical model ==&lt;br /&gt;
This section describes the physical model. You don't need to fully understand the math here to be able to use Wingflexer, but you should understand the parameters involved -- you will need to adapt them to your aircraft.&lt;br /&gt;
&lt;br /&gt;
We use a simple spring-mass-damper system sketched below to model a flexible wing:&lt;br /&gt;
   --&amp;gt;       |&amp;lt;---- z ---&amp;gt;|&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
&lt;br /&gt;
Lift is trying to pull the wing upwards (to the left in the sketch), which is countered by gravity acting on the wing mass. The wing's inertia, in combination with its stiffness and damping characteristics, will create damped oscillations after an initial deflection.&lt;br /&gt;
&lt;br /&gt;
Mathematically speaking, the wing's motion, measured by the deflection z(t), is governed by the following parameters:&lt;br /&gt;
&lt;br /&gt;
 k          wing stiffness&lt;br /&gt;
 d          damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass = dry wing mass + fuel mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L    lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f        acceleration of the frame of reference (fuselage)&lt;br /&gt;
&lt;br /&gt;
We integrate the equation of motion&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/systems/wingflexer/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates a neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences leads to&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;br /&gt;
&lt;br /&gt;
== Obtaining plausible parameters ==&lt;br /&gt;
To make our model produce a convincing dynamic behaviour, you will need to obtain estimates and fine-tune the parameters.&lt;br /&gt;
&lt;br /&gt;
These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
There's a python script wingflexer.py which assists you in fine-tuning. It will quickly simulate the dynamics of the model with your parameters.&lt;br /&gt;
So how to estimate the parameters?&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's natural frequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
where&lt;br /&gt;
 m_ac   aircraft mass&lt;br /&gt;
 g      9.81 m/s^2&lt;br /&gt;
 z_fac  scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the natural frequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the wing's natural frequency, the wing's deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection (bounce)&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
* A lower wing mass increases the natural frequency, and weakens the touchdown bounce&lt;br /&gt;
* A higher stiffness K reduces the deflection and increases the natural frequency&lt;br /&gt;
&lt;br /&gt;
== Enable developer options ==&lt;br /&gt;
By default, Wingflexer and the user-tunable parameters live in&lt;br /&gt;
 /sim/systems/wingflexer/&lt;br /&gt;
 /sim/systems/wingflexer/params/&lt;br /&gt;
&lt;br /&gt;
There are two properties disabled by default which are only useful when you're tuning the parameters. To enable them, uncomment the developer section in Aircraft/Generic/wingflexer.xml.&lt;br /&gt;
This will activate&lt;br /&gt;
 /sim/systems/wingflexer/params/z-fac&lt;br /&gt;
 /sim/systems/wingflexer/sink-rate-fps&lt;br /&gt;
Z-fac simply scales the output. Once you're happy with the results, include this factor in the animation.&lt;br /&gt;
Sink-rate-fps allows you to simulate a touchdown at given vertical speed.&lt;br /&gt;
&lt;br /&gt;
It will become clear in the next section why these two settings are useful.&lt;br /&gt;
&lt;br /&gt;
== An example: the 787 ==&lt;br /&gt;
The 787 is known for its very flexible wings; the deflection in&lt;br /&gt;
unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds&lt;br /&gt;
23,000 kg of fuel. Because the fuel is distributed over the wing, we use a&lt;br /&gt;
fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason&lt;br /&gt;
we don't use the true wing mass, but rather something that makes our model look&lt;br /&gt;
plausible.&lt;br /&gt;
&lt;br /&gt;
So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.&lt;br /&gt;
That frequency might be a bit low, videos of a 777 wing in turbulence show about&lt;br /&gt;
2-3 Hz. (I didn't research 787 videos).&lt;br /&gt;
&lt;br /&gt;
To increase it, we could either reduce m_dw or increase K. A lower m_dw results&lt;br /&gt;
in a rather weak bounce on touchdown which might look odd. A higher K reduces&lt;br /&gt;
the deflection z_flight, but we can simply scale the animation to account for&lt;br /&gt;
that. We'll multiply the deflection z by a factor z_fac to get an angle for the&lt;br /&gt;
&amp;lt;rotate&amp;gt; animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.&lt;br /&gt;
Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects&lt;br /&gt;
to 0.3 m instead of 3 m, the animation scale factor will make sure the wing&lt;br /&gt;
bends to 3 m. This way, we can match both natural frequency and observed deflection,&lt;br /&gt;
and still get a realistic bounce on touch down. Finally, adjust D such that an&lt;br /&gt;
impulse is damped out after about one or two oscillations; D = 12 seems to work&lt;br /&gt;
OK in our example.&lt;br /&gt;
&lt;br /&gt;
It's difficult to get real-world data on the deflection during touchdown.&lt;br /&gt;
Touchdown at more than 10 ft/s is considered a hard landing and could result in some significant wing bending.&lt;br /&gt;
There's a video of a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the&lt;br /&gt;
wings bend perhaps 1 m.&lt;br /&gt;
&lt;br /&gt;
To assist you in tuning parameters for the touchdown bounce you can initialize your&lt;br /&gt;
wing mass with a (touchdown) vertical speed via /sim/systems/wingflexer/sink-rate-fps, and then observe the deflection and oscillation. This avoids you having to fly too many touch-and-go's while developing ;)&lt;br /&gt;
&lt;br /&gt;
Finally, our model outputs the deflection in meters, but the &amp;lt;rotate&amp;gt; animation expects an&lt;br /&gt;
angle. It is up to you convert appropriately, depending on your wing&lt;br /&gt;
span and number of segments in the animation. Also don't forget to include z_fac.&lt;br /&gt;
&lt;br /&gt;
== How to add to your aircraft ==&lt;br /&gt;
Create a file &amp;lt;tt&amp;gt;''[[$FG_ROOT]]/Aircraft/&amp;lt;your aircraft&amp;gt;/Systems/wingflexer-params.xml''&amp;lt;/tt&amp;gt; which contains the parameters adjusted to your aircraft:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;PropertyList&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;params&amp;gt;&lt;br /&gt;
  &amp;lt;m-wing-dry-kg type=&amp;quot;double&amp;quot;&amp;gt;12000&amp;lt;/m-wing-dry-kg&amp;gt;&lt;br /&gt;
  &amp;lt;K type=&amp;quot;double&amp;quot;&amp;gt;259&amp;lt;/K&amp;gt;&lt;br /&gt;
  &amp;lt;D type=&amp;quot;double&amp;quot;&amp;gt;12&amp;lt;/D&amp;gt;&lt;br /&gt;
  &amp;lt;fuel-frac type=&amp;quot;double&amp;quot;&amp;gt;0.375&amp;lt;/fuel-frac&amp;gt;&lt;br /&gt;
  &amp;lt;lift-node-lbs alias=&amp;quot;/fdm/jsbsim/forces/fbz-aero-lbs&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;fuel-node-1-kg alias=&amp;quot;/consumables/fuel/tank/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;fuel-node-2-kg alias=&amp;quot;/consumables/fuel/tank[1]/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;fuel-node-3-kg type=&amp;quot;double&amp;quot;&amp;gt;0&amp;lt;/fuel-node-3-kg&amp;gt;&lt;br /&gt;
  &amp;lt;fuel-node-4-kg type=&amp;quot;double&amp;quot;&amp;gt;0&amp;lt;/fuel-node-4-kg&amp;gt;&lt;br /&gt;
&amp;lt;/params&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also adjust the property node aliases for the wing fuel tanks. Wingflexer supports up to four tanks in total. Since we're currently only solving one equation and hence get only one deflection which is used for both wings, we have to average the wing mass. Internally, m_fuel is simply the sum of all given fuel nodes, &lt;br /&gt;
 m_fuel = fuel-node-1-kg + fuel-node-2-kg + fuel-node-3-kg + fuel-node-4-kg&lt;br /&gt;
so you must include the weighting factor in fuel-frac (e.g. 1/2 if you provide 2 fuel nodes). If you have more than 4 wing tanks in total, use another property rule to compute the average.&lt;br /&gt;
&lt;br /&gt;
In your aircraft's [[Aircraft-set.xml|*-set.xml file]], in &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;systems&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; section, load the parameters and the wingflexer module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;systems&amp;gt;&lt;br /&gt;
  &amp;lt;wingflexer include=&amp;quot;Systems/wingflexer-params.xml&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;autopilot&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;wing flexer property rule&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;path&amp;gt;Aircraft/Generic/wingflexer.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
  &amp;lt;/autopilot&amp;gt;&lt;br /&gt;
&amp;lt;/systems&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The wingflexer writes the deflection to &amp;lt;code&amp;gt;/sim/systems/wingflexer/z-m&amp;lt;/code&amp;gt;.&lt;br /&gt;
Finally, your model rotate animation has to pick it up and multiply it by z_fac:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;animation&amp;gt;&lt;br /&gt;
  &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
  &amp;lt;property&amp;gt;sim/systems/wingflexer/z-m&amp;lt;/property&amp;gt;&lt;br /&gt;
  &amp;lt;factor&amp;gt;10&amp;lt;/factor&amp;gt;&lt;br /&gt;
  &amp;lt;!-- ... --&amp;gt;&lt;br /&gt;
&amp;lt;/animation&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your aircraft uses JSBSim, you're done now. YASim requires an extra step, described next.&lt;br /&gt;
&lt;br /&gt;
== Yasim ==&lt;br /&gt;
Older Yasim does not write the lift to the property tree. But you can create a helper&lt;br /&gt;
function which computes the lift as&lt;br /&gt;
 lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs&lt;br /&gt;
and point the &amp;lt;lift-node-lbs&amp;gt; alias in wingflexer-params.xml to it.&lt;br /&gt;
&lt;br /&gt;
More recent Yasim does write the force, but it needs its sign inverted as wingflexer expects z is positive downwards, and converted to LBF.&lt;br /&gt;
&lt;br /&gt;
In Nasal that would be something like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nasal&amp;quot;&amp;gt;&lt;br /&gt;
setprop(&amp;quot;fdm/yasim/forces/f-z-lift-lbf&amp;quot;, getprop(&amp;quot;fdm/yasim/forces/f-z-lift&amp;quot;)*-0.224809);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As an expression:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;expression&amp;gt;&lt;br /&gt;
                &amp;lt;product&amp;gt;&lt;br /&gt;
                    &amp;lt;property&amp;gt;fdm/yasim/forces/f-z-lift&amp;lt;/property&amp;gt;&lt;br /&gt;
                    &amp;lt;value&amp;gt;-0.224809&amp;lt;/value&amp;gt;&amp;lt;!-- invert and convert from Newton to LBF --&amp;gt;&lt;br /&gt;
                &amp;lt;/product&amp;gt;&lt;br /&gt;
&amp;lt;/expression&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Implementation details ==&lt;br /&gt;
The autopilot/Property rules implementation lives in Aircraft/Generic/wingflexer.xml&lt;br /&gt;
&lt;br /&gt;
The ODE x&amp;quot; + ax' + bx + c = 0 is integrated by DampedOsciFilterImplementation in FG/src/autopilot/digitalfilter.cxx.&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
* write Yasim helper&lt;br /&gt;
* input for fuselage acceleration should rather be acceleration at CG instead of the pilot's location -- is there a property?&lt;br /&gt;
* add wingflexer.py (to where?)&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
=== Wiki articles ===&lt;br /&gt;
* [[Howto:Implement wing flex]] – An older way to add wing flex, though the wingflexer need to be animated in a similar way, but based on /sim/model/wing-flex/z-m.&lt;br /&gt;
* [[Wingflex Shader]] - A shader that can animate the wingflex.&lt;br /&gt;
&lt;br /&gt;
=== Forum topics ===&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=30&amp;amp;t=24699 Wing flex -- spring/damper Nasal module] – Development topic&lt;br /&gt;
&lt;br /&gt;
=== Source code ===&lt;br /&gt;
* {{fgdata file|Aircraft/Generic/wingflexer.xml}} – [[Autopilot configuration reference|Autopilot/property rule]] part of the implementation&lt;br /&gt;
* {{fgdata file|Aircraft/Generic/wingflexer.nas}} – Nasal part of the implementation&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=107304</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=107304"/>
		<updated>2017-03-09T23:26:30Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Physical model */ explain basic oscillation&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:787 wing flex hard landing.gif|thumb|Wingflex after a touchdown at 9 ft/s on a 787-8.]]&lt;br /&gt;
&lt;br /&gt;
The '''Wingflexer''' module aims at animating the 3-D model of a wing in a somewhat realistic fashion. Wings of large aspect ratio tend to behave similar to a spring. They bend under load and oscillate for a while when the load changes, for example when entering a turn, during turbulence, or on touchdown. The method used is a significant improvement over what has been described [[Howto:Implement_wing_flex|here]]. However, the actual model animation part is identical and will not be covered.&lt;br /&gt;
&lt;br /&gt;
Including this in your aircraft is fairly straightforward, but obtaining plausible parameters can require some research and trial-and-error. We will give an example (for the 787) below.&lt;br /&gt;
&lt;br /&gt;
Introduced in FG 3.5, there are two implementations available. The first, which this article is focused on, uses autopilot/property rules. It is therefore very optimized and should be your first choice. The second implementation uses Nasal. It is a bit more flexible in the sense that it could also be applied to AI aircraft.&lt;br /&gt;
&lt;br /&gt;
== Physical model ==&lt;br /&gt;
This section describes the physical model. You don't need to fully understand the math here to be able to use Wingflexer, but you should understand the parameters involved -- you will need to adapt them to your aircraft.&lt;br /&gt;
&lt;br /&gt;
We use a simple spring-mass-damper system sketched below to model a flexible wing:&lt;br /&gt;
   --&amp;gt;       |&amp;lt;---- z ---&amp;gt;|&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
&lt;br /&gt;
Lift is trying to pull the wing upwards (to the left in the sketch), which is countered by gravity acting on the wing mass. The wing's inertia, in combination with its stiffness and damping characteristics, will create damped oscillations after an initial deflection.&lt;br /&gt;
&lt;br /&gt;
Mathematically speaking, the wing's motion, measured by the deflection z(t), is governed by the following parameters:&lt;br /&gt;
&lt;br /&gt;
 k          wing stiffness&lt;br /&gt;
 d          damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass = dry wing mass + fuel mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L    lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f        acceleration of the frame of reference (fuselage)&lt;br /&gt;
&lt;br /&gt;
We integrate the equation of motion&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/systems/wingflexer/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates a neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences leads to&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;br /&gt;
&lt;br /&gt;
== Obtaining plausible parameters ==&lt;br /&gt;
To make our model produce a convincing dynamic behaviour, you will need to obtain estimates and fine-tune the parameters.&lt;br /&gt;
&lt;br /&gt;
These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
There's a python script wingflexer.py which assists you in fine-tuning. It will quickly simulate the dynamics of the model with your parameters.&lt;br /&gt;
So how to estimate the parameters?&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's natural frequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
where&lt;br /&gt;
 m_ac   aircraft mass&lt;br /&gt;
 g      9.81 m/s^2&lt;br /&gt;
 z_fac  scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the natural frequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the wing's natural frequency, the wing's deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection (bounce)&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
* A lower wing mass increases the natural frequency, and weakens the touchdown bounce&lt;br /&gt;
* A higher stiffness K reduces the deflection and increases the natural frequency&lt;br /&gt;
&lt;br /&gt;
== Enable developer options ==&lt;br /&gt;
By default, Wingflexer and the user-tunable parameters live in&lt;br /&gt;
 /sim/systems/wingflexer/&lt;br /&gt;
 /sim/systems/wingflexer/params/&lt;br /&gt;
&lt;br /&gt;
There are two properties disabled by default which are only useful when you're tuning the parameters. To enable them, uncomment the developer section in Aircraft/Generic/wingflexer.xml.&lt;br /&gt;
This will activate&lt;br /&gt;
 /sim/systems/wingflexer/params/z-fac&lt;br /&gt;
 /sim/systems/wingflexer/sink-rate-fps&lt;br /&gt;
Z-fac simply scales the output. Once you're happy with the results, include this factor in the animation.&lt;br /&gt;
Sink-rate-fps allows you to simulate a touchdown at given vertical speed.&lt;br /&gt;
&lt;br /&gt;
It will become clear in the next section why these two settings are useful.&lt;br /&gt;
&lt;br /&gt;
== An example: the 787 ==&lt;br /&gt;
The 787 is known for its very flexible wings; the deflection in&lt;br /&gt;
unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds&lt;br /&gt;
23,000 kg of fuel. Because the fuel is distributed over the wing, we use a&lt;br /&gt;
fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason&lt;br /&gt;
we don't use the true wing mass, but rather something that makes our model look&lt;br /&gt;
plausible.&lt;br /&gt;
&lt;br /&gt;
So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.&lt;br /&gt;
That frequency might be a bit low, videos of a 777 wing in turbulence show about&lt;br /&gt;
2-3 Hz. (I didn't research 787 videos).&lt;br /&gt;
&lt;br /&gt;
To increase it, we could either reduce m_dw or increase K. A lower m_dw results&lt;br /&gt;
in a rather weak bounce on touchdown which might look odd. A higher K reduces&lt;br /&gt;
the deflection z_flight, but we can simply scale the animation to account for&lt;br /&gt;
that. We'll multiply the deflection z by a factor z_fac to get an angle for the&lt;br /&gt;
&amp;lt;rotate&amp;gt; animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.&lt;br /&gt;
Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects&lt;br /&gt;
to 0.3 m instead of 3 m, the animation scale factor will make sure the wing&lt;br /&gt;
bends to 3 m. This way, we can match both natural frequency and observed deflection,&lt;br /&gt;
and still get a realistic bounce on touch down. Finally, adjust D such that an&lt;br /&gt;
impulse is damped out after about one or two oscillations; D = 12 seems to work&lt;br /&gt;
OK in our example.&lt;br /&gt;
&lt;br /&gt;
It's difficult to get real-world data on the deflection during touchdown.&lt;br /&gt;
Touchdown at more than 10 ft/s is considered a hard landing and could result in some significant wing bending.&lt;br /&gt;
There's a video of a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the&lt;br /&gt;
wings bend perhaps 1 m.&lt;br /&gt;
&lt;br /&gt;
To assist you in tuning parameters for the touchdown bounce you can initialize your&lt;br /&gt;
wing mass with a (touchdown) vertical speed via /sim/systems/wingflexer/sink-rate-fps, and then observe the deflection and oscillation. This avoids you having to fly too many touch-and-go's while developing ;)&lt;br /&gt;
&lt;br /&gt;
Finally, our model outputs the deflection in meters, but the &amp;lt;rotate&amp;gt; animation expects an&lt;br /&gt;
angle. It is up to you convert appropriately, depending on your wing&lt;br /&gt;
span and number of segments in the animation. Also don't forget to include z_fac.&lt;br /&gt;
&lt;br /&gt;
== How to add to your aircraft ==&lt;br /&gt;
Create a file &amp;lt;tt&amp;gt;''[[$FG_ROOT]]/Aircraft/&amp;lt;your aircraft&amp;gt;/Systems/wingflexer-params.xml''&amp;lt;/tt&amp;gt; which contains the parameters adjusted to your aircraft:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;PropertyList&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;params&amp;gt;&lt;br /&gt;
  &amp;lt;m-wing-dry-kg type=&amp;quot;double&amp;quot;&amp;gt;12000&amp;lt;/m-wing-dry-kg&amp;gt;&lt;br /&gt;
  &amp;lt;K type=&amp;quot;double&amp;quot;&amp;gt;259&amp;lt;/K&amp;gt;&lt;br /&gt;
  &amp;lt;D type=&amp;quot;double&amp;quot;&amp;gt;12&amp;lt;/D&amp;gt;&lt;br /&gt;
  &amp;lt;fuel-frac type=&amp;quot;double&amp;quot;&amp;gt;0.375&amp;lt;/fuel-frac&amp;gt;&lt;br /&gt;
  &amp;lt;lift-node-lbs alias=&amp;quot;/fdm/jsbsim/forces/fbz-aero-lbs&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;fuel-node-1-kg alias=&amp;quot;/consumables/fuel/tank/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;fuel-node-2-kg alias=&amp;quot;/consumables/fuel/tank[1]/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;fuel-node-3-kg type=&amp;quot;double&amp;quot;&amp;gt;0&amp;lt;/fuel-node-3-kg&amp;gt;&lt;br /&gt;
  &amp;lt;fuel-node-4-kg type=&amp;quot;double&amp;quot;&amp;gt;0&amp;lt;/fuel-node-4-kg&amp;gt;&lt;br /&gt;
&amp;lt;/params&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also adjust the property node aliases for the wing fuel tanks. Wingflexer supports up to four tanks in total. Since we're currently only solving one equation and hence get only one deflection which is used for both wings, we have to average the wing mass. Internally, m_fuel is simply the sum of all given fuel nodes, &lt;br /&gt;
 m_fuel = fuel-node-1-kg + fuel-node-2-kg + fuel-node-3-kg + fuel-node-4-kg&lt;br /&gt;
so you must include the weighting factor in fuel-frac (e.g. 1/2 if you provide 2 fuel nodes). If you have more than 4 wing tanks in total, use another property rule to compute the average.&lt;br /&gt;
&lt;br /&gt;
In your aircraft's [[Aircraft-set.xml|*-set.xml file]], in &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;systems&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; section, load the parameters and the wingflexer module:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;systems&amp;gt;&lt;br /&gt;
  &amp;lt;wingflexer include=&amp;quot;Systems/wingflexer-params.xml&amp;quot;/&amp;gt;&lt;br /&gt;
  &amp;lt;property-rule n=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;name&amp;gt;wing flexer property rule&amp;lt;/name&amp;gt;&lt;br /&gt;
    &amp;lt;path&amp;gt;Aircraft/Generic/wingflexer.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
  &amp;lt;/property-rule&amp;gt;&lt;br /&gt;
&amp;lt;/systems&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The wingflexer writes the deflection to &amp;lt;code&amp;gt;/sim/systems/wingflexer/z-m&amp;lt;/code&amp;gt;.&lt;br /&gt;
Finally, your model rotate animation has to pick it up and multiply it by z_fac:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;xml&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;animation&amp;gt;&lt;br /&gt;
  &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
  &amp;lt;property&amp;gt;sim/systems/wingflexer/z-m&amp;lt;/property&amp;gt;&lt;br /&gt;
  &amp;lt;factor&amp;gt;10&amp;lt;/factor&amp;gt;&lt;br /&gt;
  &amp;lt;!-- ... --&amp;gt;&lt;br /&gt;
&amp;lt;/animation&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your aircraft uses JSBSim, you're done now. YASim requires an extra step, described next.&lt;br /&gt;
&lt;br /&gt;
== Yasim ==&lt;br /&gt;
Yasim does not write the lift to the property tree. But you can create a helper&lt;br /&gt;
function which computes the lift as&lt;br /&gt;
 lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs&lt;br /&gt;
and point the &amp;lt;lift-node-lbs&amp;gt; alias in wingflexer-params.xml to it.&lt;br /&gt;
&lt;br /&gt;
== Implementation details ==&lt;br /&gt;
The autopilot/Property rules implementation lives in Aircraft/Generic/wingflexer.xml&lt;br /&gt;
&lt;br /&gt;
The ODE x&amp;quot; + ax' + bx + c = 0 is integrated by DampedOsciFilterImplementation in FG/src/autopilot/digitalfilter.cxx.&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
* write Yasim helper&lt;br /&gt;
* input for fuselage acceleration should rather be acceleration at CG instead of the pilot's location -- is there a property?&lt;br /&gt;
* add wingflexer.py (to where?)&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
=== Wiki articles ===&lt;br /&gt;
* [[Howto:Implement wing flex]] – An older way to add wing flex, though the wingflexer need to be animated in a similar way, but based on /sim/model/wing-flex/z-m.&lt;br /&gt;
&lt;br /&gt;
=== Forum topics ===&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=30&amp;amp;t=24699 Wing flex -- spring/damper Nasal module] – Development topic&lt;br /&gt;
&lt;br /&gt;
=== Source code ===&lt;br /&gt;
* {{fgdata file|Aircraft/Generic/wingflexer.xml}} – [[Autopilot configuration reference|Autopilot/property rule]] part of the implementation&lt;br /&gt;
* {{fgdata file|Aircraft/Generic/wingflexer.nas}} – Nasal part of the implementation&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Changelog_3.6&amp;diff=87188</id>
		<title>Changelog 3.6</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Changelog_3.6&amp;diff=87188"/>
		<updated>2015-09-17T21:59:13Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Major enhancements in this release */ wingflexer: wording, add link to wiki page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{draft|changelog|This changelog is currently being written for the FlightGear v3.6 release.  Feel free to help! If you are aware of any FlightGear related changes, please add them to the changelog.}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote|1= As many people have noticed, the v3.6 release has been slightly delayed. The main reason is that too many key developers have been out of town for work or holiday this month. We are currently hoping for a mid-September release. We will post further updates once our release manager returns and we can regroup from all the end of the summer (northern hemisphere) :-) activities. Thank you, Curt.|2= {{cite web  | url    = http://sourceforge.net/p/flightgear/mailman/message/34407279/  | title  = &amp;lt;nowiki&amp;gt;[Flightgear-devel] Release v3.6 update&amp;lt;/nowiki&amp;gt;  | author = &amp;lt;nowiki&amp;gt;Curtis Olson&amp;lt;/nowiki&amp;gt;  | date   = Aug 26th, 2015  }}}}&lt;br /&gt;
&lt;br /&gt;
The FlightGear development team is delighted to announce the v3.6 release of FlightGear, the free, open-source flight simulator.  This new version contains many exciting new features, enhancements and bugfixes.  Highlights in this release include a reduced base installation size, improvements to the built-in Web UI, cockpit shadows without Rembrandt, and a massively improved default aircraft - the Cessna 172P.&lt;br /&gt;
&lt;br /&gt;
Founded in 1997, FlightGear is developed by a worldwide group of volunteers, brought together by a shared ambition to create &lt;br /&gt;
the most realistic flight simulator possible that is free to use, modify and distribute. FlightGear is used all over the world &lt;br /&gt;
by desktop flight simulator enthusiasts, for research in universities and for interactive exhibits in museums.&lt;br /&gt;
&lt;br /&gt;
FlightGear features more than 400 aircraft, a worldwide scenery database, a multiplayer environment, detailed sky modelling, a flexible and open aircraft modelling system, varied networking options, multiple display support, a powerful scripting language and an open architecture. Best of all, being open-source, the simulator is owned by the community and everyone is encouraged to contribute. &lt;br /&gt;
&lt;br /&gt;
Download FlightGear v3.6 for free from [http://www.flightgear.org/ FlightGear.org]&lt;br /&gt;
&lt;br /&gt;
FlightGear - Fly Free!&lt;br /&gt;
&lt;br /&gt;
=== Major enhancements in this release ===&lt;br /&gt;
'''Project Organization'''&lt;br /&gt;
* The base package has been reduced in size to 1.3GB and moved to  http://sourceforge.net/p/flightgear/fgdata/.  All aircraft except the c172p and ufo have been removed.&lt;br /&gt;
* All core repositories have been moved to sourceforge.  They can be found at https://sourceforge.net/projects/flightgear/&lt;br /&gt;
&lt;br /&gt;
'''Core'''&lt;br /&gt;
* Numerous improvements to Phi, the built in web interface.&lt;br /&gt;
* Interactive traffic system re-enabled, having been disabled by mistake some releases previously.&lt;br /&gt;
* Various security improvements, including the disabling of system.fgfsrc,&lt;br /&gt;
&lt;br /&gt;
'''Launcher'''&lt;br /&gt;
[[File:Qt launcher for FlightGear 3.5 on Windows 7.jpg|thumb|The aircraft page of the Qt launcher for FlightGear 3.5 as rendered on Windows 7.]]&lt;br /&gt;
&lt;br /&gt;
The [[Integrated Qt5 Launcher|built-in Qt launcher]], developed by James Turner shipped by default with the Mac version of FlightGear 3.4, will be used for other OSes&amp;lt;ref&amp;gt;{{cite web&lt;br /&gt;
|url = http://sourceforge.net/p/flightgear/codetickets/1591/#4cb7&lt;br /&gt;
|title = Issue #1591&lt;br /&gt;
|author = Gijs&lt;br /&gt;
|authorlink-wiki = User:Gijs&lt;br /&gt;
|date = April 8th, 2015&lt;br /&gt;
}}&amp;lt;/ref&amp;gt;.  In addition, [[FGRun]] will be dropped in favor of this.&lt;br /&gt;
&lt;br /&gt;
{{inote|In future FlightGear releases, there will be an additional HTML5-based version ([[Phi]], developed by Torsten D), and the Qt launcher, based on well-supported libraries, will be used as the main launcher (replacing [[FGRun]]).  This parallel development is intentional&amp;lt;ref&amp;gt;http://forum.flightgear.org/viewtopic.php?p=229445#p229445&amp;lt;/ref&amp;gt;, and it is likely that both will use a common service layer to provide the necessary data&amp;lt;ref&amp;gt;http://forum.flightgear.org/viewtopic.php?p=229303#p229303&amp;lt;/ref&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
To learn more, see [[Integrated Qt5 Launcher]]&lt;br /&gt;
&lt;br /&gt;
'''Aircraft Modeling'''&lt;br /&gt;
* [[Tooltips]] can now be positioned at a specific place on-screen.&lt;br /&gt;
* [[Wingflexer|wing flex]] module added, controlled via Nasal or Property Rules.&lt;br /&gt;
* Bug-fixes and improvements to the [[Failure Manager]].&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;variant-of&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; tag in the [[Aircraft-set.xml|*-set.xml]] file has been added. See [[FlightGear Newsletter March 2015]].&lt;br /&gt;
* Automatic checklist execution, e.g. for autostart&lt;br /&gt;
* 8.33 kHz spacing is now supported on comms radios.&lt;br /&gt;
&lt;br /&gt;
'''JSBSim'''&lt;br /&gt;
* Sync with latest version of JSBSim&lt;br /&gt;
* The Pitot angle can now be tweaked with the &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;pitot_angle&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; tag in the &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;metrics&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; block.&lt;br /&gt;
* The refuel rate is now configurable with the &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;refuel-rate&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; tag in the &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;propulsion&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; block.&lt;br /&gt;
&lt;br /&gt;
'''Atmospheric Light Scattering'''&lt;br /&gt;
* The addition of volumetric grass to the random vegetation system.&lt;br /&gt;
* Interior cockpit shadows.&lt;br /&gt;
* Interior glass reflections, frosting and fogging.&lt;br /&gt;
* Interior panel backlighting.&lt;br /&gt;
* New thruster effect (Afterburners, Rockets, etc).&lt;br /&gt;
&lt;br /&gt;
'''Environment Rendering'''&lt;br /&gt;
* Improved rendering of the sun, particularly in space.&lt;br /&gt;
&lt;br /&gt;
'''Usability'''&lt;br /&gt;
* Many improvements to Phi - the built-in web interface&lt;br /&gt;
* GUI cleanup to improve support for multiple GUI styles&lt;br /&gt;
&lt;br /&gt;
'''Scenery'''&lt;br /&gt;
* Regional texture definitions for Florida, Brazil, Latin America, Africa, Middle East and Southeastern Asia.&lt;br /&gt;
* stgmerge tool added to merge objects in a scenery tile into a small number of meshes&lt;br /&gt;
&lt;br /&gt;
'''Canvas System'''&lt;br /&gt;
* Improvements to Canvas/MapStructure and NavDisplay&lt;br /&gt;
* Canvas failure manager GUI dialog&lt;br /&gt;
&lt;br /&gt;
'''Highlighted new and improved aircraft'''&lt;br /&gt;
* Complete refresh of the default c172p, including engine options, various tire sizes and floats.&lt;br /&gt;
* Major enhancements to the Shuttle.  Shuttle can be flown as per the Crew Operations manual from launch to touchdown.&lt;br /&gt;
* The following aircraft have received significant updates: 787-8, F-15, B-1B, JA37, Citation II, Lockheed1049h, 737-300, Mirage 2000-5&lt;br /&gt;
&lt;br /&gt;
'''Misc/Uncategorized'''&lt;br /&gt;
* Improved support for KDI572-574 DME equipment&lt;br /&gt;
* Update the World Magnetic Model to 2015.0&lt;br /&gt;
&lt;br /&gt;
'''Bug fixes'''&lt;br /&gt;
* See [http://sourceforge.net/p/flightgear/codetickets/search/?q=status%3AFixed+AND+_milestone%3A3.6 our bugtracker] for an extensive, yet incomplete, list of the bugs fixed in this release.&lt;br /&gt;
&lt;br /&gt;
{{Appendix}}&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear changelogs]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Howto:Implement_wing_flex&amp;diff=86967</id>
		<title>Howto:Implement wing flex</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Howto:Implement_wing_flex&amp;diff=86967"/>
		<updated>2015-09-03T21:32:22Z</updated>

		<summary type="html">&lt;p&gt;Radi: link the wingflexer article&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:747-400_wing_flex.jpg|thumb|270px|Wing flex as seen on the [[Boeing 747-400]].]]&lt;br /&gt;
&lt;br /&gt;
'''Wing flex''' is the flexing of wings on [[aircraft]], due to lift and fuselage load. [[FlightGear]] is able to show realistic wing flex. Currently the [[Boeing 787]], [[Airbus A330-200|A330-200]], [[Boeing 747-400|747-400]], and [[Bombardier CRJ-900|CRJ-900]] are equipped with flexing wings.&lt;br /&gt;
&lt;br /&gt;
This article describes a simple approach to model static wing flex. Using this approach, the wing will bend realistically under load, but it will not oscillate after load changes, e.g., on hard touchdown. For a more sophisticated model for dynamic wing flex, please see the [[Wingflexer|Wingflexer article]].&lt;br /&gt;
&lt;br /&gt;
== Model ==&lt;br /&gt;
A few edits have to be made to the aircraft model. Each wing has to be cut into multiple sections. The more sections, the smoother the wing flex. Be carefull that you do not cut through flaps or engines. Naming our wing sections, from fuselage to wing tip: wing.1, wing.2 and wing.3. &lt;br /&gt;
&lt;br /&gt;
Measure the coordinates of the start of each new wing section, you will need them to animate the wings.&lt;br /&gt;
&lt;br /&gt;
== Animation ==&lt;br /&gt;
The following lines have to be added to the aircraft model .xml file. These lines are used with three wing sections, and a [[JSBSim]] [[FDM]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source&amp;gt;&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
  &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
  &amp;lt;object-name&amp;gt;LeftWing.1&amp;lt;/object-name&amp;gt;&lt;br /&gt;
  &amp;lt;object-name&amp;gt;LeftWing.2&amp;lt;/object-name&amp;gt;&lt;br /&gt;
  &amp;lt;object-name&amp;gt;LeftWing.3&amp;lt;/object-name&amp;gt;&lt;br /&gt;
  &amp;lt;property&amp;gt;fdm/jsbsim/aero/coefficient/CLalpha&amp;lt;/property&amp;gt;&lt;br /&gt;
  &amp;lt;factor&amp;gt;-0.0000045&amp;lt;/factor&amp;gt;&lt;br /&gt;
  &amp;lt;offset-deg&amp;gt;0&amp;lt;/offset-deg&amp;gt;   &lt;br /&gt;
  &amp;lt;center&amp;gt;&lt;br /&gt;
   &amp;lt;x-m&amp;gt; 0.00&amp;lt;/x-m&amp;gt;&lt;br /&gt;
   &amp;lt;y-m&amp;gt;-4.00&amp;lt;/y-m&amp;gt;&lt;br /&gt;
   &amp;lt;z-m&amp;gt;-1.70&amp;lt;/z-m&amp;gt;&lt;br /&gt;
  &amp;lt;/center&amp;gt;&lt;br /&gt;
  &amp;lt;axis&amp;gt;&lt;br /&gt;
   &amp;lt;x&amp;gt;1.0&amp;lt;/x&amp;gt;&lt;br /&gt;
   &amp;lt;y&amp;gt;0.0&amp;lt;/y&amp;gt;&lt;br /&gt;
   &amp;lt;z&amp;gt;0.0&amp;lt;/z&amp;gt;&lt;br /&gt;
  &amp;lt;/axis&amp;gt;&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
  &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
  &amp;lt;object-name&amp;gt;LeftWing.2&amp;lt;/object-name&amp;gt;&lt;br /&gt;
  &amp;lt;object-name&amp;gt;LeftWing.3&amp;lt;/object-name&amp;gt;&lt;br /&gt;
  &amp;lt;property&amp;gt;fdm/jsbsim/aero/coefficient/CLalpha&amp;lt;/property&amp;gt;&lt;br /&gt;
  &amp;lt;factor&amp;gt;-0.0000045&amp;lt;/factor&amp;gt;&lt;br /&gt;
  &amp;lt;offset-deg&amp;gt;0&amp;lt;/offset-deg&amp;gt;   &lt;br /&gt;
  &amp;lt;center&amp;gt;&lt;br /&gt;
   &amp;lt;x-m&amp;gt; 0.00&amp;lt;/x-m&amp;gt;&lt;br /&gt;
   &amp;lt;y-m&amp;gt;-8.00&amp;lt;/y-m&amp;gt;&lt;br /&gt;
   &amp;lt;z-m&amp;gt;-1.50&amp;lt;/z-m&amp;gt;&lt;br /&gt;
  &amp;lt;/center&amp;gt;&lt;br /&gt;
  &amp;lt;axis&amp;gt;&lt;br /&gt;
   &amp;lt;x&amp;gt;1.0&amp;lt;/x&amp;gt;&lt;br /&gt;
   &amp;lt;y&amp;gt;0.0&amp;lt;/y&amp;gt;&lt;br /&gt;
   &amp;lt;z&amp;gt;0.0&amp;lt;/z&amp;gt;&lt;br /&gt;
  &amp;lt;/axis&amp;gt;&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
  &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
  &amp;lt;object-name&amp;gt;LeftWing.3&amp;lt;/object-name&amp;gt;&lt;br /&gt;
  &amp;lt;property&amp;gt;fdm/jsbsim/aero/coefficient/CLalpha&amp;lt;/property&amp;gt;&lt;br /&gt;
  &amp;lt;factor&amp;gt;-0.0000045&amp;lt;/factor&amp;gt;&lt;br /&gt;
  &amp;lt;offset-deg&amp;gt;0&amp;lt;/offset-deg&amp;gt;&lt;br /&gt;
  &amp;lt;center&amp;gt;&lt;br /&gt;
   &amp;lt;x-m&amp;gt;  0.00&amp;lt;/x-m&amp;gt;&lt;br /&gt;
   &amp;lt;y-m&amp;gt;-12.25&amp;lt;/y-m&amp;gt;&lt;br /&gt;
   &amp;lt;z-m&amp;gt; -1.25&amp;lt;/z-m&amp;gt;&lt;br /&gt;
  &amp;lt;/center&amp;gt;&lt;br /&gt;
  &amp;lt;axis&amp;gt;&lt;br /&gt;
   &amp;lt;x&amp;gt;1.0&amp;lt;/x&amp;gt;&lt;br /&gt;
   &amp;lt;y&amp;gt;0.0&amp;lt;/y&amp;gt;&lt;br /&gt;
   &amp;lt;z&amp;gt;0.0&amp;lt;/z&amp;gt;&lt;br /&gt;
  &amp;lt;/axis&amp;gt;&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You probably need to add a lot more objects to each section (like engines, flaps, ailerons etc.) and also change the ''center'' coordinates according to your aircraft. For the right wing, just change the sign of the center &amp;lt;y-m&amp;gt; coordinate and the factor value.&lt;br /&gt;
&lt;br /&gt;
=== JSBSim ===&lt;br /&gt;
[[JSBSim]] calculates the lift force of the aircraft. The lift reacts on the G-forces, the velocity and turbulences. The respective property is: &amp;lt;tt&amp;gt;fdm/jsbsim/aero/coefficient/CLalpha&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== YASim ===&lt;br /&gt;
[[YASim]] does not calculate wingflex as nice as JSBSim, but a pretty realistic effect can be reached by using the &amp;lt;tt&amp;gt;accelerations/pilot-g[0]&amp;lt;/tt&amp;gt; property instead.&lt;br /&gt;
&lt;br /&gt;
[[es:Howto: Implement wing flex]]&lt;br /&gt;
[[Category:Aircraft enhancement|Implement wing flex]]&lt;br /&gt;
[[Category:Howto|Implement wing flex]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=86966</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=86966"/>
		<updated>2015-09-03T21:06:17Z</updated>

		<summary type="html">&lt;p&gt;Radi: wording&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:787 wing flex hard landing.gif|thumb|Wingflex after a touchdown at 9 ft/s on a 787-8.]]&lt;br /&gt;
&lt;br /&gt;
The '''Wingflexer''' module aims at animating the 3-D model of a wing in a somewhat realistic fashion. Wings of large aspect ratio tend to behave similar to a spring. They bend under load and oscillate for a while when the load changes, for example when entering a turn, during turbulence, or on touchdown. The method used is a significant improvement over what has been described [[Howto:Implement_wing_flex|here]]. However, the actual model animation part is identical and will not be covered.&lt;br /&gt;
&lt;br /&gt;
Including this in your aircraft is fairly straightforward, but obtaining plausible parameters can require some research and trial-and-error. We will give an example (for the 787) below.&lt;br /&gt;
&lt;br /&gt;
Introduced in FG 3.5, there are two implementations available. The first, which this article is focused on, uses autopilot/property rules. It is therefore very optimized and should be your first choice. The second implementation uses Nasal. It is a bit more flexible in the sense that it could also be applied to AI aircraft.&lt;br /&gt;
&lt;br /&gt;
== Physical model ==&lt;br /&gt;
This section describes the physical model. You don't need to fully understand the math here to be able to use Wingflexer, but you should understand the parameters involved -- you will need to adapt them to your aircraft.&lt;br /&gt;
&lt;br /&gt;
We use a simple spring-mass-damper system sketched below to model a flexible wing:&lt;br /&gt;
   --&amp;gt;       |&amp;lt;---- z ---&amp;gt;|&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
&lt;br /&gt;
The wing's motion, measured by the deflection z(t), is governed by the following parameters:&lt;br /&gt;
&lt;br /&gt;
 k          wing stiffness&lt;br /&gt;
 d          damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L    lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f        acceleration of the frame of reference (fuselage)&lt;br /&gt;
&lt;br /&gt;
We integrate the equation of motion&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/systems/wingflexer/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates a neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences leads to&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;br /&gt;
&lt;br /&gt;
== Obtaining plausible parameters ==&lt;br /&gt;
To make our model produce a convinving dynamic behaviour, you will need to obtain estimates and fine-tune the parameters.&lt;br /&gt;
&lt;br /&gt;
These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
There's a python script wingflexer.py which assists you in fine-tuning. It will quickly simulate the dynamics of the model with your parameters.&lt;br /&gt;
So how to estimate the parameters?&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's natural frequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
where&lt;br /&gt;
 m_ac   aircraft mass&lt;br /&gt;
 g      9.81 m/s^2&lt;br /&gt;
 z_fac  scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the natural frequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the wing's natural frequency, the wing's deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection (bounce)&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
* a lower wing mass increases the natural frequency, and weakens the touchdown bounce&lt;br /&gt;
* a higher stiffness K reduces the deflection and increases the natural frequency&lt;br /&gt;
&lt;br /&gt;
== Enable developer options ==&lt;br /&gt;
By default, Wingflexer and the user-tunable parameters live in&lt;br /&gt;
 /sim/systems/wingflexer/&lt;br /&gt;
 /sim/systems/wingflexer/params/&lt;br /&gt;
&lt;br /&gt;
There are two properties disabled by default which are only useful when you're tuning the parameters. To enable them, uncomment the developer section in Aircraft/Generic/wingflexer.xml.&lt;br /&gt;
This will activate&lt;br /&gt;
 /sim/systems/wingflexer/params/z-fac&lt;br /&gt;
 /sim/systems/wingflexer/sink-rate-fps&lt;br /&gt;
Z-fac simply scales the output. Once you're happy with the results, include this factor in the animation.&lt;br /&gt;
Sink-rate-fps allows you to simulate a touchdown at given vertical speed.&lt;br /&gt;
&lt;br /&gt;
It will become clear in the next section why these two settings are useful.&lt;br /&gt;
&lt;br /&gt;
== An example: the 787 ==&lt;br /&gt;
The 787 is known for its very flexible wings; the deflection in&lt;br /&gt;
unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds&lt;br /&gt;
23,000 kg of fuel. Because the fuel is distributed over the wing, we use a&lt;br /&gt;
fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason&lt;br /&gt;
we don't use the true wing mass, but rather something that makes our model look&lt;br /&gt;
plausible.&lt;br /&gt;
&lt;br /&gt;
So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.&lt;br /&gt;
That frequency might be a bit low, videos of a 777 wing in turbulence show about&lt;br /&gt;
2-3 Hz. (I didn't research 787 videos).&lt;br /&gt;
&lt;br /&gt;
To increase it, we could either reduce m_dw or increase K. A lower m_dw results&lt;br /&gt;
in a rather weak bounce on touchdown which might look odd. A higher K reduces&lt;br /&gt;
the deflection z_flight, but we can simply scale the animation to account for&lt;br /&gt;
that. We'll multiply the deflection z by a factor z_fac to get an angle for the&lt;br /&gt;
&amp;lt;rotate&amp;gt; animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.&lt;br /&gt;
Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects&lt;br /&gt;
to 0.3 m instead of 3 m, the animation scale factor will make sure the wing&lt;br /&gt;
bends to 3 m. This way, we can match both natural frequency and observed deflection,&lt;br /&gt;
and still get a realistic bounce on touch down. Finally, adjust D such that an&lt;br /&gt;
impulse is damped out after about one or two oscillations; D = 12 seems to work&lt;br /&gt;
OK in our example.&lt;br /&gt;
&lt;br /&gt;
It's difficult to get real-world data on the deflection during touchdown.&lt;br /&gt;
Touchdown at more than 10 ft/s is considered a hard landing and could result in some significant wing bending.&lt;br /&gt;
There's a video of a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the&lt;br /&gt;
wings bend perhaps 1 m.&lt;br /&gt;
&lt;br /&gt;
To assist you in tuning parameters for the touchdown bounce you can initialize your&lt;br /&gt;
wing mass with a (touchdown) vertical speed via /sim/systems/wingflexer/sink-rate-fps, and then observe the deflection and oscillation. This avoids you having to fly too many touch-and-go's while developing ;)&lt;br /&gt;
&lt;br /&gt;
Finally, our model outputs the deflection in meters, but the &amp;lt;rotate&amp;gt; animation expects an&lt;br /&gt;
angle. It is up to you convert appropriately, depending on your wing&lt;br /&gt;
span and number of segments in the animation. Also don't forget to include z_fac.&lt;br /&gt;
&lt;br /&gt;
== How to add to your aircraft ==&lt;br /&gt;
Create a file $YourAircraft/Systems/wingflexer-params.xml which contains the parameters adjusted to your aircraft&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;PropertyList&amp;gt;&lt;br /&gt;
     &amp;lt;params&amp;gt;&lt;br /&gt;
         &amp;lt;m-wing-dry-kg type=&amp;quot;double&amp;quot;&amp;gt;12000.&amp;lt;/m-wing-dry-kg&amp;gt;&lt;br /&gt;
         &amp;lt;K type=&amp;quot;double&amp;quot;&amp;gt;259.&amp;lt;/K&amp;gt;&lt;br /&gt;
         &amp;lt;D type=&amp;quot;double&amp;quot;&amp;gt;12.&amp;lt;/D&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-frac type=&amp;quot;double&amp;quot;&amp;gt;0.375&amp;lt;/fuel-frac&amp;gt;&lt;br /&gt;
         &amp;lt;lift-node-lbs alias=&amp;quot;/fdm/jsbsim/forces/fbz-aero-lbs&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-1-kg alias=&amp;quot;/consumables/fuel/tank/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-2-kg alias=&amp;quot;/consumables/fuel/tank[1]/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-3-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-3-kg&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-4-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-4-kg&amp;gt;&lt;br /&gt;
     &amp;lt;/params&amp;gt;&lt;br /&gt;
 &amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
Also adjust the property node aliases for the wing fuel tanks. Wingflexer supports up to four tanks in total. Since we're currently only solving one equation and hence get only one deflection which is used for both wings, we have to average the wing mass. Internally, m_fuel is simply the sum of all given fuel nodes, &lt;br /&gt;
  m_fuel = fuel-node-1-kg + fuel-node-2-kg + fuel-node-3-kg + fuel-node-4-kg&lt;br /&gt;
so you must include the weighting factor in fuel-frac (e.g. 1/2 if you provide 2 fuel nodes). If you have more than 4 wing tanks in total, use another property rule to compute the average.&lt;br /&gt;
&lt;br /&gt;
In $yourAircraft-set.xml, in &amp;lt;systems&amp;gt; section, load the parameters and the wingflexer module:&lt;br /&gt;
 &amp;lt;systems&amp;gt;&lt;br /&gt;
     &amp;lt;wingflexer include=&amp;quot;Systems/wingflexer-params.xml&amp;quot;/&amp;gt;&lt;br /&gt;
     &amp;lt;property-rule n=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;name&amp;gt;wing flexer property rule&amp;lt;/name&amp;gt;&lt;br /&gt;
         &amp;lt;path&amp;gt;Aircraft/Generic/wingflexer.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
     &amp;lt;/property-rule&amp;gt;&lt;br /&gt;
 &amp;lt;/systems&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The wingflexer writes the deflection to /sim/systems/wingflexer/z-m.&lt;br /&gt;
Finally, your model rotate animation has to pick it up and multiply it by z_fac&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
     &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
     &amp;lt;property&amp;gt;sim/systems/wingflexer/z-m&amp;lt;/property&amp;gt;&lt;br /&gt;
     &amp;lt;factor&amp;gt;10.&amp;lt;/factor&amp;gt;&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your aircraft uses JSBSim, you're done now. Yasim requires an extra step, described next.&lt;br /&gt;
&lt;br /&gt;
== Yasim ==&lt;br /&gt;
Yasim does not write the lift to the property tree. But you can create a helper&lt;br /&gt;
function which computes the lift as&lt;br /&gt;
 lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs&lt;br /&gt;
and point the &amp;lt;lift-node-lbs&amp;gt; alias in wingflexer-params.xml to it.&lt;br /&gt;
&lt;br /&gt;
== Implementation details ==&lt;br /&gt;
=== Autopilot/Property rules implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.xml&lt;br /&gt;
&lt;br /&gt;
The ODE x&amp;quot; + ax' + bx + c = 0 is integrated by DampedOsciFilterImplementation in FG/src/autopilot/digitalfilter.cxx.&lt;br /&gt;
&lt;br /&gt;
=== Nasal implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.nas, see comment therein.&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
* write Yasim helper&lt;br /&gt;
* input for fuselage acceleration should rather be acceleration at CG instead of the pilot's location -- is there a property?&lt;br /&gt;
* add wingflexer.py (to where?)&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=86491</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=86491"/>
		<updated>2015-07-31T01:07:22Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* get OSM data */ formatting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitlab.com/fg-radi/osm2city repository] is hosted on &amp;lt;del&amp;gt;gitorious&amp;lt;/del&amp;gt; gitlab.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitlab.com/fg-radi/osm2city-data]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx curl&lt;br /&gt;
2. get [https://gitlab.com/fg-radi/osm2city osm2city] and [https://gitlab.com/fg-radi/osm2city-data osm2city-data] from gitlab.&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
You can add &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PYTHONPATH=$PYTHONPATH:/path/of/osm2city&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
or &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PYTHONPATH=$PYTHONPATH:.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
into your hidden configuration file &amp;lt;b&amp;gt;.bashrc&amp;lt;/b&amp;gt; located in your home directory.&lt;br /&gt;
&lt;br /&gt;
4. soft link osm2city-data/tex and osm2city-data/tex.src into osm2city/. Typically you will have to &amp;quot;adapt&amp;quot; and execute these commands.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  cd osm2city&lt;br /&gt;
  ln -sf ../osm2city-data/tex.src&lt;br /&gt;
  ln -sf ../osm2city-data/tex&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then the sub-directory of osm2city will appears like that&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city/&lt;br /&gt;
  tex.src/&lt;br /&gt;
  tex/&lt;br /&gt;
  osm2city.py&lt;br /&gt;
  textures.py&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{caution|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?*[key=value][bbox=11.16898,47.20837,11.79108,47.38161]&lt;br /&gt;
&lt;br /&gt;
Note that you either need to give a valid ''key=value'' pair, or remove ''[key=value]'' altogether. The alternative &lt;br /&gt;
&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
will result in a file compatible with JOSM, at the cost of a larger download. If unsure, use the first option.&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = &amp;quot;LOWI&amp;quot; (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = &amp;quot;buildings.osm&amp;quot;&lt;br /&gt;
:* 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 &amp;quot;/home/user/fgfs/scenery/TerraSync&amp;quot; .&lt;br /&gt;
:* set PATH_TO_OUTPUT to a ''different'' scenery path, e.g. &amp;quot;/home/user/fgfs/scenery/osm2city&amp;quot; . 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
{{note|Python does not recognize environment variables, please use full paths in the parameters file (no $HOME etc).}}&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
{{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 = &amp;quot;Manual&amp;quot;.}}&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;FgelevCaching&amp;quot;&lt;br /&gt;
:* Set FG_ELEV to your fgelev executable. For example: FG_ELEV = &amp;quot;/usr/local/fg/bin/fgelev&amp;quot; or just FG_ELEV = &amp;quot;fgelev&amp;quot; if fgelev is already in your OS's path.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;Manual&amp;quot;&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FG_ROOT/Nasal/&lt;br /&gt;
:* Open $FG_ROOT/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_ROOT/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;Telnet&amp;quot;&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* Make sure you're in osm2city's directory and run &lt;br /&gt;
&lt;br /&gt;
 python osm2city.py -f LOWI/params.ini. &lt;br /&gt;
&lt;br /&gt;
The parsed OSM data is cached to file LOWI/buildings.osm.pkl which is used on next startup if you set USE_PKL = 1.&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
=== FGElev crashes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
CRITICAL:root:1173 -95.5767 37.0965&lt;br /&gt;
CRITICAL:root:fgelev returned &amp;lt;&amp;gt;, resulting in list index out of range. Did fgelev start OK (Record : 1173)?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The first line is the last input to fgelev. &lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter the line last sent to fgelev. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173 -95.5767 37.0965&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The response should look like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173: 226.793&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. ===&lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
=== Buildings/roads have no texture. I get errors &amp;quot;osgDB ac3d reader: could not find texture &amp;quot;tex/atlas_facades.png&amp;quot;. ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===  ImportError: No module named calc_tile ===&lt;br /&gt;
&lt;br /&gt;
Copy calc_tile.py into batch_processing folder&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
=== Wiki articles ===&lt;br /&gt;
* [[Areas populated with osm2city scenery]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
&lt;br /&gt;
=== Forum topics ===&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625 LOWI city buildings]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;Proposal&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt; Autogen Cities using PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=17598 Procedural buildings in OSM before part of Scenery]&lt;br /&gt;
&lt;br /&gt;
=== Mailing list threads ===&lt;br /&gt;
* [http://sourceforge.net/p/flightgear/mailman/message/30825768/ &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;Flightgear-devel&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt; osm2city.py]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=86490</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=86490"/>
		<updated>2015-07-31T01:06:30Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* get OSM data */ fix download URL&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitlab.com/fg-radi/osm2city repository] is hosted on &amp;lt;del&amp;gt;gitorious&amp;lt;/del&amp;gt; gitlab.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitlab.com/fg-radi/osm2city-data]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx curl&lt;br /&gt;
2. get [https://gitlab.com/fg-radi/osm2city osm2city] and [https://gitlab.com/fg-radi/osm2city-data osm2city-data] from gitlab.&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
You can add &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PYTHONPATH=$PYTHONPATH:/path/of/osm2city&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
or &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
PYTHONPATH=$PYTHONPATH:.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
into your hidden configuration file &amp;lt;b&amp;gt;.bashrc&amp;lt;/b&amp;gt; located in your home directory.&lt;br /&gt;
&lt;br /&gt;
4. soft link osm2city-data/tex and osm2city-data/tex.src into osm2city/. Typically you will have to &amp;quot;adapt&amp;quot; and execute these commands.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  cd osm2city&lt;br /&gt;
  ln -sf ../osm2city-data/tex.src&lt;br /&gt;
  ln -sf ../osm2city-data/tex&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Then the sub-directory of osm2city will appears like that&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city/&lt;br /&gt;
  tex.src/&lt;br /&gt;
  tex/&lt;br /&gt;
  osm2city.py&lt;br /&gt;
  textures.py&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{caution|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?*[key=value][bbox=11.16898,47.20837,11.79108,47.38161]&lt;br /&gt;
&lt;br /&gt;
Note that you either need to give a valid ''key=value pair'', or remove ''[key=value]'' altogether. The alternative &lt;br /&gt;
&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
will result in a file compatible with JOSM, at the cost of a larger download. If unsure, use the first option.&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = &amp;quot;LOWI&amp;quot; (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = &amp;quot;buildings.osm&amp;quot;&lt;br /&gt;
:* 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 &amp;quot;/home/user/fgfs/scenery/TerraSync&amp;quot; .&lt;br /&gt;
:* set PATH_TO_OUTPUT to a ''different'' scenery path, e.g. &amp;quot;/home/user/fgfs/scenery/osm2city&amp;quot; . 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
{{note|Python does not recognize environment variables, please use full paths in the parameters file (no $HOME etc).}}&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
{{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 = &amp;quot;Manual&amp;quot;.}}&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;FgelevCaching&amp;quot;&lt;br /&gt;
:* Set FG_ELEV to your fgelev executable. For example: FG_ELEV = &amp;quot;/usr/local/fg/bin/fgelev&amp;quot; or just FG_ELEV = &amp;quot;fgelev&amp;quot; if fgelev is already in your OS's path.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;Manual&amp;quot;&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FG_ROOT/Nasal/&lt;br /&gt;
:* Open $FG_ROOT/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_ROOT/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;Telnet&amp;quot;&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* Make sure you're in osm2city's directory and run &lt;br /&gt;
&lt;br /&gt;
 python osm2city.py -f LOWI/params.ini. &lt;br /&gt;
&lt;br /&gt;
The parsed OSM data is cached to file LOWI/buildings.osm.pkl which is used on next startup if you set USE_PKL = 1.&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
=== FGElev crashes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
CRITICAL:root:1173 -95.5767 37.0965&lt;br /&gt;
CRITICAL:root:fgelev returned &amp;lt;&amp;gt;, resulting in list index out of range. Did fgelev start OK (Record : 1173)?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The first line is the last input to fgelev. &lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter the line last sent to fgelev. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173 -95.5767 37.0965&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The response should look like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173: 226.793&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. ===&lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
=== Buildings/roads have no texture. I get errors &amp;quot;osgDB ac3d reader: could not find texture &amp;quot;tex/atlas_facades.png&amp;quot;. ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===  ImportError: No module named calc_tile ===&lt;br /&gt;
&lt;br /&gt;
Copy calc_tile.py into batch_processing folder&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
=== Wiki articles ===&lt;br /&gt;
* [[Areas populated with osm2city scenery]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
&lt;br /&gt;
=== Forum topics ===&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625 LOWI city buildings]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;Proposal&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt; Autogen Cities using PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=17598 Procedural buildings in OSM before part of Scenery]&lt;br /&gt;
&lt;br /&gt;
=== Mailing list threads ===&lt;br /&gt;
* [http://sourceforge.net/p/flightgear/mailman/message/30825768/ &amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;Flightgear-devel&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt; osm2city.py]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Project_Hong_Kong&amp;diff=83837</id>
		<title>Project Hong Kong</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Project_Hong_Kong&amp;diff=83837"/>
		<updated>2015-05-02T05:46:16Z</updated>

		<summary type="html">&lt;p&gt;Radi: current status 05/2015&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Project Hong Kong is aimed to improve the Hong Kong scenery in FlightGear.&lt;br /&gt;
&lt;br /&gt;
Forum development thread: http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=24508&amp;amp;start=45#p238855&lt;br /&gt;
&lt;br /&gt;
== Current status (May 2015) ==&lt;br /&gt;
* built custom scenery, using landcover provided by statto and Martin&lt;br /&gt;
* &amp;quot;fixed&amp;quot; airport layout -- had to remove a taxiway because I couldn't create an airport with holes in it.&lt;br /&gt;
* add OSM forest/parks (some prominent ones are still missing)&lt;br /&gt;
* add osm2city buildings and roads&lt;br /&gt;
* add curved approach lights, based on OT-666's LOWI approach lights&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Airports we are planning to work on ==&lt;br /&gt;
* VHHH&lt;br /&gt;
* VHXX&lt;br /&gt;
* VHSK&lt;br /&gt;
&lt;br /&gt;
== Hong Kong terrain improvements ==&lt;br /&gt;
We also will fix the FG terrain in Hong Kong to be close as possible to Real Hong Kong &lt;br /&gt;
&lt;br /&gt;
=== To Do List ===&lt;br /&gt;
* New Models for all airports and sounding areas &lt;br /&gt;
* Adding Detailed markings on runways and taxiways&lt;br /&gt;
* Moving existing models to their correct possessions &lt;br /&gt;
* Replacing inaccurate models &lt;br /&gt;
* Building the Victoria Harbor skyline &lt;br /&gt;
* Building Kowloon City &lt;br /&gt;
* Urbanizing the City &lt;br /&gt;
* Regenerating the Hong Kong terrain using TerraGear&lt;br /&gt;
* Building realistic roads with moving traffic &lt;br /&gt;
* Building realistic tracks with moving trains  &lt;br /&gt;
&lt;br /&gt;
== Volunteers are welcomed ==&lt;br /&gt;
If you wish to help in this project, please contact Pakistan-1 or Radi on the FlightGear Forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Community|Hong Kong]]&lt;br /&gt;
[[Category:Development projects|Hong Kong]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Using_TerraGear&amp;diff=83399</id>
		<title>Using TerraGear</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Using_TerraGear&amp;diff=83399"/>
		<updated>2015-04-11T13:07:16Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Troubleshooting */ apt.dat.gt must be unzipped!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Out of date}}&lt;br /&gt;
&lt;br /&gt;
[[File:Terragearprocesschart.png|thumb|TerraGear Process Flow Chart]]&lt;br /&gt;
The [[TerraGear]] software project supports [[FlightGear]] by creating the files used by FlightGear to represent the elevation and texture of the earth, including airports, cities, fields, forests, rivers, roads and so on. The TerraGear software reads data files containing ground elevation, airport locations and layouts, geographical land-cover data, and more, and produces the scenery files used by FlightGear to represent the terrain of the world.&lt;br /&gt;
&lt;br /&gt;
For simplicity and convenience, most FlightGear users simply download the plug-and-play scenery files from the FlightGear scenery server, or use [[TerraSync]] to automatically download scenery as needed. But there is a variety of reasons you might want to use TerraGear to produce your own terrain files, rather than downloading the standard FlightGear scenery. &lt;br /&gt;
&lt;br /&gt;
For instance, if you use [[WorldEditor]] to modify/improve information about an [[:Category:Airports|airport]]'s taxiway/apron layout, you might wish to see how that modified airport would look in the scenery before deciding you're happy with the results. Maybe the official scenery is too detailed for your slow machine, and you'd like to build terrain using a digital elevation model (DEM) with poorer resolution, to decrease the number of polygons and thus improve your framerates. Or maybe you've got a fantastically fast machine, and you want to build your own terrain using higher-resolution vector data (vmap1, Tiger, osm) to get better roads/streams. For all these reasons, learning how to use TerraGear is a good idea.&lt;br /&gt;
&lt;br /&gt;
== Obtaining TerraGear ==&lt;br /&gt;
You can either build TerraGear yourself, or download a pre-compiled binary. The later is the easiest and advised for starters.&lt;br /&gt;
&lt;br /&gt;
* '''Option 1 - Download TerraGear pre-compiled (recommended for beginners) on Windows'''&lt;br /&gt;
*# Download the latest TerraGear build from [http://flightgear.simpits.org:8080/job/TerraGear-Win-Cmake/lastSuccessfulBuild/artifact/*zip*/archive.zip the FlightGear Build Server].&lt;br /&gt;
*# Create or choose a directory to hold the TerraGear tools. &lt;br /&gt;
*# Unzip the package and move the files from &amp;lt;tt&amp;gt;archive/install/msvc100/TerraGear/bin&amp;lt;/tt&amp;gt; into a sub-directory named &amp;lt;tt&amp;gt;Terragear/&amp;lt;/tt&amp;gt; in the base directory.&lt;br /&gt;
* '''Option 2 - Compile TerraGear from source code''' as explained in [[Building TerraGear|this article]].&lt;br /&gt;
&lt;br /&gt;
''Note:'' You might need default_priorities.txt from the [https://gitorious.org/fg/terragear/blobs/raw/master/src/BuildTiles/Clipper/default_priorities.txt Git repository] or from the archive downloaded from the build server (in the &amp;lt;tt&amp;gt;archive/install/msvc100/TerraGear/share&amp;lt;/tt&amp;gt; subdirectory). See [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;p=77950 this forum thread] for details, &lt;br /&gt;
&lt;br /&gt;
=== GUI tool ===&lt;br /&gt;
A [[TerraGear GUI]] is available for those that would like to use TerraGear without knowing/using the command line options.&lt;br /&gt;
&lt;br /&gt;
== Using TerraGear ==&lt;br /&gt;
First, choose the boundaries for the area of scenery you want to build, in terms of latitude and longitude. The smaller the area of scenery you generate, the smaller the amount of data you will need, and the less CPU time it will take. For example, if you are just interested in generating a new airport layout at 12.3W 34.4N, then simply generating the scenery between 12W 34N and 13W 35N would be sufficient. &lt;br /&gt;
&lt;br /&gt;
Write down the bounding box (minimum and maximum longitude and latitude) for the scenery you want to generate. Remember that West and South are negative - i.e. 4W 10S would be -4, -10. Try not to get mixed up, otherwise you'll end up generating scenery or airports on the other side of the planet! &lt;br /&gt;
&lt;br /&gt;
You'll be dealing with multiple different types of data in various formats. Create a new directory for your scenery work. Within that directory, create the following sub-directories: &lt;br /&gt;
&lt;br /&gt;
* '''data/''' - for raw and pre-processed data (eg elevation files) &lt;br /&gt;
* '''output/''' - for the scenery files you will create &lt;br /&gt;
* '''work/''' - for data that has been processed (eg by shape-decode) and is ready to be munged into scenery &lt;br /&gt;
&lt;br /&gt;
=== Obtaining and processing data ===&lt;br /&gt;
Terragear uses three different kinds of information to generate scenery:&lt;br /&gt;
&lt;br /&gt;
# The elevation of the land (provided by SRTM) &lt;br /&gt;
# The location and layout of airports (provided by apt.dat or a custom .dat) &lt;br /&gt;
# Whether a given lat/lon is sea, land, city, forest, town, road, railway (provided by VMAP0, [[CORINE]] etc. or custom shapefiles) &lt;br /&gt;
&lt;br /&gt;
This article describes how obtain and process each of these types of data in order, and bring it together for use by FlightGear. The order of these steps is important. For example, the airport data step needs the elevation data to determine the elevation of the airports and thus you should start with preparing elevation data.&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;u&amp;gt;Please note:&amp;lt;/u&amp;gt; for inclusion in the official FlightGear scenery, all data &amp;lt;u&amp;gt;must&amp;lt;/u&amp;gt; come from [[GNU GPL]] compatible sources!'''&lt;br /&gt;
&lt;br /&gt;
==== Elevation data ====&lt;br /&gt;
The best worldwide elevation data currently available is from the Shuttle Radar Topography Mission (SRTM). There are two types of SRTM data: &lt;br /&gt;
* Highly accurate 1-arcsecond resolution data, known as SRTM-1, for the USA &lt;br /&gt;
* Less accurate 3-arcsecond data, known as SRTM-3, for the rest of the world. &lt;br /&gt;
From now on, we'll assume you are using SRTM-3 data. Unless otherwise noted, the process for SRTM-1 is identical.&lt;br /&gt;
&lt;br /&gt;
You can download the appropriate data from http://dds.cr.usgs.gov/srtm/version2_1/. You want all .hgt.zip files covering your region of interest. Depending on the size of your scenery, there may be quite a few. Download them to &amp;lt;tt&amp;gt;data/SRTM-1/&amp;lt;/tt&amp;gt;(or SRTM-3/SRTM-30 depending on the type you downloaded) in your base directory. (Genapts looks for a few known, hardcoded elevation data directories in its working directory. SRTM-30 is one of them and this is the least confusing in that list. Note: W.E.F. 31st July 2010, the genapts tool now also looks for SRTM-1/SRTM-3 directories. If you are using an older version, please supply the directories using --dem-path).&lt;br /&gt;
&lt;br /&gt;
Now we've got the data, we need to convert it into something of use to TerraGear. First, you need to unzip each of the .hgt files. After that, open the commandline (Windows: &amp;lt;tt&amp;gt;Start &amp;gt; Run &amp;gt; cmd.exe&amp;lt;/tt&amp;gt;) and change into the base directory (&amp;lt;tt&amp;gt;cd .../.../TerraGear&amp;lt;/tt&amp;gt;). &lt;br /&gt;
* '''NOTE:''' If you want to create a batch-file, replace &amp;lt;tt&amp;gt;%f&amp;lt;/tt&amp;gt; with &amp;lt;tt&amp;gt;%%f&amp;lt;/tt&amp;gt;, see [http://technet.microsoft.com/en-us/library/bb490909.aspx]&lt;br /&gt;
* '''NOTE:''' For SRTM-1 data, replace the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; by a &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt; in the first argument to hgtchop&lt;br /&gt;
&lt;br /&gt;
'''Note: According to [[TerraGear_Documentation]], hgtchop is superseded by gdalchop.'''&lt;br /&gt;
&lt;br /&gt;
For Windows:&lt;br /&gt;
 for %f in (.\data\SRTM-3\*.hgt) do .\Terragear\hgtchop.exe 3 %f .\work\SRTM-3&lt;br /&gt;
or&lt;br /&gt;
 for %f in (.\data\SRTM-3\*.hgt) do .\Terragear\hgtchop.exe 3 .\data\SRTM-3\%f .\work\SRTM-3&lt;br /&gt;
&lt;br /&gt;
For Linux:&lt;br /&gt;
 for i in $PWD/data/SRTM-3/*.hgt; do ./Terragear/hgtchop 3 $i $PWD/work/SRTM-3; done&lt;br /&gt;
&lt;br /&gt;
Now you will get a lot of .arr.gz files in your work/SRTM-3/ directory. We need to convert these to the .fit.gz format. Run the commandline again with&lt;br /&gt;
* '''NOTE:''' the space and dot at the and are important!&lt;br /&gt;
&lt;br /&gt;
For Windows:&lt;br /&gt;
 .\Terragear\terrafit.exe work\SRTM-3&lt;br /&gt;
&lt;br /&gt;
For Linux:&lt;br /&gt;
 ./Terragear/terrafit work/SRTM-3&lt;br /&gt;
&lt;br /&gt;
==== Airport data ====&lt;br /&gt;
Now we've got elevation data, we can generate our airports. First, create a &amp;lt;tt&amp;gt;data/airports/&amp;lt;/tt&amp;gt; directory and copy in your apt.dat file. This may be direct from your FlightGear data package (though you'll need to unzip it), or it may be one that you've modified with [[WorldEditor]]. &lt;br /&gt;
&lt;br /&gt;
The command to create airports is &amp;quot;genapts850&amp;quot;. Run it without any arguments to see the various command-line options. &lt;br /&gt;
&lt;br /&gt;
If it is simply run with a specified apt.dat and work directory, it will generate airport layouts for every airport in the file, which can take a long time. &lt;br /&gt;
&lt;br /&gt;
If you are just creating a single airport and you know the ICAO ID (e.g. [[KSFO]], EGPH, EG32), use is as follows from your root scenery directory (i.e. the directory above your data, work and output directories). If you use an apt.dat file with one single airport in it you should omit the &amp;quot;--airport&amp;quot; parameter. &lt;br /&gt;
&lt;br /&gt;
 genapts850 --input=data/airports/apt.dat --work=./work --airport=&amp;lt;AIRPORT_ID&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are generating a larger set of scenery, then you can specify the minimum and maximum longitude and latitude. &lt;br /&gt;
&lt;br /&gt;
Genapts will create two sub-directories in your work directory:&lt;br /&gt;
* &amp;lt;tt&amp;gt;AirportArea/&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;AirportObj/&amp;lt;/tt&amp;gt;&lt;br /&gt;
These contain the definitions of the airport layout and any objects present (e.g. windsocks and beacons). &lt;br /&gt;
&lt;br /&gt;
==== Landuse data ====&lt;br /&gt;
The final piece of data we need to generate is the landuse data. In general, this is taken from the VMAP0 dataset as shapefiles from the scenery database mapserver, but other sources can also be used.&lt;br /&gt;
&lt;br /&gt;
The landuse data can be split into a number of different types:&lt;br /&gt;
* '''Landmass''' separates the land from the sea. It can be used as a mask for all other data. The most commonly used is the VMAP0 Landmass, but GSHHS can also be used. When running tg-construct with &amp;lt;code&amp;gt;--ignore-landmass&amp;lt;/code&amp;gt;, all input shapefiles will be taken into consideration, so no landmass mask is required then.&lt;br /&gt;
* '''Land use data:''' defines whether a piece of land is forest, urban, sand, lava, glacier etc. These are usually VMAP0 data, defined as polygons.&lt;br /&gt;
* '''Line data:''' includes railroads, streams, roads. Typically VMAP0, but also Open Street Map for roads.&lt;br /&gt;
* '''Point data:''' is currently only used for defining towns.&lt;br /&gt;
 &lt;br /&gt;
By far the easiest way to get this data is to download shapefiles from the wonderful [http://mapserver.flightgear.org MapServer]. The MapServer lets you download the shapefiles for any selected scenery area. Click on the &amp;quot;Download Shapefiles&amp;quot; link (or go direct: http://mapserver.flightgear.org/download.psp). Enter in the bounding box of the scenery you want to generate, select the type of shapefile data you want, and click download. &lt;br /&gt;
&lt;br /&gt;
'''Layer differences'''&lt;br /&gt;
&lt;br /&gt;
* '''v0''': global coverage, low detail. This is &amp;quot;the last resort&amp;quot;, but unfortunately it is the only layer that covers the entire world.&lt;br /&gt;
* '''cs''': it is v0 with some contributions someone did in the past. Get this instead of v0.&lt;br /&gt;
* '''v1''': only parts of some countries available, higher detail than v0.&lt;br /&gt;
* '''clc06''': European '''only'''. Very high detail, this is the preferred choice for an European country.&lt;br /&gt;
* '''osm''': global coverage, high resolution but very low detail. This means: if you are interested in an area out of Europe and forests are defined in OpenStreetMaps for your area, this is going to be the best data source. If forests are not defined, you will get a dull, neverending DEFAULT landclass. OSM provides the best coastline and I encourage you to use this coastline even in Europe. [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=25549&amp;amp;sid=d501cb651ef9e34ca9dc8fae429d51ab&amp;amp;p=234002#p234002]&lt;br /&gt;
&lt;br /&gt;
{{caution|Make sure each shape file is in its own directory whether you download shape files or create your own otherwise the ogrDecode step will fail.}}&lt;br /&gt;
Download each shapefile into a seperate (!) &amp;lt;tt&amp;gt;data/shapefiles/...&amp;lt;/tt&amp;gt; directory. So, for v0_landmass, you would end up with &amp;lt;tt&amp;gt;data/shapefiles/v0_landmass/v0_landmass.shp&amp;lt;/tt&amp;gt; etc.&lt;br /&gt;
&lt;br /&gt;
You can load these shapefiles into a GIS editor such as [[QGIS]] or GRASS to view and edit. This is a good idea to verify you have the correct files! Later on, you can experiment with replacing various shapefiles with other versions (GSHHS for coastline, OSM for roads etc.).&lt;br /&gt;
&lt;br /&gt;
The next step is to decode the shape-files into TerraGear format using the '''ogr-decode''' command. &lt;br /&gt;
&lt;br /&gt;
There are three important command-line arguments for ogr-decode:&lt;br /&gt;
* the destination directory for the decoded data&lt;br /&gt;
* the location of the shapefile's directory&lt;br /&gt;
* the material type&lt;br /&gt;
&lt;br /&gt;
Each shape-file corresponds with one of the material types defined in the materials.xml files. The mapping is pretty obvious. For example, v0_mixedcroppasturecover maps to MixedCropPastureCover. Note that the material types are case-sensitive, so it is a good idea to refer to the &amp;lt;tt&amp;gt;[[$FG_ROOT]]/Materials/default/materials.xml&amp;lt;/tt&amp;gt; file (&amp;lt;tt&amp;gt;[[$FG ROOT]]/materials.xml&amp;lt;/tt&amp;gt; in FlightGear 2.6.0 and older) to hand so you can check. The exception is landmass, which - when used - MUST be mapped onto the type Default.&lt;br /&gt;
&lt;br /&gt;
Additionally, there are a number of optional arguments, to indicate the width of line data (for roads, streams, railways), how large to make point data (for towns) and how long the longest straight line is allowed to be.&lt;br /&gt;
&lt;br /&gt;
For example, to decode the v0_landmass shapefile, you use the following command:&lt;br /&gt;
&lt;br /&gt;
 ogr-decode --max-segment 500 --area-type Default work/Default data/shapefiles/v0_landmass&lt;br /&gt;
&lt;br /&gt;
To create streams of width 10 metres&lt;br /&gt;
&lt;br /&gt;
 ogr-decode --max-segment 500 --line-width 10 --area-type Stream work/Stream data/shapefiles/v0_stream&lt;br /&gt;
&lt;br /&gt;
To generate some towns about 1km across&lt;br /&gt;
&lt;br /&gt;
 ogr-decode --point-width 500 --area-type Town work/Town data/shapefiles/v0_town&lt;br /&gt;
&lt;br /&gt;
Run this command for each shapefile in the set.&lt;br /&gt;
&lt;br /&gt;
== Generating scenery ==&lt;br /&gt;
You will now have a work directory, with subdirectories like:&lt;br /&gt;
{|&lt;br /&gt;
|&lt;br /&gt;
: AirportArea&lt;br /&gt;
: AirportObj&lt;br /&gt;
: Bog&lt;br /&gt;
: Default&lt;br /&gt;
: DryCropPastureCover&lt;br /&gt;
: EvergreenBroadCover&lt;br /&gt;
: GrassCover&lt;br /&gt;
: IrrCropPastureCover&lt;br /&gt;
: Lake&lt;br /&gt;
: Marsh&lt;br /&gt;
: MixedCropPastureCover&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
: MixedForestCover&lt;br /&gt;
: Railroad&lt;br /&gt;
: Road&lt;br /&gt;
: Sand&lt;br /&gt;
: ScrubCover&lt;br /&gt;
: Shared&lt;br /&gt;
: SRTM-3&lt;br /&gt;
: Stream&lt;br /&gt;
: Town&lt;br /&gt;
: Urban&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now we can actually generate the scenery. This is done by the tg-construct command. Run the command with &amp;lt;code&amp;gt;--help&amp;lt;/code&amp;gt; to get usage information. &lt;br /&gt;
&lt;br /&gt;
We need to define:&lt;br /&gt;
* The work (--work-dir) and output (--output-dir) directories.&lt;br /&gt;
** '''Note''' about the output directory: this must point to a &amp;lt;tt&amp;gt;Terrain/&amp;lt;/tt&amp;gt; directory, else recent FlightGear versions will be unable to load the terrain.&lt;br /&gt;
* The center of the scenery we want to generate (--lat, --lon).&lt;br /&gt;
* The radius (--xdist, --ydist) from which to generate.&lt;br /&gt;
* All the work directories to include in the scenery.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{{Pre2|&amp;lt;nowiki&amp;gt;tg-construct --work-dir=./work --output-dir=./output/Terrain --min-lon=55 --max-lon=57 --min-lat=60 --max-lat=62 AirportArea SRTM-3 AirportObj Default Stream Bog IrrCropPastureCover Town Lake Urban Railroad DryCropPastureCover Road EvergreenBroadCover Marsh Sand MixedCropPastureCover ScrubCover GrassCover MixedForestCover&amp;lt;/nowiki&amp;gt; }}&lt;br /&gt;
&lt;br /&gt;
When this finishes, the output directory will contain a scenery sub-tree. Point to it by setting either [[$FG_SCENERY]] or by using the --fg-scenery command-line option to fgfs, and give your new scenery a try!&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
Below is a list of common problems and solutions. If in doubt - Google it. Many problems (particularly when compiling TerraGear) have been hit before: &lt;br /&gt;
&lt;br /&gt;
* Crashes in genapts. Sometimes genapts will crash when dealing with a particular airport. In that case, try running it again with the --start-id argument to start at the airport it failed on, and the --nudge argument which tries to nudge the calculations in the right direction. &lt;br /&gt;
* tg-construct Killed. The tg-construct process may kill itself if it is using too many system resources. Increasing the values for setrlimit in src/BuildTiles/Main/main.cxx is the best solution. &lt;br /&gt;
* tg-construct silently stops immediately without an error and nothing goes to the &amp;quot;output&amp;quot; directory: make sure that lon/lat values correspond to tiles boundaries. See [[Tile_Index_Scheme]]&lt;br /&gt;
* Airports appear in the bottom of holes, or there are spaces between the airports and the scenery. This typically happens when genapts is unable to find the correct elevation data, or the elevation data changed between running genapts and shape-decode. Try generating a single airport in your scenery area using genapts, and look at the output. In particular, make sure there is a work/SRTM-3 directory. &lt;br /&gt;
* Only the airports appear in the scenery. There are three typical causes for this: &lt;br /&gt;
** You didn't download the correct shapefiles for the area. &lt;br /&gt;
** You haven't run shape-decode on the v0_landmass shapefile as Default &lt;br /&gt;
** You didn't include the correct directories in tg-construct. &lt;br /&gt;
* Generate scenery includes data removed from the shapefiles. If you are editing shapefiles, you need to delete the appropriate work subdirectory before running shape-decode. Otherwise your changes will be in addition to those already present. &lt;br /&gt;
* All the scenery is flat and at sea-level. Typically this is because you didn't include any elevation data in your tg-construct command. Make sure there's a STRM-3 directory included in the command-line. &lt;br /&gt;
* All terrain copies the material of a certain shapefile. You have probably forgotten to put each of the downloaded shapefiles in a seperate directory inside the Data/shapefiles directory.&lt;br /&gt;
* genapts850 never passes the stage &amp;quot;Adding airport &amp;lt;ICAO&amp;gt; to parse list&amp;quot;: did you unzip apt.dat.gz?&lt;br /&gt;
&lt;br /&gt;
== General comments from forum discussion ==&lt;br /&gt;
{{cquote|f-ojac, you are right, the parameters used in scenery 2.0 were &amp;quot;-e 5 -x 20000&amp;quot; according to the wiki. I don't know why I had the impression these parameters were not public. In any case, it does not matter because using the same parameters will create closer results, but they are not guaranteed to be the same.&lt;br /&gt;
&lt;br /&gt;
The parameters used to create scenery 2,0 seem to be:&lt;br /&gt;
&lt;br /&gt;
-m ??: the minimum number of vertices in a tile. In FG, any number bellow 100 (and probably, any number below 1000) will do. I don't think there is any surface on the world perfectly flat for several kilometers. The default value is 50 and I'm sure is ok for any normal use.&lt;br /&gt;
-e 5: the max allowed error for elevation, in meters. That is: if terrafit calculates a simplification of the terrain where all points are at most this distance from the real elevation, no more vertices are created. The default value is 40 meters: a point may have an elevation error up to 40m (~100ft) High values for this parameter create less detailed mountains and smaller (in disk size) and more efficient (in FPS) terrain.&lt;br /&gt;
-x 20000: the max number of vertices in a tile. If this number of vertices is reached, terrafit stop regardless the max error of the vertices. The default value is 1000&lt;br /&gt;
&lt;br /&gt;
Keep in mind you can set values that do not make sense:&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;-e 1 -x 100&amp;quot; does not make sense because it is going to be impossible to calculate errors less than 1 meters using only 100 vertices. The max number of vertices will be reached always and the max error will be probably ignored.&lt;br /&gt;
* &amp;quot;-e 300 -x 20000&amp;quot; does not make sense, tiles are going to use for sure much less vertices than 20,000 because you are allowing huge elevation errors.&lt;br /&gt;
&lt;br /&gt;
If you want an efficient scenery (less vertices), use the default values &amp;quot;-e 40 -x 1000&amp;quot;. If you want more accurate elevation at the cost of disk space and FPS, use values similar to scenery 2.0 (&amp;quot;-e 5 -x 20000&amp;quot;) Anything in the middle will produce performance and disk use in the middle.&amp;lt;ref&amp;gt;{{cite web |url=http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=24681#p225363 &lt;br /&gt;
|title=Re: Terrasync Help (surprinsingly!) :)&lt;br /&gt;
|author=ludomotico |date= Mon Nov 24, 2014 4:28 am}}&amp;lt;/ref&amp;gt;|ludomotico}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
* [[Howto:Create custom terrain]], editing/making terrain data.&lt;br /&gt;
* [[TerraGear CORINE]], building terrain from CORINE data.&lt;br /&gt;
* [[TerraGear Documentation]], using TerraGear details.&lt;br /&gt;
&lt;br /&gt;
{{Terra}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery enhancement|TerraGear, Using]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Utiliser TerraGear]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Using_TerraGear&amp;diff=83398</id>
		<title>Using TerraGear</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Using_TerraGear&amp;diff=83398"/>
		<updated>2015-04-11T13:04:26Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Elevation data */ hgtchop is deprecated?&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Out of date}}&lt;br /&gt;
&lt;br /&gt;
[[File:Terragearprocesschart.png|thumb|TerraGear Process Flow Chart]]&lt;br /&gt;
The [[TerraGear]] software project supports [[FlightGear]] by creating the files used by FlightGear to represent the elevation and texture of the earth, including airports, cities, fields, forests, rivers, roads and so on. The TerraGear software reads data files containing ground elevation, airport locations and layouts, geographical land-cover data, and more, and produces the scenery files used by FlightGear to represent the terrain of the world.&lt;br /&gt;
&lt;br /&gt;
For simplicity and convenience, most FlightGear users simply download the plug-and-play scenery files from the FlightGear scenery server, or use [[TerraSync]] to automatically download scenery as needed. But there is a variety of reasons you might want to use TerraGear to produce your own terrain files, rather than downloading the standard FlightGear scenery. &lt;br /&gt;
&lt;br /&gt;
For instance, if you use [[WorldEditor]] to modify/improve information about an [[:Category:Airports|airport]]'s taxiway/apron layout, you might wish to see how that modified airport would look in the scenery before deciding you're happy with the results. Maybe the official scenery is too detailed for your slow machine, and you'd like to build terrain using a digital elevation model (DEM) with poorer resolution, to decrease the number of polygons and thus improve your framerates. Or maybe you've got a fantastically fast machine, and you want to build your own terrain using higher-resolution vector data (vmap1, Tiger, osm) to get better roads/streams. For all these reasons, learning how to use TerraGear is a good idea.&lt;br /&gt;
&lt;br /&gt;
== Obtaining TerraGear ==&lt;br /&gt;
You can either build TerraGear yourself, or download a pre-compiled binary. The later is the easiest and advised for starters.&lt;br /&gt;
&lt;br /&gt;
* '''Option 1 - Download TerraGear pre-compiled (recommended for beginners) on Windows'''&lt;br /&gt;
*# Download the latest TerraGear build from [http://flightgear.simpits.org:8080/job/TerraGear-Win-Cmake/lastSuccessfulBuild/artifact/*zip*/archive.zip the FlightGear Build Server].&lt;br /&gt;
*# Create or choose a directory to hold the TerraGear tools. &lt;br /&gt;
*# Unzip the package and move the files from &amp;lt;tt&amp;gt;archive/install/msvc100/TerraGear/bin&amp;lt;/tt&amp;gt; into a sub-directory named &amp;lt;tt&amp;gt;Terragear/&amp;lt;/tt&amp;gt; in the base directory.&lt;br /&gt;
* '''Option 2 - Compile TerraGear from source code''' as explained in [[Building TerraGear|this article]].&lt;br /&gt;
&lt;br /&gt;
''Note:'' You might need default_priorities.txt from the [https://gitorious.org/fg/terragear/blobs/raw/master/src/BuildTiles/Clipper/default_priorities.txt Git repository] or from the archive downloaded from the build server (in the &amp;lt;tt&amp;gt;archive/install/msvc100/TerraGear/share&amp;lt;/tt&amp;gt; subdirectory). See [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;p=77950 this forum thread] for details, &lt;br /&gt;
&lt;br /&gt;
=== GUI tool ===&lt;br /&gt;
A [[TerraGear GUI]] is available for those that would like to use TerraGear without knowing/using the command line options.&lt;br /&gt;
&lt;br /&gt;
== Using TerraGear ==&lt;br /&gt;
First, choose the boundaries for the area of scenery you want to build, in terms of latitude and longitude. The smaller the area of scenery you generate, the smaller the amount of data you will need, and the less CPU time it will take. For example, if you are just interested in generating a new airport layout at 12.3W 34.4N, then simply generating the scenery between 12W 34N and 13W 35N would be sufficient. &lt;br /&gt;
&lt;br /&gt;
Write down the bounding box (minimum and maximum longitude and latitude) for the scenery you want to generate. Remember that West and South are negative - i.e. 4W 10S would be -4, -10. Try not to get mixed up, otherwise you'll end up generating scenery or airports on the other side of the planet! &lt;br /&gt;
&lt;br /&gt;
You'll be dealing with multiple different types of data in various formats. Create a new directory for your scenery work. Within that directory, create the following sub-directories: &lt;br /&gt;
&lt;br /&gt;
* '''data/''' - for raw and pre-processed data (eg elevation files) &lt;br /&gt;
* '''output/''' - for the scenery files you will create &lt;br /&gt;
* '''work/''' - for data that has been processed (eg by shape-decode) and is ready to be munged into scenery &lt;br /&gt;
&lt;br /&gt;
=== Obtaining and processing data ===&lt;br /&gt;
Terragear uses three different kinds of information to generate scenery:&lt;br /&gt;
&lt;br /&gt;
# The elevation of the land (provided by SRTM) &lt;br /&gt;
# The location and layout of airports (provided by apt.dat or a custom .dat) &lt;br /&gt;
# Whether a given lat/lon is sea, land, city, forest, town, road, railway (provided by VMAP0, [[CORINE]] etc. or custom shapefiles) &lt;br /&gt;
&lt;br /&gt;
This article describes how obtain and process each of these types of data in order, and bring it together for use by FlightGear. The order of these steps is important. For example, the airport data step needs the elevation data to determine the elevation of the airports and thus you should start with preparing elevation data.&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;u&amp;gt;Please note:&amp;lt;/u&amp;gt; for inclusion in the official FlightGear scenery, all data &amp;lt;u&amp;gt;must&amp;lt;/u&amp;gt; come from [[GNU GPL]] compatible sources!'''&lt;br /&gt;
&lt;br /&gt;
==== Elevation data ====&lt;br /&gt;
The best worldwide elevation data currently available is from the Shuttle Radar Topography Mission (SRTM). There are two types of SRTM data: &lt;br /&gt;
* Highly accurate 1-arcsecond resolution data, known as SRTM-1, for the USA &lt;br /&gt;
* Less accurate 3-arcsecond data, known as SRTM-3, for the rest of the world. &lt;br /&gt;
From now on, we'll assume you are using SRTM-3 data. Unless otherwise noted, the process for SRTM-1 is identical.&lt;br /&gt;
&lt;br /&gt;
You can download the appropriate data from http://dds.cr.usgs.gov/srtm/version2_1/. You want all .hgt.zip files covering your region of interest. Depending on the size of your scenery, there may be quite a few. Download them to &amp;lt;tt&amp;gt;data/SRTM-1/&amp;lt;/tt&amp;gt;(or SRTM-3/SRTM-30 depending on the type you downloaded) in your base directory. (Genapts looks for a few known, hardcoded elevation data directories in its working directory. SRTM-30 is one of them and this is the least confusing in that list. Note: W.E.F. 31st July 2010, the genapts tool now also looks for SRTM-1/SRTM-3 directories. If you are using an older version, please supply the directories using --dem-path).&lt;br /&gt;
&lt;br /&gt;
Now we've got the data, we need to convert it into something of use to TerraGear. First, you need to unzip each of the .hgt files. After that, open the commandline (Windows: &amp;lt;tt&amp;gt;Start &amp;gt; Run &amp;gt; cmd.exe&amp;lt;/tt&amp;gt;) and change into the base directory (&amp;lt;tt&amp;gt;cd .../.../TerraGear&amp;lt;/tt&amp;gt;). &lt;br /&gt;
* '''NOTE:''' If you want to create a batch-file, replace &amp;lt;tt&amp;gt;%f&amp;lt;/tt&amp;gt; with &amp;lt;tt&amp;gt;%%f&amp;lt;/tt&amp;gt;, see [http://technet.microsoft.com/en-us/library/bb490909.aspx]&lt;br /&gt;
* '''NOTE:''' For SRTM-1 data, replace the &amp;lt;tt&amp;gt;3&amp;lt;/tt&amp;gt; by a &amp;lt;tt&amp;gt;1&amp;lt;/tt&amp;gt; in the first argument to hgtchop&lt;br /&gt;
&lt;br /&gt;
'''Note: According to [[TerraGear_Documentation]], hgtchop is superseded by gdalchop.'''&lt;br /&gt;
&lt;br /&gt;
For Windows:&lt;br /&gt;
 for %f in (.\data\SRTM-3\*.hgt) do .\Terragear\hgtchop.exe 3 %f .\work\SRTM-3&lt;br /&gt;
or&lt;br /&gt;
 for %f in (.\data\SRTM-3\*.hgt) do .\Terragear\hgtchop.exe 3 .\data\SRTM-3\%f .\work\SRTM-3&lt;br /&gt;
&lt;br /&gt;
For Linux:&lt;br /&gt;
 for i in $PWD/data/SRTM-3/*.hgt; do ./Terragear/hgtchop 3 $i $PWD/work/SRTM-3; done&lt;br /&gt;
&lt;br /&gt;
Now you will get a lot of .arr.gz files in your work/SRTM-3/ directory. We need to convert these to the .fit.gz format. Run the commandline again with&lt;br /&gt;
* '''NOTE:''' the space and dot at the and are important!&lt;br /&gt;
&lt;br /&gt;
For Windows:&lt;br /&gt;
 .\Terragear\terrafit.exe work\SRTM-3&lt;br /&gt;
&lt;br /&gt;
For Linux:&lt;br /&gt;
 ./Terragear/terrafit work/SRTM-3&lt;br /&gt;
&lt;br /&gt;
==== Airport data ====&lt;br /&gt;
Now we've got elevation data, we can generate our airports. First, create a &amp;lt;tt&amp;gt;data/airports/&amp;lt;/tt&amp;gt; directory and copy in your apt.dat file. This may be direct from your FlightGear data package (though you'll need to unzip it), or it may be one that you've modified with [[WorldEditor]]. &lt;br /&gt;
&lt;br /&gt;
The command to create airports is &amp;quot;genapts850&amp;quot;. Run it without any arguments to see the various command-line options. &lt;br /&gt;
&lt;br /&gt;
If it is simply run with a specified apt.dat and work directory, it will generate airport layouts for every airport in the file, which can take a long time. &lt;br /&gt;
&lt;br /&gt;
If you are just creating a single airport and you know the ICAO ID (e.g. [[KSFO]], EGPH, EG32), use is as follows from your root scenery directory (i.e. the directory above your data, work and output directories). If you use an apt.dat file with one single airport in it you should omit the &amp;quot;--airport&amp;quot; parameter. &lt;br /&gt;
&lt;br /&gt;
 genapts850 --input=data/airports/apt.dat --work=./work --airport=&amp;lt;AIRPORT_ID&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are generating a larger set of scenery, then you can specify the minimum and maximum longitude and latitude. &lt;br /&gt;
&lt;br /&gt;
Genapts will create two sub-directories in your work directory:&lt;br /&gt;
* &amp;lt;tt&amp;gt;AirportArea/&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;AirportObj/&amp;lt;/tt&amp;gt;&lt;br /&gt;
These contain the definitions of the airport layout and any objects present (e.g. windsocks and beacons). &lt;br /&gt;
&lt;br /&gt;
==== Landuse data ====&lt;br /&gt;
The final piece of data we need to generate is the landuse data. In general, this is taken from the VMAP0 dataset as shapefiles from the scenery database mapserver, but other sources can also be used.&lt;br /&gt;
&lt;br /&gt;
The landuse data can be split into a number of different types:&lt;br /&gt;
* '''Landmass''' separates the land from the sea. It can be used as a mask for all other data. The most commonly used is the VMAP0 Landmass, but GSHHS can also be used. When running tg-construct with &amp;lt;code&amp;gt;--ignore-landmass&amp;lt;/code&amp;gt;, all input shapefiles will be taken into consideration, so no landmass mask is required then.&lt;br /&gt;
* '''Land use data:''' defines whether a piece of land is forest, urban, sand, lava, glacier etc. These are usually VMAP0 data, defined as polygons.&lt;br /&gt;
* '''Line data:''' includes railroads, streams, roads. Typically VMAP0, but also Open Street Map for roads.&lt;br /&gt;
* '''Point data:''' is currently only used for defining towns.&lt;br /&gt;
 &lt;br /&gt;
By far the easiest way to get this data is to download shapefiles from the wonderful [http://mapserver.flightgear.org MapServer]. The MapServer lets you download the shapefiles for any selected scenery area. Click on the &amp;quot;Download Shapefiles&amp;quot; link (or go direct: http://mapserver.flightgear.org/download.psp). Enter in the bounding box of the scenery you want to generate, select the type of shapefile data you want, and click download. &lt;br /&gt;
&lt;br /&gt;
'''Layer differences'''&lt;br /&gt;
&lt;br /&gt;
* '''v0''': global coverage, low detail. This is &amp;quot;the last resort&amp;quot;, but unfortunately it is the only layer that covers the entire world.&lt;br /&gt;
* '''cs''': it is v0 with some contributions someone did in the past. Get this instead of v0.&lt;br /&gt;
* '''v1''': only parts of some countries available, higher detail than v0.&lt;br /&gt;
* '''clc06''': European '''only'''. Very high detail, this is the preferred choice for an European country.&lt;br /&gt;
* '''osm''': global coverage, high resolution but very low detail. This means: if you are interested in an area out of Europe and forests are defined in OpenStreetMaps for your area, this is going to be the best data source. If forests are not defined, you will get a dull, neverending DEFAULT landclass. OSM provides the best coastline and I encourage you to use this coastline even in Europe. [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=25549&amp;amp;sid=d501cb651ef9e34ca9dc8fae429d51ab&amp;amp;p=234002#p234002]&lt;br /&gt;
&lt;br /&gt;
{{caution|Make sure each shape file is in its own directory whether you download shape files or create your own otherwise the ogrDecode step will fail.}}&lt;br /&gt;
Download each shapefile into a seperate (!) &amp;lt;tt&amp;gt;data/shapefiles/...&amp;lt;/tt&amp;gt; directory. So, for v0_landmass, you would end up with &amp;lt;tt&amp;gt;data/shapefiles/v0_landmass/v0_landmass.shp&amp;lt;/tt&amp;gt; etc.&lt;br /&gt;
&lt;br /&gt;
You can load these shapefiles into a GIS editor such as [[QGIS]] or GRASS to view and edit. This is a good idea to verify you have the correct files! Later on, you can experiment with replacing various shapefiles with other versions (GSHHS for coastline, OSM for roads etc.).&lt;br /&gt;
&lt;br /&gt;
The next step is to decode the shape-files into TerraGear format using the '''ogr-decode''' command. &lt;br /&gt;
&lt;br /&gt;
There are three important command-line arguments for ogr-decode:&lt;br /&gt;
* the destination directory for the decoded data&lt;br /&gt;
* the location of the shapefile's directory&lt;br /&gt;
* the material type&lt;br /&gt;
&lt;br /&gt;
Each shape-file corresponds with one of the material types defined in the materials.xml files. The mapping is pretty obvious. For example, v0_mixedcroppasturecover maps to MixedCropPastureCover. Note that the material types are case-sensitive, so it is a good idea to refer to the &amp;lt;tt&amp;gt;[[$FG_ROOT]]/Materials/default/materials.xml&amp;lt;/tt&amp;gt; file (&amp;lt;tt&amp;gt;[[$FG ROOT]]/materials.xml&amp;lt;/tt&amp;gt; in FlightGear 2.6.0 and older) to hand so you can check. The exception is landmass, which - when used - MUST be mapped onto the type Default.&lt;br /&gt;
&lt;br /&gt;
Additionally, there are a number of optional arguments, to indicate the width of line data (for roads, streams, railways), how large to make point data (for towns) and how long the longest straight line is allowed to be.&lt;br /&gt;
&lt;br /&gt;
For example, to decode the v0_landmass shapefile, you use the following command:&lt;br /&gt;
&lt;br /&gt;
 ogr-decode --max-segment 500 --area-type Default work/Default data/shapefiles/v0_landmass&lt;br /&gt;
&lt;br /&gt;
To create streams of width 10 metres&lt;br /&gt;
&lt;br /&gt;
 ogr-decode --max-segment 500 --line-width 10 --area-type Stream work/Stream data/shapefiles/v0_stream&lt;br /&gt;
&lt;br /&gt;
To generate some towns about 1km across&lt;br /&gt;
&lt;br /&gt;
 ogr-decode --point-width 500 --area-type Town work/Town data/shapefiles/v0_town&lt;br /&gt;
&lt;br /&gt;
Run this command for each shapefile in the set.&lt;br /&gt;
&lt;br /&gt;
== Generating scenery ==&lt;br /&gt;
You will now have a work directory, with subdirectories like:&lt;br /&gt;
{|&lt;br /&gt;
|&lt;br /&gt;
: AirportArea&lt;br /&gt;
: AirportObj&lt;br /&gt;
: Bog&lt;br /&gt;
: Default&lt;br /&gt;
: DryCropPastureCover&lt;br /&gt;
: EvergreenBroadCover&lt;br /&gt;
: GrassCover&lt;br /&gt;
: IrrCropPastureCover&lt;br /&gt;
: Lake&lt;br /&gt;
: Marsh&lt;br /&gt;
: MixedCropPastureCover&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
: MixedForestCover&lt;br /&gt;
: Railroad&lt;br /&gt;
: Road&lt;br /&gt;
: Sand&lt;br /&gt;
: ScrubCover&lt;br /&gt;
: Shared&lt;br /&gt;
: SRTM-3&lt;br /&gt;
: Stream&lt;br /&gt;
: Town&lt;br /&gt;
: Urban&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now we can actually generate the scenery. This is done by the tg-construct command. Run the command with &amp;lt;code&amp;gt;--help&amp;lt;/code&amp;gt; to get usage information. &lt;br /&gt;
&lt;br /&gt;
We need to define:&lt;br /&gt;
* The work (--work-dir) and output (--output-dir) directories.&lt;br /&gt;
** '''Note''' about the output directory: this must point to a &amp;lt;tt&amp;gt;Terrain/&amp;lt;/tt&amp;gt; directory, else recent FlightGear versions will be unable to load the terrain.&lt;br /&gt;
* The center of the scenery we want to generate (--lat, --lon).&lt;br /&gt;
* The radius (--xdist, --ydist) from which to generate.&lt;br /&gt;
* All the work directories to include in the scenery.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{{Pre2|&amp;lt;nowiki&amp;gt;tg-construct --work-dir=./work --output-dir=./output/Terrain --min-lon=55 --max-lon=57 --min-lat=60 --max-lat=62 AirportArea SRTM-3 AirportObj Default Stream Bog IrrCropPastureCover Town Lake Urban Railroad DryCropPastureCover Road EvergreenBroadCover Marsh Sand MixedCropPastureCover ScrubCover GrassCover MixedForestCover&amp;lt;/nowiki&amp;gt; }}&lt;br /&gt;
&lt;br /&gt;
When this finishes, the output directory will contain a scenery sub-tree. Point to it by setting either [[$FG_SCENERY]] or by using the --fg-scenery command-line option to fgfs, and give your new scenery a try!&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
Below is a list of common problems and solutions. If in doubt - Google it. Many problems (particularly when compiling TerraGear) have been hit before: &lt;br /&gt;
&lt;br /&gt;
* Crashes in genapts. Sometimes genapts will crash when dealing with a particular airport. In that case, try running it again with the --start-id argument to start at the airport it failed on, and the --nudge argument which tries to nudge the calculations in the right direction. &lt;br /&gt;
* tg-construct Killed. The tg-construct process may kill itself if it is using too many system resources. Increasing the values for setrlimit in src/BuildTiles/Main/main.cxx is the best solution. &lt;br /&gt;
* tg-construct silently stops immediately without an error and nothing goes to the &amp;quot;output&amp;quot; directory: make sure that lon/lat values correspond to tiles boundaries. See [[Tile_Index_Scheme]]&lt;br /&gt;
* Airports appear in the bottom of holes, or there are spaces between the airports and the scenery. This typically happens when genapts is unable to find the correct elevation data, or the elevation data changed between running genapts and shape-decode. Try generating a single airport in your scenery area using genapts, and look at the output. In particular, make sure there is a work/SRTM-3 directory. &lt;br /&gt;
* Only the airports appear in the scenery. There are three typical causes for this: &lt;br /&gt;
** You didn't download the correct shapefiles for the area. &lt;br /&gt;
** You haven't run shape-decode on the v0_landmass shapefile as Default &lt;br /&gt;
** You didn't include the correct directories in tg-construct. &lt;br /&gt;
* Generate scenery includes data removed from the shapefiles. If you are editing shapefiles, you need to delete the appropriate work subdirectory before running shape-decode. Otherwise your changes will be in addition to those already present. &lt;br /&gt;
* All the scenery is flat and at sea-level. Typically this is because you didn't include any elevation data in your tg-construct command. Make sure there's a STRM-3 directory included in the command-line. &lt;br /&gt;
* All terrain copies the material of a certain shapefile. You have probably forgotten to put each of the downloaded shapefiles in a seperate directory inside the Data/shapefiles directory.&lt;br /&gt;
&lt;br /&gt;
== General comments from forum discussion ==&lt;br /&gt;
{{cquote|f-ojac, you are right, the parameters used in scenery 2.0 were &amp;quot;-e 5 -x 20000&amp;quot; according to the wiki. I don't know why I had the impression these parameters were not public. In any case, it does not matter because using the same parameters will create closer results, but they are not guaranteed to be the same.&lt;br /&gt;
&lt;br /&gt;
The parameters used to create scenery 2,0 seem to be:&lt;br /&gt;
&lt;br /&gt;
-m ??: the minimum number of vertices in a tile. In FG, any number bellow 100 (and probably, any number below 1000) will do. I don't think there is any surface on the world perfectly flat for several kilometers. The default value is 50 and I'm sure is ok for any normal use.&lt;br /&gt;
-e 5: the max allowed error for elevation, in meters. That is: if terrafit calculates a simplification of the terrain where all points are at most this distance from the real elevation, no more vertices are created. The default value is 40 meters: a point may have an elevation error up to 40m (~100ft) High values for this parameter create less detailed mountains and smaller (in disk size) and more efficient (in FPS) terrain.&lt;br /&gt;
-x 20000: the max number of vertices in a tile. If this number of vertices is reached, terrafit stop regardless the max error of the vertices. The default value is 1000&lt;br /&gt;
&lt;br /&gt;
Keep in mind you can set values that do not make sense:&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;-e 1 -x 100&amp;quot; does not make sense because it is going to be impossible to calculate errors less than 1 meters using only 100 vertices. The max number of vertices will be reached always and the max error will be probably ignored.&lt;br /&gt;
* &amp;quot;-e 300 -x 20000&amp;quot; does not make sense, tiles are going to use for sure much less vertices than 20,000 because you are allowing huge elevation errors.&lt;br /&gt;
&lt;br /&gt;
If you want an efficient scenery (less vertices), use the default values &amp;quot;-e 40 -x 1000&amp;quot;. If you want more accurate elevation at the cost of disk space and FPS, use values similar to scenery 2.0 (&amp;quot;-e 5 -x 20000&amp;quot;) Anything in the middle will produce performance and disk use in the middle.&amp;lt;ref&amp;gt;{{cite web |url=http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=24681#p225363 &lt;br /&gt;
|title=Re: Terrasync Help (surprinsingly!) :)&lt;br /&gt;
|author=ludomotico |date= Mon Nov 24, 2014 4:28 am}}&amp;lt;/ref&amp;gt;|ludomotico}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Related content ==&lt;br /&gt;
* [[Howto:Create custom terrain]], editing/making terrain data.&lt;br /&gt;
* [[TerraGear CORINE]], building terrain from CORINE data.&lt;br /&gt;
* [[TerraGear Documentation]], using TerraGear details.&lt;br /&gt;
&lt;br /&gt;
{{Terra}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery enhancement|TerraGear, Using]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Utiliser TerraGear]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Template:OSM_Navigation&amp;diff=82634</id>
		<title>Template:OSM Navigation</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Template:OSM_Navigation&amp;diff=82634"/>
		<updated>2015-03-20T08:14:17Z</updated>

		<summary type="html">&lt;p&gt;Radi: add link to osm2roads&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;!--&lt;br /&gt;
{{Template:Non-stable|version=4.2|progress=30}}&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{infobox subsystem&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
|image =MapStructureDialog.png&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
|name =Autogen Scenery&lt;br /&gt;
|started= 11/2013 &lt;br /&gt;
|description = Improved autogen support for FlightGear using OSM data&lt;br /&gt;
|status = [https://gitorious.org/+flightgear-autogen-team Under active development as of 05/2014]&lt;br /&gt;
|developers = radi, vanosten, Soitanen, portreekid&lt;br /&gt;
|topic-sg = https://gitorious.org/fg/fg-autogen-simgear&lt;br /&gt;
|topic-fg = https://gitorious.org/fg/fg-autogen-flightgear&lt;br /&gt;
|topic-fgdata = https://gitorious.org/fg/fg-autogen-fgdata&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{sidebar&lt;br /&gt;
| name	= OSM Navigation&lt;br /&gt;
| title = OpenStreetMap use in FlightGear&lt;br /&gt;
| contentstyle= text-align: left;&lt;br /&gt;
&lt;br /&gt;
| content1 = &lt;br /&gt;
* [[OpenStreetMap]]&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[Osm2city.py]]&lt;br /&gt;
** [[Osm2city.py Development]]&lt;br /&gt;
** [[Osm2city.py Batch]]&lt;br /&gt;
** [[Osm2city.py Textures]]&lt;br /&gt;
** [[Osm2pylons.py]]&lt;br /&gt;
** [[OsmPiers.py]]&lt;br /&gt;
** [[OsmPlatforms.py]]&lt;br /&gt;
** [[Osm2city_landuse.py]]&lt;br /&gt;
** [[Osm2roads.py]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [[OpenStreetMap import]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
TODO:&lt;br /&gt;
* add discussions&lt;br /&gt;
* add repos&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}{{main other|&lt;br /&gt;
&lt;br /&gt;
[[Category:OpenStreetMap]]&lt;br /&gt;
[[Category:Core development projects]]}}&lt;br /&gt;
&amp;lt;noinclude&amp;gt;{{Informative template|1=&lt;br /&gt;
== Goal ==&lt;br /&gt;
This template can be used at the top of articles related to using OpenStreetMap with FlightGear or the scenery tools.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
Put this at the top of the article:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;{{OSM Navigation}}&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Navigation templates]]&lt;br /&gt;
[[Category:OpenStreetMap|OSM Navigation]]&lt;br /&gt;
&amp;lt;/noinclude&amp;gt;&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py_textures&amp;diff=82574</id>
		<title>Osm2city.py textures</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py_textures&amp;diff=82574"/>
		<updated>2015-03-18T07:39:25Z</updated>

		<summary type="html">&lt;p&gt;Radi: updated texture atlas restrictions&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how you can prepare and register your own textures for use with osm2city.py.&lt;br /&gt;
It assumes you already have a texture image file. If not, see [[Howto:Create_textures_from_photos]].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
To texture a facade or a roof, you need&lt;br /&gt;
* two image files: the texture itself and a lightmap&lt;br /&gt;
* the texture's dimensions in meters&lt;br /&gt;
* locations in pixels at which osm2city.py may cut the texture to fit it to a given facade geometry, e.g. to apply a photo of a 15-storey building to a 12 storey model without shrinking it.&lt;br /&gt;
* 'provides' and 'requires' tags, e.g., a texture could require a black roof, while providing a commercial facade.&lt;br /&gt;
&lt;br /&gt;
Osm2city uses a texture atlas to improve performance. But that places some restrictions:&lt;br /&gt;
# textures can only wrap around in zero or one direction.&lt;br /&gt;
# textures that don't wrap around must come in 2^n sizes (32, 64, 128px ...)&lt;br /&gt;
# textures that wrap around in one direction will be resized to (currently hardcoded) 256 px in that direction&lt;br /&gt;
&lt;br /&gt;
== texGUI.py ==&lt;br /&gt;
The script texGUI.py eases calibration and finding the cut locations. Run the GUI and supply your texture file:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
texGUI.py facade.png&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TexGUI calibrating width.jpg|thumb|texGUI: Calibrating a texture's width using an aircon as a reference object. Note the red line.]]&lt;br /&gt;
[[File:TexGUI added cut locations.jpg|thumb|texGUI: Added horizontal and vertical cut locations.]]&lt;br /&gt;
&lt;br /&gt;
It is generally a good idea to use descriptive names, such as &amp;quot;facade_industrial_old_white.png&amp;quot;, but for this example we simply use &amp;quot;facade.png&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
# Calibrate the image width/height. Find a feature in the image whose dimensions you know or can estimate. For example, simple windows are typically about 0.8 m wide. Here, we're using the aircon's width, estimated 0.82 m. Left drag to select that horizontal feature, then enter its length. Right drag for a vertical feature. You need only one of them. If both are given, both are used (e.g. if your image is stretched in one direction).&lt;br /&gt;
# Mark locations at which osm2city.py may cut the texture. Use left and right mouse buttons. Shift+click removes the last marker.&lt;br /&gt;
# Once you're satisfied, click &amp;quot;dump and quit&amp;quot;. This writes calibration/cut data to a file &amp;quot;facade_24x19m.py&amp;quot;. Note that texGUI added &amp;quot;_24x19m&amp;quot; to the texture file name (the original file is still in place), since you're likely to have more than one texture for an industrial facade.&lt;br /&gt;
&lt;br /&gt;
== Texture metadata ==&lt;br /&gt;
&lt;br /&gt;
Now edit facade_24x19m.py:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
facades.append(Texture('tex.src/facade_24x19m.png',&lt;br /&gt;
    23.8, [364, 742, 1086], h_can_repeat=True,&lt;br /&gt;
    18.5, [295, 565, 842], v_can_repeat=False,&lt;br /&gt;
    v_align_bottom = True,&lt;br /&gt;
    requires=[],&lt;br /&gt;
    provides=[]))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usually you need to change very little here.&lt;br /&gt;
* You can set the texture to wrap around in at most one direction using ''h_can_repeat'' or ''v_can_repeat''&lt;br /&gt;
* If ''v_align_bottom'' is True, osm2city.py will align the bottom part of the texture with the ground and cut away the top part if neccessary. Otherwise, it will align the top part with the roof and cut away the bottom.&lt;br /&gt;
&lt;br /&gt;
For reference, we now descibe the format in a bit more detail. You might want to skip to the [[Osm2city.py_Textures#Texture_compatibility|next section]].&lt;br /&gt;
&lt;br /&gt;
First line is the path to our texture.&lt;br /&gt;
Second line says the texture&lt;br /&gt;
* is 23.8m wide&lt;br /&gt;
* can be cut at u = 364, 742, and 1068 px, where u is the horizontal coordinate. The last value 1086 also gives the width in px. Note that the .ac file uses normalized coordinates (0 ... 1). Internally, osm2city.py divides all coordinates by the last value. Therefore, when preparing the textures, you can work with the highest resolution possible and register those numbers, then just downscale the texture for actual flightgear use. Once the next generation of graphics cards arrives you just replace the textures with higher resolution ones without touching the cut locations.&lt;br /&gt;
* the texture can repeat in horizontal direction.&lt;br /&gt;
&lt;br /&gt;
The third line gives the same information for the vertical direction:&lt;br /&gt;
* 18.5m height&lt;br /&gt;
* can cut at 295, 565, 842 px,&lt;br /&gt;
* the texture cannot repeat in vertical direction&lt;br /&gt;
&lt;br /&gt;
== Texture compatibility ==&lt;br /&gt;
&lt;br /&gt;
The fourth and fifth line state compatibility with other textures. TexGUI.py just creates an empty template here. A useful example could look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
    requires=['roof:color:black'],&lt;br /&gt;
    provides=['shape:industrial','age:old','compat:roof-flat','compat:roof-gable']))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This facade texture requires a black roof. It provides an old-aged, industrial facade, and is compatible with both flat and gable roofs. TODO: describe details on our requires/provides mechanism.&lt;br /&gt;
&lt;br /&gt;
== Lightmap ==&lt;br /&gt;
&lt;br /&gt;
A lightmap &amp;lt;del&amp;gt;is required for every texture, having&amp;lt;/del&amp;gt;has the same file name with a postfix &amp;quot;_LM&amp;quot;.  So for our example this would be&lt;br /&gt;
&amp;quot;facade_24x19m_LM.png&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Osm2city uses&lt;br /&gt;
* red channel for window lights&lt;br /&gt;
* green channel for ambient street lights shining onto facade&lt;br /&gt;
* blue and alpha unused&lt;br /&gt;
&lt;br /&gt;
TODO describe add_streetlight.py&lt;br /&gt;
&lt;br /&gt;
== Install texture and lightmap ==&lt;br /&gt;
* copy texture and lightmap to tex.src/&lt;br /&gt;
* add the snippet from &amp;quot;facade_24x19m.py&amp;quot; to textures/catalog.py&lt;br /&gt;
&lt;br /&gt;
If you're adding a roof, name your texture &amp;quot;roof_something.png&amp;quot; and append it to the list of ''roofs'' (instead of ''facades'')&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
roofs.append(Texture('tex.src/roof_something.png',&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See roof examples starting around line 400.&amp;lt;del&amp;gt;Note that also roofs need a lightmap.&amp;lt;/del&amp;gt; They no longer need a LM.&lt;br /&gt;
&lt;br /&gt;
Finally, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city.py -A&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to re-create the texture atlas. If there are no errors, your texture is registered and will be used next time you run osm2city.py. If your texture is GPL compatible, please consider&lt;br /&gt;
sending it (along with the meta data) to one of the osm2city.py devs to have it included in the official distribution.&lt;br /&gt;
&lt;br /&gt;
[[Category:Modeling]]&lt;br /&gt;
[[Category:OpenStreetMap]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=82496</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=82496"/>
		<updated>2015-03-16T10:51:24Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Install */ gitlab links&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitlab.com/fg-radi/osm2city repository] is hosted on &amp;lt;del&amp;gt;gitorious&amp;lt;/del&amp;gt; gitlab.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitlab.com/fg-radi/osm2city osm2city] and [https://gitlab.com/fg-radi/osm2city-data osm2city-data] from gitlab.&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. soft link osm2city-data/tex and osm2city-data/tex.src into osm2city/ such that it appears as a sub-directory of osm2city&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city/&lt;br /&gt;
  tex.src/&lt;br /&gt;
  tex/&lt;br /&gt;
  osm2city.py&lt;br /&gt;
  textures.py&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{caution|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = &amp;quot;LOWI&amp;quot; (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = &amp;quot;buildings.osm&amp;quot;&lt;br /&gt;
:* 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 &amp;quot;/home/user/fgfs/scenery/TerraSync&amp;quot; .&lt;br /&gt;
:* set PATH_TO_OUTPUT to a ''different'' scenery path, e.g. &amp;quot;/home/user/fgfs/scenery/osm2city&amp;quot; . 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
{{note|Python does not recognize environment variables, please use full paths in the parameters file (no $HOME etc).}}&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
{{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 = &amp;quot;Manual&amp;quot;.}}&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;FgelevCaching&amp;quot;&lt;br /&gt;
:* Set FG_ELEV to your fgelev executable. For example: FG_ELEV = &amp;quot;/usr/local/fg/bin/fgelev&amp;quot; or just FG_ELEV = &amp;quot;fgelev&amp;quot; if fgelev is already in your OS's path.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;Manual&amp;quot;&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FG_ROOT/Nasal/&lt;br /&gt;
:* Open $FG_ROOT/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_ROOT/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;Telnet&amp;quot;&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* Make sure you're in osm2city's directory and run &lt;br /&gt;
&lt;br /&gt;
 python osm2city.py -f LOWI/params.ini. &lt;br /&gt;
&lt;br /&gt;
The parsed OSM data is cached to file LOWI/buildings.osm.pkl which is used on next startup if you set USE_PKL = 1.&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
=== FGElev crashes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
CRITICAL:root:1173 -95.5767 37.0965&lt;br /&gt;
CRITICAL:root:fgelev returned &amp;lt;&amp;gt;, resulting in list index out of range. Did fgelev start OK (Record : 1173)?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The first line is the last input to fgelev. &lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter the line last sent to fgelev. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173 -95.5767 37.0965&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The response should look like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173: 226.793&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. ===&lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
=== Buildings/roads have no texture. I get errors &amp;quot;osgDB ac3d reader: could not find texture &amp;quot;tex/atlas_facades.png&amp;quot;. ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=82495</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=82495"/>
		<updated>2015-03-16T10:46:11Z</updated>

		<summary type="html">&lt;p&gt;Radi: we moved to gitlab&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitlab.com/fg-radi/osm2city repository] is hosted on &amp;lt;del&amp;gt;gitorious&amp;lt;/del&amp;gt; gitlab.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. soft link osm2city-data/tex and osm2city-data/tex.src into osm2city/ such that it appears as a sub-directory of osm2city&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city/&lt;br /&gt;
  tex.src/&lt;br /&gt;
  tex/&lt;br /&gt;
  osm2city.py&lt;br /&gt;
  textures.py&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{caution|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = &amp;quot;LOWI&amp;quot; (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = &amp;quot;buildings.osm&amp;quot;&lt;br /&gt;
:* 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 &amp;quot;/home/user/fgfs/scenery/TerraSync&amp;quot; .&lt;br /&gt;
:* set PATH_TO_OUTPUT to a ''different'' scenery path, e.g. &amp;quot;/home/user/fgfs/scenery/osm2city&amp;quot; . 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
{{note|Python does not recognize environment variables, please use full paths in the parameters file (no $HOME etc).}}&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
{{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 = &amp;quot;Manual&amp;quot;.}}&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;FgelevCaching&amp;quot;&lt;br /&gt;
:* Set FG_ELEV to your fgelev executable. For example: FG_ELEV = &amp;quot;/usr/local/fg/bin/fgelev&amp;quot; or just FG_ELEV = &amp;quot;fgelev&amp;quot; if fgelev is already in your OS's path.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;Manual&amp;quot;&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FG_ROOT/Nasal/&lt;br /&gt;
:* Open $FG_ROOT/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_ROOT/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;Telnet&amp;quot;&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* Make sure you're in osm2city's directory and run &lt;br /&gt;
&lt;br /&gt;
 python osm2city.py -f LOWI/params.ini. &lt;br /&gt;
&lt;br /&gt;
The parsed OSM data is cached to file LOWI/buildings.osm.pkl which is used on next startup if you set USE_PKL = 1.&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
=== FGElev crashes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
CRITICAL:root:1173 -95.5767 37.0965&lt;br /&gt;
CRITICAL:root:fgelev returned &amp;lt;&amp;gt;, resulting in list index out of range. Did fgelev start OK (Record : 1173)?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The first line is the last input to fgelev. &lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter the line last sent to fgelev. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173 -95.5767 37.0965&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The response should look like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173: 226.793&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. ===&lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
=== Buildings/roads have no texture. I get errors &amp;quot;osgDB ac3d reader: could not find texture &amp;quot;tex/atlas_facades.png&amp;quot;. ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82308</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82308"/>
		<updated>2015-03-12T13:44:23Z</updated>

		<summary type="html">&lt;p&gt;Radi: add animated gif&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:787 wing flex hard landing.gif|thumb|Wingflex after a touchdown at 9 ft/s on a 787-8.]]&lt;br /&gt;
&lt;br /&gt;
Wings of large aspect ratio tend to behave similar to a spring. They bend under load and oscillate for a while when the load changes, for example in a turn, during turbulence, or on touchdown. This article describes the Wingflexer module, which aims at animating the 3-D model of a wing in a somewhat realistic fashion. The method used is a significant improvement over what has been described [[Howto:Implement_wing_flex|here]]. However, the actual model animation part is identical and will not be covered.&lt;br /&gt;
&lt;br /&gt;
Including this in your aircraft is fairly straightforward, but obtaining plausible parameters can require some research and trial-and-error. We will give an example (the 787) below.&lt;br /&gt;
&lt;br /&gt;
Introduced in FG 3.5, there are two implementations available. The first, which this article is focused on, uses autopilot/property rules. It is therefore very optimized and should be your first choice. The second implementation uses Nasal. It is a bit more flexible in the sense that it could also be applied to AI aircraft.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Physical model ==&lt;br /&gt;
This section describes the physical model. You don't need to fully understand the maths here to be able to use Wingflexer, but you should understand the parameters involved -- you will need to adapt them to your aircraft.&lt;br /&gt;
&lt;br /&gt;
We use a simple spring-mass-damper system sketched below to model a flexible wing:&lt;br /&gt;
   --&amp;gt;       |&amp;lt;---- z ---&amp;gt;|&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
&lt;br /&gt;
The wing's motion, measured by the deflection z(t), is governed by the following parameters:&lt;br /&gt;
&lt;br /&gt;
 k          wing stiffness&lt;br /&gt;
 d          damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L    lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f        acceleration of the frame of reference (fuselage)&lt;br /&gt;
&lt;br /&gt;
We integrate the equation of motion&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/systems/wingflexer/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates a neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences leads to&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;br /&gt;
&lt;br /&gt;
== Obtaining plausible parameters ==&lt;br /&gt;
To make our model produce a convinving dynamic behaviour, you will need to obtain estimates and fine-tune the parameters.&lt;br /&gt;
&lt;br /&gt;
These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
There's a python script wingflexer.py which assists you in fine-tuning. It will quickly simulate the dynamics of the model with your parameters.&lt;br /&gt;
So how to estimate the parameters?&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's natural frequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
where&lt;br /&gt;
 m_ac   aircraft mass&lt;br /&gt;
 g      9.81 m/s^2&lt;br /&gt;
 z_fac  scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the natural frequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the wing's natural frequency, the wing's deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection (bounce)&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
* a lower wing mass increases the natural frequency, and weakens the touchdown bounce&lt;br /&gt;
* a higher stiffness K reduces the deflection and increases the natural frequency&lt;br /&gt;
&lt;br /&gt;
== Enable developer options ==&lt;br /&gt;
By default, Wingflexer and the user-tunable parameters live in&lt;br /&gt;
 /sim/systems/wingflexer/&lt;br /&gt;
 /sim/systems/wingflexer/params/&lt;br /&gt;
&lt;br /&gt;
There are two properties disabled by default which are only useful when you're tuning the parameters. To enable them, uncomment the developer section in Aircraft/Generic/wingflexer.xml.&lt;br /&gt;
This will activate&lt;br /&gt;
 /sim/systems/wingflexer/params/z-fac&lt;br /&gt;
 /sim/systems/wingflexer/sink-rate-fps&lt;br /&gt;
Z-fac simply scales the output. Once you're happy with the results, include this factor in the animation.&lt;br /&gt;
Sink-rate-fps allows you to simulate a touchdown at given vertical speed.&lt;br /&gt;
&lt;br /&gt;
It will become clear in the next section why these two settings are useful.&lt;br /&gt;
&lt;br /&gt;
== An example: the 787 ==&lt;br /&gt;
The 787 is known for its very flexible wings; the deflection in&lt;br /&gt;
unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds&lt;br /&gt;
23,000 kg of fuel. Because the fuel is distributed over the wing, we use a&lt;br /&gt;
fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason&lt;br /&gt;
we don't use the true wing mass, but rather something that makes our model look&lt;br /&gt;
plausible.&lt;br /&gt;
&lt;br /&gt;
So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.&lt;br /&gt;
That frequency might be a bit low, videos of a 777 wing in turbulence show about&lt;br /&gt;
2-3 Hz. (I didn't research 787 videos).&lt;br /&gt;
&lt;br /&gt;
To increase it, we could either reduce m_dw or increase K. A lower m_dw results&lt;br /&gt;
in a rather weak bounce on touchdown which might look odd. A higher K reduces&lt;br /&gt;
the deflection z_flight, but we can simply scale the animation to account for&lt;br /&gt;
that. We'll multiply the deflection z by a factor z_fac to get an angle for the&lt;br /&gt;
&amp;lt;rotate&amp;gt; animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.&lt;br /&gt;
Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects&lt;br /&gt;
to 0.3 m instead of 3 m, the animation scale factor will make sure the wing&lt;br /&gt;
bends to 3 m. This way, we can match both natural frequency and observed deflection,&lt;br /&gt;
and still get a realistic bounce on touch down. Finally, adjust D such that an&lt;br /&gt;
impulse is damped out after about one or two oscillations; D = 12 seems to work&lt;br /&gt;
OK in our example.&lt;br /&gt;
&lt;br /&gt;
It's difficult to get real-world data on the deflection during touchdown.&lt;br /&gt;
Touchdown at more than 10 ft/s is considered a hard landing and could result in some significant wing bending.&lt;br /&gt;
There's a video of a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the&lt;br /&gt;
wings bend perhaps 1 m.&lt;br /&gt;
&lt;br /&gt;
To assist you in tuning parameters for the touchdown bounce you can initialize your&lt;br /&gt;
wing mass with a (touchdown) vertical speed via /sim/systems/wingflexer/sink-rate-fps, and then observe the deflection and oscillation. This avoids you having to fly too many touch-and-go's while developing ;)&lt;br /&gt;
&lt;br /&gt;
Finally, our model outputs the deflection in meters, but the &amp;lt;rotate&amp;gt; animation expects an&lt;br /&gt;
angle. It is up to you convert appropriately, depending on your wing&lt;br /&gt;
span and number of segments in the animation. Also don't forget to include z_fac.&lt;br /&gt;
&lt;br /&gt;
== How to add to your aircraft ==&lt;br /&gt;
Create a file $YourAircraft/Systems/wingflexer-params.xml which contains the parameters adjusted to your aircraft&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;PropertyList&amp;gt;&lt;br /&gt;
     &amp;lt;params&amp;gt;&lt;br /&gt;
         &amp;lt;m-wing-dry-kg type=&amp;quot;double&amp;quot;&amp;gt;12000.&amp;lt;/m-wing-dry-kg&amp;gt;&lt;br /&gt;
         &amp;lt;K type=&amp;quot;double&amp;quot;&amp;gt;259.&amp;lt;/K&amp;gt;&lt;br /&gt;
         &amp;lt;D type=&amp;quot;double&amp;quot;&amp;gt;12.&amp;lt;/D&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-frac type=&amp;quot;double&amp;quot;&amp;gt;0.375&amp;lt;/fuel-frac&amp;gt;&lt;br /&gt;
         &amp;lt;lift-node-lbs alias=&amp;quot;/fdm/jsbsim/forces/fbz-aero-lbs&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-1-kg alias=&amp;quot;/consumables/fuel/tank/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-2-kg alias=&amp;quot;/consumables/fuel/tank[1]/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-3-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-3-kg&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-4-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-4-kg&amp;gt;&lt;br /&gt;
     &amp;lt;/params&amp;gt;&lt;br /&gt;
 &amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
Also adjust the property node aliases for the wing fuel tanks. Wingflexer supports up to four tanks in total. Since we're currently only solving one equation and hence get only one deflection which is used for both wings, we have to average the wing mass. Internally, m_fuel is simply the sum of all given fuel nodes, &lt;br /&gt;
  m_fuel = fuel-node-1-kg + fuel-node-2-kg + fuel-node-3-kg + fuel-node-4-kg&lt;br /&gt;
so you must include the weighting factor in fuel-frac (e.g. 1/2 if you provide 2 fuel nodes). If you have more than 4 wing tanks in total, use another property rule to compute the average.&lt;br /&gt;
&lt;br /&gt;
In $yourAircraft-set.xml, in &amp;lt;systems&amp;gt; section, load the parameters and the wingflexer module:&lt;br /&gt;
 &amp;lt;systems&amp;gt;&lt;br /&gt;
     &amp;lt;wingflexer include=&amp;quot;Systems/wingflexer-params.xml&amp;quot;/&amp;gt;&lt;br /&gt;
     &amp;lt;property-rule n=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;name&amp;gt;wing flexer property rule&amp;lt;/name&amp;gt;&lt;br /&gt;
         &amp;lt;path&amp;gt;Aircraft/Generic/wingflexer.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
     &amp;lt;/property-rule&amp;gt;&lt;br /&gt;
 &amp;lt;/systems&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The wingflexer writes the deflection to /sim/systems/wingflexer/z-m.&lt;br /&gt;
Finally, your model rotate animation has to pick it up and multiply it by z_fac&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
     &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
     &amp;lt;property&amp;gt;sim/systems/wingflexer/z-m&amp;lt;/property&amp;gt;&lt;br /&gt;
     &amp;lt;factor&amp;gt;10.&amp;lt;/factor&amp;gt;&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your aircraft uses JSBSim, you're done now. Yasim requires an extra step, described next.&lt;br /&gt;
&lt;br /&gt;
== Yasim ==&lt;br /&gt;
Yasim does not write the lift to the property tree. But you can create a helper&lt;br /&gt;
function which computes the lift as&lt;br /&gt;
 lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs&lt;br /&gt;
and point the &amp;lt;lift-node-lbs&amp;gt; alias in wingflexer-params.xml to it.&lt;br /&gt;
&lt;br /&gt;
== Implementation details ==&lt;br /&gt;
=== Autopilot/Property rules implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.xml&lt;br /&gt;
&lt;br /&gt;
The ODE x&amp;quot; + ax' + bx + c = 0 is integrated by DampedOsciFilterImplementation in FG/src/autopilot/digitalfilter.cxx.&lt;br /&gt;
&lt;br /&gt;
=== Nasal implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.nas, see comment therein.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
* write Yasim helper&lt;br /&gt;
* input for fuselage acceleration should rather be acceleration at CG instead of the pilot's location -- is there a property?&lt;br /&gt;
* add wingflexer.py (to where?)&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=File:787_wing_flex_hard_landing.gif&amp;diff=82307</id>
		<title>File:787 wing flex hard landing.gif</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=File:787_wing_flex_hard_landing.gif&amp;diff=82307"/>
		<updated>2015-03-12T13:39:55Z</updated>

		<summary type="html">&lt;p&gt;Radi: User created page with UploadWizard&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=={{int:filedesc}}==&lt;br /&gt;
{{Information&lt;br /&gt;
|description={{en|1=Wingflex after a rather hard touchdown (9 ft/s) on a 787-8.}}&lt;br /&gt;
|date=2015-03-13 00:35:34&lt;br /&gt;
|source={{own}}&lt;br /&gt;
|author=[[User:Radi|Radi]]&lt;br /&gt;
|permission=&lt;br /&gt;
|other versions=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=={{int:license-header}}==&lt;br /&gt;
{{self|cc-by-sa-4.0}}&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82251</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82251"/>
		<updated>2015-03-11T10:26:08Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Enable developer options */ fix sink-rate-fps path&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wings of large aspect ratio tend to behave similar to a spring. They bend under load and oscillate for a while when the load changes, for example in a turn, during turbulence, or on touchdown. This article describes the Wingflexer module, which aims at animating the 3-D model of a wing in a somewhat realistic fashion. The method used is a significant improvement over what has been described [[Howto:Implement_wing_flex|here]]. However, the actual model animation part is identical and will not be covered.&lt;br /&gt;
&lt;br /&gt;
Including this in your aircraft is fairly straightforward, but obtaining plausible parameters can require some research and trial-and-error. We will give an example (the 787) below.&lt;br /&gt;
&lt;br /&gt;
Introduced in FG 3.5, there are two implementations available. The first, which this article is focused on, uses autopilot/property rules. It is therefore very optimized and should be your first choice. The second implementation uses Nasal. It is a bit more flexible in the sense that it could also be applied to AI aircraft.&lt;br /&gt;
&lt;br /&gt;
== Physical model ==&lt;br /&gt;
This section describes the physical model. You don't need to fully understand the maths here to be able to use Wingflexer, but you should understand the parameters involved -- you will need to adapt them to your aircraft.&lt;br /&gt;
&lt;br /&gt;
We use a simple spring-mass-damper system sketched below to model a flexible wing:&lt;br /&gt;
   --&amp;gt;       |&amp;lt;---- z ---&amp;gt;|&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
&lt;br /&gt;
The wing's motion, measured by the deflection z(t), is governed by the following parameters:&lt;br /&gt;
&lt;br /&gt;
 k          wing stiffness&lt;br /&gt;
 d          damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L    lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f        acceleration of the frame of reference (fuselage)&lt;br /&gt;
&lt;br /&gt;
We integrate the equation of motion&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/systems/wingflexer/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates a neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences leads to&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;br /&gt;
&lt;br /&gt;
== Obtaining plausible parameters ==&lt;br /&gt;
To make our model produce a convinving dynamic behaviour, you will need to obtain estimates and fine-tune the parameters.&lt;br /&gt;
&lt;br /&gt;
These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
There's a python script wingflexer.py which assists you in fine-tuning. It will quickly simulate the dynamics of the model with your parameters.&lt;br /&gt;
So how to estimate the parameters?&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's natural frequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
where&lt;br /&gt;
 m_ac   aircraft mass&lt;br /&gt;
 g      9.81 m/s^2&lt;br /&gt;
 z_fac  scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the natural frequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the wing's natural frequency, the wing's deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection (bounce)&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
* a lower wing mass increases the natural frequency, and weakens the touchdown bounce&lt;br /&gt;
* a higher stiffness K reduces the deflection and increases the natural frequency&lt;br /&gt;
&lt;br /&gt;
== Enable developer options ==&lt;br /&gt;
By default, Wingflexer and the user-tunable parameters live in&lt;br /&gt;
 /sim/systems/wingflexer/&lt;br /&gt;
 /sim/systems/wingflexer/params/&lt;br /&gt;
&lt;br /&gt;
There are two properties disabled by default which are only useful when you're tuning the parameters. To enable them, uncomment the developer section in Aircraft/Generic/wingflexer.xml.&lt;br /&gt;
This will activate&lt;br /&gt;
 /sim/systems/wingflexer/params/z-fac&lt;br /&gt;
 /sim/systems/wingflexer/sink-rate-fps&lt;br /&gt;
Z-fac simply scales the output. Once you're happy with the results, include this factor in the animation.&lt;br /&gt;
Sink-rate-fps allows you to simulate a touchdown at given vertical speed.&lt;br /&gt;
&lt;br /&gt;
It will become clear in the next section why these two settings are useful.&lt;br /&gt;
&lt;br /&gt;
== An example: the 787 ==&lt;br /&gt;
The 787 is known for its very flexible wings; the deflection in&lt;br /&gt;
unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds&lt;br /&gt;
23,000 kg of fuel. Because the fuel is distributed over the wing, we use a&lt;br /&gt;
fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason&lt;br /&gt;
we don't use the true wing mass, but rather something that makes our model look&lt;br /&gt;
plausible.&lt;br /&gt;
&lt;br /&gt;
So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.&lt;br /&gt;
That frequency might be a bit low, videos of a 777 wing in turbulence show about&lt;br /&gt;
2-3 Hz. (I didn't research 787 videos).&lt;br /&gt;
&lt;br /&gt;
To increase it, we could either reduce m_dw or increase K. A lower m_dw results&lt;br /&gt;
in a rather weak bounce on touchdown which might look odd. A higher K reduces&lt;br /&gt;
the deflection z_flight, but we can simply scale the animation to account for&lt;br /&gt;
that. We'll multiply the deflection z by a factor z_fac to get an angle for the&lt;br /&gt;
&amp;lt;rotate&amp;gt; animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.&lt;br /&gt;
Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects&lt;br /&gt;
to 0.3 m instead of 3 m, the animation scale factor will make sure the wing&lt;br /&gt;
bends to 3 m. This way, we can match both natural frequency and observed deflection,&lt;br /&gt;
and still get a realistic bounce on touch down. Finally, adjust D such that an&lt;br /&gt;
impulse is damped out after about one or two oscillations; D = 12 seems to work&lt;br /&gt;
OK in our example.&lt;br /&gt;
&lt;br /&gt;
It's difficult to get real-world data on the deflection during touchdown.&lt;br /&gt;
Touchdown at more than 10 ft/s is considered a hard landing and could result in some significant wing bending.&lt;br /&gt;
There's a video of a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the&lt;br /&gt;
wings bend perhaps 1 m.&lt;br /&gt;
&lt;br /&gt;
To assist you in tuning parameters for the touchdown bounce you can initialize your&lt;br /&gt;
wing mass with a (touchdown) vertical speed via /sim/systems/wingflexer/sink-rate-fps, and then observe the deflection and oscillation. This avoids you having to fly too many touch-and-go's while developing ;)&lt;br /&gt;
&lt;br /&gt;
Finally, our model outputs the deflection in meters, but the &amp;lt;rotate&amp;gt; animation expects an&lt;br /&gt;
angle. It is up to you convert appropriately, depending on your wing&lt;br /&gt;
span and number of segments in the animation. Also don't forget to include z_fac.&lt;br /&gt;
&lt;br /&gt;
== How to add to your aircraft ==&lt;br /&gt;
Create a file $YourAircraft/Systems/wingflexer-params.xml which contains the parameters adjusted to your aircraft&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;PropertyList&amp;gt;&lt;br /&gt;
     &amp;lt;params&amp;gt;&lt;br /&gt;
         &amp;lt;m-wing-dry-kg type=&amp;quot;double&amp;quot;&amp;gt;12000.&amp;lt;/m-wing-dry-kg&amp;gt;&lt;br /&gt;
         &amp;lt;K type=&amp;quot;double&amp;quot;&amp;gt;259.&amp;lt;/K&amp;gt;&lt;br /&gt;
         &amp;lt;D type=&amp;quot;double&amp;quot;&amp;gt;12.&amp;lt;/D&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-frac type=&amp;quot;double&amp;quot;&amp;gt;0.375&amp;lt;/fuel-frac&amp;gt;&lt;br /&gt;
         &amp;lt;lift-node-lbs alias=&amp;quot;/fdm/jsbsim/forces/fbz-aero-lbs&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-1-kg alias=&amp;quot;/consumables/fuel/tank/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-2-kg alias=&amp;quot;/consumables/fuel/tank[1]/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-3-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-3-kg&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-4-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-4-kg&amp;gt;&lt;br /&gt;
     &amp;lt;/params&amp;gt;&lt;br /&gt;
 &amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
Also adjust the property node aliases for the wing fuel tanks. Wingflexer supports up to four tanks in total. Since we're currently only solving one equation and hence get only one deflection which is used for both wings, we have to average the wing mass. Internally, m_fuel is simply the sum of all given fuel nodes, &lt;br /&gt;
  m_fuel = fuel-node-1-kg + fuel-node-2-kg + fuel-node-3-kg + fuel-node-4-kg&lt;br /&gt;
so you must include the weighting factor in fuel-frac (e.g. 1/2 if you provide 2 fuel nodes). If you have more than 4 wing tanks in total, use another property rule to compute the average.&lt;br /&gt;
&lt;br /&gt;
In $yourAircraft-set.xml, in &amp;lt;systems&amp;gt; section, load the parameters and the wingflexer module:&lt;br /&gt;
 &amp;lt;systems&amp;gt;&lt;br /&gt;
     &amp;lt;wingflexer include=&amp;quot;Systems/wingflexer-params.xml&amp;quot;/&amp;gt;&lt;br /&gt;
     &amp;lt;property-rule n=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;name&amp;gt;wing flexer property rule&amp;lt;/name&amp;gt;&lt;br /&gt;
         &amp;lt;path&amp;gt;Aircraft/Generic/wingflexer.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
     &amp;lt;/property-rule&amp;gt;&lt;br /&gt;
 &amp;lt;/systems&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The wingflexer writes the deflection to /sim/systems/wingflexer/z-m.&lt;br /&gt;
Finally, your model rotate animation has to pick it up and multiply it by z_fac&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
     &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
     &amp;lt;property&amp;gt;sim/systems/wingflexer/z-m&amp;lt;/property&amp;gt;&lt;br /&gt;
     &amp;lt;factor&amp;gt;10.&amp;lt;/factor&amp;gt;&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your aircraft uses JSBSim, you're done now. Yasim requires an extra step, described next.&lt;br /&gt;
&lt;br /&gt;
== Yasim ==&lt;br /&gt;
Yasim does not write the lift to the property tree. But you can create a helper&lt;br /&gt;
function which computes the lift as&lt;br /&gt;
 lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs&lt;br /&gt;
and point the &amp;lt;lift-node-lbs&amp;gt; alias in wingflexer-params.xml to it.&lt;br /&gt;
&lt;br /&gt;
== Implementation details ==&lt;br /&gt;
=== Autopilot/Property rules implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.xml&lt;br /&gt;
&lt;br /&gt;
The ODE x&amp;quot; + ax' + bx + c = 0 is integrated by DampedOsciFilterImplementation in FG/src/autopilot/digitalfilter.cxx.&lt;br /&gt;
&lt;br /&gt;
=== Nasal implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.nas, see comment therein.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
* write Yasim helper&lt;br /&gt;
* input for fuselage acceleration should rather be acceleration at CG instead of the pilot's location -- is there a property?&lt;br /&gt;
* add wingflexer.py (to where?)&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82242</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82242"/>
		<updated>2015-03-11T00:23:02Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* How to add to your aircraft */ fix m_fuel&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wings of large aspect ratio tend to behave similar to a spring. They bend under load and oscillate for a while when the load changes, for example in a turn, during turbulence, or on touchdown. This article describes the Wingflexer module, which aims at animating the 3-D model of a wing in a somewhat realistic fashion. The method used is a significant improvement over what has been described [[Howto:Implement_wing_flex|here]]. However, the actual model animation part is identical and will not be covered.&lt;br /&gt;
&lt;br /&gt;
Including this in your aircraft is fairly straightforward, but obtaining plausible parameters can require some research and trial-and-error. We will give an example (the 787) below.&lt;br /&gt;
&lt;br /&gt;
Introduced in FG 3.5, there are two implementations available. The first, which this article is focused on, uses autopilot/property rules. It is therefore very optimized and should be your first choice. The second implementation uses Nasal. It is a bit more flexible in the sense that it could also be applied to AI aircraft.&lt;br /&gt;
&lt;br /&gt;
== Physical model ==&lt;br /&gt;
This section describes the physical model. You don't need to fully understand the maths here to be able to use Wingflexer, but you should understand the parameters involved -- you will need to adapt them to your aircraft.&lt;br /&gt;
&lt;br /&gt;
We use a simple spring-mass-damper system sketched below to model a flexible wing:&lt;br /&gt;
   --&amp;gt;       |&amp;lt;---- z ---&amp;gt;|&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
&lt;br /&gt;
The wing's motion, measured by the deflection z(t), is governed by the following parameters:&lt;br /&gt;
&lt;br /&gt;
 k          wing stiffness&lt;br /&gt;
 d          damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L    lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f        acceleration of the frame of reference (fuselage)&lt;br /&gt;
&lt;br /&gt;
We integrate the equation of motion&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/systems/wingflexer/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates a neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences leads to&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;br /&gt;
&lt;br /&gt;
== Obtaining plausible parameters ==&lt;br /&gt;
To make our model produce a convinving dynamic behaviour, you will need to obtain estimates and fine-tune the parameters.&lt;br /&gt;
&lt;br /&gt;
These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
There's a python script wingflexer.py which assists you in fine-tuning. It will quickly simulate the dynamics of the model with your parameters.&lt;br /&gt;
So how to estimate the parameters?&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's natural frequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
where&lt;br /&gt;
 m_ac   aircraft mass&lt;br /&gt;
 g      9.81 m/s^2&lt;br /&gt;
 z_fac  scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the natural frequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the wing's natural frequency, the wing's deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection (bounce)&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
* a lower wing mass increases the natural frequency, and weakens the touchdown bounce&lt;br /&gt;
* a higher stiffness K reduces the deflection and increases the natural frequency&lt;br /&gt;
&lt;br /&gt;
== Enable developer options ==&lt;br /&gt;
By default, Wingflexer and the user-tunable parameters live in&lt;br /&gt;
 /sim/systems/wingflexer/&lt;br /&gt;
 /sim/systems/wingflexer/params/&lt;br /&gt;
&lt;br /&gt;
There are two properties disabled by default which are only useful when you're tuning the parameters. To enable them, uncomment the developer section in Aircraft/Generic/wingflexer.xml.&lt;br /&gt;
This will activate&lt;br /&gt;
 /sim/systems/wingflexer/params/z-fac&lt;br /&gt;
 /sim/systems/wingflexer/params/sink-rate-fps&lt;br /&gt;
Z-fac simply scales the output. Once you're happy with the results, include this factor in the animation.&lt;br /&gt;
Sink-rate-fps allows you to simulate a touchdown at given vertical speed.&lt;br /&gt;
&lt;br /&gt;
It will become clear in the next section why these two settings are useful.&lt;br /&gt;
&lt;br /&gt;
== An example: the 787 ==&lt;br /&gt;
The 787 is known for its very flexible wings; the deflection in&lt;br /&gt;
unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds&lt;br /&gt;
23,000 kg of fuel. Because the fuel is distributed over the wing, we use a&lt;br /&gt;
fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason&lt;br /&gt;
we don't use the true wing mass, but rather something that makes our model look&lt;br /&gt;
plausible.&lt;br /&gt;
&lt;br /&gt;
So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.&lt;br /&gt;
That frequency might be a bit low, videos of a 777 wing in turbulence show about&lt;br /&gt;
2-3 Hz. (I didn't research 787 videos).&lt;br /&gt;
&lt;br /&gt;
To increase it, we could either reduce m_dw or increase K. A lower m_dw results&lt;br /&gt;
in a rather weak bounce on touchdown which might look odd. A higher K reduces&lt;br /&gt;
the deflection z_flight, but we can simply scale the animation to account for&lt;br /&gt;
that. We'll multiply the deflection z by a factor z_fac to get an angle for the&lt;br /&gt;
&amp;lt;rotate&amp;gt; animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.&lt;br /&gt;
Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects&lt;br /&gt;
to 0.3 m instead of 3 m, the animation scale factor will make sure the wing&lt;br /&gt;
bends to 3 m. This way, we can match both natural frequency and observed deflection,&lt;br /&gt;
and still get a realistic bounce on touch down. Finally, adjust D such that an&lt;br /&gt;
impulse is damped out after about one or two oscillations; D = 12 seems to work&lt;br /&gt;
OK in our example.&lt;br /&gt;
&lt;br /&gt;
It's difficult to get real-world data on the deflection during touchdown.&lt;br /&gt;
Touchdown at more than 10 ft/s is considered a hard landing and could result in some significant wing bending.&lt;br /&gt;
There's a video of a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the&lt;br /&gt;
wings bend perhaps 1 m.&lt;br /&gt;
&lt;br /&gt;
To assist you in tuning parameters for the touchdown bounce you can initialize your&lt;br /&gt;
wing mass with a (touchdown) vertical speed via /sim/systems/wingflexer/sink-rate-fps, and then observe the deflection and oscillation. This avoids you having to fly too many touch-and-go's while developing ;)&lt;br /&gt;
&lt;br /&gt;
Finally, our model outputs the deflection in meters, but the &amp;lt;rotate&amp;gt; animation expects an&lt;br /&gt;
angle. It is up to you convert appropriately, depending on your wing&lt;br /&gt;
span and number of segments in the animation. Also don't forget to include z_fac.&lt;br /&gt;
&lt;br /&gt;
== How to add to your aircraft ==&lt;br /&gt;
Create a file $YourAircraft/Systems/wingflexer-params.xml which contains the parameters adjusted to your aircraft&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;PropertyList&amp;gt;&lt;br /&gt;
     &amp;lt;params&amp;gt;&lt;br /&gt;
         &amp;lt;m-wing-dry-kg type=&amp;quot;double&amp;quot;&amp;gt;12000.&amp;lt;/m-wing-dry-kg&amp;gt;&lt;br /&gt;
         &amp;lt;K type=&amp;quot;double&amp;quot;&amp;gt;259.&amp;lt;/K&amp;gt;&lt;br /&gt;
         &amp;lt;D type=&amp;quot;double&amp;quot;&amp;gt;12.&amp;lt;/D&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-frac type=&amp;quot;double&amp;quot;&amp;gt;0.375&amp;lt;/fuel-frac&amp;gt;&lt;br /&gt;
         &amp;lt;lift-node-lbs alias=&amp;quot;/fdm/jsbsim/forces/fbz-aero-lbs&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-1-kg alias=&amp;quot;/consumables/fuel/tank/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-2-kg alias=&amp;quot;/consumables/fuel/tank[1]/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-3-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-3-kg&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-4-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-4-kg&amp;gt;&lt;br /&gt;
     &amp;lt;/params&amp;gt;&lt;br /&gt;
 &amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
Also adjust the property node aliases for the wing fuel tanks. Wingflexer supports up to four tanks in total. Since we're currently only solving one equation and hence get only one deflection which is used for both wings, we have to average the wing mass. Internally, m_fuel is simply the sum of all given fuel nodes, &lt;br /&gt;
  m_fuel = fuel-node-1-kg + fuel-node-2-kg + fuel-node-3-kg + fuel-node-4-kg&lt;br /&gt;
so you must include the weighting factor in fuel-frac (e.g. 1/2 if you provide 2 fuel nodes). If you have more than 4 wing tanks in total, use another property rule to compute the average.&lt;br /&gt;
&lt;br /&gt;
In $yourAircraft-set.xml, in &amp;lt;systems&amp;gt; section, load the parameters and the wingflexer module:&lt;br /&gt;
 &amp;lt;systems&amp;gt;&lt;br /&gt;
     &amp;lt;wingflexer include=&amp;quot;Systems/wingflexer-params.xml&amp;quot;/&amp;gt;&lt;br /&gt;
     &amp;lt;property-rule n=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;name&amp;gt;wing flexer property rule&amp;lt;/name&amp;gt;&lt;br /&gt;
         &amp;lt;path&amp;gt;Aircraft/Generic/wingflexer.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
     &amp;lt;/property-rule&amp;gt;&lt;br /&gt;
 &amp;lt;/systems&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The wingflexer writes the deflection to /sim/systems/wingflexer/z-m.&lt;br /&gt;
Finally, your model rotate animation has to pick it up and multiply it by z_fac&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
     &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
     &amp;lt;property&amp;gt;sim/systems/wingflexer/z-m&amp;lt;/property&amp;gt;&lt;br /&gt;
     &amp;lt;factor&amp;gt;10.&amp;lt;/factor&amp;gt;&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your aircraft uses JSBSim, you're done now. Yasim requires an extra step, described next.&lt;br /&gt;
&lt;br /&gt;
== Yasim ==&lt;br /&gt;
Yasim does not write the lift to the property tree. But you can create a helper&lt;br /&gt;
function which computes the lift as&lt;br /&gt;
 lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs&lt;br /&gt;
and point the &amp;lt;lift-node-lbs&amp;gt; alias in wingflexer-params.xml to it.&lt;br /&gt;
&lt;br /&gt;
== Implementation details ==&lt;br /&gt;
=== Autopilot/Property rules implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.xml&lt;br /&gt;
&lt;br /&gt;
The ODE x&amp;quot; + ax' + bx + c = 0 is integrated by DampedOsciFilterImplementation in FG/src/autopilot/digitalfilter.cxx.&lt;br /&gt;
&lt;br /&gt;
=== Nasal implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.nas, see comment therein.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
* write Yasim helper&lt;br /&gt;
* input for fuselage acceleration should rather be acceleration at CG instead of the pilot's location -- is there a property?&lt;br /&gt;
* add wingflexer.py (to where?)&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82241</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82241"/>
		<updated>2015-03-11T00:19:04Z</updated>

		<summary type="html">&lt;p&gt;Radi: nasal implementation, link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wings of large aspect ratio tend to behave similar to a spring. They bend under load and oscillate for a while when the load changes, for example in a turn, during turbulence, or on touchdown. This article describes the Wingflexer module, which aims at animating the 3-D model of a wing in a somewhat realistic fashion. The method used is a significant improvement over what has been described [[Howto:Implement_wing_flex|here]]. However, the actual model animation part is identical and will not be covered.&lt;br /&gt;
&lt;br /&gt;
Including this in your aircraft is fairly straightforward, but obtaining plausible parameters can require some research and trial-and-error. We will give an example (the 787) below.&lt;br /&gt;
&lt;br /&gt;
Introduced in FG 3.5, there are two implementations available. The first, which this article is focused on, uses autopilot/property rules. It is therefore very optimized and should be your first choice. The second implementation uses Nasal. It is a bit more flexible in the sense that it could also be applied to AI aircraft.&lt;br /&gt;
&lt;br /&gt;
== Physical model ==&lt;br /&gt;
This section describes the physical model. You don't need to fully understand the maths here to be able to use Wingflexer, but you should understand the parameters involved -- you will need to adapt them to your aircraft.&lt;br /&gt;
&lt;br /&gt;
We use a simple spring-mass-damper system sketched below to model a flexible wing:&lt;br /&gt;
   --&amp;gt;       |&amp;lt;---- z ---&amp;gt;|&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
&lt;br /&gt;
The wing's motion, measured by the deflection z(t), is governed by the following parameters:&lt;br /&gt;
&lt;br /&gt;
 k          wing stiffness&lt;br /&gt;
 d          damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L    lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f        acceleration of the frame of reference (fuselage)&lt;br /&gt;
&lt;br /&gt;
We integrate the equation of motion&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/systems/wingflexer/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates a neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences leads to&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;br /&gt;
&lt;br /&gt;
== Obtaining plausible parameters ==&lt;br /&gt;
To make our model produce a convinving dynamic behaviour, you will need to obtain estimates and fine-tune the parameters.&lt;br /&gt;
&lt;br /&gt;
These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
There's a python script wingflexer.py which assists you in fine-tuning. It will quickly simulate the dynamics of the model with your parameters.&lt;br /&gt;
So how to estimate the parameters?&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's natural frequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
where&lt;br /&gt;
 m_ac   aircraft mass&lt;br /&gt;
 g      9.81 m/s^2&lt;br /&gt;
 z_fac  scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the natural frequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the wing's natural frequency, the wing's deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection (bounce)&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
* a lower wing mass increases the natural frequency, and weakens the touchdown bounce&lt;br /&gt;
* a higher stiffness K reduces the deflection and increases the natural frequency&lt;br /&gt;
&lt;br /&gt;
== Enable developer options ==&lt;br /&gt;
By default, Wingflexer and the user-tunable parameters live in&lt;br /&gt;
 /sim/systems/wingflexer/&lt;br /&gt;
 /sim/systems/wingflexer/params/&lt;br /&gt;
&lt;br /&gt;
There are two properties disabled by default which are only useful when you're tuning the parameters. To enable them, uncomment the developer section in Aircraft/Generic/wingflexer.xml.&lt;br /&gt;
This will activate&lt;br /&gt;
 /sim/systems/wingflexer/params/z-fac&lt;br /&gt;
 /sim/systems/wingflexer/params/sink-rate-fps&lt;br /&gt;
Z-fac simply scales the output. Once you're happy with the results, include this factor in the animation.&lt;br /&gt;
Sink-rate-fps allows you to simulate a touchdown at given vertical speed.&lt;br /&gt;
&lt;br /&gt;
It will become clear in the next section why these two settings are useful.&lt;br /&gt;
&lt;br /&gt;
== An example: the 787 ==&lt;br /&gt;
The 787 is known for its very flexible wings; the deflection in&lt;br /&gt;
unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds&lt;br /&gt;
23,000 kg of fuel. Because the fuel is distributed over the wing, we use a&lt;br /&gt;
fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason&lt;br /&gt;
we don't use the true wing mass, but rather something that makes our model look&lt;br /&gt;
plausible.&lt;br /&gt;
&lt;br /&gt;
So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.&lt;br /&gt;
That frequency might be a bit low, videos of a 777 wing in turbulence show about&lt;br /&gt;
2-3 Hz. (I didn't research 787 videos).&lt;br /&gt;
&lt;br /&gt;
To increase it, we could either reduce m_dw or increase K. A lower m_dw results&lt;br /&gt;
in a rather weak bounce on touchdown which might look odd. A higher K reduces&lt;br /&gt;
the deflection z_flight, but we can simply scale the animation to account for&lt;br /&gt;
that. We'll multiply the deflection z by a factor z_fac to get an angle for the&lt;br /&gt;
&amp;lt;rotate&amp;gt; animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.&lt;br /&gt;
Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects&lt;br /&gt;
to 0.3 m instead of 3 m, the animation scale factor will make sure the wing&lt;br /&gt;
bends to 3 m. This way, we can match both natural frequency and observed deflection,&lt;br /&gt;
and still get a realistic bounce on touch down. Finally, adjust D such that an&lt;br /&gt;
impulse is damped out after about one or two oscillations; D = 12 seems to work&lt;br /&gt;
OK in our example.&lt;br /&gt;
&lt;br /&gt;
It's difficult to get real-world data on the deflection during touchdown.&lt;br /&gt;
Touchdown at more than 10 ft/s is considered a hard landing and could result in some significant wing bending.&lt;br /&gt;
There's a video of a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the&lt;br /&gt;
wings bend perhaps 1 m.&lt;br /&gt;
&lt;br /&gt;
To assist you in tuning parameters for the touchdown bounce you can initialize your&lt;br /&gt;
wing mass with a (touchdown) vertical speed via /sim/systems/wingflexer/sink-rate-fps, and then observe the deflection and oscillation. This avoids you having to fly too many touch-and-go's while developing ;)&lt;br /&gt;
&lt;br /&gt;
Finally, our model outputs the deflection in meters, but the &amp;lt;rotate&amp;gt; animation expects an&lt;br /&gt;
angle. It is up to you convert appropriately, depending on your wing&lt;br /&gt;
span and number of segments in the animation. Also don't forget to include z_fac.&lt;br /&gt;
&lt;br /&gt;
== How to add to your aircraft ==&lt;br /&gt;
Create a file $YourAircraft/Systems/wingflexer-params.xml which contains the parameters adjusted to your aircraft&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;PropertyList&amp;gt;&lt;br /&gt;
     &amp;lt;params&amp;gt;&lt;br /&gt;
         &amp;lt;m-wing-dry-kg type=&amp;quot;double&amp;quot;&amp;gt;12000.&amp;lt;/m-wing-dry-kg&amp;gt;&lt;br /&gt;
         &amp;lt;K type=&amp;quot;double&amp;quot;&amp;gt;259.&amp;lt;/K&amp;gt;&lt;br /&gt;
         &amp;lt;D type=&amp;quot;double&amp;quot;&amp;gt;12.&amp;lt;/D&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-frac type=&amp;quot;double&amp;quot;&amp;gt;0.375&amp;lt;/fuel-frac&amp;gt;&lt;br /&gt;
         &amp;lt;lift-node-lbs alias=&amp;quot;/fdm/jsbsim/forces/fbz-aero-lbs&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-1-kg alias=&amp;quot;/consumables/fuel/tank/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-2-kg alias=&amp;quot;/consumables/fuel/tank[1]/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-3-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-3-kg&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-4-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-4-kg&amp;gt;&lt;br /&gt;
     &amp;lt;/params&amp;gt;&lt;br /&gt;
 &amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
Also adjust the property node aliases for the wing fuel tanks. Wingflexer supports up to four tanks in total. Since we're currently only solving one equation and hence get only one deflection which is used for both wings, we have to average the wing mass. This is done by&lt;br /&gt;
  m_fuel = fuel-frac * (fuel-node-1-kg + fuel-node-2-kg + fuel-node-3-kg + fuel-node-4-kg).&lt;br /&gt;
Include the weighting factor in fuel-frac (e.g. 1/2 if you provide 2 fuel nodes). If you have more than 4 wing tanks in total, use another property rule to compute the average.&lt;br /&gt;
&lt;br /&gt;
In $yourAircraft-set.xml, in &amp;lt;systems&amp;gt; section, load the parameters and the wingflexer module:&lt;br /&gt;
 &amp;lt;systems&amp;gt;&lt;br /&gt;
     &amp;lt;wingflexer include=&amp;quot;Systems/wingflexer-params.xml&amp;quot;/&amp;gt;&lt;br /&gt;
     &amp;lt;property-rule n=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;name&amp;gt;wing flexer property rule&amp;lt;/name&amp;gt;&lt;br /&gt;
         &amp;lt;path&amp;gt;Aircraft/Generic/wingflexer.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
     &amp;lt;/property-rule&amp;gt;&lt;br /&gt;
 &amp;lt;/systems&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The wingflexer writes the deflection to /sim/systems/wingflexer/z-m.&lt;br /&gt;
Finally, your model rotate animation has to pick it up and multiply it by z_fac&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
     &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
     &amp;lt;property&amp;gt;sim/systems/wingflexer/z-m&amp;lt;/property&amp;gt;&lt;br /&gt;
     &amp;lt;factor&amp;gt;10.&amp;lt;/factor&amp;gt;&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your aircraft uses JSBSim, you're done now. Yasim requires an extra step, described next.&lt;br /&gt;
&lt;br /&gt;
== Yasim ==&lt;br /&gt;
Yasim does not write the lift to the property tree. But you can create a helper&lt;br /&gt;
function which computes the lift as&lt;br /&gt;
 lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs&lt;br /&gt;
and point the &amp;lt;lift-node-lbs&amp;gt; alias in wingflexer-params.xml to it.&lt;br /&gt;
&lt;br /&gt;
== Implementation details ==&lt;br /&gt;
=== Autopilot/Property rules implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.xml&lt;br /&gt;
&lt;br /&gt;
The ODE x&amp;quot; + ax' + bx + c = 0 is integrated by DampedOsciFilterImplementation in FG/src/autopilot/digitalfilter.cxx.&lt;br /&gt;
&lt;br /&gt;
=== Nasal implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.nas, see comment therein.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
* write Yasim helper&lt;br /&gt;
* input for fuselage acceleration should rather be acceleration at CG instead of the pilot's location -- is there a property?&lt;br /&gt;
* add wingflexer.py (to where?)&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82240</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82240"/>
		<updated>2015-03-11T00:07:46Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* How to add to your aircraft */ make equation less ambigous, wording&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wings of large aspect ratio tend to behave similar to a spring. They bend under load and oscillate for a while when the load changes, for example in a turn, during turbulence, or on touchdown. This article describes the Wingflexer module, which aims at animating the 3-D model of a wing in a somewhat realistic fashion. The method used is a significant improvement over what has been described here. However, the actual model animation part is identical and will not be covered.&lt;br /&gt;
&lt;br /&gt;
Including this in your aircraft is fairly straightforward, but obtaining plausible parameters can require some research and trial-and-error. We will give an example (the 787) below.&lt;br /&gt;
&lt;br /&gt;
Introduced in FG 3.5, there are two implementations available. One uses autopilot/property rules, is therefore very optimized and should be your first choice. The other uses Nasal. It is a bit more flexible in the sense that it could also be applied to AI aircraft.&lt;br /&gt;
&lt;br /&gt;
== Physical model ==&lt;br /&gt;
This section describes the physical model. You don't need to fully understand the maths here to be able to use Wingflexer, but you should understand the parameters involved -- you will need to adapt them to your aircraft.&lt;br /&gt;
&lt;br /&gt;
We use a simple spring-mass-damper system sketched below to model a flexible wing:&lt;br /&gt;
   --&amp;gt;       |&amp;lt;---- z ---&amp;gt;|&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
&lt;br /&gt;
The wing's motion, measured by the deflection z(t), is governed by the following parameters:&lt;br /&gt;
&lt;br /&gt;
 k          wing stiffness&lt;br /&gt;
 d          damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L    lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f        acceleration of the frame of reference (fuselage)&lt;br /&gt;
&lt;br /&gt;
We integrate the equation of motion&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/systems/wingflexer/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates a neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences leads to&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;br /&gt;
&lt;br /&gt;
== Obtaining plausible parameters ==&lt;br /&gt;
To make our model produce a convinving dynamic behaviour, you will need to obtain estimates and fine-tune the parameters.&lt;br /&gt;
&lt;br /&gt;
These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
There's a python script wingflexer.py which assists you in fine-tuning. It will quickly simulate the dynamics of the model with your parameters.&lt;br /&gt;
So how to estimate the parameters?&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's natural frequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
where&lt;br /&gt;
 m_ac   aircraft mass&lt;br /&gt;
 g      9.81 m/s^2&lt;br /&gt;
 z_fac  scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the natural frequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the wing's natural frequency, the wing's deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection (bounce)&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
* a lower wing mass increases the natural frequency, and weakens the touchdown bounce&lt;br /&gt;
* a higher stiffness K reduces the deflection and increases the natural frequency&lt;br /&gt;
&lt;br /&gt;
== Enable developer options ==&lt;br /&gt;
By default, Wingflexer and the user-tunable parameters live in&lt;br /&gt;
 /sim/systems/wingflexer/&lt;br /&gt;
 /sim/systems/wingflexer/params/&lt;br /&gt;
&lt;br /&gt;
There are two properties disabled by default which are only useful when you're tuning the parameters. To enable them, uncomment the developer section in Aircraft/Generic/wingflexer.xml.&lt;br /&gt;
This will activate&lt;br /&gt;
 /sim/systems/wingflexer/params/z-fac&lt;br /&gt;
 /sim/systems/wingflexer/params/sink-rate-fps&lt;br /&gt;
Z-fac simply scales the output. Once you're happy with the results, include this factor in the animation.&lt;br /&gt;
Sink-rate-fps allows you to simulate a touchdown at given vertical speed.&lt;br /&gt;
&lt;br /&gt;
It will become clear in the next section why these two settings are useful.&lt;br /&gt;
&lt;br /&gt;
== An example: the 787 ==&lt;br /&gt;
The 787 is known for its very flexible wings; the deflection in&lt;br /&gt;
unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds&lt;br /&gt;
23,000 kg of fuel. Because the fuel is distributed over the wing, we use a&lt;br /&gt;
fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason&lt;br /&gt;
we don't use the true wing mass, but rather something that makes our model look&lt;br /&gt;
plausible.&lt;br /&gt;
&lt;br /&gt;
So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.&lt;br /&gt;
That frequency might be a bit low, videos of a 777 wing in turbulence show about&lt;br /&gt;
2-3 Hz. (I didn't research 787 videos).&lt;br /&gt;
&lt;br /&gt;
To increase it, we could either reduce m_dw or increase K. A lower m_dw results&lt;br /&gt;
in a rather weak bounce on touchdown which might look odd. A higher K reduces&lt;br /&gt;
the deflection z_flight, but we can simply scale the animation to account for&lt;br /&gt;
that. We'll multiply the deflection z by a factor z_fac to get an angle for the&lt;br /&gt;
&amp;lt;rotate&amp;gt; animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.&lt;br /&gt;
Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects&lt;br /&gt;
to 0.3 m instead of 3 m, the animation scale factor will make sure the wing&lt;br /&gt;
bends to 3 m. This way, we can match both natural frequency and observed deflection,&lt;br /&gt;
and still get a realistic bounce on touch down. Finally, adjust D such that an&lt;br /&gt;
impulse is damped out after about one or two oscillations; D = 12 seems to work&lt;br /&gt;
OK in our example.&lt;br /&gt;
&lt;br /&gt;
It's difficult to get real-world data on the deflection during touchdown.&lt;br /&gt;
Touchdown at more than 10 ft/s is considered a hard landing and could result in some significant wing bending.&lt;br /&gt;
There's a video of a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the&lt;br /&gt;
wings bend perhaps 1 m.&lt;br /&gt;
&lt;br /&gt;
To assist you in tuning parameters for the touchdown bounce you can initialize your&lt;br /&gt;
wing mass with a (touchdown) vertical speed via /sim/systems/wingflexer/sink-rate-fps, and then observe the deflection and oscillation. This avoids you having to fly too many touch-and-go's while developing ;)&lt;br /&gt;
&lt;br /&gt;
Finally, our model outputs the deflection in meters, but the &amp;lt;rotate&amp;gt; animation expects an&lt;br /&gt;
angle. It is up to you convert appropriately, depending on your wing&lt;br /&gt;
span and number of segments in the animation. Also don't forget to include z_fac.&lt;br /&gt;
&lt;br /&gt;
== How to add to your aircraft ==&lt;br /&gt;
Create a file $YourAircraft/Systems/wingflexer-params.xml which contains the parameters adjusted to your aircraft&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;PropertyList&amp;gt;&lt;br /&gt;
     &amp;lt;params&amp;gt;&lt;br /&gt;
         &amp;lt;m-wing-dry-kg type=&amp;quot;double&amp;quot;&amp;gt;12000.&amp;lt;/m-wing-dry-kg&amp;gt;&lt;br /&gt;
         &amp;lt;K type=&amp;quot;double&amp;quot;&amp;gt;259.&amp;lt;/K&amp;gt;&lt;br /&gt;
         &amp;lt;D type=&amp;quot;double&amp;quot;&amp;gt;12.&amp;lt;/D&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-frac type=&amp;quot;double&amp;quot;&amp;gt;0.375&amp;lt;/fuel-frac&amp;gt;&lt;br /&gt;
         &amp;lt;lift-node-lbs alias=&amp;quot;/fdm/jsbsim/forces/fbz-aero-lbs&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-1-kg alias=&amp;quot;/consumables/fuel/tank/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-2-kg alias=&amp;quot;/consumables/fuel/tank[1]/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-3-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-3-kg&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-4-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-4-kg&amp;gt;&lt;br /&gt;
     &amp;lt;/params&amp;gt;&lt;br /&gt;
 &amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
Also adjust the property node aliases for the wing fuel tanks. Wingflexer supports up to four tanks in total. Since we're currently only solving one equation and hence get only one deflection which is used for both wings, we have to average the wing mass. This is done by&lt;br /&gt;
  m_fuel = fuel-frac * (fuel-node-1-kg + fuel-node-2-kg + fuel-node-3-kg + fuel-node-4-kg).&lt;br /&gt;
Include the weighting factor in fuel-frac (e.g. 1/2 if you provide 2 fuel nodes). If you have more than 4 wing tanks in total, use another property rule to compute the average.&lt;br /&gt;
&lt;br /&gt;
In $yourAircraft-set.xml, in &amp;lt;systems&amp;gt; section, load the parameters and the wingflexer module:&lt;br /&gt;
 &amp;lt;systems&amp;gt;&lt;br /&gt;
     &amp;lt;wingflexer include=&amp;quot;Systems/wingflexer-params.xml&amp;quot;/&amp;gt;&lt;br /&gt;
     &amp;lt;property-rule n=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;name&amp;gt;wing flexer property rule&amp;lt;/name&amp;gt;&lt;br /&gt;
         &amp;lt;path&amp;gt;Aircraft/Generic/wingflexer.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
     &amp;lt;/property-rule&amp;gt;&lt;br /&gt;
 &amp;lt;/systems&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The wingflexer writes the deflection to /sim/systems/wingflexer/z-m.&lt;br /&gt;
Finally, your model rotate animation has to pick it up and multiply it by z_fac&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
     &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
     &amp;lt;property&amp;gt;sim/systems/wingflexer/z-m&amp;lt;/property&amp;gt;&lt;br /&gt;
     &amp;lt;factor&amp;gt;10.&amp;lt;/factor&amp;gt;&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your aircraft uses JSBSim, you're done now. Yasim requires an extra step, described next.&lt;br /&gt;
&lt;br /&gt;
== Yasim ==&lt;br /&gt;
Yasim does not write the lift to the property tree. But you can create a helper&lt;br /&gt;
function which computes the lift as&lt;br /&gt;
 lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs&lt;br /&gt;
and point the &amp;lt;lift-node-lbs&amp;gt; alias in wingflexer-params.xml to it.&lt;br /&gt;
&lt;br /&gt;
== Implementation details ==&lt;br /&gt;
=== Autopilot/Property rules implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.xml&lt;br /&gt;
&lt;br /&gt;
The ODE x&amp;quot; + ax' + bx + c = 0 is integrated by DampedOsciFilterImplementation in FG/src/autopilot/digitalfilter.cxx.&lt;br /&gt;
&lt;br /&gt;
=== Nasal implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.nas&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
* write Yasim helper&lt;br /&gt;
* input for fuselage acceleration should rather be acceleration at CG instead of the pilot's location -- is there a property?&lt;br /&gt;
* add wingflexer.py (to where?)&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82239</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82239"/>
		<updated>2015-03-11T00:03:14Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Autopilot/Property rules implementation */ line break&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wings of large aspect ratio tend to behave similar to a spring. They bend under load and oscillate for a while when the load changes, for example in a turn, during turbulence, or on touchdown. This article describes the Wingflexer module, which aims at animating the 3-D model of a wing in a somewhat realistic fashion. The method used is a significant improvement over what has been described here. However, the actual model animation part is identical and will not be covered.&lt;br /&gt;
&lt;br /&gt;
Including this in your aircraft is fairly straightforward, but obtaining plausible parameters can require some research and trial-and-error. We will give an example (the 787) below.&lt;br /&gt;
&lt;br /&gt;
Introduced in FG 3.5, there are two implementations available. One uses autopilot/property rules, is therefore very optimized and should be your first choice. The other uses Nasal. It is a bit more flexible in the sense that it could also be applied to AI aircraft.&lt;br /&gt;
&lt;br /&gt;
== Physical model ==&lt;br /&gt;
This section describes the physical model. You don't need to fully understand the maths here to be able to use Wingflexer, but you should understand the parameters involved -- you will need to adapt them to your aircraft.&lt;br /&gt;
&lt;br /&gt;
We use a simple spring-mass-damper system sketched below to model a flexible wing:&lt;br /&gt;
   --&amp;gt;       |&amp;lt;---- z ---&amp;gt;|&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
&lt;br /&gt;
The wing's motion, measured by the deflection z(t), is governed by the following parameters:&lt;br /&gt;
&lt;br /&gt;
 k          wing stiffness&lt;br /&gt;
 d          damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L    lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f        acceleration of the frame of reference (fuselage)&lt;br /&gt;
&lt;br /&gt;
We integrate the equation of motion&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/systems/wingflexer/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates a neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences leads to&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;br /&gt;
&lt;br /&gt;
== Obtaining plausible parameters ==&lt;br /&gt;
To make our model produce a convinving dynamic behaviour, you will need to obtain estimates and fine-tune the parameters.&lt;br /&gt;
&lt;br /&gt;
These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
There's a python script wingflexer.py which assists you in fine-tuning. It will quickly simulate the dynamics of the model with your parameters.&lt;br /&gt;
So how to estimate the parameters?&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's natural frequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
where&lt;br /&gt;
 m_ac   aircraft mass&lt;br /&gt;
 g      9.81 m/s^2&lt;br /&gt;
 z_fac  scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the natural frequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the wing's natural frequency, the wing's deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection (bounce)&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
* a lower wing mass increases the natural frequency, and weakens the touchdown bounce&lt;br /&gt;
* a higher stiffness K reduces the deflection and increases the natural frequency&lt;br /&gt;
&lt;br /&gt;
== Enable developer options ==&lt;br /&gt;
By default, Wingflexer and the user-tunable parameters live in&lt;br /&gt;
 /sim/systems/wingflexer/&lt;br /&gt;
 /sim/systems/wingflexer/params/&lt;br /&gt;
&lt;br /&gt;
There are two properties disabled by default which are only useful when you're tuning the parameters. To enable them, uncomment the developer section in Aircraft/Generic/wingflexer.xml.&lt;br /&gt;
This will activate&lt;br /&gt;
 /sim/systems/wingflexer/params/z-fac&lt;br /&gt;
 /sim/systems/wingflexer/params/sink-rate-fps&lt;br /&gt;
Z-fac simply scales the output. Once you're happy with the results, include this factor in the animation.&lt;br /&gt;
Sink-rate-fps allows you to simulate a touchdown at given vertical speed.&lt;br /&gt;
&lt;br /&gt;
It will become clear in the next section why these two settings are useful.&lt;br /&gt;
&lt;br /&gt;
== An example: the 787 ==&lt;br /&gt;
The 787 is known for its very flexible wings; the deflection in&lt;br /&gt;
unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds&lt;br /&gt;
23,000 kg of fuel. Because the fuel is distributed over the wing, we use a&lt;br /&gt;
fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason&lt;br /&gt;
we don't use the true wing mass, but rather something that makes our model look&lt;br /&gt;
plausible.&lt;br /&gt;
&lt;br /&gt;
So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.&lt;br /&gt;
That frequency might be a bit low, videos of a 777 wing in turbulence show about&lt;br /&gt;
2-3 Hz. (I didn't research 787 videos).&lt;br /&gt;
&lt;br /&gt;
To increase it, we could either reduce m_dw or increase K. A lower m_dw results&lt;br /&gt;
in a rather weak bounce on touchdown which might look odd. A higher K reduces&lt;br /&gt;
the deflection z_flight, but we can simply scale the animation to account for&lt;br /&gt;
that. We'll multiply the deflection z by a factor z_fac to get an angle for the&lt;br /&gt;
&amp;lt;rotate&amp;gt; animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.&lt;br /&gt;
Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects&lt;br /&gt;
to 0.3 m instead of 3 m, the animation scale factor will make sure the wing&lt;br /&gt;
bends to 3 m. This way, we can match both natural frequency and observed deflection,&lt;br /&gt;
and still get a realistic bounce on touch down. Finally, adjust D such that an&lt;br /&gt;
impulse is damped out after about one or two oscillations; D = 12 seems to work&lt;br /&gt;
OK in our example.&lt;br /&gt;
&lt;br /&gt;
It's difficult to get real-world data on the deflection during touchdown.&lt;br /&gt;
Touchdown at more than 10 ft/s is considered a hard landing and could result in some significant wing bending.&lt;br /&gt;
There's a video of a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the&lt;br /&gt;
wings bend perhaps 1 m.&lt;br /&gt;
&lt;br /&gt;
To assist you in tuning parameters for the touchdown bounce you can initialize your&lt;br /&gt;
wing mass with a (touchdown) vertical speed via /sim/systems/wingflexer/sink-rate-fps, and then observe the deflection and oscillation. This avoids you having to fly too many touch-and-go's while developing ;)&lt;br /&gt;
&lt;br /&gt;
Finally, our model outputs the deflection in meters, but the &amp;lt;rotate&amp;gt; animation expects an&lt;br /&gt;
angle. It is up to you convert appropriately, depending on your wing&lt;br /&gt;
span and number of segments in the animation. Also don't forget to include z_fac.&lt;br /&gt;
&lt;br /&gt;
== How to add to your aircraft ==&lt;br /&gt;
Create a file $YourAircraft/Systems/wingflexer-params.xml which contains the parameters adjusted to your aircraft&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;PropertyList&amp;gt;&lt;br /&gt;
     &amp;lt;params&amp;gt;&lt;br /&gt;
         &amp;lt;m-wing-dry-kg type=&amp;quot;double&amp;quot;&amp;gt;12000.&amp;lt;/m-wing-dry-kg&amp;gt;&lt;br /&gt;
         &amp;lt;K type=&amp;quot;double&amp;quot;&amp;gt;259.&amp;lt;/K&amp;gt;&lt;br /&gt;
         &amp;lt;D type=&amp;quot;double&amp;quot;&amp;gt;12.&amp;lt;/D&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-frac type=&amp;quot;double&amp;quot;&amp;gt;0.375&amp;lt;/fuel-frac&amp;gt;&lt;br /&gt;
         &amp;lt;lift-node-lbs alias=&amp;quot;/fdm/jsbsim/forces/fbz-aero-lbs&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-1-kg alias=&amp;quot;/consumables/fuel/tank/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-2-kg alias=&amp;quot;/consumables/fuel/tank[1]/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-3-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-3-kg&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-4-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-4-kg&amp;gt;&lt;br /&gt;
     &amp;lt;/params&amp;gt;&lt;br /&gt;
 &amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
Also adjust the property node aliases for the wing fuel tanks. Wingflexer supports up to four tanks in total. Since we're currently only solving one equation and hence get only one deflection which is used for both wings, we have to average the wing mass. This is done by&lt;br /&gt;
  m_fuel = fuel-frac * (fuel-node-1 + fuel-node-2 + fuel-node-3 + fuel-node-4).&lt;br /&gt;
Include the averaging weight factor in fuel-frac (e.g. 1/2 if you provide 2 fuel nodes). If you have more than 4 wing tanks in total, use another property rule to compute the average.&lt;br /&gt;
&lt;br /&gt;
In $yourAircraft-set.xml, in &amp;lt;systems&amp;gt; section, load the parameters and the wingflexer module:&lt;br /&gt;
 &amp;lt;systems&amp;gt;&lt;br /&gt;
     &amp;lt;wingflexer include=&amp;quot;Systems/wingflexer-params.xml&amp;quot;/&amp;gt;&lt;br /&gt;
     &amp;lt;property-rule n=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;name&amp;gt;wing flexer property rule&amp;lt;/name&amp;gt;&lt;br /&gt;
         &amp;lt;path&amp;gt;Aircraft/Generic/wingflexer.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
     &amp;lt;/property-rule&amp;gt;&lt;br /&gt;
 &amp;lt;/systems&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The wingflexer writes the deflection to /sim/systems/wingflexer/z-m.&lt;br /&gt;
Finally, your model rotate animation has to pick it up and multiply it by z_fac&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
     &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
     &amp;lt;property&amp;gt;sim/systems/wingflexer/z-m&amp;lt;/property&amp;gt;&lt;br /&gt;
     &amp;lt;factor&amp;gt;10.&amp;lt;/factor&amp;gt;&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your aircraft uses JSBSim, you're done now. Yasim requires an extra step, described next.&lt;br /&gt;
&lt;br /&gt;
== Yasim ==&lt;br /&gt;
Yasim does not write the lift to the property tree. But you can create a helper&lt;br /&gt;
function which computes the lift as&lt;br /&gt;
 lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs&lt;br /&gt;
and point the &amp;lt;lift-node-lbs&amp;gt; alias in wingflexer-params.xml to it.&lt;br /&gt;
&lt;br /&gt;
== Implementation details ==&lt;br /&gt;
=== Autopilot/Property rules implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.xml&lt;br /&gt;
&lt;br /&gt;
The ODE x&amp;quot; + ax' + bx + c = 0 is integrated by DampedOsciFilterImplementation in FG/src/autopilot/digitalfilter.cxx.&lt;br /&gt;
&lt;br /&gt;
=== Nasal implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.nas&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
* write Yasim helper&lt;br /&gt;
* input for fuselage acceleration should rather be acceleration at CG instead of the pilot's location -- is there a property?&lt;br /&gt;
* add wingflexer.py (to where?)&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82238</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82238"/>
		<updated>2015-03-10T23:54:33Z</updated>

		<summary type="html">&lt;p&gt;Radi: final version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wings of large aspect ratio tend to behave similar to a spring. They bend under load and oscillate for a while when the load changes, for example in a turn, during turbulence, or on touchdown. This article describes the Wingflexer module, which aims at animating the 3-D model of a wing in a somewhat realistic fashion. The method used is a significant improvement over what has been described here. However, the actual model animation part is identical and will not be covered.&lt;br /&gt;
&lt;br /&gt;
Including this in your aircraft is fairly straightforward, but obtaining plausible parameters can require some research and trial-and-error. We will give an example (the 787) below.&lt;br /&gt;
&lt;br /&gt;
Introduced in FG 3.5, there are two implementations available. One uses autopilot/property rules, is therefore very optimized and should be your first choice. The other uses Nasal. It is a bit more flexible in the sense that it could also be applied to AI aircraft.&lt;br /&gt;
&lt;br /&gt;
== Physical model ==&lt;br /&gt;
This section describes the physical model. You don't need to fully understand the maths here to be able to use Wingflexer, but you should understand the parameters involved -- you will need to adapt them to your aircraft.&lt;br /&gt;
&lt;br /&gt;
We use a simple spring-mass-damper system sketched below to model a flexible wing:&lt;br /&gt;
   --&amp;gt;       |&amp;lt;---- z ---&amp;gt;|&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
&lt;br /&gt;
The wing's motion, measured by the deflection z(t), is governed by the following parameters:&lt;br /&gt;
&lt;br /&gt;
 k          wing stiffness&lt;br /&gt;
 d          damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L    lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f        acceleration of the frame of reference (fuselage)&lt;br /&gt;
&lt;br /&gt;
We integrate the equation of motion&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/systems/wingflexer/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates a neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences leads to&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;br /&gt;
&lt;br /&gt;
== Obtaining plausible parameters ==&lt;br /&gt;
To make our model produce a convinving dynamic behaviour, you will need to obtain estimates and fine-tune the parameters.&lt;br /&gt;
&lt;br /&gt;
These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
There's a python script wingflexer.py which assists you in fine-tuning. It will quickly simulate the dynamics of the model with your parameters.&lt;br /&gt;
So how to estimate the parameters?&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's natural frequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
where&lt;br /&gt;
 m_ac   aircraft mass&lt;br /&gt;
 g      9.81 m/s^2&lt;br /&gt;
 z_fac  scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the natural frequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the wing's natural frequency, the wing's deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection (bounce)&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
* a lower wing mass increases the natural frequency, and weakens the touchdown bounce&lt;br /&gt;
* a higher stiffness K reduces the deflection and increases the natural frequency&lt;br /&gt;
&lt;br /&gt;
== Enable developer options ==&lt;br /&gt;
By default, Wingflexer and the user-tunable parameters live in&lt;br /&gt;
 /sim/systems/wingflexer/&lt;br /&gt;
 /sim/systems/wingflexer/params/&lt;br /&gt;
&lt;br /&gt;
There are two properties disabled by default which are only useful when you're tuning the parameters. To enable them, uncomment the developer section in Aircraft/Generic/wingflexer.xml.&lt;br /&gt;
This will activate&lt;br /&gt;
 /sim/systems/wingflexer/params/z-fac&lt;br /&gt;
 /sim/systems/wingflexer/params/sink-rate-fps&lt;br /&gt;
Z-fac simply scales the output. Once you're happy with the results, include this factor in the animation.&lt;br /&gt;
Sink-rate-fps allows you to simulate a touchdown at given vertical speed.&lt;br /&gt;
&lt;br /&gt;
It will become clear in the next section why these two settings are useful.&lt;br /&gt;
&lt;br /&gt;
== An example: the 787 ==&lt;br /&gt;
The 787 is known for its very flexible wings; the deflection in&lt;br /&gt;
unaccelerated flight is quoted as z = 3 m. One wing tank of FG's 787-8 holds&lt;br /&gt;
23,000 kg of fuel. Because the fuel is distributed over the wing, we use a&lt;br /&gt;
fraction of the fuel mass in the calculation: fuel_frac = 0.75. For the same reason&lt;br /&gt;
we don't use the true wing mass, but rather something that makes our model look&lt;br /&gt;
plausible.&lt;br /&gt;
&lt;br /&gt;
So assuming a wing mass of 12000 kg, we get K=25.9 and f_empty = 0.5 Hz.&lt;br /&gt;
That frequency might be a bit low, videos of a 777 wing in turbulence show about&lt;br /&gt;
2-3 Hz. (I didn't research 787 videos).&lt;br /&gt;
&lt;br /&gt;
To increase it, we could either reduce m_dw or increase K. A lower m_dw results&lt;br /&gt;
in a rather weak bounce on touchdown which might look odd. A higher K reduces&lt;br /&gt;
the deflection z_flight, but we can simply scale the animation to account for&lt;br /&gt;
that. We'll multiply the deflection z by a factor z_fac to get an angle for the&lt;br /&gt;
&amp;lt;rotate&amp;gt; animation later on anyway. So repeat 3. and 4. using e.g. z_fac = 10.&lt;br /&gt;
Now K = 259 and f_empty=2.6 Hz. While our model spring now only deflects&lt;br /&gt;
to 0.3 m instead of 3 m, the animation scale factor will make sure the wing&lt;br /&gt;
bends to 3 m. This way, we can match both natural frequency and observed deflection,&lt;br /&gt;
and still get a realistic bounce on touch down. Finally, adjust D such that an&lt;br /&gt;
impulse is damped out after about one or two oscillations; D = 12 seems to work&lt;br /&gt;
OK in our example.&lt;br /&gt;
&lt;br /&gt;
It's difficult to get real-world data on the deflection during touchdown.&lt;br /&gt;
Touchdown at more than 10 ft/s is considered a hard landing and could result in some significant wing bending.&lt;br /&gt;
There's a video of a hard landing of an A346 (http://avherald.com/h?article=471e70e9), showing the&lt;br /&gt;
wings bend perhaps 1 m.&lt;br /&gt;
&lt;br /&gt;
To assist you in tuning parameters for the touchdown bounce you can initialize your&lt;br /&gt;
wing mass with a (touchdown) vertical speed via /sim/systems/wingflexer/sink-rate-fps, and then observe the deflection and oscillation. This avoids you having to fly too many touch-and-go's while developing ;)&lt;br /&gt;
&lt;br /&gt;
Finally, our model outputs the deflection in meters, but the &amp;lt;rotate&amp;gt; animation expects an&lt;br /&gt;
angle. It is up to you convert appropriately, depending on your wing&lt;br /&gt;
span and number of segments in the animation. Also don't forget to include z_fac.&lt;br /&gt;
&lt;br /&gt;
== How to add to your aircraft ==&lt;br /&gt;
Create a file $YourAircraft/Systems/wingflexer-params.xml which contains the parameters adjusted to your aircraft&lt;br /&gt;
 &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;br /&gt;
 &amp;lt;PropertyList&amp;gt;&lt;br /&gt;
     &amp;lt;params&amp;gt;&lt;br /&gt;
         &amp;lt;m-wing-dry-kg type=&amp;quot;double&amp;quot;&amp;gt;12000.&amp;lt;/m-wing-dry-kg&amp;gt;&lt;br /&gt;
         &amp;lt;K type=&amp;quot;double&amp;quot;&amp;gt;259.&amp;lt;/K&amp;gt;&lt;br /&gt;
         &amp;lt;D type=&amp;quot;double&amp;quot;&amp;gt;12.&amp;lt;/D&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-frac type=&amp;quot;double&amp;quot;&amp;gt;0.375&amp;lt;/fuel-frac&amp;gt;&lt;br /&gt;
         &amp;lt;lift-node-lbs alias=&amp;quot;/fdm/jsbsim/forces/fbz-aero-lbs&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-1-kg alias=&amp;quot;/consumables/fuel/tank/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-2-kg alias=&amp;quot;/consumables/fuel/tank[1]/level-kg&amp;quot;/&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-3-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-3-kg&amp;gt;&lt;br /&gt;
         &amp;lt;fuel-node-4-kg type=&amp;quot;double&amp;quot;&amp;gt;0.&amp;lt;/fuel-node-4-kg&amp;gt;&lt;br /&gt;
     &amp;lt;/params&amp;gt;&lt;br /&gt;
 &amp;lt;/PropertyList&amp;gt;&lt;br /&gt;
Also adjust the property node aliases for the wing fuel tanks. Wingflexer supports up to four tanks in total. Since we're currently only solving one equation and hence get only one deflection which is used for both wings, we have to average the wing mass. This is done by&lt;br /&gt;
  m_fuel = fuel-frac * (fuel-node-1 + fuel-node-2 + fuel-node-3 + fuel-node-4).&lt;br /&gt;
Include the averaging weight factor in fuel-frac (e.g. 1/2 if you provide 2 fuel nodes). If you have more than 4 wing tanks in total, use another property rule to compute the average.&lt;br /&gt;
&lt;br /&gt;
In $yourAircraft-set.xml, in &amp;lt;systems&amp;gt; section, load the parameters and the wingflexer module:&lt;br /&gt;
 &amp;lt;systems&amp;gt;&lt;br /&gt;
     &amp;lt;wingflexer include=&amp;quot;Systems/wingflexer-params.xml&amp;quot;/&amp;gt;&lt;br /&gt;
     &amp;lt;property-rule n=&amp;quot;100&amp;quot;&amp;gt;&lt;br /&gt;
         &amp;lt;name&amp;gt;wing flexer property rule&amp;lt;/name&amp;gt;&lt;br /&gt;
         &amp;lt;path&amp;gt;Aircraft/Generic/wingflexer.xml&amp;lt;/path&amp;gt;&lt;br /&gt;
     &amp;lt;/property-rule&amp;gt;&lt;br /&gt;
 &amp;lt;/systems&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The wingflexer writes the deflection to /sim/systems/wingflexer/z-m.&lt;br /&gt;
Finally, your model rotate animation has to pick it up and multiply it by z_fac&lt;br /&gt;
 &amp;lt;animation&amp;gt;&lt;br /&gt;
     &amp;lt;type&amp;gt;rotate&amp;lt;/type&amp;gt;&lt;br /&gt;
     &amp;lt;property&amp;gt;sim/systems/wingflexer/z-m&amp;lt;/property&amp;gt;&lt;br /&gt;
     &amp;lt;factor&amp;gt;10.&amp;lt;/factor&amp;gt;&lt;br /&gt;
     ...&lt;br /&gt;
 &amp;lt;/animation&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If your aircraft uses JSBSim, you're done now. Yasim requires an extra step, described next.&lt;br /&gt;
&lt;br /&gt;
== Yasim ==&lt;br /&gt;
Yasim does not write the lift to the property tree. But you can create a helper&lt;br /&gt;
function which computes the lift as&lt;br /&gt;
 lift_force_lbs = aircraft_weight_lbs * load_factor - total_weight_on_wheels_lbs&lt;br /&gt;
and point the &amp;lt;lift-node-lbs&amp;gt; alias in wingflexer-params.xml to it.&lt;br /&gt;
&lt;br /&gt;
== Implementation details ==&lt;br /&gt;
=== Autopilot/Property rules implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.xml&lt;br /&gt;
The ODE x&amp;quot; + ax' + bx + c = 0 is integrated by DampedOsciFilterImplementation in FG/src/autopilot/digitalfilter.cxx.&lt;br /&gt;
&lt;br /&gt;
=== Nasal implementation ===&lt;br /&gt;
Code lives in Aircraft/Generic/wingflexer.nas&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
* write Yasim helper&lt;br /&gt;
* input for fuselage acceleration should rather be acceleration at CG instead of the pilot's location -- is there a property?&lt;br /&gt;
* add wingflexer.py (to where?)&lt;br /&gt;
&lt;br /&gt;
[[Category:FlightGear feature]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82133</id>
		<title>Wingflexer</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Wingflexer&amp;diff=82133"/>
		<updated>2015-03-09T10:58:52Z</updated>

		<summary type="html">&lt;p&gt;Radi: initial import&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Wingflexer intro text&lt;br /&gt;
&lt;br /&gt;
This article describes how to add wingflex to your aircraft and how to obtain plausible parameters. The physical model is given at the end.&lt;br /&gt;
&lt;br /&gt;
= How to add to your aircraft =&lt;br /&gt;
&lt;br /&gt;
= Obtain plausible parameters =&lt;br /&gt;
To make our model produce a convinving dynamic behaviour, you will need to obtain estimates (and fine-tune) a number of parameters. These include the wing mass m_w, the wing stiffness K, the damping D, and a scaling factor z_fac.&lt;br /&gt;
&lt;br /&gt;
1. Assume a dry wing mass m_dw. Research the wing fuel mass m_fuel.&lt;br /&gt;
&lt;br /&gt;
2. Obtain estimates of&lt;br /&gt;
* the deflection z_flight in level flight, e.g by comparing photos of the real aircraft on ground and in air,&lt;br /&gt;
* the wing's eigenfrequency, perhaps from videos of the wing's oscillation in turbulence,&lt;br /&gt;
* the deflection with full and empty tanks while sitting on the ground.&lt;br /&gt;
&lt;br /&gt;
3. Compute K to match in-flight deflection with full tanks:&lt;br /&gt;
 K = g * (m_ac / 2 - (fuel_frac * m_fuel)) / (z_in_flight / z_fac) / m_dw&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
&lt;br /&gt;
 m_ac : aircraft mass&lt;br /&gt;
 g    : 9.81 m/s^2&lt;br /&gt;
 z_fac: scaling factor for the deflection, start with 1&lt;br /&gt;
&lt;br /&gt;
4. Compute the eigenfrequency of this system for full and empty wing tanks:&lt;br /&gt;
 f_full  = sqrt(K * m_dw / (m_dw + fuel_frac * m_fuel)) / (2 pi)&lt;br /&gt;
 f_empty = sqrt(K) / (2 pi)&lt;br /&gt;
&lt;br /&gt;
Ideally we want our model to match the eigenfrequency, the deflection&lt;br /&gt;
while sitting on the ground with full or empty tanks, and the deflection&lt;br /&gt;
during a hard landing. Getting real-world data for the latter is difficult.&lt;br /&gt;
&lt;br /&gt;
Here are some relations:&lt;br /&gt;
- a lower wing mass increases the eigenfrequency, and weakens the touchdown bounce&lt;br /&gt;
- a higher stiffness K reduces the deflection and increases the eigenfrequency&lt;br /&gt;
&lt;br /&gt;
= Physical model =&lt;br /&gt;
   --&amp;gt;&lt;br /&gt;
    g&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
  &amp;lt;--- | m_w |---/\/\/\---|     |&lt;br /&gt;
       +-----+            +-----+&lt;br /&gt;
 Lift   wing     spring   fuselage&lt;br /&gt;
 force  mass&lt;br /&gt;
We integrate&lt;br /&gt;
      ..    k       d   .   0.5*F_L       ..&lt;br /&gt;
 0 = -z  + --- z + ---- z - ------- - g - z_f&lt;br /&gt;
           m_w     m_w       m_w&lt;br /&gt;
where&lt;br /&gt;
 z :        deflection&lt;br /&gt;
 k :        wing stiffness&lt;br /&gt;
 d :        damping&lt;br /&gt;
 m_w = m_dw + fuel_frac * m_fuel&lt;br /&gt;
            Total wing mass. Because the fuel is distributed over the wing, we use&lt;br /&gt;
            a fraction of the fuel mass in the calculation.&lt;br /&gt;
 0.5*F_L :  lift force/2 (we look at one wing only)&lt;br /&gt;
 ..&lt;br /&gt;
 z_f :      acceleration of the frame of reference (fuselage)&lt;br /&gt;
and write the deflection (z + z_ofs) in meters to /sim/model/wing-flex/z-m.&lt;br /&gt;
The offset z_ofs is calculated automatically and ensures that the dry wing&lt;br /&gt;
(which still has a non-zero mass) creates neutral deflection.&lt;br /&gt;
&lt;br /&gt;
Discretisation by first order finite differences:&lt;br /&gt;
 z_0 - 2 z_1 + z_2    k         d  (z_0 - z_1)   1/2 F_L       ..&lt;br /&gt;
 ----------------- + --- z_1 + --- ----------- - ------- - g - z_f = 0&lt;br /&gt;
      dt^2           m_w       m_w     dt          m_w&lt;br /&gt;
It is convenient to divide k and d by a (constant) reference mass:&lt;br /&gt;
 K = k / m_dw&lt;br /&gt;
 D = d / m_dw&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Project_Hong_Kong&amp;diff=81952</id>
		<title>Project Hong Kong</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Project_Hong_Kong&amp;diff=81952"/>
		<updated>2015-03-06T04:47:22Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Airports he are planning to work on */ spelling&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Project Hong Kong is aimed to improve the Hong Kong scenery in FlightGear.&lt;br /&gt;
&lt;br /&gt;
== Airports we are planning to work on ==&lt;br /&gt;
* VHHH&lt;br /&gt;
* VHXX&lt;br /&gt;
* VHSK&lt;br /&gt;
&lt;br /&gt;
== Hong Kong terrain improvements ==&lt;br /&gt;
We also will fix the FG terrain in Hong Kong to be close as possible to Real Hong Kong &lt;br /&gt;
&lt;br /&gt;
=== To Do List ===&lt;br /&gt;
* New Models for all airports and sounding areas &lt;br /&gt;
* Adding Detailed markings on runways and taxiways&lt;br /&gt;
* Moving existing models to their correct possessions &lt;br /&gt;
* Replacing inaccurate models &lt;br /&gt;
* Building the Victoria Harbor skyline &lt;br /&gt;
* Building Kowloon City &lt;br /&gt;
* Urbanizing the City &lt;br /&gt;
* Regenerating the Hong Kong terrain using TerraGear&lt;br /&gt;
* Building realistic roads with moving traffic &lt;br /&gt;
* Building realistic tracks with moving trains  &lt;br /&gt;
&lt;br /&gt;
== Volunteers are welcomed ==&lt;br /&gt;
If you wish to help in this project, please contact Pakistan-1 or Radi on the FlightGear Forum.&lt;br /&gt;
&lt;br /&gt;
[[Category:Community|Hong Kong |Development| ]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py_textures&amp;diff=81882</id>
		<title>Osm2city.py textures</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py_textures&amp;diff=81882"/>
		<updated>2015-03-05T01:33:08Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Install texture and lightmap */ reflect recent code changes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how you can prepare and register your own textures for use with osm2city.py.&lt;br /&gt;
It assumes you already have a texture image file. If not, see [[Howto:Create_textures_from_photos]].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
To texture a facade or a roof, you need&lt;br /&gt;
* two image files: the texture itself and a lightmap&lt;br /&gt;
* the texture's dimensions in meters&lt;br /&gt;
* locations in pixels at which osm2city.py may cut the texture to fit it to a given facade geometry, e.g. to apply a photo of a 15-storey building to a 12 storey model without shrinking it.&lt;br /&gt;
* 'provides' and 'requires' tags, e.g., a texture could require a black roof, while providing a commercial facade.&lt;br /&gt;
&lt;br /&gt;
Osm2city uses a texture atlas. This improves performance, but has two drawbacks:&lt;br /&gt;
# Textures can wrap around in at most one direction.&lt;br /&gt;
# Textures are scaled to one width (currently hardcoded 256 px)&lt;br /&gt;
&lt;br /&gt;
== texGUI.py ==&lt;br /&gt;
The script texGUI.py eases calibration and finding the cut locations. Run the GUI and supply your texture file:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
texGUI.py facade.png&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TexGUI calibrating width.jpg|thumb|texGUI: Calibrating a texture's width using an aircon as a reference object. Note the red line.]]&lt;br /&gt;
[[File:TexGUI added cut locations.jpg|thumb|texGUI: Added horizontal and vertical cut locations.]]&lt;br /&gt;
&lt;br /&gt;
It is generally a good idea to use descriptive names, such as &amp;quot;facade_industrial_old_white.png&amp;quot;, but for this example we simply use &amp;quot;facade.png&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
# Calibrate the image width/height. Find a feature in the image whose dimensions you know or can estimate. For example, simple windows are typically about 0.8 m wide. Here, we're using the aircon's width, estimated 0.82 m. Left drag to select that horizontal feature, then enter its length. Right drag for a vertical feature. You need only one of them. If both are given, both are used (e.g. if your image is stretched in one direction).&lt;br /&gt;
# Mark locations at which osm2city.py may cut the texture. Use left and right mouse buttons. Shift+click removes the last marker.&lt;br /&gt;
# Once you're satisfied, click &amp;quot;dump and quit&amp;quot;. This writes calibration/cut data to a file &amp;quot;facade_24x19m.py&amp;quot;. Note that texGUI added &amp;quot;_24x19m&amp;quot; to the texture file name (the original file is still in place), since you're likely to have more than one texture for an industrial facade.&lt;br /&gt;
&lt;br /&gt;
== Texture metadata ==&lt;br /&gt;
&lt;br /&gt;
Now edit facade_24x19m.py:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
facades.append(Texture('tex.src/facade_24x19m.png',&lt;br /&gt;
    23.8, [364, 742, 1086], h_can_repeat=True,&lt;br /&gt;
    18.5, [295, 565, 842], v_can_repeat=False,&lt;br /&gt;
    v_align_bottom = True,&lt;br /&gt;
    requires=[],&lt;br /&gt;
    provides=[]))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usually you need to change very little here.&lt;br /&gt;
* You can set the texture to wrap around in at most one direction using ''h_can_repeat'' or ''v_can_repeat''&lt;br /&gt;
* If ''v_align_bottom'' is True, osm2city.py will align the bottom part of the texture with the ground and cut away the top part if neccessary. Otherwise, it will align the top part with the roof and cut away the bottom.&lt;br /&gt;
&lt;br /&gt;
For reference, we now descibe the format in a bit more detail. You might want to skip to the [[Osm2city.py_Textures#Texture_compatibility|next section]].&lt;br /&gt;
&lt;br /&gt;
First line is the path to our texture.&lt;br /&gt;
Second line says the texture&lt;br /&gt;
* is 23.8m wide&lt;br /&gt;
* can be cut at u = 364, 742, and 1068 px, where u is the horizontal coordinate. The last value 1086 also gives the width in px. Note that the .ac file uses normalized coordinates (0 ... 1). Internally, osm2city.py divides all coordinates by the last value. Therefore, when preparing the textures, you can work with the highest resolution possible and register those numbers, then just downscale the texture for actual flightgear use. Once the next generation of graphics cards arrives you just replace the textures with higher resolution ones without touching the cut locations.&lt;br /&gt;
* the texture can repeat in horizontal direction.&lt;br /&gt;
&lt;br /&gt;
The third line gives the same information for the vertical direction:&lt;br /&gt;
* 18.5m height&lt;br /&gt;
* can cut at 295, 565, 842 px,&lt;br /&gt;
* the texture cannot repeat in vertical direction&lt;br /&gt;
&lt;br /&gt;
== Texture compatibility ==&lt;br /&gt;
&lt;br /&gt;
The fourth and fifth line state compatibility with other textures. TexGUI.py just creates an empty template here. A useful example could look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
    requires=['roof:color:black'],&lt;br /&gt;
    provides=['shape:industrial','age:old','compat:roof-flat','compat:roof-gable']))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This facade texture requires a black roof. It provides an old-aged, industrial facade, and is compatible with both flat and gable roofs. TODO: describe details on our requires/provides mechanism.&lt;br /&gt;
&lt;br /&gt;
== Lightmap ==&lt;br /&gt;
&lt;br /&gt;
A lightmap &amp;lt;del&amp;gt;is required for every texture, having&amp;lt;/del&amp;gt;has the same file name with a postfix &amp;quot;_LM&amp;quot;.  So for our example this would be&lt;br /&gt;
&amp;quot;facade_24x19m_LM.png&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Osm2city uses&lt;br /&gt;
* red channel for window lights&lt;br /&gt;
* green channel for ambient street lights shining onto facade&lt;br /&gt;
* blue and alpha unused&lt;br /&gt;
&lt;br /&gt;
TODO describe add_streetlight.py&lt;br /&gt;
&lt;br /&gt;
== Install texture and lightmap ==&lt;br /&gt;
* copy texture and lightmap to tex.src/&lt;br /&gt;
* add the snippet from &amp;quot;facade_24x19m.py&amp;quot; to textures/catalog.py&lt;br /&gt;
&lt;br /&gt;
If you're adding a roof, name your texture &amp;quot;roof_something.png&amp;quot; and append it to the list of ''roofs'' (instead of ''facades'')&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
roofs.append(Texture('tex.src/roof_something.png',&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See roof examples starting around line 400. Note that also roofs need a lightmap.&lt;br /&gt;
&lt;br /&gt;
Finally, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city.py -A&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to re-create the texture atlas. If there are no errors, your texture is registered and will be used next time you run osm2city.py. If your texture is GPL compatible, please consider&lt;br /&gt;
sending it (along with the meta data) to one of the osm2city.py devs to have it included in the official distribution.&lt;br /&gt;
&lt;br /&gt;
[[Category:Modeling]]&lt;br /&gt;
[[Category:OpenStreetMap]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py_textures&amp;diff=81881</id>
		<title>Osm2city.py textures</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py_textures&amp;diff=81881"/>
		<updated>2015-03-05T01:30:25Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Lightmap */ we can work without LM, but then we won't have lighting, of course&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how you can prepare and register your own textures for use with osm2city.py.&lt;br /&gt;
It assumes you already have a texture image file. If not, see [[Howto:Create_textures_from_photos]].&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
To texture a facade or a roof, you need&lt;br /&gt;
* two image files: the texture itself and a lightmap&lt;br /&gt;
* the texture's dimensions in meters&lt;br /&gt;
* locations in pixels at which osm2city.py may cut the texture to fit it to a given facade geometry, e.g. to apply a photo of a 15-storey building to a 12 storey model without shrinking it.&lt;br /&gt;
* 'provides' and 'requires' tags, e.g., a texture could require a black roof, while providing a commercial facade.&lt;br /&gt;
&lt;br /&gt;
Osm2city uses a texture atlas. This improves performance, but has two drawbacks:&lt;br /&gt;
# Textures can wrap around in at most one direction.&lt;br /&gt;
# Textures are scaled to one width (currently hardcoded 256 px)&lt;br /&gt;
&lt;br /&gt;
== texGUI.py ==&lt;br /&gt;
The script texGUI.py eases calibration and finding the cut locations. Run the GUI and supply your texture file:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
texGUI.py facade.png&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:TexGUI calibrating width.jpg|thumb|texGUI: Calibrating a texture's width using an aircon as a reference object. Note the red line.]]&lt;br /&gt;
[[File:TexGUI added cut locations.jpg|thumb|texGUI: Added horizontal and vertical cut locations.]]&lt;br /&gt;
&lt;br /&gt;
It is generally a good idea to use descriptive names, such as &amp;quot;facade_industrial_old_white.png&amp;quot;, but for this example we simply use &amp;quot;facade.png&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
# Calibrate the image width/height. Find a feature in the image whose dimensions you know or can estimate. For example, simple windows are typically about 0.8 m wide. Here, we're using the aircon's width, estimated 0.82 m. Left drag to select that horizontal feature, then enter its length. Right drag for a vertical feature. You need only one of them. If both are given, both are used (e.g. if your image is stretched in one direction).&lt;br /&gt;
# Mark locations at which osm2city.py may cut the texture. Use left and right mouse buttons. Shift+click removes the last marker.&lt;br /&gt;
# Once you're satisfied, click &amp;quot;dump and quit&amp;quot;. This writes calibration/cut data to a file &amp;quot;facade_24x19m.py&amp;quot;. Note that texGUI added &amp;quot;_24x19m&amp;quot; to the texture file name (the original file is still in place), since you're likely to have more than one texture for an industrial facade.&lt;br /&gt;
&lt;br /&gt;
== Texture metadata ==&lt;br /&gt;
&lt;br /&gt;
Now edit facade_24x19m.py:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
facades.append(Texture('tex.src/facade_24x19m.png',&lt;br /&gt;
    23.8, [364, 742, 1086], h_can_repeat=True,&lt;br /&gt;
    18.5, [295, 565, 842], v_can_repeat=False,&lt;br /&gt;
    v_align_bottom = True,&lt;br /&gt;
    requires=[],&lt;br /&gt;
    provides=[]))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Usually you need to change very little here.&lt;br /&gt;
* You can set the texture to wrap around in at most one direction using ''h_can_repeat'' or ''v_can_repeat''&lt;br /&gt;
* If ''v_align_bottom'' is True, osm2city.py will align the bottom part of the texture with the ground and cut away the top part if neccessary. Otherwise, it will align the top part with the roof and cut away the bottom.&lt;br /&gt;
&lt;br /&gt;
For reference, we now descibe the format in a bit more detail. You might want to skip to the [[Osm2city.py_Textures#Texture_compatibility|next section]].&lt;br /&gt;
&lt;br /&gt;
First line is the path to our texture.&lt;br /&gt;
Second line says the texture&lt;br /&gt;
* is 23.8m wide&lt;br /&gt;
* can be cut at u = 364, 742, and 1068 px, where u is the horizontal coordinate. The last value 1086 also gives the width in px. Note that the .ac file uses normalized coordinates (0 ... 1). Internally, osm2city.py divides all coordinates by the last value. Therefore, when preparing the textures, you can work with the highest resolution possible and register those numbers, then just downscale the texture for actual flightgear use. Once the next generation of graphics cards arrives you just replace the textures with higher resolution ones without touching the cut locations.&lt;br /&gt;
* the texture can repeat in horizontal direction.&lt;br /&gt;
&lt;br /&gt;
The third line gives the same information for the vertical direction:&lt;br /&gt;
* 18.5m height&lt;br /&gt;
* can cut at 295, 565, 842 px,&lt;br /&gt;
* the texture cannot repeat in vertical direction&lt;br /&gt;
&lt;br /&gt;
== Texture compatibility ==&lt;br /&gt;
&lt;br /&gt;
The fourth and fifth line state compatibility with other textures. TexGUI.py just creates an empty template here. A useful example could look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
    requires=['roof:color:black'],&lt;br /&gt;
    provides=['shape:industrial','age:old','compat:roof-flat','compat:roof-gable']))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This facade texture requires a black roof. It provides an old-aged, industrial facade, and is compatible with both flat and gable roofs. TODO: describe details on our requires/provides mechanism.&lt;br /&gt;
&lt;br /&gt;
== Lightmap ==&lt;br /&gt;
&lt;br /&gt;
A lightmap &amp;lt;del&amp;gt;is required for every texture, having&amp;lt;/del&amp;gt;has the same file name with a postfix &amp;quot;_LM&amp;quot;.  So for our example this would be&lt;br /&gt;
&amp;quot;facade_24x19m_LM.png&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Osm2city uses&lt;br /&gt;
* red channel for window lights&lt;br /&gt;
* green channel for ambient street lights shining onto facade&lt;br /&gt;
* blue and alpha unused&lt;br /&gt;
&lt;br /&gt;
TODO describe add_streetlight.py&lt;br /&gt;
&lt;br /&gt;
== Install texture and lightmap ==&lt;br /&gt;
* copy texture and lightmap to tex.src/&lt;br /&gt;
* add the snippet from &amp;quot;facade_24x19m.py&amp;quot; to textures.py:init() starting around line 300&lt;br /&gt;
&lt;br /&gt;
If you're adding a roof, name your texture &amp;quot;roof_something.png&amp;quot; and append it to the list of ''roofs'' (instead of ''facades'')&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
roofs.append(Texture('tex.src/roof_something.png',&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See roof examples starting around line 400. Note that also roofs need a lightmap.&lt;br /&gt;
&lt;br /&gt;
Finally, run&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
textures.py&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If there are no errors, your texture is registered and will be used next time you run osm2city.py. If your texture is GPL compatible, please consider&lt;br /&gt;
sending it (along with the meta data) to one of the osm2city.py devs to have it included in the official distribution.&lt;br /&gt;
&lt;br /&gt;
[[Category:Modeling]]&lt;br /&gt;
[[Category:OpenStreetMap]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=81867</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=81867"/>
		<updated>2015-03-04T23:19:47Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Probe elevation */ quote strings&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. soft link osm2city-data/tex and osm2city-data/tex.src into osm2city/ such that it appears as a sub-directory of osm2city&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city/&lt;br /&gt;
  tex.src/&lt;br /&gt;
  tex/&lt;br /&gt;
  osm2city.py&lt;br /&gt;
  textures.py&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{caution|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = &amp;quot;LOWI&amp;quot; (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = &amp;quot;buildings.osm&amp;quot;&lt;br /&gt;
:* 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 &amp;quot;/home/user/fgfs/scenery/TerraSync&amp;quot; .&lt;br /&gt;
:* set PATH_TO_OUTPUT to a ''different'' scenery path, e.g. &amp;quot;/home/user/fgfs/scenery/osm2city&amp;quot; . 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
{{note|Python does not recognize environment variables, please use full paths in the parameters file (no $HOME etc).}}&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
{{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 = &amp;quot;Manual&amp;quot;.}}&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;FgelevCaching&amp;quot;&lt;br /&gt;
:* Set FG_ELEV to your fgelev executable. For example: FG_ELEV = &amp;quot;/usr/local/fg/bin/fgelev&amp;quot; or just FG_ELEV = &amp;quot;fgelev&amp;quot; if fgelev is already in your OS's path.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;Manual&amp;quot;&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FG_ROOT/Nasal/&lt;br /&gt;
:* Open $FG_ROOT/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_ROOT/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = &amp;quot;Telnet&amp;quot;&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* Make sure you're in osm2city's directory and run &lt;br /&gt;
&lt;br /&gt;
 python osm2city.py -f LOWI/params.ini. &lt;br /&gt;
&lt;br /&gt;
The parsed OSM data is cached to file LOWI/buildings.osm.pkl which is used on next startup if you set USE_PKL = 1.&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
=== FGElev crashes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
CRITICAL:root:1173 -95.5767 37.0965&lt;br /&gt;
CRITICAL:root:fgelev returned &amp;lt;&amp;gt;, resulting in list index out of range. Did fgelev start OK (Record : 1173)?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The first line is the last input to fgelev. &lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter the line last sent to fgelev. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173 -95.5767 37.0965&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The response should look like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173: 226.793&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. ===&lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
=== Buildings/roads have no texture. I get errors &amp;quot;osgDB ac3d reader: could not find texture &amp;quot;tex/atlas_facades.png&amp;quot;. ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=81866</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=81866"/>
		<updated>2015-03-04T23:17:56Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Adjust input file */ new params file requires quoted strings&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. soft link osm2city-data/tex and osm2city-data/tex.src into osm2city/ such that it appears as a sub-directory of osm2city&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city/&lt;br /&gt;
  tex.src/&lt;br /&gt;
  tex/&lt;br /&gt;
  osm2city.py&lt;br /&gt;
  textures.py&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{caution|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = &amp;quot;LOWI&amp;quot; (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = &amp;quot;buildings.osm&amp;quot;&lt;br /&gt;
:* 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 &amp;quot;/home/user/fgfs/scenery/TerraSync&amp;quot; .&lt;br /&gt;
:* set PATH_TO_OUTPUT to a ''different'' scenery path, e.g. &amp;quot;/home/user/fgfs/scenery/osm2city&amp;quot; . 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
{{note|Python does not recognize environment variables, please use full paths in the parameters file (no $HOME etc).}}&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FG_ROOT/Nasal/&lt;br /&gt;
:* Open $FG_ROOT/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_ROOT/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* Make sure you're in osm2city's directory and run &lt;br /&gt;
&lt;br /&gt;
 python osm2city.py -f LOWI/params.ini. &lt;br /&gt;
&lt;br /&gt;
The parsed OSM data is cached to file LOWI/buildings.osm.pkl which is used on next startup if you set USE_PKL = 1.&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
=== FGElev crashes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
CRITICAL:root:1173 -95.5767 37.0965&lt;br /&gt;
CRITICAL:root:fgelev returned &amp;lt;&amp;gt;, resulting in list index out of range. Did fgelev start OK (Record : 1173)?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The first line is the last input to fgelev. &lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter the line last sent to fgelev. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173 -95.5767 37.0965&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The response should look like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173: 226.793&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. ===&lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
=== Buildings/roads have no texture. I get errors &amp;quot;osgDB ac3d reader: could not find texture &amp;quot;tex/atlas_facades.png&amp;quot;. ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Howto:Convert_objects_from_X-Plane&amp;diff=81008</id>
		<title>Howto:Convert objects from X-Plane</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Howto:Convert_objects_from_X-Plane&amp;diff=81008"/>
		<updated>2015-02-16T05:27:41Z</updated>

		<summary type="html">&lt;p&gt;Radi: Announce new scripts&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This [[:Category:Howto|tutorial]] explains how to '''convert X-Plane scenery objects''' to the [[File Formats#.2A.ac|AC3D format]] (.ac) used by [[FlightGear]] (mostly) automatically using the xplane2fg collection of scripts. To convert '''Microsoft (R) Flight Simulator scenery objects''', first convert them to X-Plane format using [http://marginal.org.uk/x-planescenery/tools.html FS2XPlane], then follow the method described below.&lt;br /&gt;
&lt;br /&gt;
'''Note: [[Howto:Convert objects with ModelConverterX|ModelConverterX]] also seems well suited for this task, having even more features and is probably easier to set up.'''&lt;br /&gt;
&lt;br /&gt;
'''Note 2: MCX doesnt't work for me on Linux (tried with Wine + Mono). As of Feb 2015, I'm re-writing conversion scripts. The new version will  come bundled with everything you need, be a lot easier to set-up, and be almost 100% automated.'''&lt;br /&gt;
&lt;br /&gt;
These scripts were developed on Linux and should work fine on any Unix system including Mac ([[Howto: Convert objects from MSFS#Note to Windows Users|note to Windows users]]).&lt;br /&gt;
&lt;br /&gt;
The conversion consists of three steps, all conveniently handled by scripts:&lt;br /&gt;
* convert the actual 3-D objects from .obj to .ac format using blender,&lt;br /&gt;
* extract position of objects (longitude, latitude, altitude, and heading) from .dsf file(s) and write them to FlightGear's .stg file(s),&lt;br /&gt;
* copy the objects and their textures to the respective tile folders.&lt;br /&gt;
&lt;br /&gt;
This Howto assumes that you&lt;br /&gt;
* are able to use the command line to enter basic commands&lt;br /&gt;
* know where FlightGear, its scenery, and its source code are installed&lt;br /&gt;
&lt;br /&gt;
'''Please note: objects that are uploaded to the [[FlightGear Scenery Database]] (and thus official FG scenery) must be released under the [[GNU GPL]] license. Most X-Plane/MSFS scenery does ''not'' comply with this license. Therefore, it cannot be included with the official scenery, unless the author granted you permission to release his work under GNU GPL. Basically, it mostly means that it is for your own private use only.'''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Installation and setup ==&lt;br /&gt;
=== Prerequisites ===&lt;br /&gt;
Besides a Unix environment, you'll need the following tools:&lt;br /&gt;
&lt;br /&gt;
* [http://ubuntuone.com/0sAOY4lB1OVCWP3zy8jfn8 xplane2fg]&lt;br /&gt;
* [http://www.blender.org Blender] (tested with ver. 2.48a-r3)&lt;br /&gt;
* XPlane2blender from [http://marginal.org.uk/x-planescenery/tools.html Jonathan Harris' page], tested with ver. 3.09&lt;br /&gt;
* [http://winehq.com Wine]&lt;br /&gt;
* [http://scenery.x-plane.com/tools.php X-Plane scenery tools]&lt;br /&gt;
* [[FlightGear]]&lt;br /&gt;
* perl helpers from FlightGear's [http://www.flightgear.org/Downloads/source.shtml source code]:&lt;br /&gt;
** calc-tile.pl&lt;br /&gt;
** find_elevations.pl&lt;br /&gt;
* telnet&lt;br /&gt;
&lt;br /&gt;
Optionally (if the scenery to convert contains .dds textures)&lt;br /&gt;
* convert (from [http://www.imagemagick.org ImageMagick])&lt;br /&gt;
&lt;br /&gt;
=== Installation ===&lt;br /&gt;
Install xplane2fg:&lt;br /&gt;
&lt;br /&gt;
 mkdir -p ~/fgfs/convert/&lt;br /&gt;
 cd ~/fgfs/convert/&lt;br /&gt;
 tar xzf /path/to/xplane2fg.tgz&lt;br /&gt;
&lt;br /&gt;
Copy the autoimport.py helper to Blender's scripts folder:&lt;br /&gt;
 cp ~/fgfs/convert/xplane2fg/lib/autoimport.py ~/.blender/scripts&lt;br /&gt;
&lt;br /&gt;
Install X-Plane tools in $HOME/convert/xptools&lt;br /&gt;
&lt;br /&gt;
=== Hack the tools ===&lt;br /&gt;
For the first step - importing objects into blender - we use Jonathan Harris' XPlane2Blender import filter. The .ac export filter shipped with Blender does the export. As we will batch convert a large number of objects, both import and export filters need to be 'hacked' as to not stop and wait for user interaction on warnings etc:&lt;br /&gt;
&lt;br /&gt;
Open XPlaneImport.py in a text editor, change line 466 (of ver. 3.09) to: &lt;br /&gt;
 self.verbose = 0&lt;br /&gt;
Save this file as XPlaneImportVerbose0.py&lt;br /&gt;
&lt;br /&gt;
Open ac3d_export.py (part of Blender, located for example in /usr/share/blender/scripts/) in a text editor, replace line 823: &lt;br /&gt;
 Blender.Draw.PupMenu('ERROR: no objects selected')&lt;br /&gt;
with &lt;br /&gt;
 pass&lt;br /&gt;
Make sure you keep indention. Save this file as ac3d_export_hack.py&lt;br /&gt;
&lt;br /&gt;
=== Setting up the environment according to your system ===&lt;br /&gt;
The xplane2fg scripts glue together a number of tools. To have the scripts find these tools, you have to adjust the paths in $HOME/fgfs/convert/xplane2fg/profile according to your system (using a text editor).&lt;br /&gt;
&lt;br /&gt;
Now everything should be set up to actually convert scenery!&lt;br /&gt;
&lt;br /&gt;
== Conversion ==&lt;br /&gt;
First load xplane2fg's environment profile:&lt;br /&gt;
 source $HOME/fgfs/convert/xplane2fg/profile&lt;br /&gt;
&lt;br /&gt;
=== Prepare X-Plane scenery ===&lt;br /&gt;
In the following, we assume the X-Plane scenery we want to convert is named EDDN (make sure it contains no spaces!) and lives in&lt;br /&gt;
  $HOME/fgfs/convert/EDDN/&lt;br /&gt;
with the following sub folders&lt;br /&gt;
    Earth nav data&lt;br /&gt;
    objects&lt;br /&gt;
    textures&lt;br /&gt;
&lt;br /&gt;
Those sub folders may have slightly different names. If so, rename them to fit the above scheme. Remember that Unix file names are case sensitive.&lt;br /&gt;
&lt;br /&gt;
=== Prepare FlightGear ===&lt;br /&gt;
X-Plane objects are positioned using [http://en.wikipedia.org/wiki/Above_ground_level AGL], while FlightGear's .stg files expect [http://en.wikipedia.org/wiki/Above_mean_sea_level AMSL]. We will use FlightGear to automatically query the elevation at the object's postition. Therefore, the corresponding scenery tile must be installed. Find out on which tile the scenery you want to convert is located. See [[Howto: Install scenery]] for details on how to install FlightGear scenery. The most convenient way may be to use [[TerraSync]].&lt;br /&gt;
&lt;br /&gt;
=== Convert ===&lt;br /&gt;
Now run the main conversion script:&lt;br /&gt;
 cd $HOME/fgfs/convert/&lt;br /&gt;
 xplane2fg.sh  EDDN  EDDN.fg&lt;br /&gt;
&lt;br /&gt;
The converted scenery will be written to the path indicated by the second argument, EDDN.fg. It should '''not''' point to FG's actual scenery paths.&lt;br /&gt;
&lt;br /&gt;
After some seconds, this will stop and ask you to run blender. By that time, it should have created an input file for blender named&lt;br /&gt;
 blender-autoimport-source.py&lt;br /&gt;
in the current directory.&lt;br /&gt;
  &lt;br /&gt;
Now open a second terminal and run blender from that directory.&lt;br /&gt;
 cd $HOME/fgfs/convert&lt;br /&gt;
 blender&lt;br /&gt;
&lt;br /&gt;
Click file -&amp;gt; import -&amp;gt; autoimport, it should now convert all objects, this may take a while.&lt;br /&gt;
When finished, close blender (and the second terminal), and press {{Key press|Enter}} in the xplane2fg terminal.&lt;br /&gt;
  &lt;br /&gt;
xplane2fg will now fire up FlightGear. Press {{Key press|Enter}} when FlightGear is up and running.&lt;br /&gt;
The script then queries the elevation for all objects; this might take a while.&lt;br /&gt;
During this process, .stg files are written to their respective tile paths under EDDN.fg. Also, xplane2fg searches for texture files used by the scenery objects, copies them to EDDN.fg or complains in case they're missing.&lt;br /&gt;
  &lt;br /&gt;
When xplane2fg is finished, you should have something like&lt;br /&gt;
  ls $HOME/fgfs/convert/EDDN.fg/Objects/e000n40/e006n46/&lt;br /&gt;
      3056136.stg&lt;br /&gt;
      3056139.stg&lt;br /&gt;
      Terminal.ac&lt;br /&gt;
      ...&lt;br /&gt;
&lt;br /&gt;
We're almost done!&lt;br /&gt;
&lt;br /&gt;
=== Check textures ===&lt;br /&gt;
X-Plane may use .dds textures, which '''can''' be converted to .png format. However, following recent discussion on the developers mailing list, FlightGear/OSG can also use .dds textures. Hence, you may also skip this step. I have not tested using .dds textures with FlightGear. Your milage may vary.&lt;br /&gt;
&lt;br /&gt;
Go to the converted scenery folder&lt;br /&gt;
 cd EDDN.fg/Objects/e000n40/e006n46/&lt;br /&gt;
and run&lt;br /&gt;
 check_and_fix_textures.sh  *.ac&lt;br /&gt;
You may want to remove .dds files afterwards to save space:&lt;br /&gt;
 rm *.dds&lt;br /&gt;
&lt;br /&gt;
=== Integrate the converted files into FlightGear scenery ===&lt;br /&gt;
Finally you have to copy the converted scenery to FlightGear's scenery folder. Make sure to backup the respective scenery folder beforehand.&lt;br /&gt;
&lt;br /&gt;
The .stg files should be '''appended''' instead of overwritten should they exist already in FlightGear's Scenery folder; otherwise you'll lose previously defined scenery objects. You may want to use a file manager such as Konqueror, Nautilus, or Midnight Commander for this step, as they tend to ask whether to overwrite or append existing files.&lt;br /&gt;
&lt;br /&gt;
Now you can fire up FlightGear and enjoy the converted scenery!&lt;br /&gt;
&lt;br /&gt;
== Final steps ==&lt;br /&gt;
=== Cleanup ===&lt;br /&gt;
Temporary files were written to $HOME/fgfs/convert/tmp. You can remove them now:&lt;br /&gt;
 rm -rf $HOME/fgfs/convert/tmp&lt;br /&gt;
&lt;br /&gt;
=== Share the converted scenery ===&lt;br /&gt;
If you want to publish the scenery you need to obtain authorization to do so from the scenery's original authors.&lt;br /&gt;
&lt;br /&gt;
If you want it to be included in FlightGear's official scenery via the [[FlightGear Scenery Database]], the converted scenery (including all textures) must comply with the [[GNU GPL]].&lt;br /&gt;
&lt;br /&gt;
=== Optional ===&lt;br /&gt;
You may use&lt;br /&gt;
&lt;br /&gt;
 xplane2fg.sh --prefix EDDN_  EDDN  EDDN.fg&lt;br /&gt;
&lt;br /&gt;
to prepend all converted objects with a prefix, e.g., EDDN_objectname.ac&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
xplane2fg.sh may complain about funny elevations reported by FlightGear:&lt;br /&gt;
&lt;br /&gt;
 WARNING: Zero alt for LSGS-grasss-1.ac?&lt;br /&gt;
 &lt;br /&gt;
I suspect this happens when a tile is just being loaded in background, as subsequent calls would return correct elevation. However, since we might query objects floating on water, I did not implement automatic retrying (yet). Instead, you should manually query these objects. Start Flightgear&lt;br /&gt;
&lt;br /&gt;
 xplane2fg.sh --run-fgfs&lt;br /&gt;
&lt;br /&gt;
then run&lt;br /&gt;
&lt;br /&gt;
 xplane2fg.sh --query-alt LSGS-grasss-1.ac&lt;br /&gt;
&lt;br /&gt;
which would return something like&lt;br /&gt;
&lt;br /&gt;
 OBJECT_STATIC LSGS-grasss-1.ac 7.3416857 46.2201743 482.24 357.99&lt;br /&gt;
 in /e000n40/e007n46/3072521.stg&lt;br /&gt;
&lt;br /&gt;
and correct the respective line in the indicated .stg file.&lt;br /&gt;
&lt;br /&gt;
=== Note to Windows Users ===&lt;br /&gt;
I developed these scripts on Linux. They are written in bash and make heavy use of GNU utilities (sed, awk, grep etc.). Some helpers require Perl. &lt;br /&gt;
To run these scripts on Windows, you will need to install cygwin and perl (at least). You will have to fix some further issues yourself; the wine part, for example, is probably not necessary on Windows ;)&lt;br /&gt;
&lt;br /&gt;
[[Category:Howto|Convert objects from X-Plane]]&lt;br /&gt;
[[Category:Scenery enhancement|Convert objects from X-Plane]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=78664</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=78664"/>
		<updated>2014-12-30T11:21:17Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Support and troubleshooting */ included error msg, formatting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. soft link osm2city-data/tex and osm2city-data/tex.src into osm2city/ such that it appears as a sub-directory of osm2city&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city/&lt;br /&gt;
  tex.src/&lt;br /&gt;
  tex/&lt;br /&gt;
  osm2city.py&lt;br /&gt;
  textures.py&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{caution|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
{{note|Python does not recognize environment variables, please use full paths in the parameters file (no $HOME etc).}}&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
{{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.}}&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* Open $FGDATA/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_DATA/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* Make sure you're in osm2city's directory and run &lt;br /&gt;
&lt;br /&gt;
 python osm2city.py -f LOWI/params.ini. &lt;br /&gt;
&lt;br /&gt;
The parsed OSM data is cached to file LOWI/buildings.osm.pkl which is used on next startup if you set USE_PKL = 1.&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
=== FGElev crashes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
CRITICAL:root:1173 -95.5767 37.0965&lt;br /&gt;
CRITICAL:root:fgelev returned &amp;lt;&amp;gt;, resulting in list index out of range. Did fgelev start OK (Record : 1173)?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The first line is the last input to fgelev. &lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter the line last sent to fgelev. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173 -95.5767 37.0965&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The response should look like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173: 226.793&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. ===&lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
=== Buildings/roads have no texture. I get errors &amp;quot;osgDB ac3d reader: could not find texture &amp;quot;tex/atlas_facades.png&amp;quot;. ===&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=78520</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=78520"/>
		<updated>2014-12-23T22:07:10Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Run osm2city */ should run directly from osm2city's dir&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. soft link osm2city-data/tex and osm2city-data/tex.src into osm2city/ such that it appears as a sub-directory of osm2city&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city/&lt;br /&gt;
  tex.src/&lt;br /&gt;
  tex/&lt;br /&gt;
  osm2city.py&lt;br /&gt;
  textures.py&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* Open $FGDATA/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_DATA/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* Make sure you're in osm2city's directory and run &lt;br /&gt;
&lt;br /&gt;
 python osm2city.py -f LOWI/params.ini. &lt;br /&gt;
&lt;br /&gt;
The parsed OSM data is cached to file LOWI/buildings.osm.pkl which is used on next startup if you set USE_PKL = 1.&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
* FGElev crashes &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
CRITICAL:root:1173 -95.5767 37.0965&lt;br /&gt;
CRITICAL:root:fgelev returned &amp;lt;&amp;gt;, resulting in list index out of range. Did fgelev start OK (Record : 1173)?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The first line is the last input to fgelev. &lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter the line last sent to fgelev. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173 -95.5767 37.0965&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The response should look like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173: 226.793&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=78519</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=78519"/>
		<updated>2014-12-23T21:42:35Z</updated>

		<summary type="html">&lt;p&gt;Radi: clarified tex.src/ instructions&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. soft link osm2city-data/tex and osm2city-data/tex.src into osm2city/ such that it appears as a sub-directory of osm2city&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
osm2city/&lt;br /&gt;
  tex.src/&lt;br /&gt;
  tex/&lt;br /&gt;
  osm2city.py&lt;br /&gt;
  textures.py&lt;br /&gt;
  ...&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* Open $FGDATA/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_DATA/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
* FGElev crashes &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
CRITICAL:root:1173 -95.5767 37.0965&lt;br /&gt;
CRITICAL:root:fgelev returned &amp;lt;&amp;gt;, resulting in list index out of range. Did fgelev start OK (Record : 1173)?&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The first line is the last input to fgelev. &lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter the line last sent to fgelev. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173 -95.5767 37.0965&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The response should look like &lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
1173: 226.793&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77918</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77918"/>
		<updated>2014-11-20T19:40:35Z</updated>

		<summary type="html">&lt;p&gt;Radi: Undo revision 77917 by Radi (talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* Open $FGDATA/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_DATA/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77917</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77917"/>
		<updated>2014-11-20T19:38:27Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Contributing */ link devel thread&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* Open $FGDATA/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_DATA/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Use the forum development [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 thread].&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77888</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77888"/>
		<updated>2014-11-18T16:32:26Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Probe elevation */ moved in var edit to probe elevation section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* Open $FGDATA/Nasal/elev.nas in a text editor. Point the in variable to your elev.in file e.g. var in = &amp;quot;/path/to/$FG_DATA/Nasal/elev.in&amp;quot;. &lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77887</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77887"/>
		<updated>2014-11-18T16:26:45Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Install */ moved elev.in var edit&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
* the moving cars (TRAFFIC_SHADER_ENABLE = True) are only visible when you disable Atmospheric light scattering (ALS)&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77818</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77818"/>
		<updated>2014-11-16T01:24:20Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Troubleshooting */ support rules&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
6. Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
&lt;br /&gt;
7. Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Support and troubleshooting ==&lt;br /&gt;
Time permitting, we can provide limited support on the [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 Forums]. Please don't use PM for support questions.&lt;br /&gt;
&lt;br /&gt;
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? &lt;br /&gt;
&lt;br /&gt;
We will not cover general questions like &amp;quot;I don't know how to install XY&amp;quot; -- search the Internet.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77732</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77732"/>
		<updated>2014-11-10T11:42:16Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Install */ fix numbering&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;gt;= 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 &lt;br /&gt;
&lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
6. Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
&lt;br /&gt;
7. Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77731</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77731"/>
		<updated>2014-11-10T11:36:55Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Install on Windows */ Note to follow install&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
6. Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
&lt;br /&gt;
7. Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
In general, you'll want to follow the above install section. This section lists some additional Windows particularities. &lt;br /&gt;
&lt;br /&gt;
Osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.7 is recommended unless you're an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]].&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77730</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77730"/>
		<updated>2014-11-10T11:32:02Z</updated>

		<summary type="html">&lt;p&gt;Radi: link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
6. Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
&lt;br /&gt;
7. Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.7 is recommended unless your an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with [[Osm2city.py#Install|step 2. above]]&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77729</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77729"/>
		<updated>2014-11-10T11:22:51Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Install */ fix numbering (maybe there's a better way?)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
&lt;br /&gt;
4. link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
&lt;br /&gt;
6. Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
&lt;br /&gt;
7. Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.?? is recommended unless your an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with step 2 above.&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77728</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77728"/>
		<updated>2014-11-10T11:11:28Z</updated>

		<summary type="html">&lt;p&gt;Radi: refer win install to install&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
1. dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
2. get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
3. add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
4. link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
5. copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
6. Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
7. Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python.&lt;br /&gt;
&lt;br /&gt;
https://www.python.org/downloads/release/python-278/&lt;br /&gt;
&lt;br /&gt;
{{warning|Python 2.?? is recommended unless your an experienced Python developer willing to update the Python scripts to support Python 3. Also pay attention to versions and cpu builds of the below helper files. Make sure they match your OS build and Python version.}} &lt;br /&gt;
&lt;br /&gt;
Install the following packages, then proceed with step 2 above.&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77621</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77621"/>
		<updated>2014-11-02T23:35:29Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Install */ depends on networkx&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
* dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil python-networkx&lt;br /&gt;
&lt;br /&gt;
* get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
* add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
* link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
* copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
* Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
* Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python. Install the following packages. &lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77283</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77283"/>
		<updated>2014-10-23T21:53:19Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Adjust input file */ emphasise using different PATH_TO_SCENERY and PATH_TO_OUTPUT&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
* dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil&lt;br /&gt;
&lt;br /&gt;
* get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
* add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
* link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
* copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
* Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
* Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python. Install the following packages. &lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* 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 .&lt;br /&gt;
:* 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]].&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77277</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77277"/>
		<updated>2014-10-23T11:26:59Z</updated>

		<summary type="html">&lt;p&gt;Radi: maybe FG_ROOT must be set?&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
* dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil&lt;br /&gt;
&lt;br /&gt;
* get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
* add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
* link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
* copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
* Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
* Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python. Install the following packages. &lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* set PATH_TO_SCENERY to a standard FG_SCENERY path. Suppose the area you want to populate is /home/user/fgfs/scenery/Objects/e010n40/e011n47/, PATH_TO_SCENERY would then be /home/user/fgfs/scenery/ .&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
:* make sure the environment variable [[$FG ROOT]] points to your FG base path, (e.g. export FG_ROOT=/usr/share/games/flightgear/ on Linux) &lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
then enter&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY and $FG_ROOT.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77275</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77275"/>
		<updated>2014-10-22T23:21:41Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Probe elevation */ fgelev problems note&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
* dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil&lt;br /&gt;
&lt;br /&gt;
* get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
* add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
* link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
* copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
* Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
* Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python. Install the following packages. &lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* set PATH_TO_SCENERY to a standard FG_SCENERY path. Suppose the area you want to populate is /home/user/fgfs/scenery/Objects/e010n40/e011n47/, PATH_TO_SCENERY would then be /home/user/fgfs/scenery/ .&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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?)&lt;br /&gt;
&lt;br /&gt;
'''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.'''&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
[code]&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
[code]&lt;br /&gt;
then enter&lt;br /&gt;
[code]&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
[code]&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77274</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77274"/>
		<updated>2014-10-22T22:12:03Z</updated>

		<summary type="html">&lt;p&gt;Radi: troubleshooting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
* dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil&lt;br /&gt;
&lt;br /&gt;
* get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
* add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
* link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
* copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
* Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
* Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python. Install the following packages. &lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* set PATH_TO_SCENERY to a standard FG_SCENERY path. Suppose the area you want to populate is /home/user/fgfs/scenery/Objects/e010n40/e011n47/, PATH_TO_SCENERY would then be /home/user/fgfs/scenery/ .&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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 &amp;gt;= 3.2 or FG git later than 10 Oct 2014, try FgelevCaching. Failing that, try Manual. (portreekid, what's the 3rd mode good for?)&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
* Buildings are generated, but they sit below the ground. I'm using ELEV_MODE = FgelevCaching. &lt;br /&gt;
&lt;br /&gt;
Try running fgelev directly:&lt;br /&gt;
[code]&lt;br /&gt;
/path/to/fgelev --expire 1000 --fg-root $FG_ROOT --fg-scenery $FG_SCENERY&lt;br /&gt;
[code]&lt;br /&gt;
then enter&lt;br /&gt;
[code]&lt;br /&gt;
0 $lon $lat&lt;br /&gt;
[code]&lt;br /&gt;
where $lon and $lat are coordinates in the area you want to generate. See if it returns a sane value. If it does, double-check PATH_TO_SCENERY.&lt;br /&gt;
&lt;br /&gt;
* Buildings/roads have no texture. &lt;br /&gt;
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/.&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77262</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77262"/>
		<updated>2014-10-22T02:23:47Z</updated>

		<summary type="html">&lt;p&gt;Radi: filed status sections under news&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== News ==&lt;br /&gt;
=== Status 10/2014 ===&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
=== Status 06/2014 ===&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Status 04/2014 ===&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
=== Status 10/2013 ===&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
* dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil&lt;br /&gt;
&lt;br /&gt;
* get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
* add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
* link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
* copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
* Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
* Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python. Install the following packages. &lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* set PATH_TO_SCENERY to a standard FG_SCENERY path. Suppose the area you want to populate is /home/user/fgfs/scenery/Objects/e010n40/e011n47/, PATH_TO_SCENERY would then be /home/user/fgfs/scenery/ .&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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 &amp;gt;= 3.2 or FG git later than 10 Oct 2014, try FgelevCaching. Failing that, try Manual. (portreekid, what's the 3rd mode good for?)&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77261</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77261"/>
		<updated>2014-10-22T02:21:05Z</updated>

		<summary type="html">&lt;p&gt;Radi: /* Features */  LM works&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== Status 10/2014 ==&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
== Status 06/2014 ==&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Status 04/2014 ==&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
== Status 10/2013 ==&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
* dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil&lt;br /&gt;
&lt;br /&gt;
* get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
* add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
* link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
* copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
* Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
* Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python. Install the following packages. &lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* set PATH_TO_SCENERY to a standard FG_SCENERY path. Suppose the area you want to populate is /home/user/fgfs/scenery/Objects/e010n40/e011n47/, PATH_TO_SCENERY would then be /home/user/fgfs/scenery/ .&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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 &amp;gt;= 3.2 or FG git later than 10 Oct 2014, try FgelevCaching. Failing that, try Manual. (portreekid, what's the 3rd mode good for?)&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
	<entry>
		<id>https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77260</id>
		<title>Osm2city.py</title>
		<link rel="alternate" type="text/html" href="https://wiki.flightgear.org/w/index.php?title=Osm2city.py&amp;diff=77260"/>
		<updated>2014-10-22T02:20:20Z</updated>

		<summary type="html">&lt;p&gt;Radi: Status 10/2014&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{OSM Navigation}}&lt;br /&gt;
[[File:LOWI with OSM buildings.jpg|thumb|LOWI with OSM buildings]]&lt;br /&gt;
&lt;br /&gt;
This Python script takes OpenStreetMap floorplans and creates 3d buildings ready for use in FlightGear.&lt;br /&gt;
&lt;br /&gt;
The development [https://gitorious.org/fg-radi/osm2city repository] is hosted on gitorious.&lt;br /&gt;
Forum thread [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
Written in Python 2.7, developed on GNU/Linux. It should also run on Mac OSX. Windows users, see [[Osm2city.py#Install_on_Windows|below.]]&lt;br /&gt;
&lt;br /&gt;
It's at a rather early stage of development. There's no GUI, everything is controlled by an input file. But it produces realistic city layouts (after all, it uses realistic data). The whole process -- from scratch to flying in FG -- for a city the size of LOWI takes perhaps 30 min, including maybe a total of 15 min manual work.&lt;br /&gt;
&lt;br /&gt;
It has been tested with Dresden, Germany (EDDC) and Innsbruck, Austria (LOWI). Both areas are now populated with about 50,000 buildings. Rendering this in FG is quite demanding. The FG process eats ~2.8GB RAM when flying in those areas, the download is ~50 MB each.&lt;br /&gt;
&lt;br /&gt;
== Status 10/2014 ==&lt;br /&gt;
New features: &lt;br /&gt;
* textures reside in a separate [https://gitorious.org/fg-radi/osm2city-data repository]&lt;br /&gt;
* the recommended elevation probing method is ELEV_MODE=FgelevCaching&lt;br /&gt;
* roads.py is now quite usable&lt;br /&gt;
* SKIP_LIST can contain OSM_IDs&lt;br /&gt;
&lt;br /&gt;
== Status 06/2014 ==&lt;br /&gt;
I'm currently adding textured roads, railroads, intersections and bridges.&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  | the shader is now on osm2city's git (in fgdata/). Again -- all credit goes to Emilian. He is improving the shader side, I will continue on the model side. So this is very much work in progress.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The shader requires the default renderer. No ALS/Rembrandt yet.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Get the LOWI roads pack (including the shader) here:&amp;lt;br&amp;gt;[https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz https://dl.dropboxusercontent.com/u/24846517/fg/osm2city/LOWI_roads.tar.gz]&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;The fgdata/ folder goes to your $FGDATA.&amp;lt;br&amp;gt;In roads.xml enable either the lightmap or the traffic shader.&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FGCquote&lt;br /&gt;
  |Creating your own road network is a bit cumbersome ATM, I'll try to make it more general in the next few days. But if you're really, really keen on it: &amp;lt;br&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt; get latest osm2city git&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; run roads.py -f your-parameters-file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; if you also create buildings, make sure to use the same BOUNDARY_* parameters for both osm2city.py and roads.py. Otherwise, buildings and roads might be misaligned. Basically, if your OSM file contains both roads and buildings, you can just use one parameters file.&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; roads.py will print an OBJECT_STATIC line, add this to your .stg (appears to add itself)&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.ac to your scenery&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt; copy roads.xml and tex/ from the LOWI roads pack to your scenery (roads.ac and .xml copy themselves)&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
  |{{cite web |url=http://forum.flightgear.org/viewtopic.php?p=212460#p212460&lt;br /&gt;
     |title=&amp;lt;nowiki&amp;gt;Re: osm2city.py development&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |author=&amp;lt;nowiki&amp;gt;radi&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
     |date=&amp;lt;nowiki&amp;gt;Fri Jun 13&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
   }}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Status 04/2014 ==&lt;br /&gt;
[[File:LOWI with OSM buildings from FL300.jpg|thumb|Aerial view of LOWI, with 60k OSM buildings]]&lt;br /&gt;
Following Mathias' suggestion at FS Weekend 2013, I've now changed the code such that it merges all buildings per (osm2city) tile into one object, reducing the number of drawables from O(10k) to O(10). That indeed gives a nice speed-up. In fact, I'm overwhelmed by what's possible now -- here's a scene looking down at LOWI from FL300 showing 60k buildings. Plain Scenery 2.0 gives 19 fps on i7 Intel HD 5000 2560x1440. With buildings framerate goes down to 14.&lt;br /&gt;
&lt;br /&gt;
[[File:LOWI with OSM buidings one object per tile.jpg|thumb|Approaching LOWI, with 60k OSM buildings]]&lt;br /&gt;
The second scene, approaching LOWI from the east, went from 30 fps without buildings down to 20 fps.&lt;br /&gt;
&lt;br /&gt;
== Status 10/2013 ==&lt;br /&gt;
Currently data is processed offline beforehand. Basically, it parses the OSM&lt;br /&gt;
xml, generates a list of building outlines, discards some based on their area,&lt;br /&gt;
simplifies the outlines, clusters them into ~500x500m blocks and different LODs,&lt;br /&gt;
then writes .ac, .xml, and .stgs. &amp;lt;del&amp;gt;OSM parsing is by far the most expensive,&lt;br /&gt;
easily taking 10 minutes for 50k buildings. Once that's done, the remaining parts take maybe 1 minute in total.&lt;br /&gt;
&amp;lt;/del&amp;gt; (Some optimization gave a huge speedup).&lt;br /&gt;
&lt;br /&gt;
At the moment, the code knows only the floor plans. &amp;lt;del&amp;gt;No streets&amp;lt;/del&amp;gt;, no runways, no&lt;br /&gt;
land-use. But it'll certainly process such data in the future, and then could&lt;br /&gt;
use some heuristics (some OSM buildings are labeled &amp;quot;Terminal 1&amp;quot; or so) to apply&lt;br /&gt;
terminal/hangar textures to buildings at airports. This way we could rather easily populate some airports with&lt;br /&gt;
'semi-generic' terminal/hangar buildings.&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
* reads buildings from OSM. Honors height and level tags, reads relations ('buildings with holes')&lt;br /&gt;
* reads existing .stg, won't place OSM building if there's a static model nearby&lt;br /&gt;
* reads pre-calculated terrain elevation: places buildings at correct elevation&lt;br /&gt;
* simplify/automate elevation probing by using fgelev&lt;br /&gt;
* LOD animation based on building height and area (see below)&lt;br /&gt;
* cluster a number of buildings into a single .ac files. Clusters overlap to alleviate sharp LOD borders&lt;br /&gt;
* complex sloped roof generation (using Olivier Teboul's implementation of the straight skeleton algorithm)&lt;br /&gt;
* texture manager: DB of facade/roof textures&lt;br /&gt;
:* ~10 different, hi-res facade textures, some roof textures&lt;br /&gt;
:* find matching texture for given building (number of levels, modern/old building, etc)&lt;br /&gt;
:* find matching roof texture for given facade texture&lt;br /&gt;
* basic lightmap support (currently broken)&lt;br /&gt;
* obstruction lights on tall buildings&lt;br /&gt;
* command line interface and parameters file (thanks to forum user vanosten)&lt;br /&gt;
* shows statistics on processed buildings&lt;br /&gt;
* writes .ac, .xml, .stg&lt;br /&gt;
&lt;br /&gt;
== Planned Features ==&lt;br /&gt;
(in random order)&lt;br /&gt;
* more complex facade generation. Currently, all sides get same texture  {{not done}}&lt;br /&gt;
* Rembrandt lighting {{not done}}&lt;br /&gt;
* put a piece of matching ground texture around buildings ('garden') {{progressbar|10}}&lt;br /&gt;
* put shared models if/where OSM indicates so: gas stations... {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* use residential/industrial/commercial tags/areas. ATM, all is residential. {{not done}}&lt;br /&gt;
* geometry cleanup, simplify too complex buildings {{done}}&lt;br /&gt;
* Batch processing of greater areas including downloads {{done}}&lt;br /&gt;
* use more LOD levels, write them to different .ac so users can easily reduce building density, therefore improve performance {{progressbar|50}}&lt;br /&gt;
:* put large buildings into one ac, sort/rate buildings by stand-out-ness {{done}}&lt;br /&gt;
:* then ship light/med/full .stg {{not done}}&lt;br /&gt;
* mid-term: develop this into a city-engine that procedurally generates a city based on OSM roads. {{not done}}&lt;br /&gt;
:* read, drape, texture roads and railways {{progressbar|70}}&lt;br /&gt;
:* texture road intersections  {{not done}}&lt;br /&gt;
:* illuminate roads {{not done}}&lt;br /&gt;
:* procedural bridges  {{progressbar|50}}&lt;br /&gt;
:* place shared models along roads if no OSM data available {{not done}}&lt;br /&gt;
* long-term: integrate into FG to do all this on the fly. {{not done}}&lt;br /&gt;
&lt;br /&gt;
== LOD Scheme ==&lt;br /&gt;
FlightGear knows three standard LOD: bare, rough and detail. 'Bare' sets the drawing distance of the terrain, which may easily be 50 km or more. Drawing buildings 50 km out makes little sense (unless they are ''really'' tall), so we shouldn't use this level here. Of the remaining two standard levels, 'rough' is used for large and/or tall buildings, and 'detail' for smaller ones.&lt;br /&gt;
&lt;br /&gt;
Osm2city can generate complex roof shapes. This increases the poly count further, and I believe it's a good idea to use another LOD 'roof' for complex roofs. Fortunately, we can change every aspect of FlightGear, and adding another LOD is easy. Use the FG command line&lt;br /&gt;
 --prop:double:/sim/rendering/static-lod/roof=2000&lt;br /&gt;
to set the distance for 'roof' to 2 km. If you want to adjust it via FG's GUI, copy static-lod.xml (from osm2city's git repo) to $FGDATA/gui/dialogs.&lt;br /&gt;
&lt;br /&gt;
== Ideas ==&lt;br /&gt;
* nearby hi-rise objects of similar shape get same texture? Probably too special a feature.&lt;br /&gt;
* bump map/reflection effects?&lt;br /&gt;
* a mode that generally uses shared models? If we find a shared models of matching floorplan, use this instead of creating a new, individual building? Will break clusters.&lt;br /&gt;
* a terrasync-like thing? Users get OSM buildings&lt;br /&gt;
(where available) on-the-fly? Might be quite costly in terms of runtime performance and bandwidth. The OSM download (buildings only!) is&lt;br /&gt;
~40MB for the 25x25km LOWI area.&lt;br /&gt;
&lt;br /&gt;
== Install ==&lt;br /&gt;
* dependencies: Install the following packages (names from Debian packages):&lt;br /&gt;
  python-numpy python-shapely python-matplotlib python-scipy python-pil&lt;br /&gt;
&lt;br /&gt;
* get [https://gitorious.org/fg-radi/osm2city osm2city] and [https://gitorious.org/fg-radi/osm2city-data osm2city-data] from gitorious&lt;br /&gt;
* add the directory with osm2city modules to your [http://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH PYTHONPATH] (unless your PYTHONPATH already contains . (the dot))&lt;br /&gt;
* link osm2city-data/tex and osm2city-data/tex.src into osm2city/&lt;br /&gt;
&lt;br /&gt;
If you're running FG &amp;lt; 3.2, or git older than 10 Oct 2014, or have less than 4 GB RAM, you will most likely need to use the old-fashioned way of elevation probing, which requires you to &lt;br /&gt;
* copy elev.nas to $FGDATA/Nasal/&lt;br /&gt;
* Change the in variable of elev.nas to match the elev.in file e.g. $FG_DATA/Nasal/elev.in&lt;br /&gt;
* Change the out variable of elev.nas to the export directory with a filename with write access (e.g. $FG_HOME/Export). See [[IORules]] and [[$FG_HOME]]&lt;br /&gt;
&lt;br /&gt;
== Install on Windows ==&lt;br /&gt;
osm2city is pure python. Install the following packages. &lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely&lt;br /&gt;
&lt;br /&gt;
http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy-stack&lt;br /&gt;
&lt;br /&gt;
https://pypi.python.org/pypi/Pillow/2.5.0#downloads&lt;br /&gt;
&lt;br /&gt;
== Workflow ==&lt;br /&gt;
There are five main steps:&lt;br /&gt;
* get OSM data&lt;br /&gt;
* adjust input file&lt;br /&gt;
* if neccessary, create elevation grid and run FG to probe elevation data.&lt;br /&gt;
* run osm2city&lt;br /&gt;
* &amp;lt;del&amp;gt;install the generated scenery&amp;lt;/del&amp;gt;installs itself&lt;br /&gt;
&lt;br /&gt;
We'll now walk through these steps in detail:&lt;br /&gt;
=== get OSM data ===&lt;br /&gt;
* decide on a region you want to populate. Get its lon/lat coordinates.&lt;br /&gt;
* create a project directory. We will use LOWI/ in this example.&lt;br /&gt;
* get corresponding OSM data in its native .xml format.&lt;br /&gt;
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 download URL that you can fetch with wget:&lt;br /&gt;
 wget -O buildings.osm http://www.overpass-api.de/api/xapi?map?bbox=11.16898,47.20837,11.79108,47.38161&lt;br /&gt;
&lt;br /&gt;
If you use [http://wiki.openstreetmap.org/wiki/Osmosis Osmosis] and cut the area with ''--bounding-box'' then you need to use ''completeWays=yes''.&lt;br /&gt;
&lt;br /&gt;
Put this data into LOWI/buildings.osm&lt;br /&gt;
&lt;br /&gt;
=== Adjust input file ===&lt;br /&gt;
* Now adjust the input file. You can generate a commented default parameters file by&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
parameters.py -d &amp;gt; LOWI/params.ini&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Edit this file, adjusting (at least) the following:&lt;br /&gt;
:* PREFIX = LOWI (the project directory)&lt;br /&gt;
:* BOUNDARY_EAST, BOUNDARY_NORTH, BOUNDARY_SOUTH, BOUNDARY_WEST&lt;br /&gt;
:* OSM_FILE = buildings.osm&lt;br /&gt;
:* set PATH_TO_SCENERY to a standard FG_SCENERY path. Suppose the area you want to populate is /home/user/fgfs/scenery/Objects/e010n40/e011n47/, PATH_TO_SCENERY would then be /home/user/fgfs/scenery/ .&lt;br /&gt;
:* 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.&lt;br /&gt;
:* you also need to set up elevation probing in the parameters file, described in the next section.&lt;br /&gt;
&lt;br /&gt;
=== Probe elevation ===&lt;br /&gt;
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 &amp;gt;= 3.2 or FG git later than 10 Oct 2014, try FgelevCaching. Failing that, try Manual. (portreekid, what's the 3rd mode good for?)&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = FgelevCaching&lt;br /&gt;
:* 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.&lt;br /&gt;
:* Set PATH_TO_SCENERY (Missing terrain will result in error message)&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Manual&lt;br /&gt;
:* run tools.py (tools.py -f LOWI/params.ini), this will create a file elev.in. Copy elev.in to $FGDATA/Nasal/&lt;br /&gt;
:* 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&lt;br /&gt;
:* run FG, open debug-&amp;gt;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/&lt;br /&gt;
:* unhide, rename the objects folder&lt;br /&gt;
&lt;br /&gt;
* ELEV_MODE = Telnet&lt;br /&gt;
:* Run setup.py&lt;br /&gt;
:* Start FG with the properties service on Port 5501&lt;br /&gt;
:* Run tools.py, this will create a elev.in, start the nasal script and copy the elev.out back to your project directory&lt;br /&gt;
&lt;br /&gt;
=== Run osm2city ===&lt;br /&gt;
* run osm2city.py -f LOWI/prams.ini. Parsing OSM data &amp;lt;del&amp;gt;again takes quite looong (10 minutes or more for 50k buildings)&amp;lt;/del&amp;gt; is now pretty fast, but the result is cached to file buildings.pkl. Next startup will be &amp;lt;del&amp;gt;much faster if you move buildings.pkl to LOWI/buildings.pkl and&amp;lt;/del&amp;gt; even faster if you set USE_PKL = 1.&lt;br /&gt;
&lt;br /&gt;
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&lt;br /&gt;
* copy or link the tex/ folder into the objects folder where these files were created&lt;br /&gt;
&lt;br /&gt;
=== Roads ===&lt;br /&gt;
* run roads.py in the same fashion for roads&lt;br /&gt;
* &amp;lt;del&amp;gt;copy roads.eff to the same Objects\e0XXnXX\e0XXnXX\ directory&amp;lt;/del&amp;gt; roads.eff is copied automatically&lt;br /&gt;
* 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&lt;br /&gt;
&lt;br /&gt;
== Improve frame rate ==&lt;br /&gt;
* adjust LOD ranges in FG&lt;br /&gt;
* decrease MAX_OBJECTS, increase LOD_*&lt;br /&gt;
(- use larger/smaller tiles? Tradeoff between distance calculations/xml parsing and GPU)&lt;br /&gt;
&lt;br /&gt;
== Contributing ==&lt;br /&gt;
You know some python? Or you're keen on writing docs? Or just want to use osm2city, but got stuck somewhere? Contact radi on the FG forum.&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
== Related ==&lt;br /&gt;
* [[Using OSM Vector Data in FlightGear]]&lt;br /&gt;
* [[OpenStreetMap buildings]]&lt;br /&gt;
* [[AutoGen Scenery for FlightGear]]&lt;br /&gt;
* [[Random Buildings]]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=21131#p192198 OSM buidings EHLE]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=22809 osm2city.py development]&lt;br /&gt;
* [http://www.mail-archive.com/flightgear-devel@lists.sourceforge.net/msg40092.html Osm2city.py]&lt;br /&gt;
* http://forum.flightgear.org/viewtopic.php?f=5&amp;amp;t=19625&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?f=38&amp;amp;t=8837 PixelCity]&lt;br /&gt;
* [http://forum.flightgear.org/viewtopic.php?p=166794#p166681 Procedural OSM buildings]&lt;br /&gt;
&lt;br /&gt;
[[Category:Scenery software]]&lt;/div&gt;</summary>
		<author><name>Radi</name></author>
	</entry>
</feed>