The Problem with 3D GIS

3D GIS is game changing, it can change the way you view your analysis, it can provide insights which you may have overlooked….but there is a little problem which I may had not shared in my deluge of blogs about how great 3D GIS is…..

…Sometimes it can be hard work. What I mean by this, is that it can sometimes need a lot more consideration than standard methods. Let’s look at some of the major culprits when using Esri ArcGIS Pro 1.4 & Desktop 10.5, keeping in mind that there isn’t many (or any) other 3D GIS you can do this kind of work in.

One of the 3D models built of Kendal, UK

Editing

Once you have converted or built your 3D model into a multipatch polygon you may find yourself struggling to edit or adjust your model.

Split

Having built entire cities, one issue that I’ve come across a fair bit is removing parts of multipatch polygons. For example, when adding multiple models, you may find that two features might overlap and need to remove part of one. In a 2D, standard GIS, you would simply turn the editing on and split the offending polygon.

This doesn’t work in a 3D GIS…Think about it, how does the GIS know where all the planes you require breaking lie with a 3D plane? 3D GIS can do some pretty clever assumptions but I am yet to find a way to remove part of a complex multipatch polygon.

True, within ArcGIS Pro 1.4 there are some editing tools for 3D multipatch features but it is early days at the moment. For simple cubes it is quite easy to adjust and manipulate the model a little but you don’t stand a chance if you have a curved edge.

 

Don’t despair, don’t give up on the 3D just yet, as you know, 3D isn’t new and there are many “workarounds”. One of my favourites is using the ArcGIS Pro “Replace Multipatch” tool. If you want to make multiple edits to a model (feature) you can export the multipatch to a collada format or keyhole markup language (kml) format, edit it in Sketchup, Blender, Meshlab or any of your favourite modelling suites and then import it again without affecting the other features in that layer.

 

If you are extruding simple 2D polygons with the intention of creating 3D mulitpatch polygons, it is a good idea to keep the conversion to multipatch until you explicitly need to. This way, you can edit, split and reshape your 2D polygon within normal ArcGIS Desktop without any issues at all and then draw up and extrude when you are 100% sure it all fits and works okay.

 

In my experience, pre-planning and clarity of the end goal means that you can be prepared for these slight niggles in advance.

Using 3D multipatches in ArcGIS Desktop

Overlay analysis 

So, I’ve built out an entire city of 3D buildings, it looks amazing, last thing to do is clip them by the city boundary….oh, I forgot, the 2D polygon doesn’t truly intersect the multipatch polygon in 3D space, the “clip” tool doesn’t work, the “intersect tool” nor the “merge” tool…in fact you can ignore using modelbuilder.

Clip features

I learned the hard way that 3D features work best with 3D features. Unless the boundary polygon is a 3D feature, then you won’t be able to use spatial analysis to use any kind of overlay querying.

But, there is always a way to trick the system…

Although the multipatch polygon feature is a 3D object, you can still open it in ArcGIS Desktop, meaning that you can use the good ol’ fashioned “select by location” tool. No, it shouldn’t work but it does, furthermore, you can then export your selected data to a new multipatch feature. It begs the question why you can do this and not the “clip” as, in geoprocessing terms, they are the same thing (the clip tool is just the separate bits combined into a single script).

Let’s not get too hung up on it, as it works,

Volumetric Analysis

If you thought that the  “volume” tool was just put there to look clever, think again. It can be a great tool for easily representing floor space or calculating the tonnage of aggregate that needs extracting from the ground to lay a new pipeline.

There is a slight problem though…it can be a little hit and miss, especially when using sourced models.

Calculating Volume

Try adding a model you built in Sketchup, Blender or Meshlab to ArcGIS Pro and then calculate volume (using the add z information tool), Nothing, right? But why? The reason is that it doesn’t like “open” multipatch 3D features, it isn’t fully enclosed. Even if there is a slither of a gap in the polygon and it isn’t 100% enclosed, the tool cannot calculate the volume.

There are other methods whereby you can use a raster surface, like the “surface volume” tool but this isn’t quite as accurate as using your super detailed vector multipatch.

You could try the “Enclose Multipatch” tool, as this closes the multipatch and then running the volume tool BUT you need to consider that unless the multipatch is cut to the surface, for example, where a building sits on a hill and the base isn’t perfectly flat, the volume will not be ideal. So please consider using the data as a high resolution TIN which is merged with the terrain to provide a more accurate volume result.

