Daily Discoveries of a FOSS4G User: QGIS, the Vector Doctor.

After returning from the amazing FOSS4G-NA conference in Raleigh, NC, I just couldn’t get back to my pre-conference self! In the spirit of continuous learning I decided to try finding better ways to solve common problems and explore these great free and open source geospatial technologies further.

My hope is that this review of various features and hacks I come across while tackling daily GIS/coding tasks may help you learn and better understand how to tackle the challenges the profession throws at us.

In this first post of the series I’d like to share tips on using QGIS (2.12.3 Lyon) to work with geospatial data, formats, projections, and the like.

1. Permanently define layer CRS

If you bring into QGIS a data source without defined Coordinate Reference System (CRS), you are immediately asked to select it. If you don’t do it right away, or select a wrong one, you can always re-open the selector via right-click > Set Layer CRS. Or if you like longer route: right-click > Properties> General > Coordinate reference system > Select CRS (little globe-in-cone-hat icon).

TAnnas article July 2016his is great, but only a temporary, ‘on-the-fly’, solution – the projection is not saved with the layer for the future. The  next step that I found most commonly advised (for example at these links:
, 2), and the one I always used before:  right-click > Save As… Actually, even if CRS hasn’t been defined temporarily yet, it can be specified for the new file at th
e time of saving.

This is also great, but creates a whole new copy of the dataset! It is not always what we need. I tried to overwrite this same existing file at the Save As
step and QGIS disagreed by throwing error and crashing. Luckily, if your goal is to save the CRS with the layer, there is another way to do it! Disclaimer – it only works with a vector data. So, to set the layer’s CRS permanently go to: Vector > Data Management Tools > Define Current Projection.

Then you can select your layer, choose predefined spatial reference system or import it from another existing layer, and voila – the .prj joins the rest of its shapefile sibling files! So happy for them =)

2. Merge multiple layers

Next treat I got was a dozen of one-polygon shapefiles, which in an ideal world were supposed to be a single multi-feature shapefile. My task was toAnnas article July 2016 get all of these polygons into PostGIS, so I would of course prefer to accomplish this with one operation.

Since there were just a handful of those layers, my standard approach would be to create a new shapefile, toggle editing session, then select and copy a polygon from each shapefile and paste it into the combo one. But now that I’m back from FOSS4G, I’m curious to find a better way!

And of course there is a faster and easier alternative for that (as found in: 3, 4)! You don’t even need to load the layers to the map, but need to make sure they are all in the same projection and of the same geometry type. Go to Vector > Data Management Tools > Merge Shapefiles to One. There you can pick an entire directory of layers, or select any number of them, then specify output shapefile – and merging is all done in one step. Thanks QGIS!

3. Open .gdb

Another case of input data that I had to attend to was an ESRI file geodatabase. First thought I had was that I would have to use ArcMap for that. I tried…Annas article July 2016 And unfortunately wasn’t lucky enough to score an available license. Happens all the time to me… QGIS to the rescue! Turns out per the following link: (5), it opens .gdb through a standard dialog to Add vector layer; just need to pick Directory for Source type and OpenFileGDB for Source… emmm… Type =)

That was pretty easy!

Next, I used PostGIS Shapefile Import/Export Manager to load these prepped shapefiles to the PostGIS database, where I continued to run into unexpected challenges – and will discuss that in the next post.

1 thought on “Daily Discoveries of a FOSS4G User: QGIS, the Vector Doctor.”

  1. Pingback: Daily Discoveries of a FOSS4G User: 2. PostGIS and Its Bag of Tricks - Aerial Services, Inc. (ASI)

Comments are closed.

Scroll to Top