Wind Vector Mapping and Animation in QGIS

This posting is on how to map wind vector (i.e. speed/magnitude and direction) and create an animation using QGIS. This is written for my friend, Jim at PacIOOS. Check them out for some awesome oceanographic data that are open and very accessible. I used their GeoServer services all the time for my tutorials.

What you’ll need if you want to follow along with this short tutorial.

Requirements:

  • QGIS software installed - (I’m using version 3.14 on Windows OS)

  • Wind data in netCDF format - you can download the sample below or use your own

  • Crayfish plugin for QGIS - if you want to do animation, otherwise it’s optional

For those who are not familiar with the netCDF format. It stands for network Common Data Form and is a file format for storing multi-dimensional scientific data,such as temperature, salinity, wind speed and direction. These data or variables can be mapped through time (a dimension) in GIS by making a layer from the netCDF file.

Download Wind Data

I am using the PacIOOS ERDAP (Environmental Research Division's Data Access Program) server to download my data. To download the exact data I used here, you can click the direct data download link below, or use your own data. The data set I’m using is the Regional Ocean Modeling System for the main Hawaiian Islands.

These are the parameters I used to query the data, which can be saved to a URL and shared for downloading: To use the same dataset for this tutorial, click this link: Direct Data Download.

Fig00001.png

Viewing netCDF data as a mesh

NetCDF data can be viewed in QGIS either as a raster or as a mesh. The mesh method is much more elegant and easy. Find more information about working with mesh data in the QGIS user manual.

Here’s how.

  1. Open up QGIS

  2. Browse to when you saved the netCDF data. Then either double click on the mesh data or drag and drop it into your TOC.

Fig0002A.png

3. Notice in the TOC to the left of the filename there’s a clock to indicated that the netCDF is a temporal dataset. There’s also a question mark - if you hover on it will say layer has no coordinate reference system set. Click on the question mark to bring up the CRS selector window, define the coordinate system as WGS 84.

Fig0003A.jpg

4. Open up the layer’s property window (right click layer name >> Properties). If you go to Source section to view information about available datasets in the netCDF

Fig0004A.png

5. Go to Symbology section, then click on the Setting tab and display the wind contour (raster) and vector. You’ll notice there are 3 layers (temperature, salinity, wind velocity) in the netCDF file. By default QGIS will display the first layer in the group. You can change these settings. Don’t forget to click Apply button to see your changes.

Fig0004B.png

6. Go to the Contour tab to change how you want to change the way the wind contour is displayed. Make your changes then click Apply to see your changes. I’m using the default settings with transparency of 50%.

Fig0004C.png

7. Go to the Vector tab (arrow) to change how you want the vector to display as either an arrow, streamlines or traces. Try instead of showing the arrows as a single color, try changing it to Color Ramp Shade. I’m using a default settings. Click Apply when done making your change.

Fig0004D.png

Note: if you do not see the vector arrows displayed on your map after making your changes here, go back to the Source section (#1 above) and select a time frame for the vector. Select none for the Scalar Dataset Group if you only want to view the vector on the map — see my display below.

Fig0004E.png

Feel free to explore the mesh rendering tab (regular square grid or triangular faces) and vertical layer stacking.

This is how my wind vector look likes. My display is showing only the vectors overlaid on top an ESRI bathymetry (ocean) basemap.

Fig0008.jpg

Animate vector using Crayfish plugin

If you want to animate your vector, you can do this using the Crayfish plugin. This plugin gives you more functionalities with mesh data. Here I’m using just to create an animation for my vector data. The video created will be in avi format.

  1. Install the Crayfish plugin. Go to the Plugin menu >> Manage and Install Plugins. In the Plugins window, search for Crayfish and install it.

  2. Once you have the plugin installed - you can access the tool in the Mesh menu >> Cray >> Export Animation. For other tools, you can access them in the Processing Toolbar panel

Fig0009.png

3. In the Export Animation window, enter the parameters you want. I’m using mostly the default settings. Don’t forget to select a Start Time and End Time. You have the option to save the images as well to create animated gif.

Fig0010.png

NOTE: if you get an error about FFmpeg is missing. You need to download FFmpeg and extract it to your computer then specify the path to FFmpeg.exe in the Export Animation window.

Fig0011.png
Fig0012.png

Here is my vector animation shown as a gif.

windvectorarrows_v1.gif

Converting raster wind vector to a point layer with u, v, speed and direction

So, what if you have raster(s) containing the u (eastward x-axis) and v (northward y-axis) components and you want to convert to a point layer (e.g. shapefile) and use arrows to show the wind speed and direction (wind vectors). This section will show you how to do that. But first, you’ll need to do some calculations. See this wind direction quick reference for calculating wind direction and speed and other tips. Also keep in mind that wind direction is described differently for oceanography and meteorology. Oceanographers describe the wind in the direction that it’s flowing towards and meteorologist describes wind in the direction that it’s flowing from.

Wind Speed (magnitude) = sqrt ( u * u + v * v )

Wind Direction = Atan2 (v, u) is the same as Atan2(y, x)

If you read the quick referenced guide linked above, there is tip on some software, especially spreadsheets using the Atan2 (x, y), where x and y are switched. QGIS uses the atan2(y, x), which return values in radians. To convert radians to degrees (symbol rotation), multiply it by 180/pi.

Oceanographic Convention: (180/3.14) * Atn2(v, u)

Meteorological Convention: (180/3.14) * Atn2(v, u)+180

  1. Instead of using the mesh version of the netCDF data, add the raster version of it into your map. When you double click on the netCDF raster, QGIS will ask you to select variables you want to view. Select the u and v components and add to your map

Fig014.png

2. Using the u raster grid, create a point

  • Go to the Processing Toolbar >> Vector Creation >> Raster Pixels to Points

  • In the Raster Pixels to Points window:

    • Select the u raster grid

    • Band 1 band/time frame combo

    • Field name: change to U (u values from the raster will be written out to this field)

    • Vector points: Save as a permanent layer (e.g. WindVectorPoints.shp)

    • Check the box, Open output file after running

    • Run the process

Fig0015.png

You should get a point layer that is the centroid of each raster cell of your grid.

Fig0016.png

3. Open up the attribute table of you point layer just created. You should see the U values from raster grid. Using the Raster Calculator add the v values from the v grid.

  • Toggle on table editing (pencil button)

  • Open Field Calculator

    • Check Create a new field

    • Output field name: V

    • Output field type: Decimal number

    • Output field length and Precision: 16 and 8

    • In the Expression text box: type in the following

      raster_value('NETCDF:"roms_hiig_e366_7434_fd44":v', 1, make_point($x, $y))

      The syntax: raster_value('raster', 1, make_point($x, $y)) where raster is the filename of your v raster grid

    • Click Run

Fig0017.png

4. Keep your attribute table open and calculate wind speed using the the field calculator. Remember speed = sqrt(uu + vv)

Fig0018.png

5. Calculate the wind direction using the formula given above. Don’t forget to convert radians to degrees

Fig0019.png

Save your table and don’t forget to toggle off editing. You point layer should now have values for u, v, speed, and direction.

Fig0020.png

Mapping the wind vector using the point layer

Now that you have all the information you can map the wind vector using the point layer you just created.

  1. Open the Properties window of your point layer. The following this guide below to display the points as arrows in the direction of the wind (rotated using the direction values)

    • Go to Symbology section

    • Change the Single symbology to Graduated style

    • Value: Select Speed

    • Click on the point Symbol

      • Click on Simple Marker

      • Symbol layer type: select Font maker

      • Choose an arrow character (must be point up or north)

      • For Rotation: click the custom variable button >> Field type >> Direction

      • Optional - change font symbol size if you want

      • Click OK to Symbol Settings

    • Back in the main symbology window, select a color ramp

    • Mode: Use Equal Interval

    • Click Classify (change the number of classes if you want)

    • Click Ok when done

Fig0022.png

Here’s what my point vector map looks like (zoomed in a bit to show the arrows and overlaid on to of ESRI basemap). Yours may look differently depending on how you choose to symbolize the point vectors.

Fig0023.jpg

Here’s a comparison of the point vector map and the mesh vector - the mesh version is much more refined and more efficient for mapping vectors. You can also view the mesh as a 3D map, but that’s for another time.

Point wind vector map (left) and mesh wind vector map (right).

Point wind vector map (left) and mesh wind vector map (right).

Hopefully, this tutorial provides a brief guide on how to map and animate wind vectors. There are lots of options for how you want to view wind vectors, so play around with the settings. Thanks for reading. Until my next post.

Exploring MapStore as an Opensource Web Mapping Framework

For the past weeks I have been exploring MapStore as a web mapping framework. MapStore is developed by GeoSolutions and is opensource so you can use it freely and modify as you wish. “MapStore is based on OpenLayers, Leaflet and ReactJS, and is licensed under the Simplified BSD license.”

I think MapStore has the potential to be a great alternative to ESRI for those looking for an opensource solution. Mapstore has 3 components (Web Maps, Dashboards, and Story maps) in a single framework. I'm thinking a setup with GeoServer/PosgreSQL/PostGIS combo (GIS server serving as data catalog), Apache/Tomcat (Webserver) plus Mapstore (front end web app) along with QIGS (desktop GIS) would make a decent opensource web GIS stack.

As far as I understand, the components of MapStore are modular (via plugins) and can be fully customized to users needs. If you are a developer then you can fully make this your own. If not, you can still use it by just making some configuration changes (with perhaps some help from your IT team to install with your own GeoServer setup). Or you can hire a developer or why not hire GeoSolutions, the developer of Mapstore - they provide commercial support for MapStore and GeoServer and will help you set up everything (I am not associated with GeoSolutions in anyway. I just like the work they're doing in the opensource realm).

Note, I am only exploring MapStore mainly as a user who want some easy configuration. This posting is my take on things, from set up on my local machine and changing some configuration settings.

Installation of MapStore

The installation process was easy enough. Instructions can be found on the Quick Start manual, so I won’t repeat it. On the MapStore documentation page are separate well documented User Guide and a Developer Guide. MapStore can be installed on a Windows or Linux system via the binary package or war package route. The easiest is to download and install via the binary package - this provides a contained sandbox with examples ready to be explored. I went the war installation route with Tomcat on my Windows system.

Configuring the MapStore User Interface

This is the default user interface of MapStore2. Obviously, I want to customize the look of this.

Mapstore defaut GUI

So to change the looks of the default interface, I need to make some minor changes to the configurations files - see the Developer Guide Configuration section. I’m only making some changes to the front end configuration files, mainly the following files:

localConfig.json: this is the configuration file where you can over ride the logo, customize the banner title, and remove the mailing list and footer. This is also where you can specify your data catalog(s) for the application. Because I don’t have current have a GeoServer to serve as a data catalog I included two public ones: Hawaii Statewide GIS Program’s ESRI Mapserver (WMS) and PacIOOS’s Geoserver (OWS).

new.json: this is the file where you can make changes to the default setting when creating a new map. For my configuration, I have set the map extent to show the Hawaiian Islands, change the CRS to EPSG 4326, zoom level, and added two new basemaps (Stamen terrain and ESRI Imagery).

data-en-US.json: this is the file where you can remove the “Fork me on Github” green banner and customize the subtitle in your banner (e.g. the HomeDescription text). This is the file for the English version of the application, but you can find other translation files in the Translations folder.

Configured MapStore Application

Below are some slides to show what my configured application looks like. If you’d like to explore MapStore without doing any installation, then check out the MapStore demo page.

My first impressions of and thoughts on MapStore is that it’s a very good tool that is very flexible. Used in conjunction with GeoServer, PostgreSQL/PostGIS, and QGIS - you could create a nice opensource GIS stack solution. I think it’s worth a look. There is a bit of a learning curve - at least for me since I’m not a developer - but still it was doable. The only thing I had a little trouble with was the dashboard component - I could not quite get the data layers (via a public GeoServer WFS) set up properly to make the dashboard widgets to function the way I want it to. But then again this could be how the public GeoServer WFS may have been set up in the first place since it’s not something I have control over. I might have more luck with setting up my own GeoServer. The MapStore framework has other functionalities that I haven’t explored, but overall I am impress with what MapStore has to offer.

I hope this post was useful for those looking for an opensource web GIS options. Thanks for reading. Until next time.