How to round pixel values of a raster in QGIS?

I have a raster with float number values for example: 2.544459104537964 and I want to round these up to integers. I have seen other posts on ArcGIS like this one but when I use Raster Calculator in QGIS,Int(myraster + 0.5)only makes the first value (which is 0) to 0,5 and the last one (which is 100) to 100,5. The other pixels stay float.

This is a bit of a hack but it works: The QGIS raster calculator does not support rounding as far as I know but you can use GDAL to performfloattointtype conversions.

1. Raster -> Conversion -> Translate

• change the datatype from float to int by using the-otoption

• gdal_translate -of GTiff -ot Int32 E:/float.tif E:/int.tif

How to round pixel values of a raster in QGIS? - Geographic Information Systems

QGIS raster functionality has come a long way and continues to improve. During my spare time, I am always on the lookout for interesting questions posed on https://gis.stackexchange.com.

I recently came across https://gis.stackexchange.com/questions/52353/calculating-area-of-rasters-in-qgis where a user asked how to calculate the area of each class in a raster.

The suggested solution involved a three-step approach:

• Recode the raster to simplify the raster classes.
• Vectorize the raster layer.
• Calculation of the statistics from the vector layer either by using SQL (Virtual layers) or native QGIS algorithms.

Although the suggested solution was accepted as an answer it presents a couple of challenges

• It would require a user to pre-process the raster by using the raster calculator, reclassify algorithms from processing, or the r.recode command to allow zonal statistics.
• Vectorization is a CPU intensive process. If the raster layer is very big and the computer resources are low the process could take a very long time to complete.
• The statistics produced cannot be incorporated as part of the raster legend.

I wanted a PyQGIS solution that could also generate the summary statistics as part of the classification legend.

The solution I ended up using involved PyQGIS, python GDAL, and Numpy.

The image below depicts the elevation raster prior to classification

The image below depicts the elevation of the raster post-classification.

The image below depicts the render type applied to the elevation raster.

Procedure

• Open the script from a text editor and change the raster path from https://gist.github.com/NyakudyaA/b4640ec9d2b5f43fa456083b61cfd12f#file-raster_classifier-py-L190 to specify your own single-band raster i.e you can use the SRTM Downloader plugin in QGIS to download a DEM.
• Navigate to QGIS and open the python console.
• Run the script and your raster is then loaded into QGIS.

A summary of the script is provided below

The script will emulate how a user would symbolise a single band raster using the GUI in QGIS.

Spatial Resolution

A raster consists of a series of pixels, each with the same dimensions and shape. In the case of rasters derived from airborne sensors, each pixel represents an area of space on the Earth's surface. The size of the area on the surface that each pixel covers is known as the spatial resolution of the image. For instance, an image that has a 1 m spatial resolution means that each pixel in the image represents a 1 m x 1 m area.

The spatial resolution of a raster refers the size of each cell in meters. This size in turn relates to the area on the ground that the pixel represents. Source: National Ecological Observatory Network (NEON) A raster at the same extent with more pixels will have a higher resolution (it looks more "crisp"). A raster that is stretched over the same extent with fewer pixels will look more blury and will be of lower resolution. Source: National Ecological Observatory Network (NEON)

Mdhntd

Would Buddhists help non-Buddhists continuing their attachments?

Why did Jon Snow admit his fault in S08E06?

On San Andreas Speedruns, why do players blow up the Picador in the mission Ryder?

Who knighted this Game of Thrones character?

Heat lost in ideal capacitor charging

A burglar's sunglasses, a lady's odyssey

Can you still travel to America on the ESTA waiver program if you have been to Iran in transit?

What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?

How can I properly write this equation in Latex?

Burned out due to current job, Can I take a week of vacation between jobs?

Why isn't Tyrion mentioned in the in-universe book "A Song of Ice and Fire"?

Can we assume that a hash function with high collision resistance also means highly uniform distribution?

Interpretation of ROC AUC score

