Search code examples
postgresqlpostgis

Cannot use ST_GeomFromGeoJSON even when JSON-C is installed


I have a Postgres database with the Postgis extension created on it.

I want to use the ST_GeomFromGeoJSON function. The docs state:

If you do not have JSON-C enabled, you will get an error notice instead of seeing an output. To enable JSON-C, run configure --with-jsondir=/path/to/json-c. See Section 2.2.3, “Build configuration” for details.

So I ensure that I have JSON-C installed and I configure Postgis with it...

# install json-c
curl -L --output /tmp/json-c.tar.gz https://s3.amazonaws.com/json-c_releases/releases/json-c-0.10-nodoc.tar.gz
tar -xvf /tmp/json-c.tar.gz -C /tmp/
mkdir -p /var/lib/include
cp -r /tmp/json-c-0.10 /var/lib/include/json-c

# install postgis
curl https://download.osgeo.org/postgis/source/postgis-3.0.3.tar.gz -o ./postgis-3.0.3.tar.gz \
    && tar xvzf postgis-3.0.3.tar.gz

# configure postgis
cd /tmp/postgis-3.0.3
./configure --without-raster --with-jsondir=/var/lib \
    && make \
    && make install

then, I run the following in the database

postgres=# create extension postgis;
CREATE EXTENSION
postgres=# select ST_GeomFromGeoJSON('{"type": "Point", "coordinates": [0,0]}');
ERROR:  You need JSON-C for ST_GeomFromGeoJSON

Why am I getting that error? I am including JSON-C when I am configure postgis, no? Am I missing something in my installation steps?

Postgres: 12.7

Postgis: 3.0.3


Solution

  • It turns out I was installing json-c incorrectly. When I installed it like so:

    apt-get install libjson-c-dev
    

    and used the following with ./configure:

    --with-jsondir=/usr
    

    it worked.

    you can see that json-c headers are installed at /usr/include/json-c

    ls /usr/include/json-c
    arraylist.h    json_c_version.h  json_object_iterator.h  linkhash.h
    bits.h         json.h        json_object_private.h   printbuf.h
    debug.h        json_inttypes.h   json_tokener.h      random_seed.h
    

    thus, /usr becomes your --with-jsondir