# Importing and Aligning OSM Data

## Introduction

***

Importing 3D Open Street Map data is where the magic happens in this visualization. Up until this point, importing the vector and raster data was something that all other programs could do (more efficiently too, probably). From now on, however, as we deal with 3D data, Blender is in a league of its own, with its customizability, beauty, and power, second-to-none.

We'll be using the Blosm extension in this module, so make sure it's **installed and enabled**.

Most of the difficulty in this project lies here, since the details for projection get really intricate. In fact, the changes we have to make are so slight that the creator of the Blosm add-on themselves didn't recognize that a projection method exists:&#x20;

> &#x20;Unfortunately it \[CRS projection] works only in Blender 2.8x due to external dependencies introduced in the recent version of the binaries used by the _bpyproj_ addon. Some technical details can be found [here](https://github.com/JeremyBYU/bpyproj/issues/18#issuecomment-1099333797).

With the step's we'll follow here, there will be no reason to downgrade our software.&#x20;

## Setting Up Custom Properties

***

If we go within the "Scene Properties" tab, under "Custom Properties", we can see all the values that are used to generate our scene's CRS:

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FmBYgGsYC4mOelMDa8paZ%2Fimage.png?alt=media&#x26;token=3fe6206e-50e8-4349-a462-257a956179e0" alt="" width="333"><figcaption></figcaption></figure>

We're going to use Blosm to import OSM data. However, **Blosm uses a different set of fields for its CRS** alignment: "lat" and "lon", corresponding to latitude and longitude. Right now, the fields only correspond to the parameters interpreted by BlenderGIS.

Without these parameters in place, the initial Blosm OSM import would create it's own CRS, and the mesh for whatever arbitrary location we select would **always** be placed at the (0,0,0) point of the scene, as opposed to its corresponding location on the map.

To prevent this from happening, we need to tell Blosm that there is already a CRS in place, by changing the parameter names to something interpretable. Click  on the settings icon next to latitude, and change the "Property Name" to "lat". Do the same for longitude (-> "lon"):

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FIRSAZDUHVuFElCWwVGRr%2Fimage.png?alt=media&#x26;token=3b988f97-68e8-4616-9f7f-bc813be4e8cb" alt=""><figcaption></figcaption></figure>

However, it would still be useful to have the original "longitude" and "latitude" fields, incase we want to use BlenderGIS again, for whatever reason.&#x20;

To get them back automatically, we can just open up the side panel, and look under "View" and "Geoscene":

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FcnAtgPJjQNCYU4nLL8qz%2Fimage.png?alt=media&#x26;token=da25114d-e097-4a8a-97db-11d84025edc8" alt=""><figcaption></figcaption></figure>

We can click the "Constraint" button (which looks like a rubber band _constraining_ two objects), and then press "Geo" and "Proj" to add back our references for the Geoscene (which is a attribute defined by BlenderGIS).

Now, the two panels should look like this:

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FWRbrANzJjC3JIzozRlHX%2Fimage.png?alt=media&#x26;token=679ad46d-b04d-4e64-a0b4-3ee6fc8989f9" alt=""><figcaption></figcaption></figure>

Note how the latitude and longitude properties mirror the exact values provided by their respective abbreviations.

## Importing OSM Files from a Server

***

Now that our scene is set up, we can work on getting some Open Street Map data. With the Blosm add-on enabled, we can click on its side panel:

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2Flysf3eTAJSbcUVmb9Ca7%2Fimage.png?alt=media&#x26;token=1161c8bd-d94e-4e50-835c-b68ed789aafe" alt="" width="108"><figcaption></figcaption></figure>

