Quantcast
Channel: QGIS – Digital Geography
Viewing all 87 articles
Browse latest View live

Create custom markers with R for your webmap

$
0
0

When it comes to webmapping there are thousands of possible markers you can choose from but when it comes to markers depending on the data, which is inside the shapefile, possibilities are more limited. In leaflet you can define different icons according to the attributes of your data by defining the icon url in an attribute. Let me show you, how to use the data in each feature to create a custom icon like a piechart marker using R.

piechart marker

Piecharts as markers in QGIS. Cool, huh?

For this you will need R installed. Especially if you’re new to R I highly recommend RStudio. It has a great GUI and it’s platform independent.

Getting data into R

To enable R reading shapefiles we will need to load additional libraries into R. Therefore we are using the gdal bindings to R:

setwd("~/r_pie")# set the working directory with your files inside:
install.packages("sp") #will be needed to load rgdal
library("sp")
install.packages("rgdal") #here's rgdal
library("rgdal") #enable it for your workflow

Now let’s have look at the Shapefile itself which will be exported:

ogrListLayers("places.shp")
shape<-readOGR("places.shp", layer="places") #will load the shapefile to your dataset.
data<-shape@data
view(data)

Create piecharts and store everything

As we are now having the data stored in an extra variable we can do “crazy stuff” and having a simple loop over the data and create a piechart for every entry according to the variables in columns 9 to 13:

for (i in 1:dim(data)[1]){ #will use every line of the attribute table
  svg(paste(,"/plots",i,".svg", sep = ""), bg="transparent") #creates an svg file were we will "print into"
  pie(t(data[i,9:13]), init.angle = 90, col=c("red","blue","yellow", "green", "grey"), labels=NA) #this will create the pie chart itself with five collors as we have five columns
  dev.off()
}

What we need to do now? Change the attribute table an add a new column with the pathes we just used to store the svgs.

for (i in 1:dim(data)[1]){
  shape$icon_exp[i] <- paste(getwd(),"/plots",i,".svg", sep = "") #will populate a new attribute with the paths
}
writeOGR(shape, "places", driver="ESRI Shapefile", layer="places") 

Now load it into QGIS and export it via QGIS2leaf… The icons are a bit small, but you can easily change this by looking at the code in line 47:

iconSize:     [24, 24],
iconAnchor:   [12, 12]
popupAnchor:  [0, -14] 

Increase values as you like and it could look like this:

pichart markers

piecharts as markers

Find the example shape file places_shape. The r script can be downloaded script.

The post Create custom markers with R for your webmap appeared first on Digital Geography.


Quick QGIS Tips on YouTube

$
0
0

I’ve been experimenting with very short QGIS tips on YouTube, and if you like them I’ll continue to create them. They may or may not reveal something extraordinary, and if you have an idea of something worth creating a short video on, leave a comment or send me an e-mail, tweet, or whatever.

The clips will mostly not be more than 2 – 3 minutes long, even if I will create longer clips as well, but those will not be called “quick tips”.

You can check out the first ones in a playlist of mine: Link to YouTube

As an example I’ve also included one of the clips here below.

My interests vary and focus can quickly turn from one area to another. Right now I’ve found these short videos interesting and I will most likely create some more. If you encourage me there may be a lot more, otherwise my focus will likely shift towards something new in a not so distant future. But for now I think this is fun!

The post Quick QGIS Tips on YouTube appeared first on Digital Geography.

QGIS 2.8: A Preview

$
0
0
QGIS 2.6 landed recently on this planet and it already brought great improvements to our daily work with geodata, the way we publish our results and the convenience in our workflows. But due to the very ambitious release plan of the QGIS core team and the great work of Klas we can have a look at the upcoming features in QGIS 2.8 major version already. Check em out:

Trash is Trash

This seems a bit like a minor change but the old symbol to remove entries from your attribute table was not really convenient and might have led to several “lost data problems” in former times. QGIS would like to minify misconception of this. It£s clear now how to throw away your information:

trash symbol QGIS

Postgis can perform even better

Former use of PostGIS in QGIS was based somehow on the shp2pgsql command. With QGIS 2.8 the Suisse army knife of geotools ogr2ogr will take it’s place and provide better performance when it comes to feeding your postgis database with features. Here is the result of a test from Faunalia GIS :

Adding “-D” for shp2pgsql or “–config PG_USE_COPY YES” for ogr2ogr means a huge improvement is speed: ogr2ogr takes 0.8 seconds to process the small dataset [10mb] and 2.21 minutes the process the big dataset [1.3GB]. Shp2pgsql/psql take respectively 24 seconds and 1.56 minutes.
postgis  QGIS

Heavy Rotation

You can rotate the whole map now in the main project window. That’s it:

rotate map qgis

Embedded Heat Map Style

The creation of heatmaps was always a part of an analysis and reuired the creation of raster files which were plotted over your points. In QGIS 2.8 you will have the point representation as a heat map as one of the style options. So no fancy calculation in the background needed. But be carefull as the visiual conception of such a heat map is always intense and might imply conclusions you don’t wanted with your map. But still it’s an elegant way to indicate places of high informatioon concentration…:

heat map QGIS

The post QGIS 2.8: A Preview appeared first on Digital Geography.

Posts 2014: our Top Ten List

$
0
0

Yesterday I received the mail from Anita Graser’s blog about the best 10 articles on QGIS planet. Therefore I decided to have a look on our own top ten list of most read articles this year. And I have to admit: It’s not the open source world who leads this list…The whole list only shows English articles disregarding our job page which is the most read page on this blog (sidenote: you can post your job offer for free ;-) )

#10 – #5

