Overview

edit

Every format is a static class. The classes of the formats that hold features have the same methods: Read reads a stream, Parse reads a string, Write writes to a stream and Format returns a string. They all return and take a GeoFeatureCollection.

FormatClassUse it for
GeoJSONGeoJsonweb maps and APIs: the default choice
TopoJSONTopoJsoncompact maps of regions that share borders, such as world-atlas
ShapefileShapefilethe data of GIS software and of public agencies
KML and KMZKml, KmzGoogle Earth and Google My Maps
GPXGpxGPS devices and sport apps: waypoints, routes and tracks
WKT and WKBWellKnownText, WellKnownBinarya single geometry, in a database (PostGIS, SQL Server, SQLite) or a CSV file
Encoded polylineEncodedPolylinethe routes of Google Maps, OSRM and Valhalla
FlatGeobufFlatGeobuflarge datasets: compact, fast to read, with a spatial index to read a region

Convert a file

Read the file with the class of its format and write the features with the class of the other one. Each page says what a format keeps: a format that has no place for something drops it. For instance, GPX has no polygons, and Shapefile holds a single type of geometry.

Errors and security

  • Invalid data throws a FormatException, with the error of the underlying parser, such as a JsonException or an XmlException, as its inner exception.
  • A position that is not a finite number cannot be written: the writers throw an ArgumentException.
  • The XML readers process no document type definition and resolve no external entity, and no reader downloads anything. The binary readers check every count against the size of the data before they allocate.
  • The readers load the whole document in memory: check the size of the files you accept from users.