Time series animations using QGIS

For the past couple of months, I am working with vegetation indices (NDVI and EVI) time series data. Today, I decided to visualize some of the EVI data as an animation.

QGIS has an excellent plugin know as “TimeManager“. You can install “TimeManager” by selecting Plugins-> Manage and Install Plugins from QGIS menu. Search TimeManager in plugin window (like below)

Screenshot from 2015-12-17 15:22:50

After installation, you have to activate TimeManager plugin by clicking on it. A window (like below) will appear at the bottom of monitor screen.

Screenshot from 2015-12-17 15:21:24

Assuming that you have loaded and styled all the layers that will be used in animation, click the “setting” button on the TimeManager’s window. A new window will appear like the one below

Screenshot from 2015-12-17 16:05:45

Now add the layer, start and end time. In my case, I used “Add raster” option to add EVI layers, each layer had one second of visibility during animation. Following is an image of how my setting window looked like.

Screenshot from 2015-12-17 15:21:54

Finally, press “Export Video” button, a new window will appear like the one below.

Screenshot from 2015-12-17 15:22:14

Select the output folder and click on “Animation gif” radio button. If required, modify the “Animation frame Delay”, for my dataset, 100 millisec was too low thus I changed it to 1000 millisec.

The processing might take from few seconds to few minutes, in my case it two around 4 to 5 minutes (result below)

animation3

Some very good examples of TimeManager plugin are available on youtube, like the one below

and also this one.

Advertisements

Share spatial data on web.

A lot of data produced in analysis is still being shown as pictures with almost zero interactivity. Wouldn’t it be nice to visualize (if not shared) data on an interactive detailed background base map. I think it would be but then the complexities of setting up a web GIS application scares people. Well, now a days there are many ways one can share spatial data using web GIS platforms without going into the complexities of installation/configuration. Following are some candidates for data sharing.

MapBox

Uploading and creating maps is very easy.

Features in free packages includes

  • views per month  = 50,000
  • cloud stroage  = 100MB

Once done, one can share maps through a URL or embed map object onto a web page, provided that <iframe> element is allowed, on wordpress it is not  :). Results are good (see below)Once

mapbox

Mapbox has tool for cartographic operations know as Mapbox Studio.

Mapbox also has an option for students know as Mapbox Eduction. Its a good resource to learn about web GIS.

CartoDB

Is an open source platform for hosting spatial data on cloud. It has advance options, for example

  • Many layers to select from which will be part of map.
  • Data can be uploaded from file, Google Drive, Dropbox and twitter.
  • Styling layer is very easy

Features in free packages includes

  • No limit on views
  • cloud stroage  = 50MB
  • If your data is from online resource e.g. URL, Google Drive or DropBox, updates to your data updates your maps (in real time)
  • Customizeable CSS 

Github

But if you want quick/simple way then gist is the simplest (except no rasters). You need to register with github, once done login and click on gist option. Just drag drop your geojson file and that is it.

Now share your map’s URL or you can embed your map in web page like I did (below).

Note:

There are options like mangomap (https://mangomap.com/plans) etc. but they do not have a free package thus I skipped these products. However, there are some spatial data portal like Landscape portal (http://landscapeportal.org/) that allow free data upload. Landscape portal is a geonode implementation with customization.

Web GIS application development step by step Part 3

I promised that I will publish 4 to 5 tutorials in this series and I will, however there was a bit of gap between this and the last post 😦 but here I am keeping my promise, beware this part is a big one.

This tutorial is divided into three parts, in first part, I will discuss OpenLayers, second part, GeoServer, and finally in the last part, I will show an example. But before I can start, I want to bring your attention to another excellent blog post at mangomap.com, its title is “5 things GIS professional need to know about web“. Good to know these things no matter at what level you are.

Now the above tips covered, lets discuss Client-Server architecture because web GIS is based on this architecture. In Client-Serve architecture, a software at server side waits for clients to make requests and returns specific information based on request for example like a web site. Thats it for now, you can read more about it here.

Lets move to OpenLayers. What is OpenLayers and Why I am interested in it, in fact I recommended it to many of my colleges in the past few years. OpenLayers is a JavaScript API that lets you show your maps on the web. It is the most essential part of client side when it comes to web GIS. One must know few things about web GIS to know the working the of OpenLayers.

In web GIS, we need a software (on server side) to read our data (software has to understand the source format of data in order to read), render it in memory (unless raw data is required at client side) and then pass it on to us over the internet. Now, if our data is in shape file format or it is in GeoTif format, it should not be passed due to the client side limitations e.g. shape file is not a web GIS format (plus it will actually be raw data) and GeoTiff could take a lot of time due to size. Thus, this software should send the rendered images in the form of internet friendly formats and we know that there are two image formats which are perfect for internet i.e. JPEG and PNG. Thus, this software should render our data in JPEG/PNG format and pass it on to us over the internet. Ideally, this software should know what area of map we are looking at to render it and send it back to us to avoid rendering all the map, plus this way the size of the image will be small. Thus, when ever we pan or zoom, a new image should be generated and passed on to us. Such a software is called GIS Server and the mapping service is called Web Map Serivce (WMS, read more about it on OGC). Don’t worry, I am not going to ask you to write GIS Server (and implement WMS) because it already exists, in fact we have a lot of good GIS Servers available for example GeoServer, MapServer, Mapnik, QGIS Server and ESRI GIS Server is also in the list (but its not free).

There is a problem over here (I hope you have noticed), what if the JPEG/PNG size is big, it will also take some time to download from server. Well, its true and I have covered it in one of my earlier post,  its better if you have a look at it now. In Summery, a GIS Server does the following (these are the high lights remember)

  • Reads the source data
  • Renders it according to the users viewing bounding box. The rendering is performed based on the styling information provided (default or custom)
  • perform tiling
  • send back the data

In this series, I will only work with GeoServer. Now, I am not going to teach you how to install GeoServer, read part 1 (link ) of this series for “how to install and configure development environment”. However, I just want to past below a paragraph I wrote in first part (I liked it :)).

