我有一个Postgres数据库与Postgis扩展创建在它上面。
我想使用ST_GeomFromGeoJSON函数。文档状态:
如果您没有启用JSON-C,您将得到一个错误通知,而不是看到输出。要启用JSON-C,请执行configure——with-jsondir=/path/To/JSON-C。详细信息请参见章节2.2.3,"构建配置"。
所以我确保我有JSON-C安装,我配置Postgis与它…
# 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
然后,在数据库
中运行以下命令postgres=# create extension postgis;
CREATE EXTENSION
postgres=# select ST_GeomFromGeoJSON('{"type": "Point", "coordinates": [0,0]}');
ERROR: You need JSON-C for ST_GeomFromGeoJSON
为什么我得到这个错误?当我配置postgis时,我包含JSON-C,不是吗?我在安装步骤中遗漏了什么吗?
Postgres: 12.7
Postgis: 3.0.3
原来我安装json-c不正确。当我像这样安装它时:
apt-get install libjson-c-dev
,并对./configure
使用以下命令:
--with-jsondir=/usr
它工作。
你可以看到json-c头文件安装在/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
因此,/usr
成为您的--with-jsondir
可以运行SELECT PostGIS_Full_Version();postgis_full_version
POSTGIS ="3.0.0dev r17211"(扩展)PGSQL ="110";GEOS ="3.8.0dev-CAPI-1.11.0 df24b6bb"SFCGAL ="1.3.6"项目="Rel。5.2.0, 2018.9.15 "GDAL="GDAL 2.3.2, 2018/09/21发布";LIBXML ="2.9.9">LIBJSON ="0.13.1">LIBPROTOBUF ="1.3.1"神户="0.4.3(内部);拓扑光栅(1行)
显示是否集成了LIBJSON。尝试升级到postgis的下一个服务包版本