← Back to Blog

How to Convert CSV to GeoJSON (Latitude & Longitude)

Convert a CSV file with latitude and longitude columns to GeoJSON online for free. Step-by-step guide with browser tools, Python, and JavaScript. Auto-detects coordinate columns.

If you have location data in a spreadsheet — GPS coordinates exported from a tracker, addresses after geocoding, field survey points, or IoT sensor readings — converting that CSV to GeoJSON makes it immediately usable in web mapping libraries, geospatial APIs, and GIS software. GeoJSON is the standard format for representing geographic features on the web, and a CSV with latitude and longitude columns maps directly to a GeoJSON FeatureCollection of Point features. This guide shows how to convert CSV to GeoJSON in three ways: a free browser tool that requires no coding, a Python one-liner for automation, and a JavaScript snippet for in-app use.

What Your CSV Needs

Before converting, make sure your CSV contains at least two numeric columns representing geographic coordinates in the WGS 84 (EPSG:4326) coordinate reference system — latitude (north/south, range −90 to +90) and longitude (east/west, range −180 to +180). Column names do not need to match exactly; most tools auto-detect common naming conventions:

  • Latitude column: lat, latitude, y (case-insensitive)
  • Longitude column: lng, lon, longitude, x (case-insensitive)

Every other column in the CSV becomes a property on the resulting GeoJSON Feature — name, description, category, timestamp, sensor value, or any other attribute you have. Rows with missing or non-numeric coordinate values are skipped automatically.

CSV to GeoJSON Example

Here is a minimal CSV file with 3 points and two attribute columns:

name,lat,lng,category
Eiffel Tower,48.8584,2.2945,landmark
Colosseum,41.8902,12.4922,landmark
Sagrada Família,41.4036,2.1744,landmark

After conversion, this becomes a GeoJSON FeatureCollection where each row is a Feature with a Point geometry and a properties object containing name and category:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": { "type": "Point", "coordinates": [2.2945, 48.8584] },
      "properties": { "name": "Eiffel Tower", "category": "landmark" }
    }
  ]
}

Note the coordinate order in GeoJSON: [longitude, latitude] — the opposite of how humans usually write it but consistent with the x/y mathematical convention specified in RFC 7946.

Convert CSV to GeoJSON Using GeoDataTools

The GeoDataTools CSV-to-GeoJSON converter handles the conversion entirely in your browser — no server upload, no account required. It works for CSV files up to 30 MB and auto-detects your coordinate columns.

  1. Open the CSV to GeoJSON converter.
  2. Drag and drop your .csv file onto the upload area, or click to browse your filesystem.
  3. The tool parses the CSV using PapaParse with automatic header detection and shows you which columns it identified as latitude and longitude.
  4. Review the preview: feature count, detected coordinate columns, and a sample of the first few rows.
  5. Click Download GeoJSON to save the converted FeatureCollection to your device.

Once downloaded, open the GeoJSON in the GeoDataTools map viewer to visualize all points on an interactive map, filter by any attribute, and inspect the full attribute table. You can also export a filtered subset back to GeoJSON or KML for further use.

Convert CSV to GeoJSON with Python

For automated pipelines or large files, Python with GeoPandas converts CSV to GeoJSON in three lines:

import geopandas as gpd
import pandas as pd
from shapely.geometry import Point

df = pd.read_csv("input.csv")
gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df["lng"], df["lat"]), crs="EPSG:4326")
gdf.to_file("output.geojson", driver="GeoJSON")

The gpd.points_from_xy() function creates Shapely Point geometries from separate longitude and latitude columns. The crs="EPSG:4326" argument tags the GeoDataFrame with the WGS 84 coordinate reference system, which GeoPandas writes into the GeoJSON output. Install the dependencies with pip install geopandas pandas shapely.

Handling Missing Coordinates

# Drop rows where lat or lng is missing or non-numeric
df = df.dropna(subset=["lat", "lng"])
df["lat"] = pd.to_numeric(df["lat"], errors="coerce")
df["lng"] = pd.to_numeric(df["lng"], errors="coerce")
df = df.dropna(subset=["lat", "lng"])

