Files & formats

Reading and writing shapefiles, GeoPackages, GeoJSON and CSV — and what breaks in each.

The same layer stored as a five-file shapefile set and as one GeoPackage. the same layer, as a file set and as one file.shp.shx.dbf.prj.cpgcopy four of the fiveand it opens wrong.gpkggeometry, attributes, CRS,encoding and an index — in oneWhat a format can carry decides what survives the round trip

A spatial file is a container with opinions. Shapefile truncates field names at ten characters and cannot store a datetime. GeoJSON is always WGS 84, whatever you had. GeoPackage takes almost anything and puts it in one file. Reading is rarely the problem — GDAL handles around 200 vector formats behind one interface — so the work here is identification, selection, and knowing what a round trip costs.

The failures are mostly silent. A GeoPackage holding several layers hands you the first one. A shapefile copied without its .dbf opens with no attributes. A missing .prj gives you crs = None, which is not a bug but information that was lost at the moment somebody copied the file. None of these raise anything.

Below, the concepts cover what the formats are and what each one can carry, the how-to guides are one per format plus the conversions between them, and the fixes are the specific errors each format produces.

Learning paths run through this topic too — see the end of this page.

🧭 Start with the concepts

The ideas the how-to guides below assume you already have.

Show every concept in this topic

⚙️ Then do the task

Step-by-step walkthroughs with code you can copy and adapt.

Show every how-to guide in this topic

🔧 When it breaks

The errors this topic produces, with the cause explained rather than just the command.

Show every fix in this topic

Related topics

Subjects that keep coming up alongside this one, most overlap first.

Keep browsing

Files & formats sits in Fundamentals. Every topic on the site is listed on the topics index.