GIS Data

Loading, exporting, and creating data layers are the operations you’ll use regularly in GIS. Download the Madrid datasets from the datasets page before continuing.

Loading Data

Use GeoPackage files whenever possible. However, data is often provided in other formats like Shapefiles or CSVs.

Unzip the Madrid Neighbourhoods madrid_nbhds.zip folder. Notice that this folder contains a collection of five files. Shapefiles need a bundle of multiple files, which makes them awkward; the file that serves as the entry point is the one ending in .shp.

  • It is generally easiest to drag and drop layers into your map view. In this case, you would drag the Shapefile (ending in .shp) into the map view to open it.
  • Notice the layer is now displayed and a layer will have been added to your Layer panel.
  • Select the layer, then click the Remove Layer button in the Layer panel to remove it.
  • We’ll now re-add the layer using the menu approach so you’re familiar with both methods. Go to the Layer menu, then Add Layer, then Add Vector Layer. Set source type as File, select the browse button next to the source field, then navigate to the file. Then add it to the project.

Practise the basic navigation operations. These tools are in the toolbars at the top of the screen. If you can’t find a tool, go to ViewToolbars and ensure Attributes Toolbar and Selection Toolbar are enabled.

  • Toggle layer visibility using the checkbox next to the layer name in the Layers Panel.
  • Use Select Features (yellow rectangle icon) to select a neighbourhood and see it highlighted.
  • Use Identify Features (blue circle with “i” icon) to see attribute information for a particular neighbourhood.
  • Click Zoom to Selection to zoom the map to the currently selected feature. This only works with actual selections, not features highlighted via Identify Features.
  • Click Zoom Full to return to a view of all features.
  • Click Toggle Editing (pencil icon). This lets you delete existing features or add new features. Use with caution! Don’t make any changes for now, just click Toggle Editing again to exit edit mode.

Saving and exporting data

We don’t want to edit the original dataset, so let’s make a copy and work with that instead:

  • Right click the layer in the Layer Panel and select export -> Save Features as
  • Select the GeoPackage format.
  • Select the browse button next to the File Name field, then select a file location on disk and give it a distinctive name such as test_madrid_nbhds.
  • You can export to the same or to another CRS. Keep it as EPSG:25830 (the standard CRS for Madrid that we set up in the previous module). This will ensure your exported file uses the same CRS as your project.
  • Check that Add saved file to map at the bottom of the window is selected
  • Select OK
  • The file will be saved and will automatically load into your map.
  • Remove the original SHP file from your Layers Panel since it is no longer needed. This can be done with the Remove Layer button.
Tip

Save your data in GeoPackage format unless you have a reason not to.

Warning

Create copies of important data before editing so you don’t accidentally lose anything. GIS works differently from other software: it is more like a database meaning that edits are persisted to the data source as soon as you exit edit mode.

Loading CSV files

Data sometimes comes as CSV (comma separated values) or similar text formats. If spatial, the geometry is usually stored in columns (like x and y, or easting and northing). CSVs can be opened and edited in spreadsheet software like Excel.

Some CSVs have no geometry at all. You can still add them to your project, but nothing will appear on the map. These are useful when you want to join tabular data to a spatial layer using a shared identifier.

  • To load the CSV file we’ll go to the Layer menu bar, Add Layer, then Add Delimited Text Layer.
  • For File name, click the browse button and navigate to the madrid_premises.csv file, then select the CSV file and open it. Hint: If the load window disappears, it might be hiding behind the main application window.
  • For file format, select CSV. Note that not all CSV files use commas to separate values, in which case you either need to find out which form of delimiter is used, or you can experiment with the settings until the Sample Data preview pane looks correct.
  • Under Record and Fields Options, check the Sample Data preview at the bottom of the window. Look at the first row: does it contain column names (like “id”, “name”, “easting”) or actual data values? If it contains column names, select First record has field names. In this case, there is a header row, so select that option. The preview should update to show the column names as headers rather than as a data row.
  • Place a check in the option to Detect field types as well as Trim fields.
  • If a CSV contains point geometry, it will often contain columns such as x and y or easting and northing (when working with a projected CRS).
  • In this case, notice that the last two columns listed in the Sample Data preview pane are a potential source of Point geometry information.
  • Under Geometry Definition options, select Point coordinates. Check that the X field is associated with the easting column and that the Y field is associated with the northing column.
  • In this case, the geometry coordinates are based on EPSG:25830, so set the geometry CRS accordingly.
  • Under layer settings check that Use spatial index is selected, this will speed things up!
  • Select Add then Close.