Oh, last point on this – make sure you use a projected coordinate system that uses metric for your data, a geographic coordinate system will leave you with your volume in degrees….is that even possible?!

Which brings me nicely to –

Issues occur when you don’t specify the datum

Vertical referencing

I distinctly remember my first adventures into 3D through Google Earth, trying to create some of Romsey, UK as 3D buildings using Sketchup. The first hurdle was always figuring out whether the building was “Absolute height”, “On the Ground” or “Relative to the ground”…I mean, what does that mean anyway? I just drew it to sit on the floor, why does it need to ask me more questions about it?

Correct Height Placement

Right now, if you are a regular reader of xyHt or a 3D Geoninja, you will be calling me a muppet. In reality though, you wouldn’t believe how often I am asked about this, especially now that Digital Surface Models (DSMs), Digital Terrain Models (DTMs), bathymetry and other elevation data are so readily available.

Elevation is never easy, worst still, there are either too many or too few options. With the Esri ArcGIS Pro, I am 100% confident that I know where my data sits within 3D space but it is only because I’ve worked with this day in and day out and understand the limitations and data sources.

Let’s consider the Esri “scene” – it’s a cool 3D map and as you zoom into that lovely globe you can see lovely mountains and valleys all popping out of the surface, my question to you is, what elevation data is it using? what is the resolution of that data? You see, I love that Esri provide a detailed and complete coverage elevation surface for the entire globe but the flip side of it is that you cannot know the exact limitations of that surface easily (the information is provided by Esri but it is not a simple “point & click” exercise).

My words of advice here are to use your own terrain when placing 3D multipatch features. Therefore you are in control of both the vertical datum and the resolution of the height.

While I’m here, I want to also point out that there isn’t a “snap to ground” feature in the editing tools within ArcGIS Pro either. This becomes an issue when you bring a model in which isn’t vertically reference, has no vertical datum because you then need to sit it on the surface. Even when your model is a captured point cloud and accurate to 0.5cm, you have no way to accurately place it on the ground. You can adjust it up and down and sit it by sight, though you cannot “snap” it.

The big takeaway here is that firstly, you need to ensure you are confident and know your elevation data if you plan to work in the 3D scene views and secondly that you need to set up your x,y & z coordinate systems correctly from the start to ensure that all the work you do is as precise as possible.

…and yes, I now know the difference between “absolute”, “relative to the ground” & “on the ground”….maybe an interesting blog for another day, though feel free to contact me if you need quicker answers!

And everything else

There are still many things I have not had a chance to mention, for example the complexities of cartographic representation using 3D models in a GIS, or ways of minimising the clashing of overlapping data plus other 3D centric issues such as shadow and light. Maybe a blog for another day?….

Dragons8mycat

 

 

How to Grayscale ArcGIS Pro Vector Symbology

Most of the time, ESRI software is great, it does [mostly] what you ask it and as long as you aren’t doing anything too crazy it behaves. We all know that it has it’s ‘unique-ness’ about it, after using it for a few years you start to ask “why don’t they do this….” or “How comes I can’t do that…..”. Well, a lot of this is being addressed in ArcGIS Pro, already it has answered the question as to why we needed 3 different GIS software (ArcGIS Desktop, ArcScene & ArcGlobe) by bundling it all up into one package. Now (with 1.3) we are starting to see other features which we always wanted in ArcGIS Desktop coming into ArcGIS Pro, case in point, converting symbology to grayscale.

Today, I discovered while creating a basemap, that ESRI have implemented a couple of neat little touches, firstly RGB VALUES ON HOVER.

Hovering the mouse provides RGB values
Hovering the mouse provides RGB values

Although this isn’t ground breaking, it is a nice little touch which, for us cartophiles and OCD cartographers, provides a quick and easy bit of feedback.

The other discovery was having the option to grayscale the symbology. The new ArcGIS Pro can be a little tricky to get your head around, so it is understandibly not obvious but I went to change the RGB values on a piece of road and found another option: GRAYSCALE

Grayscale dropdown
Grayscale dropdown

Selecting “Grayscale” takes you to this menu:

Grayscale removes colour while retaining it's presence.
Grayscale removes colour while retaining it’s presence.

 