Real-world CSV exports often contain rows with empty coordinate cells, text like "N/A", or coordinates formatted with degree symbols (48°51'N). Clean the data before passing it to GeoPandas to avoid ValueError exceptions.

Convert CSV to GeoJSON with JavaScript

For browser or Node.js applications, the combination of PapaParse (CSV parsing) and plain JavaScript (GeoJSON assembly) requires no GIS library:

import Papa from 'papaparse';

function csvToGeoJSON(csvText) {
  const { data } = Papa.parse(csvText, { header: true, dynamicTyping: true, skipEmptyLines: true });

  const features = data
    .filter(row => row.lat != null && row.lng != null)
    .map(({ lat, lng, ...properties }) => ({
      type: 'Feature',
      geometry: { type: 'Point', coordinates: [lng, lat] },
      properties,
    }));

  return { type: 'FeatureCollection', features };
}

// Usage
const geojson = csvToGeoJSON(csvFileContent);
console.log(`Converted ${geojson.features.length} features`);

This function destructures each row to separate lat and lng from the remaining columns, which become feature properties. You can adapt the column name detection to check multiple variants (latitude, y, etc.) before defaulting to lat.

Common Problems and How to Fix Them

  • Coordinates are swapped (map shows points in the ocean). Verify that latitude is in the range −90 to +90 and longitude in −180 to +180. If the values look reversed, swap the column assignment in your conversion script.
  • Column names not detected. Rename your coordinate columns to lat and lng (or any of the standard names listed above) before converting. Many tools cannot detect custom names like coord_y or gps_north.
  • Coordinates use a projected CRS (large numbers like 500000, 4649776). Your CSV is likely in a projected coordinate system such as UTM or a national grid, not WGS 84. Reproject to EPSG:4326 using GeoPandas (gdf.to_crs(epsg=4326)) or ogr2ogr before generating GeoJSON.
  • Decimal separator is a comma, not a period. CSV files from some European locales use commas as decimal separators (e.g., 48,8584 instead of 48.8584). Open the file in a text editor, use find-and-replace to fix the decimals, then re-save before converting.
  • File is actually TSV (tab-separated). If the CSV has a .csv extension but values are tab-separated, specify the delimiter explicitly: Papa.parse(text, { delimiter: ' ' }) or pd.read_csv("file.csv", sep=' ').

FAQ

Can I convert an Excel file to GeoJSON?

Yes, but export it as CSV first. In Excel or Google Sheets, go to File → Save As → CSV (Excel) or File → Download → CSV (Google Sheets). Then use any of the methods above to convert the CSV to GeoJSON. Excel's built-in Power Query cannot output GeoJSON directly.

Is my CSV data sent to a server?

Not with GeoDataTools. The browser-based converter uses PapaParse to parse your file entirely in JavaScript on your device. Your data never leaves your browser tab — suitable for sensitive employee locations, customer addresses, or proprietary field survey data.

What geometry type does the output GeoJSON use?

Each CSV row becomes a GeoJSON Point feature. GeoJSON defines points as [longitude, latitude] per RFC 7946. If your data represents lines or polygons (e.g., ordered GPS tracks), a CSV-to-GeoJSON converter will still produce Points — you would need to post-process them into LineStrings using a tool like Turf.js.

How do I add the GeoJSON to a Leaflet map?

Load the converted GeoJSON file and add it as a layer with L.geoJSON(data).addTo(map). See the Leaflet GeoJSON layer tutorial for a complete working example with popups and custom markers.

Can I convert a CSV with thousands of rows?

Yes. The GeoDataTools browser converter supports files up to 30 MB, which typically covers hundreds of thousands of point features. For files larger than 30 MB, use the Python GeoPandas approach — it streams the file and handles memory efficiently for millions of rows.

Ready to work with your geospatial data?

Visualize, filter, and convert GeoJSON and KML files directly in your browser.

Try GeoDataTools