Converting point data layer to raster data layer (QGIS - on mac)

3,038 views
Skip to first unread message

tiffan...@gmail.com

unread,
Sep 30, 2016, 3:43:28 PM9/30/16
to GIS In Ecology Forum
Hello,

I hope someone can help me with this issue I have while working on the workbook 7 for QGIS on a macbook.

I am on exercise 2 and have already added a new field for PRESENCE on the attribute table. However moving on, I am unable to choose PRESENCE for the attribute field on the RASTERIZE menu. I've got back and forth but the dropbox still gives me either latitude or longitude.

Any advice? 


GIS in Ecology

unread,
Sep 30, 2016, 3:55:06 PM9/30/16
to GIS In Ecology Forum
Hi Tiffany,

Thanks for the post. There are two possible reasons for this. The first is that when you created the PRESENCE field, you made it as a text field and not an integer field. However, I'm presuming that this is not what is going on here (but it is always worth checking).

The second is do to with the version of QGIS that you are using. The instructions in Workbook 7 are written for QGIS 2.6, and while they work with some versions of QGIS 2.8, they don't always work with some of the newer versions. This is because the later versions of QGIS have an issue where they don't recognise some integer fields as numbers (and so they won't appear in dropdown menus that require numbers, such as the attribute field in the tool you are trying to use).

Can you check the exact version of QGIS you are using and let me know, and I can see what I can suggest for getting this sorted.

All the best,

Colin

tiffan...@gmail.com

unread,
Oct 3, 2016, 5:42:04 PM10/3/16
to GIS In Ecology Forum
Hi Colin,

Thank you so much for your reply. 

I just tried to redo the step of adding a new field to the attribute table of the data layer and left the Length as 1 (the book says WIDTH enter the number 10, however there was no WIDTH option in the add new field box). I proceeded on to transform the point data layer into the same projection/coordinate system as the data fame and then converted in to a raster data layer. The presence option was then available to select in the drop down. 

I'm not sure the difference between length and width for attribute table but hope that won't cause a problem later? 

My QGIS version is 2.16.2 (for mac).

Regards,
Tiffany

GIS in Ecology

unread,
Oct 3, 2016, 5:53:50 PM10/3/16
to GIS In Ecology Forum
Hi Tiffany,

Thanks for the reply. It looks like when they have updated QGIS to a newer version, they've changed the name of the characteristic that describes how many characters can go into a new field from WIDTH to LENGTH (there is a tendency for this to happen with QGIS), which is why I generally recommend using the exact version described in the book for doing the exercises. This is easy to do for QGIS for windows, but more difficult for Mac users as older versions are not archived in the same way. If you have successfully made the raster data layer, what you've done shouldn't cause you any problems layer.

Anyway, your solution has solved the problem you ran into, which is good, but if you run into any more problems with the exercises in the book, it might be worth considering installing an older version of QGIS to complete them. At the moment, the version I'm recommending for people to learn on is QGIS 2.8 as it is a very good stable version. You should be able to download this from the QGIS website, but if you can't (they might have updated their Long Term Release in the last few weeks), let me know and I can email you a link where you can download this exact version.

I hope this helps, and hopefully you won't run into too many more problems.

All the best,

Colin

tiffan...@gmail.com

unread,
Oct 5, 2016, 6:48:42 AM10/5/16
to GIS In Ecology Forum
Hi Colin,

I would like to install the stable version of QGIS that you were mentioning and do the exercises all over. The one I'm using right now seems to be a bit cranky.. It went into reboot and my settings for the interface went back to default and some stuff are missing.

I tried looking on the QGIS website for the download but I think they only have the current version. 

Please do let me know where I can download it, thank you.

Regards,
Tiffany

tiffan...@gmail.com

unread,
Oct 5, 2016, 6:48:42 AM10/5/16
to GIS In Ecology Forum
Hi Colin,

Thank you for your advice. I will continue with the exercises and see how I go.. Hoping to create maps for my dissertation soon :) 