What did the 'turbo' button actually do?

Final exams: What is the most common protocol for scheduling?

Why did other houses not demand this?

Why does the hash of infinity have the digits of π?

Possibility of faking someone's public key

One word for 'the thing that attracts me'?

How to determine if a hyphen (-) exists inside a column

How to rasterize a river vector file and merge it to another raster layer?

Rasterize Point layer Error: Wrong value for -outsize parameterHow to rasterize a vector map?Rasterize shapefile using another raster's size and resolutionRasterize vector while adjusting extent and resolution to reference raster?How to merge (transfer) one layer into another PostGIS layer?How to crop a river from a raster layer?Rasterize (Vector to raster) ERROR 6how to put/reposition a vector layer on top of another vector layerRasterizing vector shapefiles using multiple burn in valuesRasterize (vector to raster) QGIS 3.4Error in Raster/Merge tool

I got a river vector file.
I want to rasterize it so that the river is 2 pixels wide.
How do I achieve that in QGIS 3.2.3?

When I try to use vector to raster, I get this and no file is created:

You need to select a different outsize parameter, units and width are set up as 0

– Roberto Zeeland
Sep 21 '18 at 8:25

It didn't help. All I get is empty folder.

Initially you got the error ERROR 1: Wrong value for -outsize parameter. Do you get the same error again? If that's the case have a look here as it might be describing the same error you are getting.

– Roberto Zeeland
Sep 21 '18 at 8:44

I don't get it, I either got nothing or black square. "OUTPUT' : 'C:/Users/vvaris/Desktop/asd.tif', 'UNITS' : 0, 'WIDTH' : 2 " UNITS is still zero for some reason.

It created a "rasterised" layer, under it there reads Min: 1.79769e+308 Max -1.79769e+308. How do I check if my shapefile is projected?

I got a river vector file.
I want to rasterize it so that the river is 2 pixels wide.
How do I achieve that in QGIS 3.2.3?

When I try to use vector to raster, I get this and no file is created:

You need to select a different outsize parameter, units and width are set up as 0

– Roberto Zeeland
Sep 21 '18 at 8:25

It didn't help. All I get is empty folder.

Initially you got the error ERROR 1: Wrong value for -outsize parameter. Do you get the same error again? If that's the case have a look here as it might be describing the same error you are getting.

– Roberto Zeeland
Sep 21 '18 at 8:44

I don't get it, I either got nothing or black square. "OUTPUT' : 'C:/Users/vvaris/Desktop/asd.tif', 'UNITS' : 0, 'WIDTH' : 2 " UNITS is still zero for some reason.

It created a "rasterised" layer, under it there reads Min: 1.79769e+308 Max -1.79769e+308. How do I check if my shapefile is projected?

I got a river vector file.
I want to rasterize it so that the river is 2 pixels wide.
How do I achieve that in QGIS 3.2.3?

When I try to use vector to raster, I get this and no file is created:

I got a river vector file.
I want to rasterize it so that the river is 2 pixels wide.
How do I achieve that in QGIS 3.2.3?

When I try to use vector to raster, I get this and no file is created:

You need to select a different outsize parameter, units and width are set up as 0

– Roberto Zeeland
Sep 21 '18 at 8:25

It didn't help. All I get is empty folder.

Initially you got the error ERROR 1: Wrong value for -outsize parameter. Do you get the same error again? If that's the case have a look here as it might be describing the same error you are getting.

– Roberto Zeeland
Sep 21 '18 at 8:44

I don't get it, I either got nothing or black square. "OUTPUT' : 'C:/Users/vvaris/Desktop/asd.tif', 'UNITS' : 0, 'WIDTH' : 2 " UNITS is still zero for some reason.

It created a "rasterised" layer, under it there reads Min: 1.79769e+308 Max -1.79769e+308. How do I check if my shapefile is projected?

You need to select a different outsize parameter, units and width are set up as 0

– Roberto Zeeland
Sep 21 '18 at 8:25