I was surprised to see an install-something article on this list but with the release of QGIS 2.0 QGIS probably hit the road big time and there were many people who would like to try it out on their Ubuntu (#10). Two out of five articles covered the topics of D3. A great technology for webmapping and data visualisation created by Mike Bostock. Unfortunately Ralf seems to be very busy with other stuff and there were no newer tutorials on D3 on our page recently but maybe you will find some news on his blog (If you know D3 and want to write about, give us a “quick call”).

D3 line simplification tool

D3 line simplification tool

The other two articles covered some ArcGIS content. One of it was a widely discussed one about the performance of ArcGIS Server were I just translated an old article from 2012 which itself cited a paper. It was going crazy with this one. But the other one was a quite normal one on how to make a topographic map by our Russian author Andrew Klikunov. Unfortunately this was a one-hit wonder

DEM classified with contours

DEM classified with contours

3D visualisations with NVIZ and a description on how to create a leaflet based webmap with your data in QGIS had also an impact on our number of visitors.

#4

Let’s enter the upper part of the list. Number four is QGIS specific and described the process of joining data with vector data/features. This a somewhat day-to-day problem as spatial data is often just a hull for meaningful data and the attributes needs to be added and enhanced to create the map for the spatial objects you would like to show. In QGIS it’s quite easy but yet I think it’s not the everyday business especially  for non GIS-ers like journalists or teachers.

shape of local areas in Germany imported in QGIS

local areas in Germany imported in QGIS

#3

Once again: D3… This was our first article on D3 and it simply described the first steps in using D3 as a JavaScript framework. It had nothing to do with webmapping. But D3 means “Data Driven Documents” and so does this tutorial: show stuff you can do with any element:

D3 with some funky example

D3 with some funky example

#2

The rating for this one so far is only 3 out of five stars but it seems to gain some attraction to our readers: How to georeference a map in QGIS. It is also an everyday task for persons working with GIS and it is not always as easy as in this case. Searching for ground control points, determining the correct projection of the image and using the best resampling technique isn’t the most easy task in QGIS. This article show you the steps from determining the projection of the scanned map, selecting the correct CRS in QGIS and using coordinate crosses from the map for a quick and dirty georeferenciation.

#1

Once again: Georeferenciation. But in this case we are using ArcGIS 10. Same steps like in QGIS: scanned image, coordinate crosses from the map choosing good resampling of pixel values and exporting the whole thing as a georeferenced image for ongoing analysis or publishing.

The Numbers

You’re more interested in numbers then in lists? Check it out here with the numbers of pageviews in the year 2014:
PageViews 2014

PageViews 2014

The post Posts 2014: our Top Ten List appeared first on Digital Geography.

Python in QGIS and ArcGIS: A Small Example

$
0
0

Often the usage of GIS never touches the world of programming and I think a lot of GIS users today feel fine with using simple tools and try to avoid tools like Python for their daily work. Despite any prejudices regarding programming, Python can be a big help in your basic tasks and is a very easy scripting language to learn. So let us check out Python in ArcGIS and QGIS with a buffer analysis as an easy example. Nevertheless I recommend to take some coding lessons in Python using CodeAcademy.

Jump to the QGIS or ArcGIS python syntax for buffer.

Accessing Python in GIS

The Python interface is not very “hidden” in both GI systems.

Access in QGIS

For QGIS simply go to Plugins –> Python Console and you will see a nice console in your QGIS working window. The console shouldn’t be the preferred way to work with Python. This should be a script you can write and were you can execute commands from:

Python console QGIS

QGIS: Python console with the script function tool marked in red.

The Python console itself has an input line in the main lower part and an output window in the upper main part. As QGIS provides an enhanced integration of Python the script editor will help you with a code-completion functionality like ArcGIS which will enables you to easily find possible functions and methods for your current “object”. Let’s make a simple first statement by writing

canvas = iface.mapCanvas()

After writing this in the input line you will have it already executed by hitting the Enter button. If you’re using the script editor you can store the script and run everything or you just select this line and use the right mouse button to select just to run this one line as it is selected. Now you have all your objects from your working canvas available in the variable called canvas. Of course the canvas has much more then just layers but let’s stick to current active one by using another command to interfere with your data in the project:

layer= iface.activelayer()

As you might expect all the layers are now stored in your variable allLayers.

Access in ArcGIS

The first real class used for Python in QGIS was called iface which is part of qgis.utils. In ArcGIS we have a similar situation as most of the functionality is part of arcpy. But let’s first check how to get there. You open the Python console in ArcGIS/ArcMAP via the main dialog Geoprocessing–>Python:

Python Console ArcGIS

Opening the Python console in ArcGIS

Unfortunateley ArcGIS 10.3 does not provide a script editor like QGIS so you need to copy paste your syntax to another application, text editor or Python IDE. Also the ArcGIS Pzthon console show syntax suggestion and a help section to explain the syntax for a given arcpy command/class/function:

snytax suggestion

arcpy syntax suggestion for the describe function

arcpy help

arcpy help section

Of course we can get some information about our layers. Therefore we use the Describe function:

arcpy.Describe("places_few_2")
If you want to make it unspecific of the name of the current layer using the pythodaddin module:
import pythonaddins
mxd = arcpy.mapping.MapDocument('current')
layer = pythonaddins.GetSelectedTOCLayerOrDataFrame()
layer.name

But it seems like the integration of Python into ArcGIS is orientated more towards ArcGIS whereas QGIS tends to utilize Python for QGIS workflows and therefore tries to make QGIS available for Python…

Using Python in GIS

As we have now enabled Python in ArcGIS or QGIS let’s create some buffers around some features.

Buffer Tool in QGIS

QGIS itself has a great toolbox where you can access all the commands for raster and feature based analysis from a central hub. Those commands are also available in the Python console after importing the library of processing algorithms:

import processing
processing.alglist()

The second command will show you a list of all algorithms and commands available with QGIS (it’s more then 600…) which are grouped into algorithm-providers like GRASS, SAGA, R or of course QGIS. As we see from this list we will find a algorithm called qgis:fixeddistancebuffer which is the normal distance buffer on features with a given distance.

processing.alghelp('qgis:fixeddistancebuffer')

The above line whill show you the help section and some usage info for this function:

usage info python console

python console usage info for function buffer

So we can easily run this tool with this line in the python console:

processing.runalg("qgis:fixeddistancebuffer","layer-name-you-need",0.1,10,False,"Path-to-file-to-store")

If you’re unsure about some parameters in the the algorithm you can check with with the function (our algroithm has none):

processing.algoptions('qgis:fixeddistancebuffer')

In our example we can determine the layer name automatically by using layer.name() instead of “layer-name-you-need”. The next parameter defines the distance in units of the input feature (in our case it was degrees) and the “10” is the nmber of segments to use for a quarter of a circle (more is better but uses more vertices on the resulting polygon). In the end my python call for a selected layer would be:

import processing
layer = iface.activeLayer()
processing.runalg("qgis:fixeddistancebuffer",layer.name(),0.1,10,False,"C:/Users/ricckli/Desktop/buffer_test.shp")
vlayer = QgsVectorLayer('C:/Users/ricckli/Desktop/buffer_test.shp', "buffer", "ogr")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)

As in the first command (where we accessed all layers in the canvas) you can also iterate over all your layers. But this is another post…

Buffer Tool in ArcGIS

The buffer function is listed as an Analysis function in the help section of ArcGIS. The content of the help is very convenient and you’ll probably find most of the stuff you need as well as usage suggestions and examples and many more:

arcgis help buffer

ArcGIS help section for the buffer function

As we see the syntax need at least three parameters (you’ll notice optional parameters as they are marked):

  • in_features: The name or the path of the features to create a buffer for
  • out_feature_class: pick a name or a path for the shapefile
  • buffer_distance_or_field: should be a field name or a value with a given unit like Meters or Feet or Decimal Degrees
I have to admit that the buffer function has more capabilities compared to the QGIS pendant as we can define the distance independent from the CRS of the input feature. But to make it comparable with the pyqgis syntax our syntax would be:
arcpy.Buffer_analysis("places_few_2","C:/Users/ricckli/Desktop/buffer_test_arcpy.shp", "0.1 DecimalDegrees")

But be warned. The result seems to be different when defining a shapefile as output instead of a simple layer like in this code line:

arcpy.Buffer_analysis("places_few_2","buffer_test_arcpy", "0.1 DecimalDegrees")

In both cases the result will be added to your table of content and you can see it right away.

Ressources

Here are some ressources on Python in QGIS and ArcGIS:

QGIS

QGIS Workshop
Developer Cookbook
Book on Amazon
Spatial Galaxy examples
QGIS tutorials
questions and answers on gis.stackexchange

ArcGIS

Arcpy at the ESRI help desk
ArcPy café
Extended tutorial on python scripts in ArcGIS
Free training by ESRI
Another training by ESRI
Pennstate course

I hope you found it usefull. I’ll upload two videos for both in a few days. I appreciate any comment.

The post Python in QGIS and ArcGIS: A Small Example appeared first on Digital Geography.

Create A Raster Layer Index With QGIS And GDAL

$
0
0

When working with raster datasets, it is hard to keep an overview of the raster files in use and their coverage. Most raster data providers may keep metadata in the filename itself, like path, row and a timestamp. But for more convenience, it is possible to create an index of your raster maps. This article will show you, how to accomplish this in QGIS or with the Terminal.

First of all, we need some raster layers. GDAL is capable of reading most of the common used remote sensing formats, so this should be no showstopper. Just load your data into QGIS. In the following screenshot, you can see two digital elevation model scenes.

QGIS 2.6.1-Brighton_008

Two DEM scenes loaded into QGIS

In the next step, go to “Raster” > “Miscellaneous” > “Tile Index”.

QGIS 2.6.1-Brighton_010

Opening GDALs Tile Index function.

 

In the Tile Index menu, you can now choose an input directory and eventually subdirectories for GDAL to look for raster datasets. If you have your datasets across different folder on your filesystem, you can even index each of them sequentially by running the programm several times and choosing the same index file. If the index file already exists, GDAL appends the new data instead of overwriting the old ones. Additionally, you can provide a name for the attribute holding the filesystem location in the shapefile to be created.

Rasterkachelindex_014

Create Tile Index

As soon as you created the Tile Index and loaded it into your project, you can see a polygon for each of the raster datasets that you indexed. For better visualization and overview, go to the layers style settings, disable the filling, and choose a contrasting color and increased width for the border.

QGIS 2.6.1-Brighton_012

A tile index layer in QGIS. The red lines mark the border of the raster datasets.

 

To get the most out of your newly created tile index, you can even set up labeling for the index polyons. For this purpose, go to the labeling settings of your index layer, activate labeling and choose “location” as labeling attribute. Additionally, I recommend applying a small buffer of e.g. white around the labels, for better readability. The result should look like this:

Auswahl_015

Finished Tile Index in QGIS. Red lines mark the dataset borders, labels indicate dataset filename and path on the filesystem.

 

Did you know that GDAL also offers a command line tool for this? If you like scripting your workflows or generally prefer the terminal over a GUI, you can create a Tile Index like this:

gdaltindex index.shp input_directory/*.tif

The post Create A Raster Layer Index With QGIS And GDAL appeared first on Digital Geography.

Creating ARCs in QGIS: The Python Way

$
0
0
So I came across this nice little project which focussed on trip planning and route over large distances… And there was this nice little post from Nathan Yau at flowingdata.com where he describes the making of great circles from one point to different other points in R and the other example from Anita Graser where she shows how to deal with an Arc in QGIS but using postgis functionality. So what about QGIS itself and a programmatic way? See yourself…Andre Joost pointed me into the right direction by describing the process with a nice example after I asked on gis.stackexchange.com . I extracted the information and would like to show you the process in Python/PyQGIS

Creating a Line with Python

The connection and creation of an Arc or great circles starts with a starting and endpoint. Let’s take it for first try as these are given in a pointshapefile. Lets extract the CRS and get the coordinates of those two points:
point_layer = qgis.utils.iface.mapCanvas().currentLayer()
point_layer_dp=point_layer.dataProvider() #we need this to extract the coordinate system
source_crs=point_layer_dp.crs() #so lets extract it
features = point_layer.getFeatures() #now determine each feature
vertexes = [] #here we will store the coordinates as I like arrays
for f in features:
	geom = f.geometry() #access to the geometry of a point
	point = geom.asPoint() #here we extract the coordinates as one point
	vertexes.append(point) #and store it in the array vertexes by appending the vertexes array
Now we have the point coordinates in a nice little array which is iterable by an index. As I just have two points in this file we can easily create a line connecting these two points in the crs defined by the points:
layer = QgsVectorLayer('LineString', 'connecting line', "memory") #this will create an in memory layer which is not stored on a HDD
layer.setCrs(source_crs) #we set the CRS to the one provided by the point layer
pr = layer.dataProvider() #once again we need the provider (should be shapefile/ESRI)
line = QgsFeature() #let's create an empty Feature which will be the box to put our segment(s) into
start_point = vertexes[0] #this is the start of the first segment
end_point = vertexes[1] #and the end of course
seg = [start_point, end_point] #so this is our whole segment
line.setGeometry(QgsGeometry.fromPolyline(seg)) #we will set the geometry of our so far empty feature from this array of points
pr.addFeatures([line]) #and add it to the layer
layer.updateExtents() #update it
QgsMapLayerRegistry.instance().addMapLayer(layer) #and put it on the map. Store it manually if you need to.
The result might look something like this:
line connection using python

connection with line from one point to another

Custom CRS for a Real Great Circle/Arc

What we will need for real great circles in a GIS is something that preserves distances and angles. Andre pointed out to use a azimuthal equidistant projection which needs to be defined for a custom starting point. The CRS for our starting point of the line would look something like this:
crs_new = QgsCoordinateReferenceSystem()
crs_new.createFromProj4("+proj=aeqd +lat_0=" + str(vertexes[0][1])+ " +lon_0=" + str(vertexes[0][0]) +" +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs") #which uses the Lat and Lon values of our starting point
But before we can do this, we need to get the coordinates of the line segments. According to this new CRS the start point will always get the coordinate (0,0) but we need to find the target coordinates for the endpoint. Therefore we will transform coordinates in Python:
crs_src = QgsCoordinateReferenceSystem(source_crs)
xform = QgsCoordinateTransform(crs_src, crs_new)
start_point_new = QgsPoint(0,0)
end_point_new = xform.transform(QgsPoint(vertexes[1]))
seg_new = [start_point_new, end_point_new]
So now we have the start and end points stored in a new segment but with transformed coordinates in a very special CRS. As we want a smooth line we will not come across to insert vertexes in this new line. The main problem now is to set the current project CRS in QGIS to the crs from the new created line. If we have done this, we can call an algroithm defined in QGIS which densifies the line with new vertexes in a given distance:
crs_old = qgis.utils.iface.mapCanvas().mapRenderer().destinationCrs() #just store it for later ;-)
qgis.utils.iface.mapCanvas().mapRenderer().setDestinationCrs(crs_new) #change current crs to fit with the desired one.
layer_new = QgsVectorLayer('LineString', 'line_new CRS', "memory") #once more...
layer_new.setCrs(crs_new) #and again
pr_new = layer_new.dataProvider() #yap, 2nd time
line_new = QgsFeature() #and...
line_new.setGeometry(QgsGeometry.fromPolyline(seg_new)) #and...
pr_new.addFeatures([line_new]) #okay now we get serious
layer_new.updateExtents() #whoha
QgsMapLayerRegistry.instance().addMapLayer(layer_new) #now we have a line with new coordinates
import processing #we need this library to use the QGIS processing tools
dens_layer = processing.runalg("qgis:densifygeometriesgivenaninterval",layer_new,'100000',None) #which densifies the line by new vertexes each 100 km
dens_layer=QgsVectorLayer(dens_layer.get('OUTPUT'), "densified_layer", "ogr") #and we would like to store the result in a new layer
QgsMapLayerRegistry.instance().addMapLayer(dens_layer) #which we put on the map
QgsMapLayerRegistry.instance().removeMapLayer(layer_new.id()) #we don't need the old one anymore
qgis.utils.iface.mapCanvas().mapRenderer().setDestinationCrs(crs_old) #and change back the CRS to the old one.
curves in QGIS

what a nice curve

If you want to use this in another project zou need to store this separately.

Difficulties

With the above situation it is not possible to create nice lines when you cross -180/180 longitude:
problems

crossing the date line…

So how to overcome this? Therefore we retransform the densified layer into a layer based on EPSG 4326 and extract the vertices of this densified layer. We will identify the vertex which is near the border and split the line into two features at this vertex (sorry, no comments from now on!):
crs_4326 = QgsCoordinateReferenceSystem(4326)
xform2 = QgsCoordinateTransform(crs_new, crs_4326)
layer_4326 = QgsVectorLayer('LineString', 'line_4326', "memory")
layer_4326.setCrs(crs_4326)
pr_4326 = layer_4326.dataProvider()
outFeat = QgsFeature()
for f in dens_layer.getFeatures():
	geom = f.geometry()
	geom.transform(xform2)
	outFeat.setGeometry(geom)
	outFeat.setAttributes(f.attributes())

pr_4326.addFeatures([outFeat])
layer_4326.updateExtents()
QgsMapLayerRegistry.instance().addMapLayer(layer_4326)
vertexes_merge = []
for f in layer_4326.getFeatures():
	line = f.geometry()
	for i in line.asPolyline():
		vertexes_merge.append(QgsPoint(i))

import math
breaks = []
for i in range(0,len(vertexes_merge)-1):
	if math.sqrt((vertexes_merge[i][0]-vertexes_merge[i+1][0])**2) > 2:
		breaks.append(i)

breaks.append(len(vertexes_merge)-1)
layer_merge = QgsVectorLayer('LineString', 'line', "memory")
layer_merge.setCrs(crs_4326)
pr_merge = layer_merge.dataProvider()
start = 0
for index in range(0,len(breaks)):
	end = breaks[index]
	line_merge = QgsFeature()
	line_merge.setGeometry(QgsGeometry.fromPolyline(vertexes_merge[start:end]))
	start = breaks[index] + 1
	pr_merge.addFeatures([line_merge])
	layer_merge.updateExtents()

QgsMapLayerRegistry.instance().addMapLayer(layer_merge)
Now we will get a nicely splitted line with two features which can be exported using the qgis2leaf plugin and be shown in a webmap…
splitted line

splitted line to avoid bad rendering

ps: this all very rough but fit the needs. You can download the sourcecode as python file here: two_points. Yet it is computational intensive if you work with a list of several points. See the current implementation status on github and the video here:  

The post Creating ARCs in QGIS: The Python Way appeared first on Digital Geography.

Short Announcement: QGIS 2.8 Wien released

$
0
0
QGIS 2.8 (the new “Long Term Release”) was released a few days ago. It is a minor release according to the changelog but it will be supported in this setup at least for the next year: Some good news for all those working in a bigger, administrated environment as it is always a problem to update software in these bigger infrastructures.
QGIS release plan

release plan for QGIS

New features:
  • >1000 issues flagged by static analysis tools fixed
  • new code commits and pull requests are now automatically tests against our testing framework.
  • more responsive browser
  • support for contextual WMS legend graphics
  • custom prefixes for joins
  • creation of memory layers in core
  • field calc bar in attribute table
  • dxf export improvements
  • advanced digitizing tools
  • improved snapping
  • better simplify tool
  • Qt5 support
  • Bookmark import/export
  • composer gui improvements
  • grid improvements
  • raster image fill type
  • live heatmap renderer
  • multiple styles per layer
  • rotation of map canvas
  • improved date defined symbology UI
  • new algorithms in processing:
    • Regular points algorithm
    • Symetrical difference algorithm
    • Vector split algorithm
    • Vector grid algorithm
    • Hypsometric curves calculation algorithm
    • Split lines with lines
  • expressions extentable with custom functions
  • comments in expressions
  • QGIS server improvements: better caching, layer style support, value relations, DescribeLayer, python plugins
Further improvements for QGIS 2.8 according to the Linfiniti changelog:
  • Measure dialog improvements
  • Custom prefix for joins
  • Python console improvements
  • Raster image fill type (tiled images in polygons… WHOOHA!)
Unfortunately the current version is only available using the OSGEO4W setup installer and can be updated on Linux systems already. The stand alone installer will be available in a few days. If you already want to get the new version choose the option “For Advanced Users:”. So look ahead friends:
Download page

Download page with old QGIS 2.6.1… will be updated soon!

OSGEO4W installer

OSGEO4W setup installer with 2.8

The post Short Announcement: QGIS 2.8 Wien released appeared first on Digital Geography.


How to create a wind map in QGIS

$
0
0
A few days ago I saw Franz Leonardo’s post on the ArcGIS group on facebook: He visualised wind speed and direction in ArcGIS for a wind map and I thought by myself: let’s do it with QGIS… Here is the tutorial which covers some aspects of interpolation, symbol levels, classification and formulas…

The Data

The whole process starts with the values for seven point location which could be potential weather stations or simple observation points. We have values for direction and speed of the wind for a single event. If you only have horizontal and vertical speeds (which seem to be a common thing for wind data) you can convert it to speed and directions using this source.

Station UTMX UTMY Direction Speed
A 615380 9531496 22.5 15
B 616004 9533157 45 14
C 617620 9533808 90 12
D 619191 9532326 135 12
E 621295 9530663 112.5 5
F 622303 9533906 180 5
G 616992 9532169 22.5 13

You can simply convert it into a shapefile by adding it as a csv layer and save it as a ESRI shapefile (download it here). After this comes the more less hardest task of interpolation of values for the vector field. As we are concentrated on the visuals instead the math behind interpolation I simply used the interpolation plugin. Ujaval has a nice tutorial on the usage of this plugin. I ended up with using a standard IDW (Inverse Distance Weighted) interpolation for both the speed and directional values. Of course this is over simplified and you can get your hands dirty with this. If you want to make it right you might read these articles:

  • Luo, W., Taylor, M. C. and Parker, S. R. (2008), A comparison of spatial interpolation methods to estimate continuous wind speed surfaces using irregularly distributed data from England and Wales. Int. J. Climatol., 28: 947–959. doi: 10.1002/joc.1583 | PDF

  • Gumiaux, C., Gapais, D., & Brun, J. P. (2003). Geostatistics applied to best-fit interpolation of orientation data. Tectonophysics, 376(3), 241-259. | PDF
After finishing you might end up with three data sets: a point layer with the input points, one raster with directional values and one raster with speed values and it could look like this:
wind speed

Wind speed interpolation raster in QGIS

Both raster will be the basis for our vector field. Now we have two possibilities: create a mesh of regular spaced points over the raster data or convert the raster to points… I’ll go with first one, as the second will result in 90.000 points which is a bit much. You can create a mesh by using Vector -> Research Tools -> Regular Points:
regular spaced points QGIS

Regular spaced points

At this grid locations we need to extract the values of the both raster layers. YOu can do so by using the Add grid values to points function from the processing toolbox in QGIS. This function will extract the values from the selected layers so you don’t need to run an extraction twice as you have two input raster files. Nice! Now, your layer with regular spaced points should have an attribute with the direction data and one with the speed data.

The Visualisation

Now let’s open the properties and adjust the style of the regular spaced points layer to create a stunning wind speed and direction layer. First we choose a graduated style and change the base symbol to be the arrow:
Arrow symbol

Arrow as symbol

After this make sure to select the entry “Simple Marker” to see the following dialog:
Marker dialog

Marker dialog

And you can see I made some selections on the size and rotation tab and guess what: size = speed values and rotation = direction values. But why should I write so much and not show you the actual options I adjusted in a short video:

The result can look like this:
vector field

Vector field for wind data

I hope you like it. I’ll appreciate any comment!

The post How to create a wind map in QGIS appeared first on Digital Geography.

Map excel data for free – 5 steps to your own print- and webmap

$
0
0

To map excel data onto a print- or webmap is one of the most needed and chosen data preparations. Companies and scientists are often highly interested in located table datasets on maps. In this how to I’ll show you, that this job could be done with free and open source software like QGIS.


What do you need?

  • a table with some data columns (one city- and street-row is necessary)
  • excel or open office or libre office or something else
  • QGIS (free open source GIS-software)
  • 10 minutes

1. georeferencing your point data

In this step we create geographic coordinates (decimal x- and y-values) for our address-row of the input table dataset.

First we need to import our datatable into QGIS. I’ll use this test dataset.

city street customer product output buydate
NewYork 355 W 16th St Peter Pan shoes 50000 01.02.1988
London Whitehall Place David Hasselhoff guitar 10000 02.10.1985
Berlin Friedrichstraße 1 Michael Jackson car 3200 02.10.1980

Now follow these steps:
a. Save your excel datasheet as .csv (comma separated values) like this:

data.csv

city,street,customer,product,output$,buydate
NewYork,355 W 16th St,Peter Pan,shoes,50000,01.02.88
London,Whitehall Place,David Hasselhoff,guitar,10000,02.10.85
Berlin,Friedrichstraße 1,Michael Jackson,car,3200,02.10.80

b. Open QGIS

c. Install the mmqgis Plugin


Manage and Install Plugins

d. Manage and Install Plugins



Install mmqgis

e. Install mmqgis


f. Geocode your table with mmqgis

Choose mmqgis' geocoding feature

g. Choose mmqgis’ geocoding feature



Set fields and define output directory

h. Set fields and define output directory



your geocoded table informations are now ready to be mapped

i. your geocoded table informations are now ready to be mapped

3. show it as map layer

For showing your new map features on top of a map you only have to import a webmap baselayer. The plugin “Open layer plugin” is very helpful in this case. Just install it in the extension manager like mmqgis Plugin described at point 3. After installing this plugin press “Web – Open Layers Plugin – MapQuest – MapQuest OSM” and gain the following map result.

Installation of OpenLayers plugin

Installation of OpenLayers plugin



mapping result

Mapping result

4. export your map data as a print map

Now open the QGIS Map Compose, click on “Add a new map” and draw a rectangle on the white canvas. After that you’re ready to export the result as raster- or vector-pdf file.

Setting the map dimension on canvas

Setting the map dimension on canvas

5. export your map data as a webmap

If you’re interested in creating a webmap, use our QGIS2leaf Plugin for an easy webmap creation. Install it from extension manager (“QGIS2leaf”). Start the plugin, “get layers” and export your first data driven web map with your own company data.

Export menu of QGIS2leaf

Export menu of QGIS2leaf



Your webmap result

Your webmap result



Popups on the webmap

Popups on the webmap

Help

You need professional help in creating proper and modern webmaps, which shows your business data – get in touch with us!

The post Map excel data for free – 5 steps to your own print- and webmap appeared first on Digital Geography.

Landsat in Love with QGIS: the newest coup from Luca

$
0
0
The normal way of getting Landsat data for your GIS projects often was: visit a Landsat data mart like landcover.org, earthexplorer or WIST, search for your area and time and download/order your desired data. Once you’ve done this, you were prepared to add, analyse and publish this data/results with QGIS. Luca Congedo from the blog “From GIS to Remote Sensing” .

The Plugin SCP

Luca developed a plugin called Semi-Automatic Classification Plugin or in short SCP:
The Semi-Automatic Classification Plugin (SCP) is a free open source plugin for QGIS that allows for the semi-automatic classification (also supervised classification) of remote sensing images. Also, it provides several tools for the pre processing of images, the post processing of classifications, and the raster calculation.
Once a domain of ERDAS, Matlab, R and other more numeric orientated software packages, SCP makes it possible to extract vector data from raster images in a convenient way:   You can download it via the plugin handler in QGIS.

Landsat and QGIS

In the newest version it uses the latest developments of Amazon which now offers Landsat data via direct access. Once installed, you can search, display and download Landsat 8 images via the SCP plugin directly in QGIS…
SCP main window

The main plugin window: SCP

The plugin has two main windows:
  1. SCP: Classification – Here you can do your fancy classification steps and also download of data.
  2. SCP: ROI creation – Here you define your Region of Interest.
Once you choose to “Import […] USGS spectral library” a new window comes up with several tabs. One of them is called “Download Landsat 8″:
landsat 8 download

Landsat 8 downloader with filled corner coordinates

You just need to define the upper left and lower right corner coordinates by typing or interactive selecting via the cursor tool, select the required maximum cloud coverage as well as the temporal coverage and press the “find images” button to get a list of appropriate scenes. There is also the possibility to add the previews to your current project which is a nice way to get an idea about scenes: a 80% cloud coverage is not so bad if your ROI falls in the remaining 20% …
landsat preview

Landsat preview in QGIS

Once you’ve found a good scene, you can download it directly into your working folder:
folder

folder with downloaded images

Summary

The newest version of the SCP plugin provides a great interactive way to browse and download Landsat 8 date for your specific area of interest. It has the advantage of offering all scenes instead of only selected snapshots as in other online services without any authentication or affiliation. Unfortunately the progress bar for downloading images was not working in my example and I got always 0% till finishing the job. Especially for Landsat 8 it could be a good thing to have, keeping in mind that one scene has 740mb  of data…

Further Information

Luca created a short “Tutorial” on this feature as a video. Enjoy it:  

The post Landsat in Love with QGIS: the newest coup from Luca appeared first on Digital Geography.

Happy B-Day QGIS2leaf

$
0
0
When I started to work on QGIS2leaf about one year ago it was a nice idea and my first real dive into Python programming and using the possibilities of pyqgis. So what is the current state and where are we going? Please, come and take a look: Happy Birthday QGIS2leaf!

QGIS2leaf – Current Usage

After some commits to QGIS2leaf Tom Chadwin from the North Umberland National Park joined the short list of contributors to the plugin and the whole thing got some drive. As far as I know the UK National Parks decided to work on and with QGIS2leaf as the preferred way to publish QGIS projects on websites. Besides this organization there are several other webmaps published on the web which were created with QGIS2leaf. Some of them are rapid prototypes (QGIS2leaf was meant to work like this 😉 ) and some others are heavily altered webmaps based on the output of QGIS2leaf: Click to view slideshow. I am impressed on the wide-spread of the plugin after one year: 25.000 downloads and many users all around the world.

QGIS2leaf: Capabilities

I started the plugin with a simple export of points, lines and polygons to geoJSON and embedding those in a leaflet based webmap. At the current version 1.5.2 and thanks to Tom and the UK National Parks as well as the Social Planning Council of Ottawa the plugin can do much more:
  • embed of WMS/WFS layers
  • legend creation for your webmap
  • cluster functionality for points
  • address search in your webmap
  • labels on hover
  • raster export (as png with opacity!!!) and opacity control
  • auto locates on your device
  • customizable and multiple basemap selection
  • save and restore your export settings
  • smaller geoJSON outputs
If you want to try it out for yourself. You can find some example project here. And here is the export:

 QGIS2leaf: the Future

QGIS2leaf will have a future. To what extend is unclear! Of course the community will try to fix current issues (which are a lot 😉 ) and will try to increase functionality but we are probably on a turning point. ATM Tom started to work on QGIS2web which tries to be a hybrid of qgis-ol3 (the openlayers exporter from Victor Olaya) and QGIS2leaf. There is plenty of work to do: Please take an active part and try the current experimental release of the plugin and report any issues you find as well as try to contribute to QGIS2web!

The post Happy B-Day QGIS2leaf appeared first on Digital Geography.

share your qgis project: the relocator plugin

$
0
0
Since I developed qgis2leaf together with some great supporters we always struggled with sharing a qgis project: we use different layers, different visualizations and so on. It’s not easy to make sure you’re talking about the same. So why not make it possible to export a whole qgs project with one click…

The relocator plugin

The first steps I designed was to copy raster as well as vector data to a single defined directory. This is straight forward and uses the
QgsVectorFileWriter.writeAsVectorFormat(layer,path,encoding,crs,type)
for vector files distributed over your hard drive(s) and the
shutil.copyfile(src_path, dst_path)
for raster files. The only problem was to change a xml document. Yes, a qgs file is a simple xml document and so I used this nice little how-to from the python documentation:
for rank in root.iter('rank'):
	new_rank = int(rank.text) + 1
	rank.text = str(new_rank)
	rank.set('updated', 'yes')
tree.write('output.xml')
First I copy the old qgs file to the defined directory and then I adjust all the given source paths to the layers:
changing xml documents and removing paths

changing xml documents and removing paths

You will find all your data in the chosen directory along with your qgs file. Furthermore you have the possibility to store this directory in a zip file so it is easy to send the whole set by email or store it on a ftp server. Sharing was never easier:


The plugin can be downloaded and developed via github. It is already pushed to the official plugin repo by qgis but is still flagged as experimental:
relocator plugin

The relocator plugin in qgis plugin installer

Can someone check it on a Windows or Mac? Thank you for any comments and/or issues on github!

The post share your qgis project: the relocator plugin appeared first on Digital Geography.

The Geography of Tweets: Reading Tweets with QGIS

$
0
0
Anita showed some nice examples of tweets in QGIS in 2012. Since then it seemed to be quiet about the twitter-content in QGIS. Yet tweets can be an interesting source of information. Sometimes they can tell you something about the spatiotemporal dimensions regarding a keyword, the digital heartbeat of a defined region and many more. Yet we need to be careful with the data as it is completely biased. But how to get this data stream into QGIS?

The First Insights: Tweets in QGIS

As in 2011/2012 the twitter API was easy to fetch with a simple line of code and you were able to stream data. Anita showed this in a nice little way:
curl -k -d @locations.txt https://stream.twitter.com/1/statuses/filter.json -uuser:password > tweets.json
With this line you collected all tweets in a file for a defined region (as stated in locations.txt) and you can then simply scan the file in QGIS for tweets with a defined location, add those lines as features in a point shapefile and of you go. But soon after, Twitter changed its API policy and switched to a more advanced authentication system. The solutions of Anita wasn’t working any more. Still nice examples from tweets in a geographic context appeared online. Most extreme map is probably this here: And also the recent versions of ArcGIS added the possibility to add tweets to ArcGIS map products . So it’s time to add it to QGIS as well.

Tweets in QGIS- Prerequisites

At the moment the most reliable way to get access to the Twitter API from a python environment seems to be tweepy. The installation is quite easy under Ubuntu. But for an installation in Windows you need some information about environment parameters and only the user knows whether he has the OS4geow shell installed. Long story short: You need to install the tweepy module by hand prior reading streams from twitter. Furthermore the twitter API needs some tokens and keys: Make sure to have a twitter account and create an application so you’ll get your codes:
  • access token
  • access token secret
  • consumer key
  • consumer key secret
Ones you have both let’s dive into the QGIS python console.

Gathering Tweets

The first part of gathering tweets is to call tweepy with a defined location:

import tweepy
access_token = "231016902-6coaqCFPNCpQoLFxCKlEtSTqoSROgykF7BbsMj88"
access_token_secret = "R3p1kMK3o8V9gvtd4hiro4xU9wrRDq9mhZly5EfsboB1R"
consumer_key = "RiaBnLlTmu0e4rxKwEjF0hC1A"
consumer_secret = "lAclBkGTjeUa9RwzI0iIZYDijKTUkMjSxDy1opqd8C4ebHCNup"
key = tweepy.OAuthHandler(consumer_key, consumer_secret)
key.set_access_token(access_token, access_token_secret)

# here come the tweepy part:

class stream2lib(tweepy.StreamListener):
output = {}
def __init__(self, api=None):
api = tweepy.API(key)
self.api = api or API()
self.n = 0 #we will start with zero tweets
self.m = 10 #let's stop with 10 tweets
def on_status(self, status):
#we will parse the interesting information into a nice format
self.output[status.id] = {
'tweet':status.text.encode('utf8'), #text could have non utf8 characters, so change this!
'user':status.user.screen_name.encode('utf8'), #user name should be utf8 conform as well
'geo':status.geo, #this is the point location of the device
'localization':status.user.location, #user location as part of the user profile (normally set fixed per user)
'time_zone':status.user.time_zone, #quite
'time':status.timestamp_ms} #the timestamp given in ms since 01.01.1970
#we will only care about tweets with geo
if self.output[status.id]['geo']!=None:
self.n = self.n+1 #we found a geotweet. but that's always true when calling the command with "locations=[-x,-y,x,y]" as below
if self.n < self.m:
return True
else:
return False
stream = tweepy.streaming.Stream(key, stream2lib()) #initiate the stream
stream.filter(locations=[-180,-90,180,90]) #filter the stream for tweets in this "box"
tweetdic = stream2lib().output #copy it in a variable
print tweetdic #just to be sure 😉

As you can see: we gather tweets and we filter the stream. Unfortunately the filtered stream can’t be stored in a variable so we added the output to the whole listener and we need to filter this for tweets with a coordinate afterwards. With the lines above we have a dictionary of tweets….

Adding Tweets as Points to QGIS

As we have the tweets in a variable we can simply iterate over the dictionary and fill a virtual layer in QGIS with the point information. First we create this virtual layer:

vl = QgsVectorLayer("Point", "temporary_twitter_results", "memory")
pr = vl.dataProvider()

# changes are only possible when editing the layer
vl.startEditing()
At the moment the layer doesn’t contains any attributes so let’s add them as well:
pr.addAttributes([QgsField("user_name", QVariant.String),QgsField("localization", QVariant.String), QgsField("tweet", QVariant.String), QgsField("time", QVariant.String)])
And the next lines will iterate over the dictionary, uses the coordinates as point locations and tweet attributes as attributes for each feature if a tweet has a coordinate:
for tweet in tweetdic:
    if tweetdic[tweet]['geo'] != None:
        fet = QgsFeature() #it's a new feature
        fet.setGeometry(QgsGeometry.fromPoint(QgsPoint(tweetdic[tweet]['geo']['coordinates'][1],tweetdic[tweet]['geo']['coordinates'][0] ))) #use the coordinates for point location
        tweettime = datetime.datetime.utcfromtimestamp(float(tweetdic[tweet]['time'][:-3] + "." + tweetdic[tweet]['time'][11:13])).strftime('%Y-%m-%d %H:%M:%S:%f') #parse the time to fit YYYY-MM-DD HH:MM:SS:MS
        fet.setAttributes([tweetdic[tweet]['user'],tweetdic[tweet]['localization'],tweetdic[tweet]['tweet'],tweettime]) #set attributes of current tweet at current location
        pr.addFeatures([fet]) #and add the feature to the layer.
And as we have finished the iteration let’s stop the editing and publish the layer to the current QGIS project:
# commit to stop editing the layer
vl.commitChanges()
# update layer's extent when new features have been added
# because change of extent in provider is not propagated to the layer
vl.updateExtents()
QgsMapLayerRegistry.instance().addMapLayer(vl)
In the end you can collect as many tweets you would like. But be warned this solution might freeze your QGIS application for a few moments until a new tweet was found.
10.000 tweets in QGIS

10’000 tweets in 3min ;-)

Together with Anita’s TimeManager plugin you can now create nice videos: The whole script can be downloaded: tester2. Furthermore I created a QGIS plugin called twitter2qgis or geotweet:
geotweet twitter2qgis

twitter2qgis/geotweet for qgis: a plugin

The plugin is also under development via github. so please report any issues or contribute with knowledge/programming…

A Warning

You can collect a large number of tweets and also mine them. But be aware: The user who uses twitter is quite specific. The user who also allows Twitter to use current location is even more specific. If you do any analysis with those tweets: keep in mind these aspects and also think about reading these articles:  

The post The Geography of Tweets: Reading Tweets with QGIS appeared first on Digital Geography.

Routing in QGIS … with Google

$
0
0
Routing in QGIS was, as far as I know, always dependent on an available network. Either you had some database which was pgrouting enabled, or you had some network and used this via the roadgraph plugin. I would like to show you, how to do routing and path finding via googlemaps and import the path into QGIS. Big advantage: You don’t even have to think about a network…

Current Solutions

My current knowledge of routing possibilities in QGIS is quite limited. I only know these three:
  • pgrouting
  • roadgraph plugin
  • points to route
So let’s have a closer look:

pgrouting

pgrouting is not a routing method. Instead it is an extension for postgresql like postgis. It requires you not only to have access to a postgresql database which you can administrate but also to have a transportation layer. Once you have it imported into the database you can use pgrouting algorithms on this network. Anita Graser covered the whole process in a blog post 2 years ago. pgrouting is probably the most versatile approach regarding routing in QGIS.

pgrouting example from Anita’s blog

roadgraph plugin

The roadgraph plugin makes it a bit easier to work with points and routes. All you need is a local shapefile which serves as a network. Once you have this, the plugin is able to snap o the network, calculate travel times (if you have the data), lengths and the shortest path from one way to another. Keep in mind that we don’t talk about real-life routing as this plugin doesn’t know any traffic lights ;-).

points to route

points to route is quite comparable to the roadgraph plugin but offers less more possibilities or outputs. It simply uses a polyline layer as a network and creates routes for a set of input points along the network.

Routing using GoogleMaps API

The primary problems on the above mentioned solutions are:
  • You need a periodic update of your network layer
  • acquire a network layer
  • prob. install a postgres DB
Therefore I asked myself whether it is possible to use the GoogleMaps API for routing. And hell yeah it is working. You’ll need an API key and the right APIs activated:
  1. log in at the Google dev page.
  2. Create a new project.
  3. Choose “Enable an API”.
  4. Browse for the API and activate the following APIs: Directions API
  5. Click on Credentials.
  6. Click Create new Key for a new public key.
  7. Select “Server Key”.
  8. Click Create.
unfortunately you will also need to “install” a module in your current Python environment to get access to the API. The module is called googlemaps can be obtained via github. It was easy to install via command line on Ubuntu:
sudo pip install googlemaps
On Windows I was using the OSGeo4W Shell and:
pip install googlemaps
Once you got this, the finding of a direction is quite easy from the python coding in the qgis python console:
import googlemaps
from datetime import datetime
now = datetime.now()
gmaps = googlemaps.Client(key="put YOUR key here!")
directions_result = gmaps.directions("Dessau, Germany", "Berlin, Germany",mode="driving",departure_time=now)
point_str = str(directions_result[0]["overview_polyline"]["points"])
The result is an ugly list of dictionaries. Especially the rout is not given as a pair of nice X-Y coordinates. Instead it is a encoded polyline as Google names it. The good thing: we can handle it!

Importing the route into QGIS

First we need to decode the polyline string into X and Y coordinate pairs as this string representing our polyline is damn ugly:
u’mak{HixkiAf@_\\bBeIzDqHbQyXzBgOe@uKcG{]_EiJOmDkAoAcMuHiBcDi@aFl@kQpAuWOcRZmHO}@wAeGoU_NmIaGe@qAl@wCdBqIaDaAmFYcTcIeETmFkCaAmB[oC_ExAe[nJiT|BaPbB}Ft@cI~DmIfBiNx@sOj@iNWcL_CwMgGaNcGaUgEmA}FeCs\\EkQeA}G}GeMoEqJwBqJwDeHyDy_@\\aaAhD}`ArDcQvNmYrDgTKiOiJqe@mMcs@}Cqr@iDgM{LgRiEqN{@oMcAuaBaAeqBhEkbBzAqZrPatAxCuTpATpBbC_@lDqAH_SmOyr@yk@kUkX}Qqa@{Qie@cSyg@qN_[iKsNcWgSsImDiuAoe@s{Ase@cTmImUuRaSe\\qTkm@iVir@cJu\\cKol@eVytAcXygAg]}sAsR}f@}mActBif@on@gWy[{KmTmRql@uKu]c\\udAwG_N_JsLoMgNiJkOqHuVcGaa@iF}QgIcOa\\uZuIqNgVws@eJgX{MuXeOgRyS_O{~@sh@sf@cZwRaPq_@u`@a}@msAqQc\\{Mi\\eUug@eq@}fAyPwXoIyQiUmr@oc@gsAyJuSaTuYav@o~@epAg{AsaA{kAyPuUkPu`@yJ_f@eMa{@i^abCgJq]{GiP_Yob@ig@as@yL_XwJm_@iPkiAkIs]cKgW{SuZi|@_aAoRySyb@we@ef@_i@wQoQwQyJuQcEuUOoUdFmR`J}y@la@cI~C{NvCyWAyWqF{d@{KkqAwZ}JeE}FaI{Hi_@yfAsyHcCsa@r@iuCLck@f@mTzBiRhO}w@tHif@\\eNs@uR_F}VmFiVeAuO`AkhAl@qi@|Aco@tBs_@{AoN}GuO_dAkm@kUaNgY}Yan@up@}J_UmH_^w^kmBaFoO{ImOqGsGiNuGyJeAmNDiiAx@gKo@cHcDyF_G_J{P{MiRoGgDsFaAy_@PmSBkHiAac@mUqN_MyFgMeDoOcTevAeCiLgKgWy]mc@au@_{@qGwCcIw@_S`C}ZbEoLdCsE~EsEnIuFpE}G\\uVyDkNmDoIcJ}[oc@op@o}@odA{vAkw@ifAwcA_pAij@ys@_l@ax@i^kh@kBcJ]sOkAmKsB_EgC]}C`@kEwEsFwDuKeAk[gQ}HyBqByACcAMmEbDo@`Do@pD{@L}G}@{_@uAie@mCuaAeBao@n@gCHkHkBmHgIcyClAaEKsE{AiCi@gKiEccB{@_[NqRdBwA~CAYgJ{AuOa@uNnDkAIcBq@mWWsJ{@HkC`@wC^w@@[wEk@oM}A_b@cMs_@’
The directions API has a very special way of providing route information as they encode the polyline. Therefore github user signed0 created a decode function and we will use the script to decode the result. We will concentrate on the overview route which has not all the points of your route but gives a first impression:
coord_chunks = [[]]
for char in point_str:
	value = ord(char) - 63
	split_after = not (value & 0x20)
	value &= 0x1F
	coord_chunks[-1].append(value)
	if split_after:
		coord_chunks.append([])

del coord_chunks[-1]
coords = []
for coord_chunk in coord_chunks:
	coord = 0
	for i, chunk in enumerate(coord_chunk):
		coord |= chunk << (i * 5)
	if coord & 0x1:
		coord = ~coord #invert
	coord >>= 1
	coord /= 100000.0
	coords.append(coord)

points = []
prev_x = 0
prev_y = 0
for i in xrange(0, len(coords) - 1, 2):
	if coords[i] == 0 and coords[i + 1] == 0:
		continue
	prev_x += coords[i + 1]
	prev_y += coords[i]
	points.append((round(prev_x, 6), round(prev_y, 6)))

print points
Now we have a smooth list of coordinates. We will convert this into vertices of a new polyline shapefile:
from PyQt4.QtCore import QVariant
layer = QgsVectorLayer('LineString', 'route', "memory") 
pr = layer.dataProvider() 
pr.addAttributes([QgsField("attribution", QVariant.String)])
layer.updateFields()
fet = QgsFeature() 
seg=[]
for i in range(0,len(points)): 
	seg.append(QgsPoint(points[i][0],points[i][1])) 

fet.setGeometry(QgsGeometry.fromPolyline(seg)) 
fet.setAttributes(["route provided by google maps api"])
pr.addFeatures([fet])
layer.updateExtents() #update it 
QgsMapLayerRegistry.instance().addMapLayer(layer)
googlemaps route in QGIS

route given by GoogleMaps API in QGIS

Limitations

As the API operates with a key you have some limitations: You can only call the API 2500 times a day and you need to give attribute to the source of the route / vertices what so ever. But I think this is a better burden than keeping your network in a db up-to-date or fetching GB of data as you need a bigger transportation layer… You can download the script here.

The post Routing in QGIS … with Google appeared first on Digital Geography.


Routing in QGIS… with OSM

$
0
0
Routing with Google is quite cool as the database/network is probably the best currently available. But the terms of services limit the possible usage. So what about OpenStreetMap? By figuring out how to use OSM for routing I found it much easier to get routes into QGIS with OSM compared to the Google way. Check it out….

Prerequisites for Routing with OSM: Coordinates

Before we will have a look on the routing and getting the web response from OSM into QGIS we need to translate our start and end locations/addresses into coordinates. If you have point features you can simply add the geometry to the attribute table: Of course you also have access to the point coordinates using the PyQGIS commands:
pl=qgis.utils.iface.activeLayer() #for your activated point shapefile
iterator = pl.getFeatures()
for feature in iterator:
    geom = feature.geometry()
    print geom.asPoint()
As we have all the coordinates we can move on to the routing.

Routing with and Import from OSM

The University of Heidelberg owns a great routing platform. Furthermore they have an API for this nice little tool which is well described on the OSM wiki. We will use this API. The API will respond a XML document which then will be parsed into a line shapefile. So let’s start:

First let’s get the response into the Python console. We will start with the route from Oedheim (Germany) to Modautal. The above described solutions will give us the coordinates from the start and end point or our route:
Oedheim	9.256506	49.240011
Modautal	8.72083	49.7606
We can use this coordinates already in the browser and open the following URL:
http://openls.geog.uni-heidelberg.de/testing2015/route?Start=9.256506,49.240011&End=8.72083,49.7606&Via=&lang=de&distunit=KM&routepref=Fastest&avoidAreas=&useTMC=false&noMotorways=false&noTollways=false&instructions=false
directions from openrouteservice

XML response from openrouteservice.org

How to do this in Python? We will use the requests module for getting the request and the build-in xml parser xml:
import requests
from xml.etree import ElementTree
url="http://openls.geog.uni-heidelberg.de/testing2015/route?Start=9.256506,49.240011&End=8.72083,49.7606&Via=&lang=de&distunit=KM&routepref=Fastest&avoidAreas=&useTMC=false&noMotorways=false&noTollways=false&instructions=false"
response = requests.get(url)
xml = ElementTree.fromstring(response.content)
Now we just need to analyze the structure (take a look at the response in your browser) and we need to know that this sentence from the Etree documentation:
Children are nested, and we can access specific child nodes by index: root[0][1].text
Keeping this in mind we can easily iterate over the point coordinates of the route and add them as vertices of a line shapefile:
from PyQt4.QtCore import QVariant
layer = QgsVectorLayer('LineString', 'route_OSM', "memory") 
pr = layer.dataProvider() 
pr.addAttributes([QgsField("attribution", QVariant.String)])
layer.updateFields()
fet = QgsFeature() 
seg=[]
for i in range(0,len(xml[1][0][1][0])): 
    seg.append(QgsPoint(float(str.split(xml[1][0][1][0][i].text)[0]),float(str.split(xml[1][0][1][0][i].text)[1]))) 

fet.setGeometry(QgsGeometry.fromPolyline(seg)) 
fet.setAttributes(["route provided by openrouteservice.org"])
pr.addFeatures([fet])
layer.updateExtents() #update it 
QgsMapLayerRegistry.instance().addMapLayer(layer)
And now let’s compare:
OSM routing

Google vs. OSM routing

Unfortunately we can’t rely on this project from the University Heidelberg:
Description: Through the OpenLS interface requests can be generated to the appropriate services without further query limitations. The offered API’s are only valid for ‘ one ‘ year. In case you plan a long-term use of the interfaces within your projects or high volume or for commercial applications , please contact openrouteservice AT geog.uni-heidelberg.de
Nevertheless: Download the example and alter it according to your needs.

The post Routing in QGIS… with OSM appeared first on Digital Geography.

Attention: QGIS 2.10 is coming!

$
0
0
Four months ago QGIS 2.8 was released. The Long Term Release will be suppported for the next 2 years. Besides this LTR version QGIS is updated in a four month cycle. So let’s say hello to QGIS 2.10.

QGIS 2.10 “PISA”: changelog

QGIS 2.10

QGIS 2.10 “PISA” Splash Screen

With the new release we will see some minor and some bigger changes in QGIS. You can download it using the OSGEO4W installer and the Linux packages. Tim from linfiniti made a nice list of features on this changelog. Let me list my favourites:
  • New zonal statistics features: The old build-in function only served a limited number of stats. This is providing way more freedom of choice.
  • Improved geometry rotation tool: it’s easier than ever to rotate vector data when digitizing. Especially for the guys in the field of line documentation (gas/oil/water/electricity) this might be helpful.
  • Layers with joins can now be filtered: I have to admit that I hate joins. I love it all in one file. But with this nice function you can apply a filter on the attributes of the “master” file.
  • Visualise and modify the graduated renderer using a histogram: A nice and convenient way of altering your colour scheme according to the visual distribution of data.
  • Live layer effects for layers and symbol layers: If you want to create stunning maps, this is definitely for you.
We have to thank the following persons:
  • Jürgen Fischer (norBIT) – Germany
  • Matthias Kuhn (OpenGIS) – Switzerland
  • Marco Hugentobler (Sourcepole AG) – Switzerland
  • Sandro Mani (Sourcepole AG) – Switzerland
  • Vincent Mora (Oslandia) – France
  • Nyall Dawson – Australia
But we should keep in mind all the testers and bug fixers around the world that help to develop QGIS to what it became today! Furthermore a thank you to the long list of sponsors.

A question on usage/ development

I am curious: How is QGIS used in the so called developing economies and “Newly Industrialized Countries”? Why is there no remarkable impact? I mean, there are loads of internet pages in Pakistan, India, Indonesia and China where you can talk about downloading and hacking products from Redland. But what about the usage of QGIS in those economies? Why is there only few development support from there? I am looking forward your comment below.

The post Attention: QGIS 2.10 is coming! appeared first on Digital Geography.

Show your Photos in QGIS and ArcGIS: a small example

$
0
0
Hi guys. Once again I found an interesting question in our Geoscientists group on facebook. One user wanted to show her photos in QGIS as she is it used from Google Maps: See a point, click on it and see the great image you’ve taken on your journey. Unfortunately the most obvious plugins failed to do it in QGIS. So check out our “at least” two usage scenarios for QGIS and ArcGIS where we will handle geotagged photos…

Geo-Tagged Photos

So first let’s start with so-coalled geo-tagged photos where the location of your photo is stored in the photo itself. In the following examples I am using photos from my Iphone which where geo-tagged as I’ve taken them near Stuttgart at the INTERGEO 2015: Click to view slideshow. So we will start with the easy task: creating this map with clickable photos using geo-tagged ones. [Spoiler-alert: non-geotagged will be presented in a follow up!)

ArcGIS

ArcGIS has a great script for dealing with this task. It is called GeoTagged Photos To Points and is found in the Data Management Tools in the -you name it- Photo folder. It works quite easy: select the folder of your photos, better leave the output as default as the photos are stored in the default DB as attachments and after a short time of geoprocessing you have a valid point shapefile with the attributes of the photos like path and time:

QGIS

images as mouse over in QGIS

images as mouse over in QGIS

The same procedure is a bit more complicated in QGIS (tried in version 2.10.1) as there seems to be no standard support for adding your geotagged photos to your QGIS project. So let’s check the possibilities. My search in the plugin-tool in QGIS revealed the following suitable plugins:
  • Geotag and import photos (needs exiftools installed :-( )
  • photo2kmz
  • Photo2Shape (needs exiftools installed :-( )
  • ???
One might say: “Com’on install exiftools and you’ll be fine”. But let’s be honest: This might be the right choose for a off-the-top user but most of the GIS-users are happy with an easy to use, not install any dependency solution. So I’ll follow the path with photo2kmz which is easy to use and creates a kmz on one hand and an easy txt file with coordinates and pathes to the images.  In the following video I demonstrate not only the import of these images as point shapefile but also two ways of showing images in QGIS interactively. One is using the “Action” commando and the other will show images when you just hover the mouse over one feature using the Map Tips tool in QGIS:

The post Show your Photos in QGIS and ArcGIS: a small example appeared first on Digital Geography.

The QGIS survey needs input!

$
0
0

The free and open source gis QGIS started an user survey on its online webpage. The project needs your input to get the best necessary community information for prioritising future adjustments and developments.




I use Qgis nearly every day and it’s astonishing how active the qgis community is. Short release cycles and a broad world of plugins makes qgis really interesting for many companies and students worldwide.

See what the QGIS survey asks and which top answers are.

As a QGIS user, I consider myself a…

Regular user 48.7 %

I use QGIS

Several times a week 38.7 %

How well does QGIS meet your needs as a general purpose GIS?

QGIS allows me to carry out most of my critical tasks, occasionally I need to use other software 65.2 %

What domain / industry do you work in?

private consulting company 34.5 %

Approximately how many people in your organisation use QGIS?

several answers

Which version of QGIS do you most regularly use?

NON LTR release 40.1 %

Which version of QGIS do you recommend to other users?

Current release 46.8 %

I currently use this QGIS version for my production work

QGIS 2.10 52.5 %

How often do you think LTR QGIS versions should be made?

Every year 58.5 %

How long do you think LTR (Long Term Release) versions of QGIS should be supported for?

2 years 40.3 %

How often do you think non LTR releases of QGIS should be made?

Every 4 months (current system) 41.1 %

How often do you use the QGIS documentation?

Occasionally 59.2 %

How frequently do you think documentation should be updated?

Rolling updates – documentation should be required to accompany all new features 42.8 %

When I get stuck using QGIS, I….

ask on stackoverflow 26.9 %

In terms of software development with QGIS, I…

Occasionally write python scripts and expressions 82.5 %

Take part in the user survey.

Here you get to the current answer statistics. In the following I’ll show you some stats from today in detail.

Current survey report.

Current survey report.

The post The QGIS survey needs input! appeared first on Digital Geography.

Short Announcement: my top 5 features of QGIS 2.12

$
0
0
QGIS is under steady development and with the new release QGIS 2.12 we get some interesting and also visible changes in QGIS. What are the best improvements? Check them out here and decide whether to update or not. First of all: Be aware! Despite the long list of new features, this QGIS version is not a LTS version (But 2.14.1 will be 😉). So if you rely on your everyday work/setup you should probably stick with QGIS 2.8 and try this version on your personal pc or inside a virtual machine.

Top 5 QGIS Improvements

Of course every user has his/her unique usage scenario for a software. When it comes to me I am using QGIS more or less always in a PyQGIS-way and with a look into web-map creation. So the following list is biased but here is my top 5:

Open scripts in external editor

I always hated to copy-paste my code between sublime and the in-line editor in the python interface. And somehow I often ended in messed up code due to tab-blank problems… Now you can open a py-script which was saved already in your standard editor and it will be reloaded in the python-script editor after editing in the editor of your choice. NICE!!! It will improve my rapid prototyping a lot!

Export thumbnails from style manager

As I started to develop qgis2leaf I was frustrated in getting the same symbols as I have used in QGIS. With the new option (which is “hidden” and needs a short-cut in the “Style” tab of the vector layer properties…) you can easily export symbols from QGIS as svg or png. So you can design your symbol in QGIS and use it in your webmapping application without asking yourself whether you need inkscape to create an identical looking svg to those used in QGIS 😉
symbol saved qgis

save a symbol used in qgis

This will increase the styling with qgis2web and the possibilities to create exact online copies of what you’ve did offline.

Rule-based labeling

This might be a bit special for most of you, but with the newest release you will get improved labelling:
rule based labels

Rule based labels. Great!

Simple define your rules in an easy interface and apply different styles for different types of features driven by attributes… Easy as one-two-three!
rule_based2

rule editor

Digitising improvements

Ever wanted to digitize arcs in QGIS? With QGIS 2.12 you can do so! One limitation: You need to say goodbye to *.shp as this new feature called “digitize arcs/curves” is supported by only a few formats like GML, PostGIS or WFS. Unfortunately GeoJSON can’t work with it… But nevertheless it looks damn sexy:
curves in QGIS

digitizing curves in QGIS

What else?

Another great enhancement for the everyday user in QGIS is probably the “recent projects” overview in QGIS after you opened it. It provides an easy way to choose the desired project as it shows a snapshot of the project, the used name, projection and location on your hard drive.
recent projects in QGIS

Recent projects short-cut in QGIS


What is really annoying is the new custom certificate dialog that pops up at first usage. You can ignore it but for the unknowing users this looks quite disturbing…:
ssl authentication

SSL and authentication “error”

Your turn?

What are your favourite features of this QGIS release? What do you want to have in QGIS 2.14.1, the next LTR? Just comment!

The post Short Announcement: my top 5 features of QGIS 2.12 appeared first on Digital Geography.

Viewing all 87 articles
Browse latest View live