“Finally it is time to install the most important component of Web GIS application i.e. GIS Server. It is important to know what a GIS Server Is? It is a software that listens for specific request (by clients). These requests could be for different services  (read OGC specification on GIS server for details) e.g. getMap request etc. A GIS server loads a dataset (e.g. a shape file or a Geo-Tiff) renders it, cut image into tiles and sends it back to the requesting client. Every time a client pans or zooms, GIS server receives requests and sends image tiles as response. Format of image tiles is specifically selected due to its size. In Free and Open Source Software for Geo  (FOSS4Geo) there are multiple choices for GIS Servers e.g. MapServer, GeoServer, mapnik. qGIS server, MapGuide etc. Some are written in C and some are in Java.”

OpenLayers, as mapping API (remember it is for client side), requests map (actually JPEG/PNG tiles) from GIS Server and when GIS Server (like GeoServer) returns OpenLayers shows them in a mapping area (basically in a HTML Div element). When ever we pan or zoom in/out, OpenLayers send a new bounding box to GIS Server requesting for a new tiles.

Why I have selected GeoServer, because of its admintration application. The last time I worked with MapServer was in 2010 and the experience was painful. I have not seen a decent administration application for MapServer but GeoServer has address this issue excellently. Plus the GeoWebCache is also integrated into the GeoServer and can be accessed through admin application (I will talk about it at the end of this tutorial).

Data prepartion 
We will be needing a shape file for out test application. Make sure 
that your shape file is in spherical Mercator projection because we 
will be overlaying it on OSM base map which is in spherical Mercator.

Enough of the explaining, If you have installed GeoServer, stat it by using the following command

 sudo ./startup.sh

The startup.sh script is in /your_path/geoserver_version_number/bin folder (see the GeoServer Section for details in part 1 of this tutorial series). Let GeoServer load properly and then open your web browser and type http://localhost:8080/geoserver and login with default user name “admin” and “geoserver” as password, you should be seeing a web page like the one below

admin_panelGeoServer has excellent user manual, read it (it will help a lot). Read more about the admin panel at here. In this part, I will focus on WMS. See the video below on how to create a WMS (just the first 15 minutes are enough for this part of the tutorial)

or see Lession 4 of Pennsylvania State University “Open Web Mapping” course (its good).

Summery is

  • Create a workspace (not necessarily every time)
  • Create a datastore (every time because this is where you are linking you data (shape file, geoTif, database etc) to GeoServer
  • Create layer (for each dataset, styles etc)

By using the above resources, I hope you have created/published a layer (have EPSG:3857) by now. Lets see how it looks, in GeoServer menu, click “Layer Preview”, this page has all the layers arranged in five columns (type, Name, Title, Comman Formats and All Formats).Search your layers through the list and click on OpenLayers (forth column i.e. Common Formats) link (in the same line). A new web page will open with an interface similar to the one below (but with your dataset of course ;))

layer_preview

What you are looking at is a web GIS application (Yes it is, simple and small but “A web GIS application”). It has controls (or components) like Map, zoom/ pand , mouse control and few more. All these controls are provided by OpenLayers API. But wait! We haven’t installed OpenLayers, when was it installed. When you installed GeoServer, the installation has its own web server and OpenLayers, thus, it is using these two to show preview pages (see I told you, GeoServer has it all).

Now lets look at the code behind this layer preview page, right click on the page (the one showing your layer), and click “view page source”. WOW, HTML+JavaScript, its 400 lines of code. But we are only interested in the section where our layer is being added to the map (it is at line 145). Search your layer’s name in the code, it should look some thing like the code below