Okay, so this isn’t groundbreaking BUT having played with photoshop a little, I’ve found that the RGB value which is automatically given is almost a perfect match for what you get if you desaturate the colour.

What does all this mean? It means that you can easily and confidently convert your vector symbology to grayscale without guesswork! Creating alternative grayscale maps should now be a lot easier! Now, the question is, will this ever make it to ArcGIS Desktop?!

Dragons8mycat

GIS Tips – Quickly Scroll Through ArcMap Icons

Little trick to save yourself hours of trawling through point icons when using ArcMap (all versions)

It’s been a while since I posted a “GIS Tip” but this is a goody, especially if you spend HOURS scrolling through the ArcMap icons looking for that symbol which you thought was in one place but it seems to have moved…..

 

  1. Select the point icon you want to replace with a new icon and go to “edit”
Click on "edit"
Click on “edit”

2. You should then be presented with the following screen:

Point Icon selection screen
Point Icon selection screen

 

3. Now for the fun part…..scroll your mouse wheel up and down. Nothing right?….

    HOVER YOUR MOUSE OVER THE FONT SELECTION BOX AND SCROLL YOUR MOUSE

Like magic, you can scroll through the icons
Like magic, you can scroll through the icons

4. With your mouse hovered over the font box, you are able to scroll through the available fonts but ALSO it shows the relevant icons in the box below, enabling you to go through                 hundreds of icons quickly. Far better than individually going through each set of fonts in the search for the icon you are after.

 

There you go….you experts might already know it, but you new kids are going to love it!

 

Dragons8mycat

QGIS 2.14 v ArcGIS 10.4

Posted in xyht magazine 21st March 2016
This post almost didn’t happen, for over 7yrs I’ve been comparing GIS software in the hope that someone would be reading and take it upon themselves to fix a few of the issues which we all run into on a daily basis. With the new releases someone told me something and it almost stopped it all from happening…..

 

“ESRI is the Apple Inc and QGIS is the Google…”

 

As painful as it is to hear, it’s true. Even though I’ve been a hardcore user of QGIS for over 5yrs, I find myself falling back into using the ArcMap tools just to save myself rummaging through lists of plugins and I especially like that I can just drag and drop my data into the data frame and it just works.

As powerful as ArcMap/Arcscene/ArcGIS Pro/ArcGlobe/ArcGIS Explorer/ArcServer/Arc*add your own term here* is, it feels old and a little clunky, like using Windows XP. For a decade it has had the same comfy interface, the same basic functions and the same symbology. This is by no means a bad thing but the cartographic capabilities of QGIS are far superior and let’s not mention the true 64bit processing…

This year, there is a new contender from ESRI which I feel I need to discuss, ArcGIS Pro 1.2. Although it is in beta,  it is already proving itself a worthy successor to ArcMap. Unfortunately, until it is out of beta, I won’t be testing it as I feel it is unfair to compare an unfinished software/

Before we get to the crux of things, I’d just like to add that there have been no major interface changes to either software and I am GIS neutral. I just want a GIS that works and is reliable, I have no bias as to one or the other.

 

Let battle ommence
Let battle ommence

So what is new in QGIS 2.14?

The most talked about is the inclusion of a 2.5D renderer (covered in earlier blogs) but what you may not have noticed are the subtle changes, changes to the processing, caching, labelling and legend. Here is a full list which links to the QGIS changelog

 

What’s new in ArcMap 10.4?

There are quite a few new raster types available for the software, some of which I have to admit that I had never heard of but interesting to see that you can now export topology errors in the ArcMap Basic license. For those wondering why I haven’t listed all the changes, please remember that this is a comparison of the basic GIS software.

 

Data Management toolbox

New tools

Changes

Tool Changes
Add Rasters To Mosaic Dataset Two new parameters added:
Alter Mosaic Dataset Schema The raster_type_names parameter has 12 new options:
Analyze Control Points The out_overlap_table parameter is now Optional.
Apply Block Adjustment New parameter added: DEM.
Compute Control Points Three new parameters added:

  • area_of_interest
  • distribution
  • density
Compute Tie Points Two new parameters added:

  • distribution
  • density
Copy Raster Two new parameters added:

  • transform
  • format
