[英]Input geometry has unknown (0) SRID
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但是,当我添加执行坐标转换的行和查询
geom
的行时,我在运行 Web 服务时收到以下错误
Input geometry has unknown (0) SRID
i am new to postgis and i hope to help me to fix this issue我是 postgis 的新手,我希望能帮助我解决这个问题
code :代码:
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)
Some PostGIS functions rely on SRS, such as ST_Transform
.一些 PostGIS 函数依赖于 SRS,例如
ST_Transform
。 You have to specify which SRS you're transforming from, otherwise the conversion script has no reference to compute the new coordinates, eg from EPSG:25832
to EPSG:4326
:您必须指定要转换的 SRS,否则转换脚本没有参考来计算新坐标,例如从
EPSG:25832
到EPSG:4326
:
SELECT ST_Transform('SRID=25832;POINT(1 1)',4326);
.. otherwise it will raise an exception ..否则会引发异常
SELECT ST_Transform('POINT(1 1)',4326); -- <-- WKT literal without SRS
ERROR: ST_Transform: Input geometry has unknown (0) SRID
With ST_SetSRID
you can set the SRS to geometries in case they haven't any - as your example suggests, eg .使用
ST_SetSRID
,您可以将 SRS 设置为几何图形,以防它们没有任何几何图形 - 正如您的示例所暗示的那样,例如 .
SELECT ST_Transform(
ST_SetSRID('POINT(1 1)'::geometry,25832),
4326);
The same principle goes for CREATE TABLE
and INSERT
/ UPDATE
statements. CREATE TABLE
和INSERT
/ UPDATE
语句的原理相同。 When creating a table we declare the SRS as follows..创建表时,我们将 SRS 声明如下..
CREATE TABLE t (geom geometry(point,4326));
.. so PostGIS expects that all incoming geometries have the same SRS.. .. 所以 PostGIS 期望所有传入的几何图形都具有相同的 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.