2
2

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 5 years have passed since last update.

ST_MultiがGeometryCollection型を返したら、Geometry型に変換する

Last updated at Posted at 2015-08-19

多数のポリゴンをST_Unionで結合したあと、ST_Multiでマルチポリゴン化すると、予期せずGeometryCollectionが返ることがある。
GeometryCollectionを扱えない関数が多いので、そんな時にはST_CollectionExtractを利用する。

例)
municipalityテーブルのgeomを、pref-code毎にUNIONしてprefテーブルに登録する。
municipalityテーブルのgeomはシングルポリゴン、prefテーブルに登録する際にはマルチポリゴンにする。


INSERT INTO pref (
	municipality-code,
	population,
	geom)
	SELECT pref-code, count(*), ST_CollectionExtract(ST_Multi(ST_Union(geom)), 3) FROM municipality GROUP BY pref-code;
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?