Create Database Connection The database_platform parameter has a new option: DAMENG.
Create Database User When the tool is run against a geodatabase in Oracle or PostgreSQL, it now creates shared log file tables for the user. With the log file tables already created, the database administrator can remove privileges to create tables from the user, if needed, without negatively affecting the user’s ability to create large selection sets, edit data, or reconcile versioned data.
Create Enterprise Geodatabase When you run the tool on an Oracle 12c database, the sde user is granted privileges required to import data using Oracle Data Pump. This allows you to complete your Oracle Data Pump export and import workflows without having to separately grant these privileges.
Create Feature Class The geometry_type parameter has a new option: MULTIPATCH.
Create LAS Dataset New parameter added: create_las_prj.
Create Map Tile Package New parameter added: extent.
Create Mosaic Dataset The product_definition parameter has nine new options:
Create Pansharpened Raster Dataset The sensor parameter has seven new options:
Detect Feature Changes New parameter added: compare_line_direction.
Export Topology Errors You can now run this tool with an ArcGIS for Desktop Basic license.
Feature Compare The ignore_options parameter has a new option: IGNORE_FIELDALIAS.
Generate Tile Cache Tiling Scheme The tile_format parameter has a new option: LERC.
Project New parameter added: vertical.
Register Raster The transformation_type parameter has a new option: POLYSIMILARITY.
Synchronize Mosaic Dataset New parameter added: estimate_statistics.
Table Compare The ignore_options parameter has a new option: IGNORE_FIELDALIAS.
Warp The transformation_type parameter has a new option: POLYSIMILARITY.
Warp From File The transformation_type parameter has a new option: POLYSIMILARITY.

Editing toolbox

New tools

Multidimension toolbox

New tools

Python and ArcPy

ArcGIS 10.4 has been upgraded to include Python 2.7.10. Additional third-party libraries including SciPy, pandas, Sympy, and nose have been included, and existing third-party libraries including NumPy and matplotlib have been upgraded to more current releases.

The GetPackageInfo function has been added to return a dictionary about packages.

Editing

The topology edit tool now supports additional commands and keyboard shortcuts for selecting and moving nodes and edges.

  • Press the N key to select topology nodes.
  • Press the E key to select topology edges.
  • Move and Move To commands are now available on the topology edit tool context menu.

Parcel Editing

Parcel merge

The parcel Merge dialog box now has additional options for managing parent parcels. Parent parcels can be deleted, flagged as historic, or remain as current, active parcels.

Parcel division

When dividing parcels into equal areas, the number of parts on the Parcel Division dialog box can be set to 1. Set the number of equal area parts to 1 when a deed calls for a specific area to be divided from the parcel, leaving a remainder parcel.

Mean points

Performance improvements have been made to the Mean Points tool. Furthermore, the tool now always stays active and can be used repeatedly without the need to specify a tolerance.

Least-squares adjustment

Collinear line sequences in the same plan are straightened during adjustment postprocessing if they lie within the specifiedStraighten Collinear Line Sequences tolerances. These tolerances are available on the Adjust Coordinates dialog box.

Geodata

Geodatabases and databases

  • A new advanced option—All records for Tables—has been added to the Create Replica wizard. Checking this option allows you to designate the inclusion of all data from all tables in your replica. In earlier releases, you had to set the option to include data for each table individually.
  • Beginning with ArcGIS 10.4, you must set an additional option (Return Output Parameters As ResultSet) when youconfigure the ODBC driver to connect to Teradata.
  • ArcGIS now supports connections to Dameng databases. You can connect to view and analyze data in ArcMap. You can also publish map and feature services to ArcGIS for Server.
  • If you use SAP HANA 1.0 SPS10, you can now use ArcGIS to load data that contains z and m values and you can view and analyze existing data that contains z and m values.

LAS Dataset

  • There is a new scrollable LAS point profile view. Using the mouse/keyboard keys the area-of-interest profile window will move or rotate and update immediately in the profile window.
  • Location of the cursor in point profile window is displayed in ArcMap inside the profile area-of-interest.
  • Elevation is now displayed and updated when moving cursor around in point profile window

Raster

There have been five improvements for raster types.

  • The SPOT-7 raster type is now supported.
  • The UAV/UAS raster type is now supported.
  • The WorldView-3 raster type now supports the SWIR bands.
  • Support netCDF and HDF data stored as irregularly spaced arrays is now supported.
  • There have also been improvements within Chinese raster types.

There are several improvements with raster geoprocessing.

The Georeferencing toolbar now has three new first-order transformations available: Only rotation and shift, Only shift and scale, Only rotation and scale.

 

 

