QGIS: turn a CSV of latitude and longitude into points

Load a spreadsheet of latitude and longitude into QGIS as a point layer with Add Delimited Text Layer, check the points landed in the right place, fix swapped or missing coordinates and save the result as a GeoPackage. Worked example: the Environment Agency's 1,046 rainfall gauges.

Level
Beginner
Tested with
Python 3.12
Source code
Download scripts

CSV to points in QGIS

With a CSV that has a latitude and a longitude column in decimal degrees:

  • 1. Open the dialogue

    Layer › Add Layer › Add Delimited Text Layer… (Ctrl+Shift+T)

    Pick your file in File name.

  • 2. Point at the columns

    Geometry Definition › Point coordinates › X field: longitude, Y field: latitude

    X is always longitude and Y is always latitude.

  • 3. Set the CRS

    Geometry CRS: EPSG:4326 - WGS 84

    For British National Grid eastings and northings, use EPSG:27700 instead.

  • 4. Add

    Add, then Close
  • 5. Save it properly

    Right-click the layer › Export › Save Features As… › Format: GeoPackage

    The delimited text layer is only a live view of the CSV.

Key takeaways

  1. Layer › Add Layer › Add Delimited Text Layer turns any CSV with coordinate columns into points. Set X field to longitude, Y field to latitude and the CRS to EPSG:4326.
  2. Swapping X and Y is the classic mistake. Our English rain gauges all landed in the Indian Ocean near the Seychelles, because 52° north had become 52° east.
  3. Rows with empty coordinates still load, as features with no location. Three of the 1,046 rows in our file had none; they appear in the attribute table but not on the map.
  4. Check your points against something you trust. Every one of our 1,043 located gauges sat within 4 m of the British National Grid position the Environment Agency publishes.
  5. Save the result as a GeoPackage. A delimited text layer is a read-only view of the CSV and is slow on large files.

Before you start

  • QGIS 3.34 or later (tested with QGIS 3.40.12 LTR)
  • A CSV with a latitude column and a longitude column, or the free Environment Agency file used here

Short answer: In QGIS choose Layer › Add Layer › Add Delimited Text Layer, pick your CSV, and under Geometry Definition choose Point coordinates. Set X field to your longitude column, Y field to your latitude column and Geometry CRS to EPSG:4326 - WGS 84, then click Add. To keep the points, right-click the new layer and choose Export › Save Features As… with the format set to GeoPackage.

This is part 1 of QGIS essentials, a weekly series of short tutorials on the jobs every QGIS user needs. We start with the commonest of all: you’ve been given a spreadsheet of places with a latitude and a longitude for each, and you want them on a map.

Our example is a real file anyone can download: the Environment Agency’s list of its 1,046 rainfall gauges, published as a CSV under the Open Government Licence. It has a column of latitudes, a column of longitudes and, usefully, each gauge’s British National Grid easting and northing too, so we can check our points against the Environment Agency’s own positions. Every step below was run in QGIS 3.40.12 LTR, and the script that repeated it, csv_to_points.py, produced every number on this page.

QGIS showing 1,043 blue points, one for each Environment Agency rainfall gauge, spread across England over an OpenStreetMap basemap.
The Environment Agency's rainfall gauges, loaded from a CSV of latitude and longitude, over OpenStreetMap. Gauge data: Environment Agency, Open Government Licence v3.0. Basemap © OpenStreetMap contributors.

What you need

  • QGIS 3.34 or later. Everything here is built in.
  • A CSV of points. Each row is one place, with one column for latitude and one for longitude. To follow along exactly, download the rainfall gauge CSV and save it as rainfall-stations.csv.

Step 1: check the CSV before you start

Open the file in a text editor or spreadsheet and look at three things.

  1. There is a header row, so QGIS can name the columns. Ours starts @id,label,notation,…,lat,long,easting,northing,….
  2. The coordinates are decimal degrees, such as 52.186277 and -1.171327. Places west of Greenwich have a negative longitude, so almost every longitude in England is negative. If yours look like 52°11'10.6"N, see degrees, minutes and seconds below.
  3. Which column is which. Latitude runs from -90 to 90 and is the north–south position; in Britain it is around 50 to 59. Longitude is the east–west position; in Britain it is around -8 to 2. Our columns are called lat and long, which makes it easy. Some files use y and x, or latitude and longitude.

Our file had 1,046 rows and 25 columns. Three rows (gauges 6666LO, 4549 and 4548) have empty lat and long cells. We left them in on purpose to see what QGIS does with them.

Step 2: open Add Delimited Text Layer

Choose Layer › Add Layer › Add Delimited Text Layer…, or press Ctrl+Shift+T. This opens the Data Source Manager on its Delimited Text page. Click the … button next to File name and pick the CSV.

