cgisgeojsongdalgrass

Parse geojson files with C


I can't find any simple C source file or library to parse geojson files (implementing rfc7946 standard).

Maybe such parsers exist in projects like GRASS or GDAL? But I still have a little trouble navigating the world of C libraries.

Some tracks ?


Solution

  • GeoJSON is in JSON format, so you can use JSON parsers. There are several out there:

    https://github.com/search?l=C&q=json+parser&type=Repositories

    You should add checks and other stuff yourself.

    If you need a certain representation of data, you can write it yourself. Mapbox wrote a C++ version of GeoJSON parser for converting GeoJSON into geometry.hpp representation based on RapidJSON in less than 1k lines of code.

    A standard-compliant (RFC 7946) implementation of GeoJSON in C can be found inside SpatiaLite, but may be it's easier for you to use typical JSON parsers instead. You can take a look in virtualgeojson.c if you want to use this library.