Testing

A lot has changed since I last ran this, I no longer have the 8 core 32GB RAM “beast” anymore for starters. I expect that times will be changed but by how much?

For those who want the spec of the machine I am using: System Spec

Although it is more home computer spec, I am reliably told that this is should be more than adequate for running ArcMap & QGIS.

 

QGIS_LoadTimetesting

 

1. Load Time

As this is a comparison of the 2 new updates, rather that witter on about my personal views, I thought it better to provide some test results. To make the test equal, the method I use was to start up the software being tested, leave it for 10 minutes (to ensure all elements have loaded) and the add ALL 2010 AIS from a folder in the root – C:GIS. If you wish to test the data yourself, it can be downloaded from here. The timer was started from the moment that the data is added to the data frame (through the add data button). The timer is stopped when all data has finished loaded, indicated in ArcGIS by the globe in the bottom right not spinning and in QGIS by watching the windows processes & seeing when the CPU demand dropped to zero again.

For those who wish to go further down the rabbit hole, I categorised the data for both QGIS and ArcGIS and saved the styles. The AIS was categorised using standard deviation (n0) with 8 categories. Data was loaded directly from the qml/lyr.

The time given is the average of the 5 runs which were made.

Results:

ArcGIS 10.2  =     27.27 seconds

ArcGIS 10.3  =     38.5 seconds

ArcGIS 10.4  =    24.04 seconds

QGIS 2.6 =     9.103 seconds

QGIS 2.8 =     8.201 seconds

QGIS 2.14 =   5.08 seconds

On average QGIS was 20 seconds faster to load the data, furthermore, there was a slight speed increase for QGIS from 2.8 to the newer 2.14

ArcGIS_AnalysisTest

2. Testing – Analysis

What use is your software if you spend your days waiting for it to finish a process? The amount of time I must have lost due to running processes is immense, so what if I could save some time? Because of this, I run a  a viewshed test. I put a single point down, Then, using standard settings (and OS Terrain50), I run a viewshed (ensuring the output raster resolutions are identical)

ArcGIS 10.2 =         42 minutes

ArcGIS 10.3 =         4 failed attempts & gave up*

ArcGIS 10.4 =         12m 55s

QGIS 2.6 =         58 minutes

QGIS 2.8 =     1hr 16min

QGIS 2.14 =   26.86s

It looks like either this machine is far superior to the old desktop OR both software has made significant improvements in its calculation algorithms. To confirm, both outputs were identical and can be obtained through the link at the end of the article.

*To eradicate any issues with the data input or user error, the ArcGIS 10.2 map was saved and then opened in 10.3, the exact same parameters were used with no success.

5. Testing – Map Export

I seem to lose days exporting PDF files from GIS, so for me, this test is one of the most relevant, so that I can compare the amount of time consumed by the simple “PDF Export”.

For this test, the same EFH shapefiles used previously were loaded, no styles applied, then the bathymetric contours (also from the Marine Cadastre website) and the ESRI world countries shapefile. I then opened the layout/composer & set the orientation to landscape & the size to A3. Scale was set to 1:50000,000 then centered on the EFH data.

Once loaded and left to settle of 10mins, I set the PDF export to 500dpi and then made sure that both the QGIS & ArcGIS settings were the same* (no layers, no georeferencing etc). This is the average times for 5 runs.

The results were as follows:

ArcGIS 10.2 =         3mins 18s – File size 795MB

ArcGIS 10.3 =        3mins 30s – File size 903MB

ArcGIS 10.4 =      7.04s – File size 1.9MB

QGIS 2.6 =         37.4s – File size 72MB

QGIS 2.8 =         35.5s – File size 69MB

QGIS 2.14 =      10.3s – File size 18.16MB

*Just to be clear, ArcGIS and QGIS were run separately

6. Stability

This is a new category, as a few comments I have had asked how many crashes I have had whilst testing. I am please to say on this occasion NONE.

6. Niggles

As I worked through, I must say that both software were pretty much as expected, nothing has really changed. The ONLY thing I would pick up on is that QGIS needs to add layers to their browser. When looking for data, QML & SLD are not visible in their relative folders.
The winner is....
The winner is….

7. Conclusion

As well as comparing the times above, I also run through both software by opening a list of tools which are used within the office on a regular basis to ensure that the software is safe to be used.