QGIS reads the first rows straight away and shows them under Sample Data, which is your first check that the file has been read properly. The Layer name defaults to the file name; you can change it to something friendlier, such as Rainfall gauges.

Under File Format, leave CSV (comma separated values) selected for a normal CSV. Choose Custom delimiters for files separated by tabs or semicolons. Semicolons are common in files saved by European versions of Excel, where the comma is the decimal separator.

Step 3: tell QGIS which columns hold the coordinates

Open Geometry Definition and set:

Setting Value
Geometry type Point coordinates
X field long (your longitude column)
Y field lat (your latitude column)
Geometry CRS EPSG:4326 - WGS 84
The QGIS Data Source Manager on the Delimited Text page, with rainfall-stations.csv chosen, CSV format selected, Point coordinates ticked, X field set to long, Y field set to lat and Geometry CRS set to EPSG:4326 - WGS 84.
Add Delimited Text Layer, set up for the rainfall gauge CSV: X field is longitude, Y field is latitude, and the CRS is EPSG:4326.

QGIS often fills in X and Y by itself when the columns have obvious names, but always check them: the next section shows what happens when they’re the wrong way round.

EPSG:4326 is the code for WGS 84 latitude and longitude. It’s the right choice for nearly every CSV of lat/long, including GPS readings, phone exports and web downloads. The CRS here describes the numbers in the file; it doesn’t have to match your project. QGIS reprojects the points on the fly, which is how they sit correctly on the OpenStreetMap basemap in Web Mercator in the map above.

Click Add, then Close. Your points appear as a new layer.

Step 4: check the points landed in the right place

A layer that draws isn’t necessarily right, so take a minute to check it.

Count the features. Right-click the layer and choose Show Feature Count. Ours shows 1,046: every row of the CSV, including the three with no coordinates. Those three load as features with no location. They’re in the attribute table but not on the map. Find them with Select Features by Expression and "lat" IS NULL, and either fix the coordinates in the CSV or delete them.

Look at the extent. Right-click › Zoom to Layer. Ours runs from longitude -5.5685 to 1.7358 and latitude 50.0353 to 55.7654: from a gauge near Land’s End in the west to one near Lowestoft in the east, and from the Lizard in the south to near Berwick-upon-Tweed in the north. That is England, as it should be.

Compare with a second source. Our file also gives each gauge’s British National Grid easting and northing. When the script converted every point to British National Grid and measured the gap, all 1,043 located gauges were within 4 m of the Environment Agency’s position, and the median gap was 2.6 m. The eastings and northings in the file are rounded to the nearest 10 m, which accounts for gaps of a few metres. If your file has a second set of coordinates, an address or a postcode, check a handful of points against it.

The classic mistake: X and Y swapped

X is longitude and Y is latitude. It feels backwards, because we say “lat/long”, but X is the horizontal axis and longitude is the horizontal, east–west position.

We loaded the same file with X = lat and Y = long to see what happens. QGIS gave no warning. All 1,046 points loaded, with an extent of x 50.04 to 55.77 and y -5.57 to 1.74. Every gauge in England had moved to the Indian Ocean, near the Seychelles, because 52° north had become 52° east.

If your points appear somewhere absurd, or in a thin sliver, swapped columns are the first thing to check. Points sitting near 0, 0 in the Gulf of Guinea usually mean the coordinates are missing or were read as zero, and points in the right shape but in the wrong country usually mean the wrong CRS.

Step 5: save the points as a GeoPackage

A delimited text layer isn’t a copy of your data. It’s a live, read-only view of the CSV that QGIS re-reads when it needs to. You can’t edit it, and it gets slow with large files.

To keep the points, right-click the layer and choose Export › Save Features As…:

  • Format: GeoPackage
  • File name: for example rainfall-gauges.gpkg
  • Layer name: rainfall_gauges
  • CRS: leave it as EPSG:4326, or pick your project’s CRS, such as EPSG:27700 for British National Grid

Our GeoPackage came to 532 KB and held all 1,046 features. The three without coordinates came across too, still with no location, so remove them first if you don’t want them.

Other ways to do the same thing

Eastings and northings instead of lat/long

If your CSV has British National Grid eastings and northings, use exactly the same dialogue with X field = easting, Y field = northing and Geometry CRS = EPSG:27700 - OSGB36 / British National Grid. Eastings are the X values here too. The same pattern works for any projected system: use the CRS the coordinates were recorded in.

Degrees, minutes and seconds

If the coordinates are written like 52°11'10.6"N, tick DMS coordinates under Geometry Definition. QGIS reads several common styles. Make sure the hemisphere letter or a minus sign is there, or western longitudes will land east of Greenwich.

The Processing tool

