Overview
editEvery 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.
| Format | Class | Use it for |
|---|---|---|
| GeoJSON | GeoJson | web maps and APIs: the default choice |
| TopoJSON | TopoJson | compact maps of regions that share borders, such as world-atlas |
| Shapefile | Shapefile | the data of GIS software and of public agencies |
| KML and KMZ | Kml, Kmz | Google Earth and Google My Maps |
| GPX | Gpx | GPS devices and sport apps: waypoints, routes and tracks |
| WKT and WKB | WellKnownText, WellKnownBinary | a single geometry, in a database (PostGIS, SQL Server, SQLite) or a CSV file |
| Encoded polyline | EncodedPolyline | the routes of Google Maps, OSRM and Valhalla |
| FlatGeobuf | FlatGeobuf | large 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 aJsonExceptionor anXmlException, 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.