Lavorare con le Proiezioni¶
Le proiezioni delle mappe - o Coordinate Reference System (CRS) - spesso causano molta frustrazione quando si lavora con i dati GIS. Ma una corretta comprensione dei concetti e l’accesso agli strumenti giusti renderanno molto più semplice gestire le proiezioni. In questo tutorial, esploreremo il modo in cui funzionano le proiezioni in QGIS e scopriremo gli strumenti disponibili per vettori e raster, in particolare riprometteremo i dati vettoriali e raster, consentendo la (ri)proiezione al volo e assegnando la proiezione ai dati senza proiezione.
Il compito è ri-proiettare e sovrapporre assieme livelli di dati da differenti proiezioni in QGIS.
Altri aspetti che avremo modo di apprendere nel corso dell’esercizio¶
Utilizziamo i file
.tfwper georeferenziare i raster
Come salvare le caratteristiche selezionate da un livello in un nuovo livello.
Come visualizzare le informazioni sui metadati per i layer in QGIS.
Ottenere i dati necessari¶
Dovrai inserire i tuoi dati personali per poter scaricare l’insieme dei dati dell’Indagine sull’Ordnanza.
For convenience, you may directly download a copy of the dataset from the link below:
minisc_gb.zip (Contains only the files required for this tutorial)
Aprite QGIS e andate su.
Browse to the downloaded
ne_10m_admin_0_countries.zipfile and click Open.
At the bottom of QGIS window, you will notice the label Coordinate. As you move your cursor over the map, it will show you the X and Y coordinates at that location. At the bottom-right corner you will see EPSG:4326. This is the code for the current CRS (Projection) for the project.
As you will later see, the project’s CRS may not match the layer’s CRS. To determine a layer’s projection, we can look into the metadata. Right click on
ne_10m_admin_0_countrieslayer and select Properties.
Switch to the Metadata tab in the Layer Properties dialog. Expand the Properties section. At the bottom, you will see the definition for the projection under Layer Spatial Reference System. This definition is in the PROJ.4 format.
Now let’s see how we can change the layer’s projection. This operation is called Re-Projection. Rather than re-projecting the entire layer, we can also re-project some features from the layer. Use the Select features by area or single click tool and click on United States feature to select it.
ne_10m_admin_0_countrieslayer and select Save As.
In the Save vector layer as… dialog, name the output layer as
united_states.shp. Also check the Save only selected features box. This will ensure that only the selected feature gets re-projected and exported. Next, we choose the new projection for the layer. Click on the Select CRS button.
In the Coordinate Reference System Selector dialog, enter
north americain the Filter search box. Scroll through the results and select
North_America_Albers_Equal_Area_Conic (EPSG:102008)projection and click OK.
We choose Albers Equal Area Conic projection for this tutorial as it is a popular projection choice for thematic maps of the US. The choice of projection for your particular use-case will depend on a lot of factors. See this guide for a good overview of Projections.
You will see the new CRS selected in the Save vector layer as… dialog. Click OK.
Once the re-projected layer gets loaded, you will notice that the new
united_stateslayer overlays perfectly on top of
ne_10m_admin_0_countrieslayer - even though they are in different projections. This is because QGIS has a feature called On-the-fly CRS transformation. The projection text at the bottom-right of QGIS now has the words
OTFnext the EPSG:4326`. To learn more, let’s explore the CRS option in QGIS.
Adesso andate su
Switch to the CRS tab in the Options dialog. You will see that the default is Automatically enable “on the fly” reprojection if the layers have different CRS. This means that when QGIS detects that you have loaded layers with different CRS, it will automatically re-project them back to a common CRS so they line up with each other. Click OK.
Let’s turn-off the On-the-fly CRS transformation and see what happens. Click on the Current CRS text at the bottom-right corner.
In the Project Properties dialog, un-check the Enable “on the fly” CRS transformation box and click OK.
Back in the main QGIS window, you will see the nice World map disappear. This is because the Project CRS changed to
North_America_Albers_Equal_Area_Conicand the coordinates and scale are different now. Right-click the
united_stateslayer and select Zoom to Layer.
Now you will see the United States in the selected projection. Notice that the features from
ne_10m_admin_0_countriesdo not appear on the canvas as they are in a different coordinate space than the
united_stateslayer. Go back to the Project Properties dialog and turn-on the Enable “on the fly” CRS transformation option for the remainder of the tutorial.
Now let’s switch gears and add a raster layer to our project. Browse to the directory where you had extracted the
minisc_gb.zipfile. Locate the
RGB_TIF_COMPRESSEDfolder containing tif files. You will notice that the .tif image files are plain TIF files, not GeoTIFF files. That means they do not have any projection information. To use these images in a GIS, you need to georeference them. A georeference contains 2 types of information - image extents and projection. Typically, the extents are stored in a file known as World file and they have extensions like
.jgw. Most GIS software, including QGIS would be able to use information stored in the world files as long as they are stored in the same directory as the original image and has the same name. The
.tfwfiles for the MiniScale raster files are in a separate folder named
Go to the
.tfwfiles are plain text files. Open one of the
.tfwfiles in a text editor.
The world files contain 6 lines with some numbers. As explained below, each line signifies some information about the raster file. Knowing this format is useful because some data do not come with the world files and you may have to create these by hand using the supplied information.
Line 1: A: pixel size in the x-direction in map units/pixel Line 2: D: rotation about y-axis Line 3: B: rotation about x-axis Line 4: E: pixel size in the y-direction in map units Line 5: C: x-coordinate of the center of the upper left pixel Line 6: F: y-coordinate of the center of the upper left pixel
MiniScale_(standard)_R17.tfwfile from the
georeferencing_filesfolder to the
RGB_TIF_COMPRESSEDfolder. This way the
.tiffiles are in the same directory and QGIS can use the information.
In the QGIS main windows, go to. Browse to the
MiniScale_(standard)_R17.tiffile and click Open.
The Ordnance Survey files are in the British National Grid projection. In the Coordinate Reference System Selector dialog, search for
british nationaland pick the
OSGB 1936 / British National Grid (EPSG:27700)CRS. Click OK.
MiniScale_(standard)_R17layer is loaded, right-click on it and select Zoom to layer.
You will see the raster layer overlaid on top of the
ne_10m_admin_0_countriesvector layer. Since we have the
OTFenabled with EPSG:4326, the
MiniScale_(standard)_R17layer gets dynamically reprojected to EPSG:4326 and shown in the same coordinate space as the other layer.