As stated previously, it would be unfair to compare the tools as some tools are unique or paid for plugins. Needless to say, I found no issues in my testing.

In this comparison, I think that, although ArcGIS 10.3 has released a HUGE number of new tools and updates, they are, in large for specialists. These tools are unlikely to get used on a regular basis like you & I.

QGIS has shown some muscle and has, in this testing, shown itsef much faster. Furthermore one of my “niggles” from the last article has been dealt with, the shadows for points and fonts. Although there are only a handful of updates & new features, the tools (for me) are more likely to be used.

Again, as before, there is no clear winner as they are both great systems and suited to different professionals in different way. For basic use or an introduction to the world of GIS, you wouldn’t go wrong whichever you choose.

Lacking geoinspiration? Might be worth looking here….

Every now and then we all lack a little inspiration, whether it is a new client looking for that special something or a personal goal to get your work noticed, inspiration seems to fly out of the door as soon as you get to thinking.

Every now and then we all lack a little inspiration, whether it is a new client looking for that special something or a personal goal to get your work noticed, inspiration seems to fly out of the door as soon as you get to thinking.

Help is at hand, believe it or not, the main GIS software providers now host themselves “showcase” sites where you can see what can be done with the software. Don’t be afraid to contact the creators too, if there is a specific technique or an effect which has been used, contact the creator! In my experience, they are usually more than happy to help [to a limit] because the great thing about cartography and creation is that someone else WILL create something better, this new technique will provide a better way of doing what you did before and then you can create something even more amazing….and so on.

Below are my current favourite sources of inspiration, though I have to admit that I also have a style….yes a little predantic but it is a way of identifying my work, so although I might gain a little inspiration from the below galleries, but my work is always in my own style. Also, look carefully, you might see a few of my maps littered amongst the galleries.

Inspirational places for the map maker

British Cartographic Society:

International Cartographic Association:

CartoDB:

ESRI:

ESRI UK:

QGIS:

Have fun!

Nick D

The Geotest….some interesting stats

Over 300 people have taken the test I set on the internet so far, for those who have taken it, I thought you might like to see some statistics on it.

So far over 300 of you amazing geofolk have had a go at my fun Geotest…and I collated some interesting results, don’t worry, there will be no naming and shaming (though someone DID call themselves GEOGOD??!!), what is interesting though is the skill level(s) and knowledge of those taking the test. Read on…

Question 1

All of the above Measurement of the Earth Representation of the Earth
Geodetics is the the study of what? 47% 40% 13%

Question 2

Gary Sherman Jack Dangermond Nicholas Duggan Roger Tomlinson
Who is the Father of GIS? 9% 21% 10% 60%

Question 3

Allocating a data with a reference in physical space Allocating a data within a sphere Allocating a geographic barrier to the data Gridding a dataset
What is “Georeferencing” 91% 4% 2% 3%

Question 4

AutoCAD, QGIS, ArcGIS AutoCAD, QGIS, ArcGIS, GRASS QGIS, ArcGIS, GRASS
Name 3 GIS software (Pick 3 below) 8% 1% 91%

Question 5

Metadata Metafile
What is the name for “data about data” which normally accompanies geospatial data? 95% 5%

Question 6

FALSE TRUE
Best practice when using text on maps is to use fonts with serifs 73% 27%

Question 7

A line which gives indication of distance A list of data & symbols for reference of the user
What is a “legend” 1% 99%

Question 8

FALSE TRUE
Does a maps scale change when the paper size is changed? 53% 47%

Question 9

Height Length Width
When dealing with datum, what is “z”? 97% 1% 2%

Question 10

Distance weighted analysis Time based analysis
What is “temporal analysis”? 1% 99%

Statistics…we all love statistics

On average the test was taken twice, the first score being 7/10 and the second being 9/10

Over a FIFTH of people think Jack Dangermond is the Father of GIS

The most common name for people taking the test a second time was F*CK

Over 40% of people need to re-read their geodetic books

Over a quarter of people aren’t bothered about serifs

The average score over the current 300 users is 79.9%

 

I’ve really had fun answering your questions and seeing your scores. THERE WILL BE ANOTHER TEST!!

WATCH THIS SPACE…..

Nick D

 

 

Dynamic text with QGIS