// setup tiled layer
     tiled = new OpenLayers.Layer.WMS(
                    "cite:Africa_boundaries_3857 - Tiled", "http://localhost:8080/geoserver/cite/wms",
     {
        LAYERS: 'cite:Africa_boundaries_3857',
        STYLES: '',
        format: format,
        tiled: true,
        tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom
      },
      {
        buffer: 0,
        displayOutsideMaxExtent: true,
        isBaseLayer: true,
        yx : {'EPSG:3857' : false}
       } 
   );

The first line is creating an object tiled (just a variable name) of WMS class (of parent class Layer), the constructor for WMS class takes layer’s title, URL , name, format, isBaseLayer, transparent etc as arguments (don’t worry with time and a lot of reading you will understand all of it ;)).

Now we will use the same code above, to add this layer to our previously created web application (remember we created a web application in part 2). Lets look at the init() function again

<script type="text/javascript">
 
 function init()
 {

    var map, layer;

    // connect OLs map object with DIV map
    map = new OpenLayers.Map('map');

    // create a layer object
    layer = new OpenLayers.Layer.O SM( "Simple OSM Map");

    // add layer object to map object
    map.addLayer(layer);

    // Zoom to level 2 and set 0,0 as map center
    map.setCenter(new OpenLayers.LonLat(0 ,0),2);
}
</script>

The init function

  1. Creats a map object and assigns it to the web page’s map DIV
  2. Creats a layer object and attaches it to the map object
  3. Sets map center and zoom level

We need to add our layer’s code  below the OSM layer and add it on to the map but first we need to make two changes to our code.

  1. Instead of format variable , use ‘image/png’
  2. isBaseLayer:true , change it to false

Finally add the layer’s code to init()  function like I have done below


 function init()
 {

    var map, layer;

    // connect OLs map object with DIV map
    map = new OpenLayers.Map('map');

    // create a layer object
    layer = new OpenLayers.Layer.OSM( "Simple OSM Map");

    // add layer object to map object
    map.addLayer(layer);

     // setup tiled layer
    var tiled = new OpenLayers.Layer.WMS(
                    "cite:Africa_boundaries_3857 - Tiled", "http://localhost:8080/geoserver/cite/wms",
     {
            LAYERS: 'cite:Africa_boundaries_3857',
            STYLES: '',
            format: 'image/png',
            tiled: true,
            transparent: true,
            //tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom
      },
      {
           buffer: 0,
           displayOutsideMaxExtent: true,
           isBaseLayer: false,
           //yx : {'EPSG:3857' : false}
       } 
   );

   // add new layer object to map object
   map.addLayer(tiled);

  // Zoom to level 2 and set 0,0 as map center 
  map.setCenter(new OpenLayers.LonLat(0 ,0),2); 

}

I have also added “tiled” layer to map object (fourth line from bottom). Now save code and open http://localhost/myapp/myapp.html in any web browser (as discussed in part 2) and when I did, I got the following output.

part3_final_map

In next part, I will discuss more about GeoServer and layer styles.

See you next time.

OSGeo Live on virtual box

Osgeolive_wordle

For those of you who still wants to keep windows as their main operating system but wants to try the goodies of Free and Open Source software for Geo (FOSS4Geo), OSGeo has many options like live DVD and virtual box VMs. All you have to do is to install Virtual Box and download OSGeo virtual machine (plus 7zip for extracting zipped file). Follow the instruction below

http://live.osgeo.org/en/quickstart/virtualization_quickstart.html

Download will take time as it is around 3GB (I downlaoded vdkm), extratct using the following command (if you are on windows, use 7zip GUI)

7z x software-backup/osgeo-live-vm-8.0.7z

When you will run command sudo apt-get update, password is require and it is “user” (on desktop, there is a file named passwords.txt, contains all the passwords e.g. OS-user ‘user’ has password ‘user’)

One more thing, to set screen to a reasonable size, at the end of OSGeo blog there are some commands, if they do not work (like in my case) go to  start -> System Tools -> Synaptic Package Manager and install the following packages (read my old blog about it Resize virtual machine’s desktop in VirtualBox)

apt-get install virtualbox-guest-dkms
virtualbox-guest-utils
virtualbox-guest-x11

The first package will install second package as dependencies however you have to install third package. If successful with installation, you should see a desktop like below

OSGeoLive

What it contains

  1. Libraries with paths configured (this is what you need the most e.g. gdal)
  2. Programming languages like python (with packages installed)
  3. QGIS, GRASS GIS, gvSIG, OpenJump, SAGA GIS and uDig
  4. R Statistics
  5. and many more 🙂

Trust me, for new users, the first two are very important as they reduce complexities and frustration (a big thanks to OSGeo of course ).