It didn't help. All I get is empty folder.

Initially you got the error ERROR 1: Wrong value for -outsize parameter. Do you get the same error again? If that's the case have a look here as it might be describing the same error you are getting.

– Roberto Zeeland
Sep 21 '18 at 8:44

I don't get it, I either got nothing or black square. "OUTPUT' : 'C:/Users/vvaris/Desktop/asd.tif', 'UNITS' : 0, 'WIDTH' : 2 " UNITS is still zero for some reason.

It created a "rasterised" layer, under it there reads Min: 1.79769e+308 Max -1.79769e+308. How do I check if my shapefile is projected?

You need to select a different outsize parameter, units and width are set up as 0

– Roberto Zeeland
Sep 21 '18 at 8:25

You need to select a different outsize parameter, units and width are set up as 0

– Roberto Zeeland
Sep 21 '18 at 8:25

It didn't help. All I get is empty folder.

It didn't help. All I get is empty folder.

Initially you got the error ERROR 1: Wrong value for -outsize parameter. Do you get the same error again? If that's the case have a look here as it might be describing the same error you are getting.

– Roberto Zeeland
Sep 21 '18 at 8:44

Initially you got the error ERROR 1: Wrong value for -outsize parameter. Do you get the same error again? If that's the case have a look here as it might be describing the same error you are getting.

– Roberto Zeeland
Sep 21 '18 at 8:44

I don't get it, I either got nothing or black square. "OUTPUT' : 'C:/Users/vvaris/Desktop/asd.tif', 'UNITS' : 0, 'WIDTH' : 2 " UNITS is still zero for some reason.

I don't get it, I either got nothing or black square. "OUTPUT' : 'C:/Users/vvaris/Desktop/asd.tif', 'UNITS' : 0, 'WIDTH' : 2 " UNITS is still zero for some reason.

It created a "rasterised" layer, under it there reads Min: 1.79769e+308 Max -1.79769e+308. How do I check if my shapefile is projected?

It created a "rasterised" layer, under it there reads Min: 1.79769e+308 Max -1.79769e+308. How do I check if my shapefile is projected?

Zoran Čučković

Important: This tutorial was made for QGIS 2, which is deprecated. For a tutorial made for QGIS 3, please go to https://landscapearchaeology.org/2020/viewshed-tutorial/.

I’ve had a remark recently that some kind of tutorial would be welcome for the visibility plugin. So here it goes…

The data which will be used can be downloaded from the plugin’s GitHub repo (link below). It comprises a DEM extracted from publicly available SRTM data (90 m resolution) and two sets of points (let’s call them A and B) which mostly correspond to archaeological sites I’m working on. The area in question is Istria (Croatia and Slovenia) and the projection is MGI Balkans 5 (EPSG : 31275).

A most basic use for the visibility analysis would be exploratory: would someone be able to see point B from point A? Such a query can be made by any viewshed algorithm available - but what about many observers from a number of points? In fact, when studying ancient landscapes we are often interested not only of what people could see, but also whether visibility influenced their preference for particular locations. For instance, is visibility a factor in the choice of settlement location?

For the purpose of this exercise, we would like to know whether sites A betray a preference for areas providing good visibility to sites B.

First step, obviously, we need to load the data in QGIS (any set of two shapefiles with points and one elevation model in raster format would do – provided coordinate reference systems match).

We can imagine two approaches to the problem: either we calculate visibility from A sites and test whether B sites tend to gather in their field of view or we calculate visibility areas from B sites and check whether A sites show a preference for good visibility zones. Let’s try the second approach.

We need, then, to calculate all visibility areas from B sites and add them up. The result would be a cumulative visibility map, i.e. each point on a map will show how many observers could see it. Now, there is a problem of mutual intervisibility: usually we test visibility from some arbitrary eye-height towards bare ground. It wouldn’t have much sense to switch these two – looking from ground level to a possibly non-existent target – which means we need to take care of target and observer heights. In our case, we are not interested in what could be seen from sites B, but rather whether these sites could be seen from anywhere around and whether locations with good visual connections were preferred. We need to reverse the parameters: switch observer (now with 0 height) with target (now with observer height).

