0
votes

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

2
Just a guess: shouldn't it be --with-jsondir=/var/lib/include/json-c instead of --with-jsondir=/var/lib? - Jim Jones

2 Answers

0
votes

Can you run SELECT PostGIS_Full_Version(); postgis_full_version

POSTGIS="3.0.0dev r17211" [EXTENSION] PGSQL="110" GEOS="3.8.0dev-CAPI-1.11.0 df24b6bb" SFCGAL="1.3.6" PROJ="Rel. 5.2.0, September 15th, 2018" GDAL="GDAL 2.3.2, released 2018/09/21" LIBXML="2.9.9" LIBJSON="0.13.1" LIBPROTOBUF="1.3.1" WAGYU="0.4.3 (Internal)" TOPOLOGY RASTER (1 row)

It will show if LIBJSON is integrated. Try upgrading to the next service pack version of postgis

0
votes

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