Visualising OS MasterMap® Topography Layer Building Height Attribute in QGIS

Our recent blog post about visualising OS MasterMap® Topography Layer Building Height Attribute (BHA) data in ArcGIS and ArcGlobe prompted a number of questions about whether it’s possible to do something similar in open source software. In this post we’ll show you how to achieve something similar using QGIS and the freely available Qgis2ThreeJS plugin.

Please see the previous post for information on BHA data coverage, an explanation of the different height attributes supplied by Ordnance Survey (OS) and for details of further information sources; including the excellent Getting Started Guide produced by OS. Please remember this is an alpha release of the data and OS do not guarantee that BHA is error free or accurate. Additionally the dataset is not yet subject to update and maintenance.

Getting started

  1. Download the following datasets for your area of interest from Digimap using the OS Data Download application:
    1. OS MasterMap® Topography Layer: select the ‘File Geodatabase’ format for your data as this format does not require any conversion to use it in QGIS;
    2. OS Terrainâ„¢ 50 DTM: this will be used as the base (surface) heights for the area;
    3. BHA data (BHA data is found in the ‘OS MasterMap’ group): select CSV as the format;
    4. Optionally download any additional data you may wish to use as a backdrop, such as OS VectorMap® Local Raster or OS 1:25,000 Scale Colour Raster;
  2. Open QGIS and load in the OS MasterMap® Topography Layer, OS Terrain™ 50 DTM and your backdrop map data.

Preparing BHA data for use

If your downloaded BHA data is made up of more than one CSV file we recommend merging them all together in to a single CSV file first to make subsequent processing easier and quicker. Use a text editor such as Notepad or TextPad rather than Excel, as Excel can change the formatting of numbers which contain leading zeros.

Each object in MasterMap Topography Layer has a unique identifier called a Topographic Identifier, or TOID for short. TOIDs supplied by OS take the format of a 13 or 16 digit number prefixed with ‘osgb’ e.g. ‘osgb1000039581300′ or ‘osgb1000002489201973′. Some applications, such as ArcGIS, automatically strip off the ‘osgb’ prefix and add three leading zeros to any TOID that has only 13 digits to make them all 16 characters long. Additionally this same formatting is applied to the File Geodatabase format of MasterMap supplied through Digimap. In order to make it easier to join BHA data to building features in MasterMap® Topography Layer the BHA files supplied by EDINA have two TOID values:

  • os_topo_toid_digimap is the TOID formatted to match TOIDs in ArcGIS and in the File Geodatabase format supplied through Digimap.
  • os_topo_toid is the original TOID as supplied by Ordnance Survey

You should check the TOID values in your MasterMap data and those in the BHA data to ensure that there is a common field that you can use to match on; we will use os_topo_toid_digimap as this field in the BHA data matches the TOID values in the MasterMap data downloaded in File Geodatabase format from Digimap.

Before BHA data can be loaded in to QGIS it is necessary to create a small text file (called filename.csvt, where ‘filename’ is the name of your BHA csv file) that specifies the data type of each field so that QGIS handles it correctly. Specifically the .csvt file is used to ensure that QGIS treats the two TOID  values as text rather than numbers, and all height values as numbers. The steps required are detailed below:

  1. Create a new file called filename.csvt (replacing ‘filename‘ with the name of your BHA csv file) in the same folder as the BHA csv file you wish to import.
  2. Open the file in a text editor such as Notepad or TextPad.
  3. Copy and paste the following text in to the file:
    "String","String","Integer","Date","String","Real","Real","Real","Real","Real","Integer"
  4. Save your changes to the file. Ensure it is saved in the same folder as the CSV file you wish to import.
  5. Add your BHA CSV file to QGIS through the Add Vector Layer function; this will add the data as a table in the QGIS project.

Creating a heighted buildings dataset