The default settings are good for most applications, but you can read more about them in the Blosm [documentation](https://github.com/vvoovv/blosm/wiki/Documentation). There are still a few changes we can make before we import. First, we need to set up a directory to store the OSM files. You can do this by going into Edit -> Preferences -> Add-Ons -> Blosm (search) -> Preferences -> Directory to store downloaded OpenStreetMap and terrain files:

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FCQUHaJwkTyU55uHDJyG2%2Fimage.png?alt=media&#x26;token=e22ce834-5fd4-453e-9f89-e9443ac7784f" alt="" width="496"><figcaption></figcaption></figure>

With that done, we'll go back to the Blosm sidebar, and (with the bpyproj add-on enabled) scroll to "Projection".

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FF9GFaLlsr49uIwBUqC60%2Fimage.png?alt=media&#x26;token=e7fc651d-6944-4f4b-af4b-832d57613620" alt=""><figcaption></figcaption></figure>

The SRID is just an identifier for the CRS we're using (i.e. EPSG:2263). We'll put that into the field:

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FOUl1S7KwENs1UMt37kIW%2Fimage.png?alt=media&#x26;token=dcad21e8-1a2a-4ab3-a529-62659715edc6" alt=""><figcaption></figcaption></figure>

From here, we can select the area we want to import. Scroll back up to the top, and press "select". This will open up a webpage where you can define a rectangular area to import and adjust it. For this example, we'll start with this small area at the bottom of Manhattan. Note that larger areas will take longer to fully import (around 2-5 minutes), but you'll probably want to scale up in size to cover more ground as you piece the city together. In fact, once you've tested that alignment works with a small set of buildings, you should delete that hierarchy and import a larger first file.

Once again, remember that we can track progress (though not as well as with BlenderGIS) via the Command Terminal.

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FxwH3ot36UPN4ZJfv9Nct%2Fimage.png?alt=media&#x26;token=bcbcbca5-8695-4d50-b626-649725f8a8af" alt="" width="563"><figcaption></figcaption></figure>

Press "Copy" on the left, then go back to Blender and press "paste" at the top. This should populate the coordinates right below it:

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2Fr4VKvXVLqQE5dtXSENml%2Fimage.png?alt=media&#x26;token=eb6d7078-368a-474d-b581-553a66048a69" alt=""><figcaption></figcaption></figure>

From here, we can just press "import" to align and bring in our data. After a few seconds, we'll see our mesh in the 3D viewport. If we zoom in, we'll see that it perfectly aligns with the backing map:

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FWV7uTgfEVON0bOdSLh1f%2Fimage.png?alt=media&#x26;token=eff60f30-de85-4720-a024-082ade7c5fc7" alt="" width="563"><figcaption></figcaption></figure>

We can now repeat this process for the rest of the city, selecting, copying, pasting, and importing the appropriate data (our settings save, so there's no need to change anything with the CRS). While not an issue right now, **try to limit the number of overlaps of buildings/coordinate boxes**. The fewer the number of overlaps, the less work we have to do later when generating material colors for the buildings  (since overlaps cause buildings to darken).

You might notice that the heights of the buildings are a bit shortened. While there isn't a way to get them 100% accurate, we can do one of two things to make them look more realistic. One is just to approximate the height by scaling up the "buildings" object along the z-axis only, until it looks "normal". Another, more complicated method is to find the real-world dimensions of a building, find the building in Blender, then measuring the X and Y dimensions in Blender-units (using its vertices) and scaling the Z-axis only, according to how the X and Y are scaled, to make everything accurate. I imagine that the first method is more efficient, since the heights of buildings don't need to be 100% accurate for the point of the video to be understood. However, this varies case-to-case.

Make sure to apply whatever changes to sizing you do to one set of buildings, **to all buildings**, to preserve scale.

### From a Path/File:

Note that we can also import OSM data from a file instead of the online server. Every time we import an OSM from the server, Blosm also saves a copy locally, to the file directory we specified in the add-on settings. If we ever need to import a file from there (say, if the file crashed or was left unsaved) we can just switch to a file import within the Blosm settings.&#x20;

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FbnwYJ5k9EOBD0CBlqyKn%2Fimage.png?alt=media&#x26;token=6ce1fb9b-26d2-4527-9238-b142fca70187" alt="" width="375"><figcaption></figcaption></figure>

Also note that when Blosm saves a copy of our import locally, it does so in two parts: map\_x.osm and map\_x\_extra.osm. The majority of the mesh is stored within the base copy, and when we import the base copy, Blosm automatically looks for the extra.osm file to fill in any gaps in the data. This means that whenever we select a file to import (through Blosm), **we should always select the base .osm file**.

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FLyQmglwKbJzLHH0T8mwk%2Fimage.png?alt=media&#x26;token=33fc2dc6-0ff7-42ee-b3d5-20366abcdbab" alt=""><figcaption></figcaption></figure>

## Conclusion

***

After filling in our city with small (but large enough to limit overlaps) .osm files, we'll end up with something like this:

<figure><img src="https://3388232048-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfzMZbzYJd16KswvkEBDA%2Fuploads%2FvVLLTE41z76bSjAQ03qn%2Fimage.png?alt=media&#x26;token=eeb86fe8-0675-4687-8f43-07502545d4a7" alt="" width="375"><figcaption></figcaption></figure>

Note that it might be desirable to rename certain collections from the base "map\_xx.osm". However, you should do this at the end of the next section, [Setting Up OSM Materials and the Environment](../materials/setting-up-materials-and-objects), since a Python script within that section requires the names to be in their original form. &#x20;
