This is an example of how you could use the Open City Model to view a 3D rendering of your city and perhaps gain a new perspective on where you live! In this example we will start by loading a portion of the Open City Model into the 3dCityDB which provides a foundation for doing geospatial work with 3D city objects. Once we've loaded some data into our database we'll export a KML visualization of the buildings which we can easily view and play with in Google Earth.
We try to keep the examples as simple as possible but the world of geospatial software is still fairly complex and it should be kept in mind that this example is meant for a more technical audience.
- Java 8+ - You'll need a recent version of Java available on your computer in order to run the Importer-Exporter tool provided as part of the 3dCityDB.
- Docker - For the sake of simplicity this example uses Docker for running the actual 3dCityDB instance which is a Postgres/PostGIS database.
- Google Earth Pro - We will use this as a visualization tool for looking at our 3D city.
This should be fairly straight forward as long as you have Docker running. Simply run the following command to download the image and run a new container ...
docker run -dit --name citydb -p 5432:5432 -e "SRID=4326" -e "SRSNAME=urn:adv:crs:EPSG::4326" tumgis/3dcitydb-postgis
NOTE: this will attempt to map port 5432 in your new docker container to port 5432 on your computer, so you must be sure that port is unused.
The importer/exporter is a Java based desktop appliction which provides a nice UI for interacting with the data inside your 3dCityDB.
- Head over to https://www.3dcitydb.org/3dcitydb/downloads/ and download the latest version of the application.
- Execute the .jar file to launch the GUI installer. On my Mac if I double-click the file I get a security warning, so I must right-click the file, then choose
Open With
>Jar Launcher.app
- Follow the installer steps along the way and leave all the options at their defaults. This is a standard installer with a language choice, a license to accept, and the option to pick where to install to.
- Once the files are installed you can safely close the installer.
- Now we want to launch the installed importer/exporter application by using the appropriate script in the
bin
folder of the location where you installed the files. For example on my Mac I am launching3DCityDB-Importer-Exporter/3dcitydb/bin/3DCityDB-Importer-Exporter
which I can simply double-click on in Finder. - If the importer/exporter is open and displaying on your desktop then you are good-to-go 👍
With the importer/exporter running lets connect it to your database so that you can actually use these tools to get something done.
- Click on the
Database
tab at the top. - Inside the
Connection Details
fill out the following data- Description =
citydb
- Username =
postgres
- Password =
postgres
- Type =
PostgreSQL/PostGIS
- Server =
localhost
- Database =
citydb
- Description =
- Then click the
Apply
button on the right to save those inputs, followed by theConnect
button at the bottom to actually connect. - With a successful connection to your 3dCityDB you should see some output on the
Console
to the right such as this ...
Now that we have a fully functioning 3dCityDB along with the importer/exporter lets get down to using some data!
- Use the Open City Model download links to find the files for the US county you are interested in and download the CityGML files
- NOTE: the files are only organized by US state & county, so if you are looking for a single city or town you'll have to do the county that location falls within. it's currently not possible to get the data for a smaller location.
- TIP: For my examples I'm using the files for San Francisco, Ca which has quite a few buildings in a small area, so it's fairly easy to work with.
- Once you've downloaded the CityGML files they should be .zip compressed, so simply uncompress them to their original .gml files
- Back in the importer/exporter application click on the
Import
tab at the top - Click the
Browse
button to locate your .gml files. Highlight all the files you have and clickChoose
. You should now see all of your selected files in the large text area at the top of the Import tab. - You are now set to simply click the
Import
button to load the Open City Model data into your 3dCityDB - After the import is completed you now have a bunch of buildings in your 3dCityDB you can use for a variety of applications 😃
Once you have a 3dCityDB running and loaded with data there are a lot of things you can do, but lets start with something simple that lets us visualize the data we just loaded in an app that's familiar to many people, Google Earth.
- In the importer/exporter app lets click on the
KML/COLLADA/glTF Export
tab at the top - Click the
Browse
button and pick a location and file name for your exported 3d model, then clickSave
. nothing is saved yet, this is just setting the file to export to. - Inside the
Export contents
section lets set the bounding box of what we want to see in our 3D model.- Click the small icon of the globe with a magnifying glass to visually pick your bounding box.
- In the window that opens up, use the viewer to zoom down to earth into the part of your city/town you want to 3d model. Go for a fairly well zoomed viewer to avoid exporting too large of a 3d model, which is slower.
- Once you have the viewer set, right-click inside the viewer and click on
Get map bounds
from the menu. This will capture the bounding box for the viewer and populate them in the upper left of the window. - Now simply click the
Apply
button in the top right corner. You should now have your bounding box populated. - In the
Tiling
section you can leave the default setting ofNo tiling
- Under
Export from level of detail
section you should pickLoD1
from the dropdown menu - Within the
Display as
section you want to click the checkbox next toExtruded
and set visible from200
pixels - Now you're ready to export your 3D model, so click the
Export
button at the bottom. - Open up Google Earth Pro
- Within Google Earth, click on
File
>Open
from the application menu. Navigate to the location you specified for your KML export in the previous step and choose that file. - You should now be looking at a 3D model of your city!
- you can reduce some of the competing information coming from Google Earth by unchecking the boxes under
Layers
. in specific I would recommend unchecking3D Buildings
andTerrain
- you can reduce some of the competing information coming from Google Earth by unchecking the boxes under