【问题标题】:PostGIS ST_DWithin distance_of_srid Using Degrees, When Should Be MetersPostGIS ST_DWithin distance_of_srid 使用度数,什么时候应该是米
【发布时间】:2013-10-20 15:11:14
【问题描述】:

我在使用 PostGIS ST_DWithin 使用几何点时遇到了一个问题,这让我完全感到困惑。即使我使用 SRID 3857 的几何点(见下文),ST_DWithin 解释似乎将第三个参数(双精度 distance_of_srid)解释为 DEGREES。这是一个例子。

使用此表 test_person_avg_lngs_lats:

       Column        |         Type         | Modifiers 
---------------------+----------------------+-----------
 avg_lng             | double precision     | 
 avg_lat             | double precision     | 
 person_avg_location | geometry(Point,3857) | 
 store_lng           | double precision     | 
 store_lat           | double precision     | 
 store_location      | geometry(Point,3857) |

以及以下查询:

SELECT avg_lat, avg_lng, store_lng, store_lat,
    ST_Distance_Spheroid(person_avg_location, store_location, CAST('SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG","7030\"]]' AS spheroid))/1000 AS distance,
    ST_DWithin(person_avg_location, store_location, 1) AS dwithin
FROM test_person_avg_lngs_lats
WHERE ST_DWithin(person_avg_location, store_location, 1)

查询返回的结果将 ST_DWithin 的第三个参数解释为 1 DEGREE 与 1 METER,即使我使用已确认的 SRID 3857 的几何点使用米单位。无论 N 作为第三个参数传递给 ST_DWithin,结果始终返回 N * 100 公里(~66 英里)左右的距离。这就是为什么我假设 ST_DWithin 将其解释为 1 DEGREE。

这是一个示例结果,应该被解释为一米(距离以英里为单位):

avg_lat         avg_lng        store_lng  store_lat  distance       dwithin
43.3275959623, -71.1169553872, -71.0626,  42.3291,   68.9794023576, true

这是我在这个主题上最接近的东西:ST_DWithin takes parameter as degree , not meters , why?

关于可能导致此问题的原因,或者我在分析问题时可能会寻找什么?

我正在使用:

postgis_full_version                                                                     
------------------------------------------------------------------
 POSTGIS="2.0.0 r9605" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.9.2, released 2012/10/08" LIBXML="2.7.8" LIBJSON="UNKNOWN" RASTER
(1 row)

version                                                   
-------------------------------------------------------------
 PostgreSQL 9.1.9 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, 64-bit
(1 row)

【问题讨论】:

  • 也许 distance_of_srid 3857 实际上是度数,而不是米?如何确认? \n 插入到 spatial_ref_sys (srid, auth_name, auth_srid, proj4text, srtext) 值 ( +units=m +no_defs ', 'PROJCS["WGS 84 / Pseudo- [SNIPS] Mercator",Sphere",6378137,0,AUTHORITY[ "EPSG","7059"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6055"]],PRIMEM["Greenwich",0,AUTHORITY[" EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4055"]],UNIT["meter",1,AUTHORITY ["EPSG","9001"]],PROJECTION["Mercator_1SP"],

标签: postgis


【解决方案1】:

显然,distance_of_srid 使用与 SRID 相同的距离单位,通常是度或米。对于geometry 类型,距离是在平面笛卡尔平面using maths familiar to most high school students 上计算的。这些单位geometry 类型解释。

但是,这假定数据实际上是使用正确的 SRID 投影的。如果您将投影的 SRID(如 3857)与以度数表示的纬度/经度坐标混合,您将得到无法解释的垃圾。查看您是如何填充 person_avg_locationstore_location 列的,因为我 99.9% 确定那里存在错误。

【讨论】:

    猜你喜欢
    • 2018-01-25
    • 2012-01-16
    • 2023-04-02
    • 2011-04-15
    • 2017-04-10
    • 2012-03-19
    • 2018-05-12
    • 2018-12-11
    • 1970-01-01
    相关资源
    最近更新 更多