In order to create a new heighted buildings dataset from the building features in OS MasterMap Topography Layer and the BHA data we use the GIS ‘join’ function. A join links these two datasets together through a common unique identifier (the TOID) resulting in a set of buildings with height values stored as additional attributes.

  1. Bring up the Layer Properties dialog for the Topographic Area layer in the MasterMap data either by double clicking on the layer in the Layer panel or by right clicking on the layer and selecting Properties from the pop-up menu.
  2. Select the ‘Joins’ tab on the left hand side to display the join panel:
    QGIS Join Window
  3. Press the green plus button to add a new join:
    1. QGIS add vector joinSelect your BHA dataset as the ‘Join Layer’.
    2. Select the correct TOID field that matches the TOIDs in your MasterMap data; as mentioned above we’re using os_topo_toid_digimap as the formatting of this matches the TOIDs supplied in the MasterMap data downloaded from Digimap in File Geodatabase format.
    3. In the ‘Target Field’ select the attribute column that contains the TOIDs in your MasterMap® data; by default this is called ‘TOID’ in MasterMap downloaded from Digimap.
    4. Leave the checkbox selected to ‘cache join layer in virtual memory’ as this will speed up query and display of the data.
    5. Press OK to create the join.
  4. Press OK on the Layer Properties dialog to close the window.
  5. Open the attribute table for the TopographicArea MasterMap layer to verify the join has worked. You will see the additional BHA columns at the end of the attribute table. Note you will see a lot of ‘null’ values in these additional columns as BHA values are only available for ‘building’ features (the TopograhicArea feature class contains features for everything, not just buildings).
  6. Having joined the datasets together, before we can create a heighted buildings dataset we need to select only those buildings which now have height information. This is done using the QGIS ‘Select features using an expression’ button: QGIS select by expression button
  7. QGIS select by expression windowWe are looking to select only features which have a value for the height attribute we wish to use in the 3D visualisation. As mentioned in the previous post, we have found that the ‘RelH2′ attribute provides a good representation of the height of buildings relative to one another. The expression used is shown below. Note the field name, in quotes below, is automatically created by QGIS by adding the BHA table name (NT27) to the attribute column name (RelH2) with an underscore between them:
    "NT27_relh2" IS NOT Null

    QGIS save vector layer

  8. Having selected just the buildings that include height information we can now export these features as a new dataset by right clicking on the TopographicArea dataset in the Layer panel and selecting ‘Save As…’ from the pop-up menu.
  9. Save the dataset as a new Shapefile in a suitable location, selecting the checkboxes ‘save only selected features’ and ‘add saved file to map’.
  10. The newly created heighted buildings dataset will be added to your QGIS project; now it’s time to visualise it in 3D.

Visualising the data in 3D

So far we have downloaded OS MasterMap® Topography Layer and BHA data for the same area and joined the two together to create a new dataset containing just the building features which now include the various height attributes published by OS. We also downloaded OS Terrain™ 50 DTM to use as the surface heights, 1:25,000 Colour Raster and OS VectorMap® Local Raster to drape over the surface.

Visualising the data in 3D in QGIS is achieved using the Qgis2ThreeJS plugin, which can be installed using the QGIS plugin manager if you don’t have it already. The steps below describe how to use the plugin to create a 3D model:

  1. Ensure you have all the data loaded in to your QGIS project that you wish to include in the 3D model, as a minimum you should have your DTM, the heighted buildings dataset and a suitable map layer to drape over the DTM.
  2. Turn off all layers in the Layers panel apart from the surface you wish to drape over the DTM; the buildings will be styled using the Qgis2ThreeJS plugin.
  3. Launch the plugin, which can be found on the Web toolbar.
  4. Using the ‘DEM’ panel of the plugin select your DTM data as the ‘DEM Layer’, leave all other settings at their default values. Tip: by default the surface has a vertical exaggeration of 1.5, if you wish to reduce or increase this, the setting is configured on the ‘World’ panel of the plugin.
  5. Qgis2ThreeJS plugin windowIn the ‘Polygon’ panel of the plugin select your heighted buildings dataset and complete the following settings:
    1. Z coordinate: set to ‘Height from surface’ – this will ensure the buildings sit on the DTM surface.
    2. Under ‘Style’: ensure the ‘Object type’ is set to ‘Extruded’ and select the height attribute you wish to use for the extrusion using the ‘Height’ drop down; as mentioned above, we’re using the RelH2 attribute from OS which is in the column ‘NT27_relh2′ in our data.
    3. Select suitable colours and transparency, we used a medium grey colour with 10% transparency to give a glasshouse effect.
  6. Optionally specify an ‘Output HTML file path’ to save the resultant files. Whilst you’re experimenting we recommend you leave this blank and the plugin will save the data in a temporary location, when you’re happy with the result you can use this setting to save your final visualisation.
  7. Press ‘Run’ to create the 3D model. Once it’s finished processing the model will open in your default web browser.

The plugin outputs an HTML file, along with a small number of accompanying files. The HTML file requires a WebGL compatible browser (WebGL is a method of generating dynamic 3D graphics using JavaScript), most modern browsers are WebGL compatible including IE 11, FireFox, Chrome, Safari and Opera, the Can I Use site offers further information on browser compatibility.

As the files are output as a web page, you can share the results of your work with colleagues without them needing to have any specialist GIS software, however you are not permitted to make the website publicly available as the html and javaScript files contain map data rather than just images of maps.  The Licence does not permit the sharing of licensed data from Digimap with anyone other than registered users of the service: Digimap Licence