Processing › Toolbox › Vector creation › Create points layer from table does the same job in one step and is handy in a model or batch. With X = long, Y = lat and EPSG:4326 it produced 1,046 features, three of them with no geometry: exactly the same result as the dialogue.

Columns read as text

Under Sample Data, each column shows the type QGIS detected. In our file lat and long came in as decimals, easting as a whole number and dateOpened as a date. period, which is nearly always 900 (15 minutes in seconds), came in as text. One gauge with two measures lists it as 900|900, and a single value that isn’t a number makes the whole column text. If a coordinate column ever shows as text, look for a stray value such as n/a, a space or a comma used as the decimal point.

The script

csv_to_points.py runs the whole workflow with the Python that ships with QGIS, without opening the QGIS window. It downloads the CSV, loads it with X = long and Y = lat, checks every point against the Environment Agency’s grid references, repeats the swapped-columns test, saves the GeoPackage, runs the Processing tool and writes a QGIS project. The key line is the layer source, which holds the same settings as the dialogue:

uri = (f"{CSV_PATH.as_uri()}?type=csv&delimiter=,&detectTypes=yes"
"&xField=long&yField=lat&crs=EPSG:4326&spatialIndex=yes")
layer = QgsVectorLayer(uri, "Rainfall gauges", "delimitedtext")

Run it from the folder that holds it:

"C:\Program Files\QGIS 3.40.12\bin\python-qgis-ltr.bat" -u csv_to_points.py

Where next

  • Put a basemap under your points: see the list of XYZ tile URLs for QGIS for OpenStreetMap, Esri World Imagery and others.
  • Find more data to map in our free GIS data sources, sorted by country and theme.
  • Next week in QGIS essentials: converting latitude and longitude to UTM.

FAQ

Which is X and which is Y, latitude or longitude?

X is longitude and Y is latitude. X is the horizontal, east–west axis, and longitude measures position east or west of Greenwich. If your points appear in the wrong ocean, swap them.

What CRS should I choose for a CSV of latitude and longitude?

EPSG:4326 - WGS 84. It’s the system GPS, phones and almost every web download use. Choose another CRS only if the file says its coordinates are in one, such as EPSG:27700 for British National Grid eastings and northings.

Why do some rows not appear on the map?

Rows with empty or unreadable coordinates load as features with no location. They are in the attribute table but don’t draw. Select them with the expression "lat" IS NULL (using your latitude column’s name) and fix or delete them.

Why can’t I edit my CSV layer?

A delimited text layer is a read-only view of the file. Save it as a GeoPackage with Export › Save Features As… and edit the copy.

Can I load a CSV of addresses or postcodes the same way?

Not directly. Add Delimited Text Layer needs coordinates. Addresses and postcodes have to be geocoded first, which means looking up a coordinate for each one with a geocoding service or a postcode lookup table, then loading the result as shown here.

Key terms

Delimited text
A plain-text table where a character such as a comma or tab separates the columns. A CSV is the commonest kind.
Decimal degrees
Latitude and longitude written as single numbers, such as 52.186277 and -1.171327. West of Greenwich and south of the equator are negative.
EPSG:4326
The code for WGS 84 latitude and longitude, the coordinate system used by GPS and by almost every CSV of lat/long.
EPSG:27700
The code for British National Grid: eastings and northings in metres across Great Britain.
GeoPackage
A single-file, open GIS format (.gpkg) that holds vector layers, rasters and attribute tables. QGIS's default format for saving data.
A QGIS 3D map view of Skiddaw and Blencathra seen from the south, with green valley floors, brown fell sides and pale summits, built from the Copernicus 30 m DEM.

Tutorial QGIS

QGIS 3D map view: turn a DEM into 3D terrain

Turn a digital elevation model into 3D terrain in QGIS without plugins: reproject the DEM, drape a hillshaded colour ramp over it, set it as the project terrain, open a 3D map view, exaggerate the relief and export images, OBJ models and animations. Worked example: Keswick, Skiddaw and Helvellyn from the free Copernicus DEM.

Beginner 10 min read

QGIS 3.40 with the Browser panel listing XYZ Tiles connections from basemap.at to IGN Plan IGN v2, and the map showing Esri World Imagery of Keswick and Derwentwater in the Lake District with Esri road and place-name overlays on top.

Tutorial QGIS

XYZ tile URLs for QGIS: 27 free basemaps, checked and ready to load

A checked list of XYZ tile URLs for QGIS: OpenStreetMap styles, Esri imagery and overlays, Sentinel-2 cloudless, and national basemaps for the US, the Netherlands, France, Austria, Switzerland and Germany. Each has its max zoom, attribution and terms, plus a connections file that adds all 27 at once and an open satellite hybrid.

Beginner 13 min read