Best wishes,
Tiffany

GIS in Ecology

unread,
Oct 5, 2016, 7:32:57 AM10/5/16
to GIS In Ecology Forum
Hi Tiffany,

The latest versions of QGIS do tend to be a bit cranky (a very good way to describe it!). 

I've uploaded a compressed file to the GIS In Ecology server which has the MAC OS version of QGIS 2.8.4 in it, and I've added a specific download link it to the download section of the GIS For Biologists homepage (http://www.gisinecology.com/GFB.htm#1 - this is for a different book, but it will work for you too). If you follow the new instructions and links on this page, you should be able to download and install it without too many problems. This version is much more stable and will match up much better with the instructions provided in Supplementary Workbook Seven. There will still be a few little differences here and there (since the book was written for QGIS 2.6), but these should be very minor and easy to work around. 

If you get stuck with downloading or installing this version, post back on this thread, and if you run into any further problems, feel free to post again on this forum.

Good luck with creating the maps for your dissertation.

All the best,

Colin  


On Wednesday, October 5, 2016 at 11:48:42 AM UTC+1, tiffan...@gmail.com wrote:
Hi Colin,

tiffan...@gmail.com

unread,
Oct 14, 2016, 5:33:44 AM10/14/16
to GIS In Ecology Forum
Hi Colin,

Thank you for the link to QGIS 2.8.4. All has been well and I not only completed your exercises, I managed to do up my own basic map with data points :) 

My next step is to achieve a table that shows depth, slope, aspect and possibly distance to seamount of every data point. The last exercise in the QGIS workbook shows how to create raster data layers of environmental variables and at the end, the contents of the attribute table had all the values for each point. I feel like this is what I should be doing but I'm unsure. 

Currently, I only have my data points with coordinates and elevation (which are in positive values but do come out as contour lines in the ocean).

Hoping you can point me to the right direction please, thank you. 

Regards,
Tiffany

GIS in Ecology

unread,
Oct 14, 2016, 5:52:17 AM10/14/16
to GIS In Ecology Forum
Hi Tiffany,

Glad that the link for QGIS 2.8.4 worked for you and that you've been getting on fine with the exercises from the book, and your own maps.

>>My next step is to achieve a table that shows depth, slope, aspect and possibly distance to seamount of every data point. The last exercise in the QGIS workbook shows how to create raster data layers of environmental variables and at the end, the contents of the attribute table had all the values for each point. I feel like this is what I should be doing but I'm unsure. 

You should be able to follow the instructions from the book for creating raster data layers of depth slope and aspect (since you have a shapefile of depth contour lines). Since your depth values are positive, the best thing to do is to turn them into negative values before you start processing them. To do this, open the attribute table for your contour line shapefile, and then use the field calculator tool to create a new field with negative values in it (this is done by selecting the field with the depth values in it, and then putting a negative sign before it in the Expression box). 

In terms of the distance to the seamount, you'd first need to have a shapefile of some description for the location of your seamount, and then you can proceed in the same way as is done for Distance To Coast in exercise 5 in the book.

Once you have done this, you can plot your data points based on their coordinates (as per exercise 1 in the book), and then extract the values from the raster data layers as outlined in the final step of exercise 5.

I hope this helps, and if you get stuck with any of it, just post back on this thread.

All the best,

Colin

tiffan...@gmail.com

unread,
Oct 17, 2016, 11:44:34 AM10/17/16
to GIS In Ecology Forum
Hi Colin,

I managed to use GEBCO's file for bathymetry and got through the steps to achieve depth, slope and aspect for each of my data points. I reprojected my GEBCO file to Selected CRS (EPSG:3395, WGS 84 / World Mercator) and then did the terrain analyses for slope and aspect. However, my slope are all near vertical? The min is 88.7388 and max is 89.9088? 

My values for depth are definitely negative now (taken from GEBCO) so I can't seem to figure out why my slope is giving such values. 

Thank you for your time!

Regards,
Tiffany

GIS in Ecology

