【问题标题】:Cannot use ST_GeomFromGeoJSON even when JSON-C is installed即使安装了 JSON-C,也无法使用 ST_GeomFromGeoJSON
【发布时间】:2021-07-30 23:33:03
【问题描述】:

我有一个 Postgres 数据库,上面创建了 Postgis 扩展。

我想使用ST_GeomFromGeoJSON function。文档状态:

如果您没有启用 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

【问题讨论】:

  • 只是猜测:不应该是--with-jsondir=/var/lib/include/json-c 而不是--with-jsondir=/var/lib

标签: postgresql postgis


【解决方案1】:

原来我错误地安装了 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

【讨论】:

    【解决方案2】:

    你能运行 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,9 月2018 年 15 月 15 日" GDAL="GDAL 2.3.2,2018/09/21 发布" LIBXML="2.9.9" LIBJSON="0.13.1" LIBPROTOBUF="1.3.1" WAGYU="0.4.3 (内部)”拓扑栅格 (1 行)

    它会显示是否集成了 LIBJSON。尝试升级到 postgis 的下一个服务包版本

    【讨论】:

      猜你喜欢
      • 2019-09-22
      • 1970-01-01
      • 2020-06-21
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 2023-03-09
      相关资源
      最近更新 更多