Tips

  • The plugin uses the extents of the current QGIS map canvas, so the bigger the area being displayed, the bigger the generated 3D scene and the slower it will display. We have found that areas of up to 10km² display okay, anything bigger tends to be a little slow to respond.
  • If you wish to define specific extents for your 3D scene instead of using the map canvas extents this can be done on the ‘World’ panel of the plugin.
  • Applying a vertical exaggeration to your buildings is achieved through the ‘Multiplier’ setting on the ‘Polygon’ panel of the plugin.
  • You can create 3D models of multiple layers. For example in the screen shot below the trees were created by selecting the ‘Positioned Non Coniferous Trees’ from the OS MasterMap Topographic Point layer. These were then added to the QGIS project twice. Using the plugin one of these layers was extruded as a brown cylinder with a radius of 0.75m and a height of 3m to form the trunk; the other was extruded as a green sphere with a radius of 4.5m and a z coordinate of 4.5m (i.e. the height above the ground surface of the centre of the sphere) to form the tree canopy:
QGIS 3D visualisation with trees

OS VectorMap® Local Raster draped on top of OS Terrain™ 50, with buildings from OS MasterMap® Topography Layer Building Height Attribute and Positioned Non Coniferous Trees extruded on top

The finished visualisation

The screen grab below shows the final visualisation centred on the south side of Edinburgh using OS 1:25,000 Colour Raster as the surface layer.

3D visualisation

1:25,000 Colour Raster draped on top of OS Terrain™ 50, with buildings from OS MasterMap® Topography Layer extruded on top using Building Height Attribute data.

Share

Inaugural Scottish QGIS user’s Group

QGIS UK

QGIS UK

“Today we have a guest blog post from one of the Geo-developers at EDINA.  Mike works as part of the data team and is usually up to his oxters in databases ensuring that the data offered through Digimap is both up to date and in a useful format. Over to Mike.”

Following on from successful meetings In England and Wales, on 19th March I attended the inaugural “Scottish QGIS User Group” hosted at Stirling University. My first thought revolved around  the level of interest that such a meeting would acquire, but as it turned out, it was very popular. I was also surprised at the geographical spread of the attendees, with several folks coming from Brighton (Lutra Consulting) and  Southampton (Ordnance Survey) as well as all over Scotland & northern England. Although the attendees were dominated by public sector organisations.

Talks/Presentations:

A more detailed breakdown of the presentations can be found here: http://ukqgis.wordpress.com/2014/03/25/scottish-qgis-user-group-overview/

From my own perspective, the talks on developing QGIS and Cartography in QGIS were of particular interest – demonstrating the every growing potential of QGIS. Additionally, the improvements (particularly speed enhancements)  that look to be coming soon (as highlighted in Martin Dobias’ presentation) are impressive.

As for the user group itself, it will be interesting to see where it goes from here and what direction it will take. How will future events be funded? How often should the group meetup? What location? A recommendation from myself would be to have general presentations and talks in the morning, then in the afternoon split into different streams for beginners / users / developers.

At the end of the meet-up (and a few geo-beers in the pub) there was definitely a sense that everybody got something out of the event and would like to attend more meetups in the future.

A special mention of thanks needs to go out to Ross McDonald – @mixedbredie (Angus Council) for his efforts to organise the event and additionally thinkWhere (formally Forth Valley GIS) for sponsoring the event.

Links and seful things

EDINA Geoforum 2013 Review

Geoforum 2013EDINA’s Geoforum 2013 was a great success with over 50 academic and support staff attending four very well received presentations:

Geoforum aims to bring together staff who support the use of Digimap and other geoservices from subscribing institutions around the country and showcase what’s new and upcoming from EDINA. It also gives people an opportunity to ask the Digimap team questions and to chat with others about how support and promote geoservices.

There was a live blog running throughout the day which is still available for you to read and find out what happened.

Keynote Address

The keynote was delivered by Shelley Mosco of The University of Greenwich and was titled: Digimap Data and a non-traditionalist approach.  Shelley is a member of the The School of Architecture, Design and Construction and  described the ways in which spatial data could be used to inform design. Shelley was keen to stress the importance of spatial data and GIS in the implementation of Building Information Models (BIMs).  BIMs have been used in large engineering projects for some time, however the government is making them mandatory for all publicly funded building projects in England and Wales. This means that commercial organisations will be looking for students to have been trained in the concept of BIMs and the software that drives them.  You can find out more about BIMs through the following links:

Geofurum 2013 keynote

Two of Shelley’s current MSc students also gave brief overviews of their experiences of learning about GIS and using spatial data in their projects.  Both David Parfitt and Robert Park were self-confessed GIS newbies, but they managed to get data from Digimap and use it in their conservation projects. The data allowed them to visualise and analyse the environment and provide evidence to support their proposed designs.  Their demo’s were excellent a they really showed the power of simple GIS analysis.

You can view the slides from this presentation here:

Slideshare Shelley Mosco Presentation at Geoforum 2013Digimap Data and a non-traditionalist approach – Shelley Mosco

Open and “Free” Geo Software & Data

After the Keynote was a presentation that focused on Open or “Free” resources for geospatial teaching and research. The presentation looked at  software, web-mapping and data. The main resources are listed below:

Data

  • OS Open data is available through the Digimap Data Download service.
  • ShareGeo Open is a repository for open geospatial data. It has lots of useful and interesting datasets on a variety of subjects such as wind farms, crime, boundaries and DTMs
  • Data.gov.uk – the UK government’s open data store

Software

  • QGIS – one of the best open source GIS out there. Lots of functionality and plugins that allow you to perform complex spatial analysis. It is also well supported by forums.
  • gvSIG – anther fully functioning GIS.
  • GRASS – a remote sensing package aimed at serious remote sensor’s. If you are a newbie to remote sensing, you can access GRASS tool through the GRASS plugin for QGIS which makes things really simple.

Web-mapping

Digimap is a great web mapping tool, but how can you create your own interactive web map for your website?

  • MapBox – simple intuitive web site that helps users build interactive web maps. Basic functionality is free, more advanced functions are available for a small fee.
  • Leaflet – the engine behind MapBox, it is free but requires user to do a “bit” of programing
  • Openlayers – an alternative to Leaflet which is more flexible. Openlayers powers Digimap. Requires a fair amount of programming knowledge.
  • MapServer – implements Openlayers for enterprise scale operations. MapServer is also used for Digimap services.

You can view the slides from this presentation on slideshare here:

OpenSourceOpen & “Free” Geo Software & Data – Tom Armitage

EDINA Geoservices Review

After lunch the lead of EDINA’s geoservices Support team, Emma Diffley, shared what we have been busy working on.

Interfaces

Digimap is being streamlined, each collection will eventually have just a Roam and a Download. These interfaces will all look and work in a very similar way. The aim is to make the service more consistent and easier to use, but also much easier to maintain.

EDINA will be withdrawing Digimap Carto on 31st July 2013. Carto, launched in 1996, is harder and harder to maintain, so we have taken the best bits and put them into Roam.

On top of the Carto functionality already added to Roam the following improvements are coming soon:

  • an improved way of saving and opening maps and annotations
  • a Basemaps button to change the style or even mapping product you are viewing at each scale
  • PDF format prints in Ancient Roam
  • all Roams having the ability to print up to A0
  • a cleaner interface, consistent across all Roams
  • additional overlay options coming soon (boundaries, contours…)

The Download interfaces will also going through a similar process.

Data

  • A single consistent style for all the vector products through all the scale levels accessible through using the basemaps button in the new Roam.
  • VectorMap Local (VML) in shapefile and DWG formats
  • ArcGIS layer files for symbolising VML shapefiles coming soon
  • OS MasterMap Topo available as DWG is being planned

Support

  • There is a new Resource Centre, which does not require login, with answers to questions, videos, case studies etc.

Beyond Digimap

  • GoGeo has added more resources and now highlights the “Editor’s Picks”
  • ShareGeoOpen now has over 210 resources all of which are open and free to use
  • FieldTrip GB is a mobile app for capturing data, see below
  • GeoTagger – a tool to allow you to edit the metadata for your photos
  • Cartogrammar – upload your data and visualise it in different ways
  • UKBORDERS is now the UK Data Service Census Support Unit

On the horizon

We are still awaiting news on funding, but are lots of things we would like to do. Currently our focus is to “mobilise” more services and we will be continuing to add new support materials once the latest round of Roam and Download changes have been made.

If there are things you would like us to do we really want to hear about them. Recommendations from the user community carry real weight for us, and we are keen to hear ideas on new data or services we should be providing.

You can view the slides from this presentation here:

Slideshare Emma Diffley Presentation at Geoforum

EDINA Geoservices Review – Emma Diffley

Fieldtrip GB – data capture, simplified

The final part of the day was about EDINA’s new mobile app for carrying out field work Fieldtrip GB. It simplifies the process of capturing data in the field against quality cartographic mapping. It is equally at home in urban environments as it is in rural ones. Custom forms allow users to design their own data capture projects and collect exactly what they need for their research.  The session gave a brief overview before running a “live” group data collection exercise.  A custom form was created and deployed to participants mobile phones. They then headed outside and captured data on things like building fabric and design.  After 15 mins everyone reconvened and the collected data was “synced” and exported to Google Earth.

You can view the slides from this presentation on slideshare here:

FtGB Slideshare

FieldtripGB – data capture simplified – Addy Pope

As mentioned earlier, there is a transcript of the whole day in the form of a live blog  so if you didn’t manage to attend and want to find out what happened please have a look.

EmailShare