Finally, our dataset may have some inaccuracies and our points may fall behind the relief: for instance, a data point placed on a slope instead of the top of a hill. We can then force our points to climb to a higher point (adapt to the highest point), let’s say in a radius of one pixel (DEM used is coarse, a larger radius would risk our points drifting too far away).

The maximum visibility distance is set to 5000 metres. I would rather not discuss this parameter here (what people could see or would prefer to see, how large was the object observed etc.).

The result is a cumulative viewshed, here visualised as a heatmap (black points are our A sites).

Now there are some sophisticated statistical analyses devised for our case (in particular the one by Wheatly [1995] developed for intervisibility analysis). But let’s keep this tutorial non-academic. As a first step we can simply check whether cumulative visibility values under points tend to be above average.

There are many ways to extract raster values at specified points, I’m using here the Point sampling plugin (reference below). Now we need to find out an average value: go to Vector > Analysis Tools > Basic statistics.

And then we check the raster average value which is normally visible in the metadata section of layer properties:

So, the average for the analysed area is just above one B site visible, while our A sites boast average visibility of close to four B sites. Now, this analysis is problematic because we didn’t take into account the fact that there is a large potion of the sea in the map - and many other “details” that I did not mention - but we do have our first visibility analysis!

Sources and bibliography

Point sampling plugin : see in QGIS repository or check dedicated QGIS tutorial

Wheatley D (1995) Cumulative viewshed analysis: a GIS-based method for investigating intervisibility, and its archaeological application. In: Lock GR, Stančič Z, editors. Archaeology And Geographic Information Systems: A European Perspective. London: Taylor and Francis. pp. 171–186. [see online]

Presentation Transcript

Introduction to Quantum GIS • http://www.qgis.org • http://www.osgeo.org

Agenda • Overview of GIS • Introduction to Quantum GIS • Vector Data • Raster Data • Plugins • Fields and Attribution • Creating Data • Map Layout

1. Overview of GIS • Geographic Information System • Wikipedia definition - is a system designed to capture, store, manipulate, analyze, manage, and present all types of geographically referenced data. • It is used in many applications: Small municipalities, forestry, military, commercial businesses, etc., etc., • What do you do with it?

GIS • Easily measure distances • Easily measure areas • Find overlap between features • Proximity • Everything is related by location.

USGS Earthquake Zones http://earthquake.usgs.gov/

