eyecatch

How to Add Latitude/Longitude Data to QGIS

Published: Last updated:
This article uses QGIS 3.34. The current LTR is 3.44.

What you'll learn


  • How to create point data from coordinates such as latitude and longitude
  • How to export the imported data as a Shapefile
  • How to fix garbled CSV text and what to do when points do not line up with the base map

Recommended for


  • Anyone who wants to display tabular data with latitude and longitude values, such as Excel or CSV files, on a QGIS map
  • Anyone whose CSV data appears garbled
  • Anyone whose CSV data does not appear in the right place

Introduction

When you work with GIS data, you sometimes have a table that includes coordinates such as latitude and longitude, and you want to create point data at those coordinates. In QGIS, you can easily generate point data from coordinate values. This article shows how to create point data from coordinates such as latitude and longitude and export it as a Shapefile. How to import CSV data that contains latitude and longitude

Prepare the CSV data

To create point data from coordinates, you first need to organize the coordinates as CSV data. This article uses the CSV data “List of Childcare Facilities in Osaka Prefecture,” which you can download from the Osaka Prefecture Open Data Catalog Site.

In Excel, the downloaded CSV data has latitude values in column B and longitude values in column C.

The list of childcare facilities in Osaka Prefecture displayed in Excel (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
The list of childcare facilities in Osaka Prefecture displayed in Excel (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

Prepare CSV data that has separate columns for coordinates such as latitude and longitude, like this data. If your data is an Excel file with an extension such as .xlsx, convert it to a CSV file first. To do so, choose Save As in Excel and set the file format to CSV UTF-8 (Comma delimited) (.csv).

Save the file in CSV UTF-8 (Comma delimited) (.csv) format (Excel for Mac)
Save the file in CSV UTF-8 (Comma delimited) (.csv) format (Excel for Mac)

Import a CSV file into QGIS

Start QGIS and, from the menu bar, choose Layer → Add Layer → Add Delimited Text Layer.

Choose Add Delimited Text Layer
Choose Add Delimited Text Layer

The Data Source Manager opens with the Delimited Text tab selected. It has many settings, but start by clicking the ... button next to File name to select the CSV file to import.

Select the CSV file to import with the ... button
Select the CSV file to import with the ... button

The Choose a Delimited Text File to Open dialog opens. Select the CSV file to import and click Open.

Select the CSV file to import and click Open
Select the CSV file to import and click Open

The Sample Data area now shows a preview of the CSV file you selected.

The Sample Data area shows a preview of the selected CSV file (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
The Sample Data area shows a preview of the selected CSV file (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

If the sample data looks right, confirm that Point coordinates is selected under Geometry Definition. Then select the 経度 (longitude) column for X field and the 緯度 (latitude) column for Y field.

Select the longitude column for X field and the latitude column for Y field
Select the longitude column for X field and the latitude column for Y field

Next, use Geometry CRS to select the coordinate reference system (CRS) of this data. Click the globe button to open the dialog for selecting a CRS. Enter 4326 in Filter, select WGS 84 (EPSG:4326) under Predefined Coordinate Reference Systems, and click OK.

Select WGS 84 (EPSG:4326)
Select WGS 84 (EPSG:4326)

When the settings are done, click Add.

When the settings are done, click Add (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
When the settings are done, click Add (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

The point data now appears in the map canvas.

The point data is added to the map canvas (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
The point data is added to the map canvas (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

Check the imported data

Once the CSV data appears correctly in QGIS, check that it was added properly.

First, add a base map and check that the points appear in the right place. Here, add GSI Maps, from the Geospatial Information Authority of Japan (GSI). In the Browser panel, double-click GSI Maps under XYZ Tiles.

Double-click GSI Maps
Double-click GSI Maps

In the map canvas, the points appear in the Osaka area, which confirms that QGIS imported the CSV data correctly.

The points appear in the right place (GSI Tiles in the background; created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
The points appear in the right place (GSI Tiles in the background; created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

Check the attribute table too. Right-click the layer and choose Open Attribute Table.

Right-click the layer and choose Open Attribute Table (GSI Tiles in the background; created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
Right-click the layer and choose Open Attribute Table (GSI Tiles in the background; created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

The attribute table also displays the data correctly.

The attribute table also displays correctly (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
The attribute table also displays correctly (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

Export the CSV data as a Shapefile

For simple visualization or light processing, the CSV data you added to QGIS works fine as it is. For spatial analysis or large amounts of data, however, a vector format such as Shapefile is more efficient, so it is important to export the imported CSV data to a vector format.

This section shows how to export to a Shapefile. First, right-click the layer and choose Export → Save Features As.

Choose Save Features As (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
Choose Save Features As (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

The Save Vector Layer as dialog opens. Use it to configure the file to export.

First, use the Format field to specify the file format of the output vector data. Select ESRI Shapefile from the drop-down list.

Next, click the ... button next to File name and specify where to save the file and what to name it. When all settings are done, click OK.

When all settings are done, click OK
When all settings are done, click OK

QGIS exports the data as a Shapefile to the location you specified and adds it to QGIS under the name you just entered.

The data is exported as a Shapefile (GSI Tiles in the background; created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
The data is exported as a Shapefile (GSI Tiles in the background; created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

Common problems when adding CSV data

What to do when the CSV text is garbled

When you add CSV data, the Sample Data area sometimes shows garbled text.

The Sample Data area shows garbled text (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
The Sample Data area shows garbled text (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

The cause is the encoding setting. Japanese CSV files are generally created in “Shift_JIS” or “UTF-8,” but QGIS may default to a different encoding, which garbles the text.

If the CSV data is garbled, try switching the Encoding field between “Shift_JIS” and “UTF-8”. This should fix the garbled text.

Changing the encoding to UTF-8 fixes the garbled text (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
Changing the encoding to UTF-8 fixes the garbled text (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

Note that if you notice garbled text after adding the CSV data to QGIS, you cannot change the Data source encoding in the layer properties, unlike with vector files such as Shapefiles. Add the CSV data again from the Data Source Manager.

You cannot change the encoding of CSV data after adding it to QGIS
You cannot change the encoding of CSV data after adding it to QGIS

Points appear in the wrong place on the map

Even after you add CSV data to QGIS and overlay it on a base map, the points sometimes do not appear where they should.

The points do not overlap the base map (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
The points do not overlap the base map (created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

When you import CSV data, the CRS setting is especially important.

For latitude and longitude data published in Japan, the usual choice is “EPSG:4326 (WGS 84)” or “EPSG:6668 (JGD2011).” If the data uses a different CRS, you must set that CRS correctly. With an incorrect CRS, the points may not appear at the right place on the map, as shown above, so it is important to check the CRS of the data before you import it.

Set the correct CRS when importing the CSV data
Set the correct CRS when importing the CSV data

A similar problem occurs when the points appear flipped, as in the figure below, and do not display correctly. This happens when the columns are swapped in the import settings, for example when X field is set to the 緯度 (latitude) column and Y field to the 経度 (longitude) column.

With incorrect settings, the points are flipped and do not overlap the base map (GSI Tiles in the background; created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)
With incorrect settings, the points are flipped and do not overlap the base map (GSI Tiles in the background; created by processing “List of Childcare Facilities in Osaka Prefecture” from the Osaka Prefecture Open Data Catalog Site)

When the points do not appear correctly on the map like this, check the CRS and the other settings, and import the CSV data again.

Conclusion

This article showed how to import CSV data that contains latitude and longitude into QGIS and export it as a Shapefile. Misplaced points and garbled CSV text are easy to run into, so it is important to stay calm and check the CRS and encoding settings.

About the author
QGIS LAB Editorial Team
QGIS LAB Editorial Team

QGIS LAB is a comprehensive information hub for QGIS, the open-source GIS software. Under the concept of “Geospatial for Greater Good,” we share the knowledge and skills to open up the world through location data.