unread,
Oct 17, 2016, 12:16:48 PM10/17/16
to GIS In Ecology Forum
Hi Tiffany,

The issue here isn't with your depth values, but rather with the projection you are using for your project. You're using a geographic projection, meaning that the map units (those used to calculate distances and so the angle of slope) are in decimal degrees and not in a real world unit like metres. Unfortunately, the Slope tool assumes that you are using a projection that uses metres for its map units, so it tries to do the calculation, it comes out with near-vertical angles (because it's assuming that one decimal degree is one metre).

The solution here is to use a different, and more suitable projection for your project, and one that uses metres as its map units. I would recommend either a suitable UTM for which ever part of the world you are working in, or creating a custom transverse mercator projection for your study area (there should be instructions in Supplementary Workbook Seven on how to do this in QGIS). Either way, once you have your depth data and your project in a suitable projection, you'll find that the Slope tool will give much more appropriate values for slope.

I hope this helps, and if you get stuck with anything else, just post back on this thread.

All the best,

Colin

Tiffany Goh

unread,
Nov 22, 2016, 6:38:42 AM11/22/16
to gis-in-eco...@googlegroups.com
Hi Colin,

I am currently trying to calculate distance to slope for my data points. Could you kindly guide me on how to do this? Is it possible to input my own slope value?

Thank you.

Regards,
Tiffany
--
-- ======================================================================
You received this message because you are subscribed to the "GIS In Ecology Forum" discussion group (http://www.gisinecology.com/GIS_in_Ecology_forum.htm).
 
To control how often you get emails from this group, go to http://groups.google.com/group/gis-in-ecology-forum/subscribe (you will need to log on to get to this page).
 
To post to this group, either log onto the group's home page or send an email to
gis-in-eco...@googlegroups.com.
 
The rules for posting to this group can be found here: http://groups.google.com/group/gis-in-ecology-forum/browse_thread/thread/df31a0822742203f#.
 
To unsubscribe from this group, email:
gis-in-ecology-f...@googlegroups.com
 
All information on this forum is provided on an 'as is' basis. GIS In Ecology is not responsible for checking the accuracy or suitability of any posting or response.
======================================================================
---
You received this message because you are subscribed to a topic in the Google Groups "GIS In Ecology Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gis-in-ecology-forum/BD0qd-eTjFA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gis-in-ecology-f...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

GIS in Ecology

unread,
Nov 23, 2016, 5:55:13 AM11/23/16
to GIS In Ecology Forum
Hi Tiffany,

It's not quite clear what you are wanting to do here. Are you wanting to calculate the distance to the nearest location with a specific slope value? Or are you wanting to calculate the distance to a physical area of slope (such as the continental shelf edge or slope? Both can be done, but the procedures are quite different, so just post back clarification and I can suggest how best to proceed.

All the best,

Colin
Tiffany
 
The rules for posting to this group can be found here: http://groups.google.com/group/gis-in-ecology-forum/browse_thread/thread/df31a0822742203f#.
 
To unsubscribe from this group, email:

 
All information on this forum is provided on an 'as is' basis. GIS In Ecology is not responsible for checking the accuracy or suitability of any posting or response.
======================================================================
---
You received this message because you are subscribed to a topic in the Google Groups "GIS In Ecology Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gis-in-ecology-forum/BD0qd-eTjFA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gis-in-ecology-forum+unsub...@googlegroups.com.

Tiffany Goh

unread,
Nov 23, 2016, 9:25:50 AM11/23/16
to gis-in-eco...@googlegroups.com
Hi Colin,

Sorry for the confusion. I would like to calculate the distance of each data point to the nearest location of a specific slope value. 

Thank you.

Tiffany
 
The rules for posting to this group can be found here: http://groups.google.com/group/gis-in-ecology-forum/browse_thread/thread/df31a0822742203f#.
 
To unsubscribe from this group, email:

 
All information on this forum is provided on an 'as is' basis. GIS In Ecology is not responsible for checking the accuracy or suitability of any posting or response.
======================================================================
---
You received this message because you are subscribed to a topic in the Google Groups "GIS In Ecology Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gis-in-ecology-forum/BD0qd-eTjFA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gis-in-ecology-f...@googlegroups.com.

GIS in Ecology

unread,
Nov 23, 2016, 9:36:53 AM11/23/16
to GIS In Ecology Forum
Hi Tiffany,

Thanks for the clarification. Given what you'd like to do, the workflow is as follows:

1. Convert your slope raster into a point data layer using the R.To.VECT tool (PROCESSING TOOLBOX> GRASS COMMANDS> RASTER> R.TO.VECT).

2. Open the attribute table of the point data layer created in step one, and then use the SELECT BY EXPRESSION option to select points with the slope values that you wish to calculate the distance to. 

3. Right click on the point data layer in the TABLE OF CONTENTS window and select SAVE AS. Make sure you select the option to only save the selected points.

4. Finally, use the NEAREST NEIGHBOUR JOIN plug in to calculate the distances between your data points and the nearest point with the slope values you are interested in (if this isn't already activated in QGIS, then click on PLUGINS on the main menu bar and select MANAGE AND INSTALL PLUGINS, and search for NEAREST NEIGHBOUR JOIN - also called NNJOIN).

If you wish to work out the distances to nearest values of a different slope value, then just repeat steps 2 to 4.

I hope this helps, and any problems in implementing this work flow, just post back on this thread.

All the best,

Colin

On Wednesday, November 23, 2016 at 2:25:50 PM UTC, Tiffany Goh wrote:
Hi Colin,

Tiffany Goh

unread,
Nov 25, 2016, 6:05:44 AM11/25/16
to gis-in-eco...@googlegroups.com
Hi Colin,

Thank you so much for your guidance. I am currently stuck at step 1. I am converting the slope raster file that I got from DEM and is taking very long. I had to force quit QGIS.. 
Do you know another way for me to convert the file to point data layer? 

I’ll give it another go and see.

Cheers,
Tiffany
On 23 Nov 2016, at 2:36 PM, GIS in Ecology <cdma...@GISinEcology.com> wrote:

Hi Tiffany,

Thanks for the clarification. Given what you'd like to do, the workflow is as follows:

1. Convert your slope raster into a point data layer using the R.To.VECT tool (PROCESSING TOOLBOX> GRASS COMMANDS> RASTER> R.TO.VECT).

2. Open the attribute table of the point data layer created in step one, and then use the SELECT BY EXPRESSION option to select points with the slope values that you wish to calculate the distance to. 

3. Right click on the point data layer in the TABLE OF CONTENTS window and select SAVE AS. Make sure you select the option to only save the selected points.

4. Finally, use the NEAREST NEIGHBOUR JOIN plug in to calculate the distances between your data points and the nearest point with the slope values you are interested in (if this isn't already activated in QGIS, then click on PLUGINS on the main menu bar and select MANAGE AND INSTALL PLUGINS, and search for NEAREST NEIGHBOUR JOIN - also called NNJOIN).

If you wish to work out the distances to nearest values of a different slope value, then just repeat steps 2 to 4.

I hope this helps, and any problems in implementing this work flow, just post back on this thread.

All the best,

Colin

On Wednesday, November 23, 2016 at 2:25:50 PM UTC, Tiffany Goh wrote:
Hi Colin,

Sorry for the confusion. I would like to calculate the distance of each data point to the nearest location of a specific slope value. 

Thank you.

Tiffany
On 23 Nov 2016, at 10:54 AM, GIS in Ecology <cdma...@GISinEcology.com> wrote:

Hi Tiffany,

It's not quite clear what you are wanting to do here. Are you wanting to calculate the distance to the nearest location with a specific slope value? Or are you wanting to calculate the distance to a physical area of slope (such as the continental shelf edge or slope? Both can be done, but the procedures are quite different, so just post back clarification and I can suggest how best to proceed.

All the best,

Colin




tiffan...@gmail.com

unread,
Nov 25, 2016, 6:05:44 AM11/25/16
to GIS In Ecology Forum
Hi Colin,

Previously I said that it took really long to to R.TO.VECT. Even after clipping, it still took really long. 
I managed to get a point data layer and managed your steps. I'm just wondering if this is okay to do compared to R.TO.VECT? I'm not sure if the values make sense as I have slope values with a lot of decimal places and I can't just put one specific value. 

What I did was specify a range of <0.5 for slope. The distances generated showed this,

Loudness of sperm whale SLOPE (at data point) Nearest slope Distance to nearest slope
0 0.27084 0.27084 535.2178216
0 0.14496 0.14496 166.7682733
1 0.73306 0.47249 897.3079653

I would think that the distance would be 0 if the data point is already at a slope that is less than 0.5? If you get what I mean.. 

Any thoughts on where I went wrong? I will try to see if I can round up the slope values and see if specifying a whole number as a slope would generated distances that make sense. 

Regards,
Tiffany

GIS in Ecology

unread,
Nov 25, 2016, 7:01:59 AM11/25/16
to GIS In Ecology Forum
Hi Tiffany,

The method you've found to generate a point data layer of your slope values will result in a point data layer that should be identical to one you get using the R.TO.VECT tool.

The slope values generated when you create a slope raster data layer will typically have lots of decimal places as they will aim to calculate slope as precisely as possible. The selection you have currently run will select all the slope values below a certain threshold. However, if you want to select all the slope values within a specific band (e.g. 0.5 to 1 degree), then you would run a selection with the expression: Slope >0.5 AND Slope <1 (you can find the options for AND under  OPERATORS in the FUNCTIONS list of the SELECT BY EXPRESSION window).

In terms of the values that you're getting, these look like they could be correct. You're very unlikely to get a 0 value for a point that falls within a cell of a specific slope value. This is because you are converting your slope values to a point that is placed at the centre of each grid cell. Unless your point also plots exactly at this central point, then you're not going to get a zero distance to the nearest point. You can identify which cells fall within a grid cell of the selected values by extracting the actual slope values (as you have done), and then creating a new field where you subtract the slope value for the grid cell a point falls in from the nearest slope value within a specific range. Any values with zero in this field will fall within a grid cell with the specified range, any other values will indicate that if falls in a non-selected grid cell.

If you wish to extract distances based on grid cells rather than based on Euclidean distances to the grid cell centre, then you can try the following work flow:

1. Convert your slope values into points (using either the R.TO.VECT. tool, or the method you mentioned below).
2. Select the points with your required slope ranges using the SELECT BY EXPRESSION tool.
3. Create a new point data layer based on the selected points using the SAVE AS tool.
4. Convert your selected points into a raster data layer using the RASTERIZE (VECTOR TO RASTER) tool (RASTER> CONVERSION> RASTERIZE).
5. Use the R.GROW.DISTANCE tool (PROCESSING TOOLBOX> GRASS COMMANDS>RASTER> R.GROW.DISTANCE) to generate a raster data layer of Euclidean distances to the grid cells with the required slope values.
6. Use the POINT SAMPLING TOOL to extract the grid cell distances to the point locations. This will give you zero values for any points that fall within a grid cell of a specified value, and will give you distances based on the centre of each grid cell to the nearest one within the specified range. Note, however, that this will give you binned distances values, with bins based on the grid cell size of your slope raster data layer, rather than a continuous set of distances. This may have implications for how you use these data in statistical analyses.

I hope this helps.

All the best,

Colin

Tiffany Goh

unread,
Nov 25, 2016, 4:03:47 PM11/25/16
to gis-in-eco...@googlegroups.com
Hi Colin,

Thank you so much for your help. I’ve really learnt a lot :) 
I think having the Euclidean distances to the grid cell centre should be sufficient for my analyses. 

Best wishes,
Tiffany
Reply all
Reply to author
Forward
0 new messages