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. GeoJSON, Shapefile, FlatGeobuf, GeoPackage and GeoParquet also have ReadFeaturesAsync, which returns the features of a large file one at a time instead of a collection.
| 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 |
| GeoPackage | GeoPackage | the layers of GDAL, QGIS and ArcGIS in a SQLite file; read only, in the Meziantou.Framework.Geo.GeoPackage package |
| GeoParquet | GeoParquet | large datasets in Parquet files, as data lakes and cloud catalogs store them; read only, in the Meziantou.Framework.Geo.GeoParquet package |
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.
ReadandParseload the whole document in memory: check the size of the files you accept from users. TheReadFeaturesAsyncmethods of GeoJson, Shapefile, FlatGeobuf and GeoPackage read the features one at a time, with bounded memory: only the feature being read is in memory, so its size is the limit. The one of GeoParquet holds a row group at a time.