如何获得以平方米为单位的WGS84多边形的面积?


10

下面以平方度给我了多边形的面积:

SELECT ST_Area(ST_GeomFromText('POLYGON((871325.790874952 6105405.3261047,871418.748307692 6105359.72944624,871346.22022442 6105215.141258,871254.85408906 6105261.72007212,871325.790874952 6105405.3261047))',4326)) As sqm;

结果:16586.2319335938

如何获得以平方米为单位的面积?我尝试了以下方法:

SELECT ST_Area(ST_Transform(ST_GeomFromText('POLYGON((871325.790874952 6105405.3261047,871418.748307692 6105359.72944624,871346.22022442 6105215.141258,871254.85408906 6105261.72007212,871325.790874952 6105405.3261047))',4326)),31467) As sqm;

但是似乎ST_Transform不起作用。我收到以下错误消息:

ERROR:  function st_transform(geometry) does not exist
LINE 1: SELECT ST_Area(ST_Transform(ST_GeomFromText('POLYGON((871325...
                       ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********
 ERROR: function st_transform(geometry) does not exist
SQL Status:42883
Hint:No function matches the given name and argument types. You might need to add explicit type casts.

缺少Proj支持应该不是问题,使用SELECT PostGIS_full_version()

"POSTGIS="1.5.3" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.8.0, 6 March 2012" LIBXML="2.8.0" USE_STATS"

Answers:


7

在查询结束时,您在错误的位置有一个结束括号。我尝试了这个,得到了NaN回报,

SELECT ST_AREA(ST_Transform(ST_GeomFromText('POLYGON((871325.790874952 6105405.3261047,871418.748307692 6105359.72944624,871346.22022442 6105215.141258,871254.85408906 6105261.72007212,871325.790874952 6105405.3261047))',4326),31467)) As sqm;

NaN结果是由于多边形超出了投影范围。


而已!谢谢!除此之外,预测值必须为900913和31467:SELECT ST_AREA(ST_Transform(ST_GeomFromText('POLYGON((871325.790874952 6105405.3261047,871418.748307692 6105359.72944624,871346.22022442 6105215.141258,871254.85408906 6105261.72007212,871325.790874952 6105405.3261047))',900913),31467)) As sqm;
Mark

2
ST_Transform(geometry,target_CRS) 

是正确的语法。您似乎混淆了一些逗号。


2

这两个查询都将多边形的SRID定义为4326,但是根据数据,肯定不是这种情况。SRID 4326(WGS84)的范围限制为纬度[-90,90],经度[-180,180]。

如果4326中有面数据,则使用ST_GeogFromText可能是更好的方法。假设您的数据位于4326,并且地理要素的度量单位为米。

一个有效的查询如下:

SELECT
ST_Area(
ST_Transform(
ST_SetSRID(
ST_GeomFromText(
'POLYGON((-98.4854749658124 29.3495134003054,-97.4374094977531 29.4150174920591,-97.2408972224919 28.4979602075071,-98.354466782305 28.4324561157534,-98.4854749658124 29.3495134003054))'
)
, 4326)
, 900913)
)

我将其转换为900913,而不是31467,因为SRID并未覆盖示例数据的区域。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.