viewhack

Shapefile viewer: open a .shp map layer without GIS software

Open the map data a council, a national mapping agency or an open-data portal hands out as a shapefile, without installing QGIS or ArcGIS. Choose the .shp together with its .dbf, .shx, .prj and .cpg, or the ZIP they came in: the shapes are drawn, the attribute table is shown and searchable, and tapping a shape finds its row.

The files are read on your device. Nothing is uploaded, and no map tiles are fetched: the shapes are drawn from their own coordinates.

What it shows

A shapefile is several files, and which ones matter

The name is singular, but a shapefile is a set of files with one base name. roads.shp holds the geometry, roads.dbf the attribute table (one row per shape, matched only by position: the 12th shape is the 12th row), roads.shx an index of where each shape starts, roads.prj the coordinate system as text, and roads.cpg the code page of the table's text. Sent on its own, a .shp shows shapes with no names; this page draws it anyway and says that the .dbf is missing. Without the .shx it reads the records in order, which works for a normally written file, but QGIS and ArcGIS refuse to open it by default, so keep the .shx with it. Other files beside them (.sbn, .sbx, .qix spatial indexes, .shp.xml metadata) are not needed to see the data and are ignored.

Why place names come out garbled, and how this page avoids it

A .dbf stores text as bytes in a code page, and the shapefile format does not say which one by itself. Read with the wrong one, “Zürich” stored in Windows-1252 (the ü is the single byte FC) becomes “Z�rich” in a UTF-8 reader, and “Zürich” stored as UTF-8 (C3 BC) becomes “Zürich” in a Windows-1252 reader. This page decodes in this order: the code page named in the .cpg file (“UTF-8”, “1252”, “ANSI 1251”, “CP1250”, “88591”, “SJIS” and similar); otherwise the language driver byte at offset 29 of the .dbf header (for example 0x57 for ANSI Windows-1252, 0xC9 for Cyrillic 1251, 0x26 for DOS 866); otherwise UTF-8 if every text value is valid UTF-8; otherwise Windows-1252, with a note saying it guessed. The code page used, and where it came from, is shown above the table.

Polygons with holes: a worked example

A shapefile polygon is a list of rings, and the direction each ring runs is what makes it an outline or a hole: the ESRI specification has outer rings run clockwise and holes counter-clockwise. Take a 10 × 10 square parcel with a 4 × 4 courtyard cut out of its middle. The outer ring (0,0) → (0,10) → (10,10) → (10,0) is clockwise; the shoelace formula gives it a signed area of −100. The courtyard ring (3,3) → (7,3) → (7,7) → (3,7) is counter-clockwise, signed area +16. So the parcel's area is 100 − 16 = 84, and a tap at (5, 5), in the courtyard, does not select it. A reader that treats every ring as an outline counts 100 + 16 = 116 and turns the courtyard into a second parcel. When this page saves GeoJSON it writes the rings the other way round, outer counter-clockwise and holes clockwise, as the GeoJSON standard (RFC 7946) asks, without changing any coordinate.

Files it opens

.shp, .shx, .dbf, .prj, .cpg
Read with a reader written for this page from the ESRI Shapefile Technical Description (1998) and the dBASE file layout, with no GIS library. All 14 shape types: Null, Point, MultiPoint, PolyLine, Polygon, their Z and M variants, and MultiPatch (drawn as the outlines of its parts).
A ZIP from a download portal
Unpacked in the page. When it holds several shapefiles (a whole dataset, or one per region), they are listed and the first is opened; tap another to switch.
A .dbf on its own
Any dBASE III, dBASE IV or Visual FoxPro table opens as a searchable table that saves as CSV, map or not.

What this cannot do