GEOJSONはこの前やってできたので今度はKMLでポリゴンデータを出力させたいと思います。
地図会社によって仕様も違うのでKMLも覚えておくとよいかと思います。
PostGISの関数としては、ST_AsKmlを使って書き出します。
目次
クエリ
select ST_AsKml(ST_Transform(geom,4326)) FROM "gis" AS
念のため、4326に変換してます。
出力結果
<Polygon> <outerBoundaryIs> <LinearRing> <coordinates>139.77993836890397,35.682253867534506 139.779680869718334,35.682212064625922 139.779548587536368,35.68217003549109 139.779396858574188,35.682095710089015 139.779258852144181,35.681983293625635 139.778870831893755,35.681612957798478 139.778586974557925,35.681268371285832 139.778236888992723,35.6807173185381 139.777969328170087,35.680318550037775 139.77795476398029,35.680294318971747 139.777721337553203,35.679931972562926 139.77756217504276,35.679672613679138 139.777317819897632,35.67929209311027 139.777069754865693,35.678920619219049 139.77687417220443,35.678595681624508 139.776825639520268,35.678504923080197 139.776693048655915,35.678315079697782 139.776546017155965,35.678080935362523 139.776032947375711,35.678300260901807 139.776019985432299,35.678299761794527 139.775547644392447,35.678496992853141 139.775526303811233,35.678460998144971 139.775387649679828,35.678514520882544 139.775415211873053,35.678555060678221 139.775130839822026,35.678679812873597 139.775123269786491,35.67868244995244 139.775604616795988,35.679487613946471 139.77650216388264,35.680954425049173 139.77665873864899,35.68121029828712 139.776729706531881,35.681326277647244 139.776705934992265,35.681339188476954 139.777292109231411,35.682256713986504 139.777304481338319,35.682260768874684 139.778041140731347,35.68341842109114 139.778080795512523,35.683544525656814 139.778102822498482,35.683566612319595 139.778162123968286,35.683795362483508 139.778398190283724,35.683639068421975 139.778656446530846,35.684023923652148 139.778651885980196,35.68402702004466 139.778657172316827,35.684035472801241 139.779526055894024,35.683445923773562 139.779571064636997,35.683410910110489 139.779952790438017,35.682266936774973 139.77993836890397,35.682253867534506</coordinates> </LinearRing> </outerBoundaryIs> </Polygon>
あとは、KMLのフォーマットに従ってPolygon部分に上部の内容を記述すればOKです。
境界線のみにしたい場合は
select ST_AsKml(ST_ExteriorRing(ST_Transform(geom,4326))) FROM "gis" AS
境界線のみの結果
<LineString> <coordinates>139.77993836890397,35.682253867534506 139.779680869718334,35.682212064625922 139.779548587536368,35.68217003549109 139.779396858574188,35.682095710089015 139.779258852144181,35.681983293625635 139.778870831893755,35.681612957798478 139.778586974557925,35.681268371285832 139.778236888992723,35.6807173185381 139.777969328170087,35.680318550037775 139.77795476398029,35.680294318971747 139.777721337553203,35.679931972562926 139.77756217504276,35.679672613679138 139.777317819897632,35.67929209311027 139.777069754865693,35.678920619219049 139.77687417220443,35.678595681624508 139.776825639520268,35.678504923080197 139.776693048655915,35.678315079697782 139.776546017155965,35.678080935362523 139.776032947375711,35.678300260901807 139.776019985432299,35.678299761794527 139.775547644392447,35.678496992853141 139.775526303811233,35.678460998144971 139.775387649679828,35.678514520882544 139.775415211873053,35.678555060678221 139.775130839822026,35.678679812873597 139.775123269786491,35.67868244995244 139.775604616795988,35.679487613946471 139.77650216388264,35.680954425049173 139.77665873864899,35.68121029828712 139.776729706531881,35.681326277647244 139.776705934992265,35.681339188476954 139.777292109231411,35.682256713986504 139.777304481338319,35.682260768874684 139.778041140731347,35.68341842109114 139.778080795512523,35.683544525656814 139.778102822498482,35.683566612319595 139.778162123968286,35.683795362483508 139.778398190283724,35.683639068421975 139.778656446530846,35.684023923652148 139.778651885980196,35.68402702004466 139.778657172316827,35.684035472801241 139.779526055894024,35.683445923773562 139.779571064636997,35.683410910110489 139.779952790438017,35.682266936774973 139.77993836890397,35.682253867534506</coordinates> </LineString>