You should now see a Point layer in your Layers panel. The premises should appear as dots scattered across Madrid.

WarningTroubleshooting

Layer appears in panel but not on map:

  • Check that the layer visibility checkbox is ticked
  • Drag the layer above any polygon layers that might be obscuring it
  • Right-click the layer and select Zoom to Layer to confirm it loaded correctly

Data appears in the wrong location (near Africa, in the ocean, etc.):

  • The CRS wasn’t set correctly. Remove the layer and re-add it, making sure to set EPSG:25830 for the geometry CRS

Sample Data preview looks garbled:

  • Try different delimiter settings (comma, semicolon, tab)
  • Check the encoding (UTF-8 is most common)

Importing CSVs involves several settings to get right. Convert to GeoPackage once you have it working. Repeat the above steps to export data, this time saving your premises data to another distinctively named GeoPackage.

Creating data

Sometimes you’ll want to create your own data layers. Let’s practise by creating a new LineString GeoPackage.

  • Go to Layer then Create Layer and select New GeoPackage Layer. Click the browse button (three dots) next to Database then browse to a file location and select a distinctive name such as new_lines.
  • For Geometry type select LineString.
  • For CRS select EPSG:25830.
  • Uncheck the option to include Z and M.
  • You can create a layer without attributes, but chances are you’ll want some sort of attribute information in your data, so let’s practise adding a new field. Under New Field enter “description” for the Name and select “Text” for the Type, then click Add to Fields List.
  • Click OK to create the new layer.

Now that the layer has been created, it will appear in your Layer panel. Let’s add a few lines.

  • Select the layer in the Layer panel, then click Toggle Editing (pencil icon) to activate editing mode.
  • Click Add Line Feature (green line with star icon). If you don’t see this tool, go to ViewToolbars and enable Sketching Toolbar. Draw a LineString by clicking a few times on the map, then right-click to finish.
  • It will now give you the option to fill your description field.
  • Select OK.
  • Click Toggle Editing to deactivate editing mode and select Save.

The new GeoPackage file now contains your lines and can be shared with others or opened in a new project. The same workflow applies for Polygon and Point data.

Challenge

NoteChallenge

Create a new Point layer to mark three locations in Madrid you’ve visited so far. Your layer should:

  1. Be saved as a GeoPackage named visited_sites.gpkg
  2. Use CRS EPSG:25830
  3. Have two text attributes: name and description
  4. Contain at least three points with filled-in attributes

When you’re done, export the attribute table to verify your data saved correctly: right-click the layer → Open Attribute Table.

  1. LayerCreate LayerNew GeoPackage Layer
  2. Browse to location, name it visited_sites.gpkg
  3. Set Geometry type to Point, CRS to EPSG:25830
  4. Add fields:
    • Name: name, Type: Text
    • Name: description, Type: Text
  5. Click OK
  6. Select the layer, click Toggle Editing to enter edit mode
  7. Click Add Point Feature, then click on the map to place a point
  8. Fill in the attributes (e.g., name: “Gran Vía / Callao”, description: “Famous shopping street”)
  9. Repeat for two more points
  10. Click Toggle Editing to exit edit mode, save when prompted

Open the attribute table to verify all three records have names and descriptions filled in.