0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SQLで3次メッシュコードをWKT形式に変換する

Last updated at Posted at 2021-10-02

次のような3次メッシュコードをWKTに変換したいとき

mesh3
mcode3
55370046
54390560

以下で変換できる。クエリエンジンはPrestoを想定

convert_wkt
WITH base as (
  SELECT
    ,cast(cast(substr(mcode3,3,2) as double) +100 + cast(substr(mcode3,6,1) as double) * 1/8   + cast(substr(mcode3,8,1) as double) * 1/8/10 as varchar) as west
    ,cast(cast(substr(mcode3,3,2) as double) +100 + cast(substr(mcode3,6,1) as double) * 1/8   + (cast(substr(mcode3,8,1) as double)+1) * 1/8/10 as varchar) as east
    ,cast(cast(substr(mcode3,1,2) as double) /1.5 + cast(substr(mcode3,5,1) as double) * 2/3/8 + cast(substr(mcode3,7,1) as double) * 2/3/8/10 as varchar) as south
    ,cast(cast(substr(mcode3,1,2) as double) /1.5 + cast(substr(mcode3,5,1) as double) * 2/3/8 + (cast(substr(mcode3,7,1) as double)+1) * 2/3/8/10 as varchar) as north
  FROM mesh3
)
SELECT
  'POLYGON((' || west || ' ' || south || ',' ||  west || ' ' || north || ',' ||  east || ' ' || north  || ',' ||  east || ' ' || south || ',' || west || ' ' || south || '))'
FROM base

参考:GISソフトウエアでメッシュコードに対応した値を表示する方法

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?