Outputs from a GIS • Maps • Printed • Digital (PDF, JPEG • Spreadsheets • Databases • Files • Shapefiles • KML

2. Introduction to Quantum GIS • Open Source – It comes with the right to download, run, copy, alter, and redistribute the software. • With source code users have the option • Suggest improvements • Make improvements themselves • Hire a professional to make the changes • Save software from abandonment

QGIS • The QGIS project began in February, 2002 • One developer • The first release was in July of that year • The first version supported only PostGIS and had no map navigation tools or layer control

Installing Quantum • http://www.qgis.org • I am going to stick with Windows and Linux Installs. There is an OSX install but I have not had that pleasure. • Linux – depending on your distribution of choice you'll have a Debian or RPM install. • Most systems with a large user base have a GIS repository • Ubuntu, Debian, Fedora

Windows • Windows Installer Method • Windows • Standalone Installer (recommended for new users) • Installs Quantum (Currently 1.7.4) • Also installs Current Release of Grass • Also installs python 2.7 that runs inside of QGIS • Updates uninstall and reinstall the software and save your settings. Must be done manually

Windows Installer cont' • Standalone Method • Geographic Abstraction Library • Installs libraries for SID and ECW • SID and ECW are proprietary formats that have special agreements to be used with GDAL • http://www.gdal.org/

OSGEO Install • OSGeo provides an installer that provides everything. • Runs in a “cygwin” type environment • Cygwin provides unix commands and environments on windows machines. • Provides a means to an easy(ier) upgrade path between releases. • Isn't “installed” on your computer.

OSGEO Installer Cont' • Quantum GIS • GDAL • GRASS • OpenEV • And UDIG (a great data viewer).

Staus Bar • Projection of the QGIS project • Scale • Coordinates

Basic Buttons • Hover mouse over them they will pop up a text message telling the user their purpose. • Pan • Zoom in • Zoom out • Pixel Resolution • Zoom to Extent • Zoom to Selection • Zoom to layer • Zoom to Last Extent • Zoom to Previous Extent • Refresh • Add vector Layer • Add Raster Layer • PostGIS Layer • Spatialite Layer • WMS Layer • New Shapefile Layer • Remove Layer • Oracle Raster Layer • WFS Layer

Attribution • Identify • Select • Deselect • Attribute Table • Measure • Maptips • Add Bookmark • Show Bookmark • Annotation

Saving a Project • As you are working with QGIS periodically save your datasets. • QGIS creates a .gqs file • XML based • Can be edited in your favorite text editor.

Exercises • Open QGIS • Explore the Toolbars. • Add some data to the Map Display • Use the Identify Features tool to show attribute to some data layers.

3. Adding Vector Data • Supports OGR vector Formats • Shapefiles • KML • CSV • Microstation • MapINFO

Properties • Once Data is added – Right Click and Select Properties • There are different Tabs to help with Vector Data • Style, Label, Fields, General, Metadata, Action Joins, Digrams, Overlay • Style sets the symbology of the Layer. • Symbology can be saved as a qml file

Styles • Set by Fields • Symbolized • Single • Categorized • Graduated • Graduated • Equal Interval, Quantile, Natural Breaks, Standard Deviation, Pretty Breaks

Equal Interval • Equal Interval groups values into equal sized ranges.

Quantile • Each class contains an equal number of features

Natural Breaks • Natural Breaks classes are based on natural groupings of the data.

Standard Deviation • Show Variation from the average value

Pretty Breaks • Data symbolized for non-statisticians

Selecting Vector Data • Selections can be manual

Selecting Vector Data • Selections can be by Attributes (Chapter 5) • Selections can also be by location (Under Vector Menu - Research)

Exercises • Change the symbology of displayed data • Label features • Add an item and categorize data by that item.

4. Adding Raster Data • Supports OGR Raster Formats • Geotiff • ESRi Grid • Jpeg • Sid • Read and not write the format • ECW • Support must be added • Included with standalone installer

Geospatial Data Abstraction Library • Approximately 128 Formats supported • http://www.gdal.org • Many command line tools • Convert • Reproject • Warp • Mosaic

WMS – WFS Standards • Web mapping service - The OpenGIS Web Map Service Interface Standard (WMS) provides a simple HTTP interface for requesting geo-registered map images from one or more distributed geospatial databases. • Web Feature Service - Web Feature Service Interface Standard (WFS) provides an interface allowing requests for geographical features across the web using platform-independent calls

WMS Example • http://isse.cr.usgs.gov/ArcGIS/services/Combined/SDDS_Imagery/MapServer/WMSServer

Exercises • Add raster data • Symbolize Raster Data • Create a Hillshaded DEM

5. Plugins • QGIS has a standard list of things that it does • Buffers • Projections • Clips • Unions • There are some things that users want it to do that it doesn't.

Satellite-based tree cover mapping for forest conservation in the drylands of Sub Saharan Africa (SSA): Application to Burkina Faso gazetted forests

While monitoring the effectiveness of forest conservation programs requires accurate data on (changes in) forest cover, many countries still lack the ability to map local forest inventory, especially in the drylands of Africa where forest areas are very sparsely covered. In this paper, we present a high resolution tree cover estimation of twelve gazetted forests in Burkina Faso using Random Forest-based supervised classification and Sentinel-2 satellite imagery sensed between March and April 2016. The methodology relies on ground truth sample points labeled manually over 10-m resolution images displaying a composite of near infrared (NIR), red and green bands extracted from Sentinel-2 multi-spectral satellite data to estimate tree cover with an average balanced accuracy rate of 80 percent. The output is a collection of rasters with binary values representing the combination of 10, and down-sampled 20 and 60-m bands indicating an estimate of the existence of trees or lack thereof, usable as a baseline for deforestation monitoring.

Presentation Transcript

Introduction to Quantum GIS • http://www.qgis.org • http://www.osgeo.org

Agenda • Overview of GIS • Introduction to Quantum GIS • Vector Data • Raster Data • Plugins • Fields and Attribution • Creating Data • Map Layout

1. Overview of GIS • Geographic Information System • Wikipedia definition - it is a system designed to capture, store, manipulate, analyze, manage, and present all types of geographically referenced data. • It is used in many applications: Small municipalities, forestry, military, commercial businesses, etc., etc., • What do you do with it?

GIS • Easily measure distances • Easily measure areas • Find overlap between features • Proximity • Everything is related by location. • Tobler's Law

USGS Earthquake Zones http://earthquake.usgs.gov

Outputs from a GIS • Maps • Printed • Digital (PDF, JPEG • Spreadsheets • Databases • Files • Shapefiles • KML

2. Introduction to Quantum GIS • Open Source – It comes with the right to download, run, copy, alter, and redistribute the software. • With source code users have the option • Suggest improvements • Make improvements themselves • Hire a professional to make the changes • Save software from abandonment

Common OS Licensing • Licenses to run in both open and proprietary systems • Apache Software License • BSD (Berkeley Software Distribution) • MIT (Massachusetts Institute of Technology) • License to run in open environments • GPL (General Public License) • LPGL (Lesser General Public License) • MPL (Mozilla Public License)

QGIS • The QGIS project began in February, 2002 • Produced by a Development team • Gary Sherman, Founder • The first release was in July of that year • The first version supported only PostGIS and had no map navigation tools or layer control.

Installing Quantum • http://www.qgis.org • I am going to stick with Windows and Linux Installs. • OSX - http://www.kyngchaos.com/software/qgis • Linux – depending on your distribution of choice you'll have a Debian or RPM install. • Most systems with a large user base have a GIS repository • Ubuntu, Debian, Fedora

Windows • Windows Installer Method • Standalone Installer (recommended for new users) • Installs Quantum (Currently 1.8) • Also installs Current Release of GRASS • Also installs python 2.7 that runs inside of QGIS • Updates uninstall and reinstall the software and save your settings. Must be done manually

Windows Installer cont' • Standalone Method • Geographic Data Abstraction Library • Installs libraries for SID and ECW • SID and ECW are proprietary formats that have special agreements to be used with GDAL • http://www.gdal.org/

OSGEO Install • OSGeo provides an installer that provides everything. • Runs in a “cygwin” type environment • Cygwin provides unix commands and environments on windows machines. • Provides a means to an easy(ier) upgrade path between releases. • Isn't “installed” on your computer.

OSGEO Installer Cont' • Quantum GIS • GDAL • GRASS • OpenEV • And UDIG (a great data viewer).

Status Bar • Projection of the QGIS project • Scale • Coordinates

Basic Buttons • Pan • Zoom In • Zoom Out • Pixel Resolution • Zoom to Extent • Zoom to Selection • Zoom to Layer • Zoom to Last Extent • Zoom to Previous Extent • Refresh • Add vector Layer • Add Raster Layer • PostGIS Layer • Spatialite Layer • WMS Layer • New Shapefile Layer • Remove Layer • Oracle Raster Layer • WFS Layer • Hover mouse over them they will pop up a text message telling the user their purpose.

Attribution, Selection, Measurements • Add BookMark • Show Bookmark • Annotation • Identify • Select • Deselect • Attribute Table • Measure • Maptips

Saving a Project • As you are working with QGIS periodically save your datasets. • QGIS creates a .gqs file • XML based • Can be edited in your favorite text editor.

Exercises • Open QGIS • Explore the Toolbars. • Add some data to the Map Display • Use the Identify Features tool to show attribute to some data layers.

Exercise 2 The Exercises are going to be an actual project completed by North River Geographic Systems, Inc in 2009. We are going to cover the Conasauga River Watershed. The watershed is located on the border of Tennessee and Georgia. The data is made up of ESRI Shapefiles. That is the easiest data format to work with for these exercises. 1. If you haven't already, open QGIS. There should be an icon on your desktop or on your start menu (or both). Once QGIS has opened right click with your mouse in the toolbar area. How Many Toolbars are in the Default Installation How many Panels are in the default Installation? Turn off your Managed Layers toolbar. Turn Off your Map Navigation Toolbar. They have disappeared from the interface. Now turn them back on. If you want you can move them from their default location by grabbing the left corner of the toolbar and moving it.

2. Turn your Layers Panel off. Now turn it on by navigating from the View Menu at the top of QGIS 3. Click your Add Vector Data button at the top. Browse to your data folder located under c:gisdataQGIStrainingdata . Add the CountyBoundaries.shp shapefile to your map. If you do not see any data please be sure to check that you are adding shapefiles.

4. Click your add vector data button at the top and add the subbasin.shp file. You should have something that looks like: 5. Using your identify features tool list all the counties in Georgia and the Counties in Tennessee. In order to identify a feature you must have that layer selected in your layer window. Georgia Tennessee

8. Click on the Subbasin shapefile in your Layers Panel and zoom to the extent of that layer. Note you have several ways to make a selection. 9. Select Whitfield County. Zoom to the extent of the selection. 10. Clear the selection. 11. Save your project in the Exercise 2 Directory! 6. Add the 2010 Urban Areas Shapefile. What is the biggest Urban Area within the CountyBoundaries Shapefile? What are the three biggest Urban Areas that touch/are within the Watershed? 7. Using your navigation tools Zoom to the full extent of all the data layers. You should see something similiar to the graphic below.

3. Adding Vector Data • Supports OGR vector Formats • Shapefiles • KML • CSV • Microstation • MapINFO

Properties • Once Data is added – Right Click and Select Properties • There are different Tabs to help with Vector Data • Style, Label, Fields, General, Metadata, Action Joins, Digrams, Overlay • Style sets the symbology of the Layer. • Symbology can be saved as a qml file

Styles • Set by Fields • Symbolized • Single • Categorized • Graduated • Graduated • Equal Interval, Quantile, Natural Breaks, Standard Deviation, Pretty Breaks

Equal Interval • Equal Interval groups values into equal sized ranges.

Quantile • Each class contains an equal number of features

Natural Breaks • Natural Breaks classes are based on natural groupings of the data.

Standard Deviation • Show Variation from the average value

Pretty Breaks • Data symbolized for non-statisticians

Selecting Vector Data • Selections can be manual

Selecting Vector Data • Selections can be by Attributes • Selections can also be by location (Under Vector Menu - Research)

Exercises • Change the symbology of displayed data • Label features • Add a layer and categorize data by that item.

2. How many main watersheds are located in the Conasauga Watershed. ___________________ BONUS: Why is the Coahulla (pronounced Koa-hull-ahhhh) split into a north and south section? You might need to add more shapefiles to answer this. 3. Label the Watersheds by name on the map display. Rick click on the shapefile layer and select properties. Select the labeling tab. Check "Display Labels". Under Basic Label Options pick Hu_10_Name Exercise Ch 3 It's time to start looking at your data and working with it.. Most of the data you will be working with was downloaded from the Census Bureau, the National Hydro Dataset, and the USDA DataGateway. Some of these datasets were built by me during the course of the CRA project. 1. Add the Watershed.shp file to the Map Display.

5. Change the style of the data layer. Make the polygon fill clear and the outline color orange. 4. Right click on the watershed shapefile and go to properties. Look at the Style tab

5. Change the style of the data layer. Make the polygon fill clear and the outline color orange. 4. Right click on the watershed shapefile and go to properties. Look at the Style tab

6. Save the Style. Right click on the watershed shapefile and click Save Style. Save the file as a .qml file. 7. Once you have saved it remove the watershed shapefile by right clicking on it and selecting remove. Add it again. Right click and select Load Style. Load the qml file you just saved. All of your original settings for this layer have been restored.

• Projection is UTM, zone 18, datum is WGS84, ellipsoid is WGS84.
• The data is in meters.
• The data comes from the eastern US seaboard.
• The EPSG system is a database of CRS information maintained by the International Association of Oil and Gas Producers. The dataset contains both CRS definitions and information on how to safely convert data from one CRS to another. Using EPSG is easy as every CRS has a integer identifier, e.g. WGS84 is EPSG:4326. The downside is that you can only use the CRSs EPSG defines and cannot customise them. Detailed information on the structure of the EPSG dataset is available on their website.

• The OGC WKT standard is used by a number of important geospatial apps and software libraries. WKT is a nested list of geodetic parameters. The structure of the information is defined on their website. WKT is valuable in that the CRS information is more transparent than in EPSG, but can be more difficult to read and compare than PROJ. Additionally, the WKT standard is implemented inconsistently across various software platforms, and the spec itself has some known issues).

Simple representation of spatial data¶

The basic data types in R are numbers, characters, logical (TRUE or FALSE) and factor values. Values of a single type can be combined in vectors and matrices, and variables of multiple types can be combined into a data.frame. We can represent (only very) basic spatial data with these data types. Let’s say we have the location (represented by longitude and latitude) of ten weather stations (named A to J) and their annual precipitation.

In the example below we make a very simple map. Note that a map is special type of plot (like a scatter plot, barplot, etc.). A map is a plot of geospatial data that also has labels and other graphical objects such as a scale bar or legend. The spatial data itself should not be referred to as a map.

A map of point locations is not that different from a basic x-y scatter plot. Here I make a plot (a map in this case) that shows the location of the weather stations, and the size of the dots is proportional to the amount of precipitation. The point size is set with argument cex .

Note that the data are represented by “longitude, latitude”, in that order, do not use “latitude, longitude” because on most maps latitude (North/South) is used for the vertical axis and longitude (East/West) for the horizontal axis. This is important to keep in mind, as it is a very common source of mistakes!

We can add multiple sets of points to the plot, and even draw lines and polygons:

The above illustrates how numeric vectors representing locations can be used to draw simple maps. It also shows how points can (and typically are) represented by pairs of numbers. A line and a polygon can be represented by a number of these points. Polygons need to “closed”, that is, the first point must coincide with the last point, but the polygon function took care of that for us.

There are cases where a simple approach like this may suffice and you may come across this in older R code or packages. Likewise, raster data could be represented by a matrix or higher-order array. Particularly when only dealing with point data such an approach may be practical. For example, a spatial data set representing points and attributes could be made by combining geometry and attributes in a single ’data.frame`.

However, wst is a data.frame and R does not automatically understand the special meaning of the first two columns, or to what coordinate reference system it refers (longitude/latitude, or perhaps UTM zone 17S, or ….?).

Moreover, it is non-trivial to do some basic spatial operations. For example, the blue polygon drawn on the map above might represent a state, and a next question might be which of the 10 stations fall within that polygon. And how about any other operation on spatial data, including reading from and writing data to files? To facilitate such operation a number of R packages have been developed that define new spatial data types that can be used for this type of specialized operations.

The foundational packages in R that define such spatial data structures are sp , sf , and raster .

We use the terra package. It is a replacement for the raster package (it is faster and easier to use).