【问题标题】:How to use geography.ST_GeometryType() function in H2 database?如何在 H2 数据库中使用 geography.ST_GeometryType() 函数?
【发布时间】:2016-02-27 22:12:00
【问题描述】:

Teradata 查询

select F.farm_id, F.name, CASE WHEN geography.ST_GeometryType() = 'ST_POINT' THEN geography.ST_X() ELSE geography.ST_Centroid().ST_X() END as LNG, CASE WHEN geography.ST_GeometryType() = 'ST_POINT' THEN geography.ST_Y() ELSE geography.ST_Centroid().ST_Y() END as LAT from V_farm F, V_farm_workforce FW where F.farm_id=FW.farm_id and FW.account_id='bf064695-b9e3-46a2-a665-0bb794073ae3' and geography is not null

在 Teradata 中运行上述查询时,得到以下响应

FarmId                                           Name                  LNG                        LAT
-----------------------------------------------------------------------------------------------------------
ea66e27f-eba4-4750-bd85-2a1e96941b10             Farm099               -88.9495943               33.5847365
2be7e35e-74a7-49eb-9e9d-5b65dbbf7c5e             VFarmJuly23           -106.6409198              31.8018379
56982275-bcad-40f7-83db-5dbfd9f9c82c             Farm112               -88.95096260000003        33.601958

如果我在 H2 中运行得到以下错误,则相同的查询

Function "ST_GEOMETRYTYPE" not found; SQL statement:

能否请您建议如何在 H2 数据库中进行操作。

【问题讨论】:

    标签: oracle hibernate h2 teradata h2db


    【解决方案1】:

    H2数据库只能存储和查询Geometry类型。

    H2GIS 库中提供了 H2 数据库中的空间函数。该库是 H2 数据库的空间扩展。它为 SQL 标准提供了 OGC 的所有简单功能。

    同样的结果应该在这个查询中

    select F.farm_id, F.name, ST_X(ST_CENTROID(THE_GEOM)) as LNG,
     ST_Y(ST_CENTROID(THE_GEOM)) as LAT 
     from V_farm F, V_farm_workforce FW 
     where F.farm_id=FW.farm_id 
      and FW.account_id='bf064695-b9e3-46a2-a665-0bb794073ae3'
      and the_geom is not null
    

    ST_CENTROID of a point 返回该点本身。

    【讨论】:

    猜你喜欢
    • 2019-02-12
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 2023-03-09
    • 2014-02-27
    • 2017-05-13
    相关资源
    最近更新 更多