Extrude 2D polygons to 3D: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(new)
 
 
(12 intermediate revisions by 3 users not shown)
Line 12: Line 12:
[[Image:Osm_map2d.png|thumb|center|300px|OSM 2D map]]
[[Image:Osm_map2d.png|thumb|center|300px|OSM 2D map]]


=== OSM map import and building extraction into new map ===
Import into a metric GRASS location (here: UTM32N), extract the buildings and extrude them to 3D:
Import into a metric GRASS location (here: UTM32N), extract the buildings and extrude them to 3D:
<source lang="bash">
<source lang="bash">
v.in.ogr polygons_UTM32.shp out=oberursel2D
v.in.ogr polygons_UTM32.shp out=oberursel2D
# colorize a bit
v.colors oberursel2D column=cat color=random
d.mon x0
d.vect -a oberursel2D
d.barscale -mt


# extract the buildings into a new map (use db.connect -p to see which driver you are using):
# extract the buildings into a new map (use db.connect -p to see which driver you are using):
Line 21: Line 28:


### statement for SQLite driver:
### statement for SQLite driver:
v.extract oberursel2D out=oberursel2D_small where="tags LIKE LIKE '%building%'"
v.extract oberursel2D out=oberursel2D_small where="tags LIKE '%building%'"
</source>
</source>


[[Image:Osm_map2d_buildings.png|thumb|center|300px|Buildings extracted from OSM 2D map]]
[[Image:Osm_map2d_buildings.png|thumb|center|300px|Buildings extracted from OSM 2D map]]


We see that a lot of buildings are actually NOT tagged as buildings. You may fix that at http://www.openstreetmap.org/
Alternative: use {{cmd|v.db.addcol}} to add an "area double precision" column and upload the area sizes in (square)meters with {{cmd|v.to.db}}. Then use {{cmd|v.extract}} to extract all areas over, say, 200 m^2. However, better fix the OSM map!
=== Extruding building polygons to 3D ===
<source lang="bash">
<source lang="bash">
# extrude 2D building polygons to 3D, here with a constant height:
# extrude 2D building polygons to 3D, here with a constant height (you can indicate an attribute column for individual heights):
v.extrude oberursel2D_small out=oberursel3D height=20
v.extrude oberursel2D_small out=oberursel3D height=20 elevation=srtm


# check that the 'areas' have become type 'faces':
# check that the 'areas' have become type 'faces':
Line 34: Line 46:
</source>
</source>


Ready! Now we can visualize them:
Ready! Note that you can make use of individual heights when stored in the attribute table for the respective building since v.extrude supports also that.
 
=== Extra ideas ===
 
To make the visualization more realistic, use the building footprint area to assign a more realistic (assumed) building height. This can done with {{cmd|v.db.update}} rather easily by applying a series of range formulas.
 
== Visualization ==
 
Now we can visualize them:


<source lang="bash">
<source lang="bash">
Line 48: Line 68:


[[Image:Osm_map3d_buildings.png|thumb|center|300px|3D buildings map from OSM]]
[[Image:Osm_map3d_buildings.png|thumb|center|300px|3D buildings map from OSM]]
'''Example of City of Trento'''
This map has been created from data provided by the municipality of Trento which includes individual building heights.
[[Image:Trento3d_colors.jpg|thumb|center|300px|Trento, Italy with 3D buildings (click on image for details, data courtesy City of Trento, Italy - see "Mostra Strumenti Dati" for geodata download)]]
== See also ==
* http://grass.osgeo.org/screenshots/3D/
* [[GRASS and Paraview]]
* http://grass.osgeo.org/programming7/vectorlib.html
== Data sources ==
* [http://www.openstreetmap.org/copyright © OpenStreetMap contributors]


[[Category: FAQ]]
[[Category: FAQ]]
[[Category: 3D]]

Latest revision as of 23:18, 14 December 2013

Creating a 3D city model

You can create a 3D city model easily in GRASS GIS even if building heights are not available using v.extrude. We'll just assume a constant building height (otherwise you can use individual heights stored in the attribute table for the respective building).

Here an example with OpenStreetMap (OSM) data:

# first reproject OSM data from LatLong to metric projection, e.g. UTM32N:
ogr2ogr -t_srs epsg:32632 polygons_UTM32.shp polygons.shp
OSM 2D map

OSM map import and building extraction into new map

Import into a metric GRASS location (here: UTM32N), extract the buildings and extrude them to 3D:

v.in.ogr polygons_UTM32.shp out=oberursel2D

# colorize a bit
v.colors oberursel2D column=cat color=random
d.mon x0
d.vect -a oberursel2D
d.barscale -mt

# extract the buildings into a new map (use db.connect -p to see which driver you are using):
### statement for DBF driver:
v.extract oberursel2D out=oberursel2D_small where="tags LIKE 'building'"

### statement for SQLite driver:
v.extract oberursel2D out=oberursel2D_small where="tags LIKE '%building%'"
Buildings extracted from OSM 2D map

We see that a lot of buildings are actually NOT tagged as buildings. You may fix that at http://www.openstreetmap.org/

Alternative: use v.db.addcol to add an "area double precision" column and upload the area sizes in (square)meters with v.to.db. Then use v.extract to extract all areas over, say, 200 m^2. However, better fix the OSM map!

Extruding building polygons to 3D

# extrude 2D building polygons to 3D, here with a constant height (you can indicate an attribute column for individual heights):
v.extrude oberursel2D_small out=oberursel3D height=20 elevation=srtm

# check that the 'areas' have become type 'faces':
v.info oberursel3D

Ready! Note that you can make use of individual heights when stored in the attribute table for the respective building since v.extrude supports also that.

Extra ideas

To make the visualization more realistic, use the building footprint area to assign a more realistic (assumed) building height. This can done with v.db.update rather easily by applying a series of range formulas.

Visualization

Now we can visualize them:

# set computation region to map:
g.region vect=oberursel3D

# generate a pseudo-DEM (if you have a real DEM, use the 'elevation=' parameter in v.extrude above):
r.mapcalc "mydem = 0.0"

# visualize in 3D:
nviz elevation=mydem vect=oberursel3D
3D buildings map from OSM

Example of City of Trento

This map has been created from data provided by the municipality of Trento which includes individual building heights.

Trento, Italy with 3D buildings (click on image for details, data courtesy City of Trento, Italy - see "Mostra Strumenti Dati" for geodata download)

See also

Data sources