输入几何具有未知 (0) SRID [英] Input geometry has unknown (0) SRID

查看:156
本文介绍了输入几何具有未知 (0) SRID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面发布的我做了一些查询,它工作正常.但是,当我添加进行坐标转换的行和查询 geom 的行时,我在运行 Web 服务时收到以下错误

in the below posted i make some queries and it works fine. however when i add the lines that do the coordinates conversion and the line that query the geom i receive the following error when i run the web-service

Input geometry has unknown (0) SRID

我是 postgis 的新手,希望能帮我解决这个问题

i am new to postgis and i hope to help me to fix this issue

代码:

query = """  WITH data AS (
        SELECT '{featuresArray}'::json AS featuresCollection
        )
        SELECT gid,geom,type::text,properties::text,
        array_to_string(array_agg(x_4326||' '||y_4326 ORDER BY gid),',') AS g4326,
        array_to_string(array_agg(x_25832||' '||y_25832 ORDER BY gid),',') AS g25832             
        FROM (
        SELECT
        ROW_NUMBER() OVER () AS gid,
        ST_AsText(ST_GeomFromGeoJSON(feature->>'geometry')) AS geom,
        feature->>'type' AS type,
        feature->>'properties' AS properties,
        ST_X((ST_DumpPoints((ST_GeomFromGeoJSON(feature->>'geometry')))).geom) x_4326,       
        ST_Y((ST_DumpPoints((ST_GeomFromGeoJSON(feature->>'geometry')))).geom) y_4326,  
        ST_X((ST_DumpPoints((ST_Transform(ST_GeomFromGeoJSON(feature->>'geometry'),25832)))).geom) x_25832,       
        ST_X((ST_DumpPoints((ST_Transform(ST_GeomFromGeoJSON(feature->>'geometry'),25832)))).geom) y_25832

        FROM (SELECT json_array_elements(featuresCollection->'features') AS feature FROM data) AS f) j
        GROUP BY gid,type::text,properties::text,geom
        ORDER BY gid;""".format(featuresArray=featuresArray)

推荐答案

一些 PostGIS 功能依赖于 SRS,例如 ST_Transform.您必须指定要从哪个 SRS 进行转换,否则转换脚本没有参考来计算新坐标,例如从 EPSG:25832EPSG:4326:

Some PostGIS functions rely on SRS, such as ST_Transform. You have to specify which SRS you're transforming from, otherwise the conversion script has no reference to compute the new coordinates, e.g. from EPSG:25832 to EPSG:4326:

SELECT ST_Transform('SRID=25832;POINT(1 1)',4326);

...否则会引发异常

SELECT ST_Transform('POINT(1 1)',4326); -- <-- WKT literal without SRS
ERROR:  ST_Transform: Input geometry has unknown (0) SRID

使用 ST_SetSRID,您可以将 SRS 设置为几何图形如果他们没有 - 正如你的例子所暗示的,例如.

With ST_SetSRID you can set the SRS to geometries in case they haven't any - as your example suggests, e.g. .

SELECT ST_Transform(
         ST_SetSRID('POINT(1 1)'::geometry,25832),
         4326);

同样的原则适用于 CREATE TABLEINSERT/UPDATE 语句.创建表时,我们按如下方式声明 SRS ..

The same principle goes for CREATE TABLE and INSERT / UPDATE statements. When creating a table we declare the SRS as follows ..

CREATE TABLE t (geom geometry(point,4326));

.. 所以 PostGIS 期望所有传入的几何图形具有相同的 SRS ..

.. so PostGIS expects that all incoming geometries have the same SRS ..

INSERT INTO t VALUES ('SRID=4326;POINT(1 1)'); 

...否则它也会引发异常

.. otherwise it raises an exception too

INSERT INTO t VALUES ('SRID=25832;POINT(1 1)'); 
ERROR:  Geometry SRID (25832) does not match column SRID (4326)

这篇关于输入几何具有未知 (0) SRID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