It’s not until you need it that you realise how much you miss it….such is the case with the ESRI ArcGIS dynamic text functionality, on the surface it seemed easy to put a little reference into a text box and then every time I opened a template or new map it would automatically show the user/coordinate system/date/time of print or any of a hundred plus options.

Originally posted on xyHt.com

It’s not until you need it that you realise how much you miss it….such is the case with the ESRI ArcGIS dynamic text functionality, on the surface it seemed easy to put a little reference into a text box and then every time I opened a template or new map it would automatically show the user/coordinate system/date/time of print or any of a hundred plus options.

With a huge workload looming and setting up templates in QGIS, I turned to the text boxes to provide some small automation…..and fell a cropper. That is not to say it can’t be done but I am not a native coder, so I became stuck, how else do others put their coordinate systems on the map….I asked and apparently the done thing is to write it all in the text box. Not very efficient or cool for such a sofisticated piece of software. So I turned to Google+ and Lord Ninja of all that is QGIS [Nathan Woodrow] as always provided a solution.

As a starter for discussion I’ll outline what I have found so far, then if any of you awesome geoninjas and Q superusers have any code or further insight you can help fill the gaps or provide snippets for the rest of us.

Date & Time labels

[% day( $now) %]/[% month( $now)%]/[% year( $now)%]
[% day( $now) %]/[% month( $now)%]/[% year( $now)%]
Date is one of the easier automatic attributes you can add. Open a new textbox and then insert expression.

Functions

On the right you will notice that you have a list of functions [as above]. If we double-click “day” and then double-click “$now” (and then close with a bracket), we have

day($now) 

If you select OK in the bottom right, you will see that you now have the day number in the textbox…..we can therefore extend this to day, month and year by copy & pasting this:

[% day( $now) %]/[% month( $now)%]/[% year( $now)%]

directly into the “main properties” box – note here that the expression in the building looks different to the expression in the properties box.

Scale

There are 2 ways of doing this, first is by using the method above and using the “$scale” referenced to a feature OR the easist way is by adding a scalebar….I know, just bear with me…

Scale

Select the “add new scalebar” option on the left, then create a box to place it [marquee an area]. You’ll end up with a jumble/scalebar as indicated below.

Scale4

Go to the properties on the right and select “numeric” as indicated above, you will then find the scalebar turns to scale TEXT…..just make sure that you reference it to the correct map frame!

Coordinate System

Okay, so this is where a little QPy is going to help. What I wanted from this was just the EPSG code as I figured that it would relate most of the primary parameters that were important. Then I found that there was a LOT more that could be done.

As with the date & time, create a textbox and open the expression editor. This time open the “functional editor”

coord5Remove the scratch text and add the text:

from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args=’auto’, group=’Custom’)
def crsstring(stringformat, feature, parent):
      settings = iface.mapCanvas().mapSettings()
      if stringformat == ‘wkt’:
            return settings.destinationCrs().toWkt()
      else:
             return settings.destinationCrs().toProj4()

Save this with a rememberable name and run…..nothing happens

So, take this text:

[% crsstring(‘wkt’) %]

and paste it in the label textbox, like this:

coord

…then refresh your screen. If you’ve done it all correctly you should have all your coordinate system information as WKT.

What if you only want a selective bit of that information OR what if you want to display a couple of those pieces of information?…..

Nathan Woodrow kindly sent me this: QGIS API Documentation

Using this you can cater the script above to extract what you [might] need. Remembering that I need the EPSG, the documentation tells me that I need QString “AuthID” (bear with me on this)….note that I have only had success playing with the QString functions for this.

from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args=’auto’, group=’Custom’)
def authid(stringformat, feature, parent):
      settings = iface.mapCanvas().mapSettings()
      if stringformat == ‘wkt’:
            return settings.destinationCrs().toWkt()
      else:
             return settings.destinationCrs().toProj4()

Note that this time instead of “def crsstring” I am using “def authid” – Even though I am still using the same text in the textbox, when I hit run script it provides me with the EPSG, it even has the text “EPSG” before it!

coordOkay…so now we are getting there! If I then open another new textbox and add the same “authid” script in again and change the references from “authid” to “description” (then save & run the script) I get the coordinate system description (change the main properties text to :

[%description(‘wkt’) %]

If you are still with me and understanding this, then you can see how this can be used to build an automated coordinate system box on your map IN QGIS.

As always, let me know if you have any questions.

Many thanks to Nathan Woodrow for his patience!

Nick D