これは何?

サンプルデータのダウンロード

Raster テーブルを作る

# psql -U gis -h localhost -W
ユーザ gis のパスワード:
psql (9.6.2)
"help" でヘルプを表示します.

gis=> \d
                  リレーションの一覧
 スキーマ |       名前        |     型     |  所有者
----------+-------------------+------------+----------
 public   | geography_columns | ビュー     | postgres
 public   | geometry_columns  | ビュー     | postgres
 public   | raster_columns    | ビュー     | postgres
 public   | raster_overviews  | ビュー     | postgres
 public   | spatial_ref_sys   | テーブル   | postgres
 topology | layer             | テーブル   | postgres
 topology | topology          | テーブル   | postgres
 topology | topology_id_seq   | シーケンス | postgres
(8 行)

gis=> CREATE TABLE wmap_tbl (
gis(>   id bigserial primary key,
gis(>   rast raster,
gis(>   filename text
gis(> );
CREATE TABLE
gis=> CREATE INDEX idx_wmap_tbl_id ON wmap_tbl USING GiST (ST_ConvexHull(rast));
CREATE INDEX
gis=> \q

index に指定した ST_ConvexHull?(raster) は、raster の凸なジオメトリ


コピペ用

CREATE TABLE wmap_tbl (
  id bigserial primary key,
  rast raster,
  filename text
);
CREATE INDEX idx_wmap_tbl_id ON wmap_tbl USING GiST (ST_ConvexHull(rast));

※ テーブル名は小文字にする。ラスタ制約テーブルのテーブル名列に、テーブル名が小文字化されて入るので、テーブル名は小文字で入れる。実害はないかもしれないけれども、少なくとも大文字テーブル名にラスタ制約を入れても gdalinfo は警告を出す。

Table へ Raster 画像を登録する

ラスタ制約をつける

# gdalinfo 'PG:host=localhost dbname=gis user=gis password=password table=wmap_tbl mode=2'
Warning 1: Cannot find (valid) information about public.wmap_tbl table in raster_columns view. The raster table load would take a lot of time. Please, execute AddRasterConstraints PostGIS function to register this table as raster table in raster_columns view. This will save a lot of time.
Driver: PostGISRaster/PostGIS Raster driver
Files: none associated
Size is 10800, 5400
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]]
Origin = (-180.000000000000000,90.000000000000000)
Pixel Size = (0.033333333333312,-0.033333333333312)
Corner Coordinates:
Upper Left  (-180.0000000,  90.0000000) (180d 0' 0.00"W, 90d 0' 0.00"N)
Lower Left  (-180.0000000, -90.0000000) (180d 0' 0.00"W, 90d 0' 0.00"S)
Upper Right ( 180.0000000,  90.0000000) (180d 0' 0.00"E, 90d 0' 0.00"N)
Lower Right ( 180.0000000, -90.0000000) (180d 0' 0.00"E, 90d 0' 0.00"S)
Center      (  -0.0000000,   0.0000000) (  0d 0' 0.00"W,  0d 0' 0.00"N)
Band 1 Block=2048x2048 Type=Byte, ColorInterp=Red
Band 2 Block=2048x2048 Type=Byte, ColorInterp=Green
Band 3 Block=2048x2048 Type=Byte, ColorInterp=Blue

"mode=2" は、テーブル全体を一枚のラスタ画像と見なす。
それはそうと、AddRasterConstraints? でラスタ制約を付けないと、検索がめちゃ遅いよという警告が出る。
ということで

# psql -U gis -h localhost -W
ユーザ gis のパスワード:
psql (9.6.2)
"help" でヘルプを表示します.

gis=> SELECT AddRasterConstraints('wmap_tbl','rast');
NOTICE:  Adding SRID constraint
NOTICE:  Adding scale-X constraint
NOTICE:  Adding scale-Y constraint
NOTICE:  Adding blocksize-X constraint
NOTICE:  Adding blocksize-Y constraint
NOTICE:  Adding alignment constraint
NOTICE:  Adding number of bands constraint
NOTICE:  Adding pixel type constraint
NOTICE:  Adding nodata value constraint
NOTICE:  Adding out-of-database constraint
NOTICE:  Adding maximum extent constraint
 addrasterconstraints
----------------------
 t
(1 行)

AddRasterConstraints?は、現在入っている raster 画像がぎりぎり満たす制約になっている。この制約外の raster 画像を追加する場合は、いったん制約を削除してから追加する

gis=> SELECT DropRasterConstraints('wmap_tbl','rast');
... raster 追加
gis=> SELECT AddRasterConstraints('wmap_tbl','rast');

GDAL でラスタ画像を切り出してみる

# gdal_translate -projwin 123 46 154 20 'PG:host=localhost dbname=gis user=gis password=password table=wmap_tbl mode=2' jp.tif
Input file size is 10800, 5400
Computed -srcwin 9090 1320 930 780 from projected window.
0...10...20...30...40...50...60...70...80...90...100 - done.

$ scp -i .vagrant/machines/gis/virtualbox/private_key -P 2222 vagrant@localhost:/home/vagrant/HYP_50M_SR_W/jp.tif ./
jp.png

Mapserver から Postgis の raster テーブルを参照する

衛星写真を重ね合わせる


GIS


添付ファイル: filealos2_2.png 1816件 [詳細] filealos2_1.png 1700件 [詳細] filescreen.png 1828件 [詳細] filejp.png 1812件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2017-02-26 (日) 15:16:29 (2609d)
Short-URL: https://at-sushi.com:443/pukiwiki/index.php?cmd=s&k=6e96eca5d1
ISBN10
ISBN13
9784061426061