8
8

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.

WebGIS

8
Last updated at Posted at 2015-08-13

Ubuntu + Geoserver + PostGis <=> Ubuntu + GeoWebCache

GIS基礎

地図表現

実世界をデジタル地図で表現する場合、実世界を個別の図形で表現する**「ベクタデータ」と、セルで表現する「ラスタデータ」**の2つの表現方法があります。

実際の地図

実世界.jpg

ベクタデータ

ベクトルで表現(ベクタデータ).gif
ベクタデータは長さと方向を持ち、それぞれ「点」(ポイント)、「線」(ライン)、「面」(ポリゴン)で、基準点(X0、Y0)からの「X方向にいくつ、Y方向にいくつの位置である」という情報をもっています。

ラスタデータ

ラスタで表現(ラスタデータ).gif
ラスタデータは座標で表現されるデータです。一般的なフォーマットとしては、BMP、JPEG、TIFF等が挙げられます。

Shapefileとは

ベクタデータの一種であり、
下記の三種類ファイルに構成され、各ファイルの名前は同じでなければならない。

  • メイン ファイル:counties.shp
  • インデックス ファイル:counties.shx
  • 属性ファイル:counties.dbf

環境作成

# Geoserverに必要なライブラリを入れておく
$ sudo apt-get install gdal-bin openjdk-7-jdk openjdk-7-jre python-gdal unzip
# Tomcatインストール
$ apt-get install tomcat7
# ブラウザで localhost:8080 確認 or
$ wget -pO- 127.0.0.1:8080
# GeoServer安定版ダウンロード(WAR式) http://geoserver.org/ にて最新版確認
$ cd ~/Downloads
$ wget http://sourceforge.net/projects/geoserver/files/GeoServer/2.7.2/geoserver-2.7.2-war.zip
$ sudo unzip geoserver-2.7.2-war.zip
$ sudo mv geoserver.war /var/lib/tomcat7/webapps/
$ sudo service tomcat7 restart
# ブラウザで localhost:8080/geoserver 確認

GeoWebCacheについて

user情報

/var/lib/tomcat7/webapps/geowebcache/WEB-INF/users.propertiesに記述されている

cache folder設定

  1. /var/lib/tomcat7/webapps/geowebcache/WEB-INF/web.xmlにて、<web-app>ノードの直下に下記の要素を追加
<context-param>
   <param-name>GEOWEBCACHE_CACHE_DIR</param-name>
   <param-value>/var/lib/tomcat7/webapps/geowebcache/cacheDir</param-value>
</context-param>
  1. cacheDir 作成
$ cd /var/lib/tomcat7/webapps/geowebcache
$ sudo mkdir cacheDir
$ sudo chmod 777 cacheDir
  1. 設定ファイルのロード
    localhost:8080/geowebcache/demoにアクセスして、Reload Configurationボタンを押す
  2. 設定結果の確認
$ cd cacheDir
$ ls -al
# diskquota_page_store tmp geowebcache.xml 三つ生成されたことを確認できればOK

★ geowebcache.xml はキャッシュするLayerの配置ファイルである。
念のため、localhost:8080/geowebcache/homeにて、ページの一番下に

Storage Locations
  Config file:/var/lib/tomcat7/webapps/geowebcache/geowebcache.xml
  Local Storage:/var/lib/tomcat7/webapps/geowebcache

となっていれば、設定が正しく反映されている。

Layers配置ファイル編集

<wmsLayer>
    <name> layer_name </name>
    <wmsUrl>
        <string>wms_url</string>
    </wmsUrl>
    <wmsLayers>layer1,layer2,layer3</wmsLayers>
</wmsLayer>
  • Layers配置ファイル:geowebcache.xml
    /tmp/tomcat7-tomcat7-tmp/geowebcache

geoserverについて

GeoServer設定

レイヤ作成

  • dataフォルダ作成
    下記のフォルダにフォルダを作って、登録したいmapデータを保存
    /var/lib/tomcat7/webapps/geoserver/data
  • Workspaceの作成
    提供したいサービスをチェック
    • WCS
    • WFS
    • ☑ WMS
  • Data Storeの作成
    mapデータファイルをgeoserverに登録する
  • Layerの作成
    登録したmapデータをレイヤに変換
  • LayerPreviewにて確認
    openlayersにてレイヤが正しく表示されるか確認
  • スタイルの作成

OpenLayersを使って、レイヤ表示

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>GIS Chou</title>
    // Import OpenLayers Script
    <script src="http://openlayers.org/api/OpenLayers.js"></script>
</head>
<body>
    // create block element(div) to contain map, id is used to add map
    <div style="width: 100%; height: 500px; background-color: pink" id="map"></div>
    <script defer="defer" type="text/javascript">
        // 初期化
        var options = {
            controls: [
                new OpenLayers.Control.MousePosition(),
                new OpenLayers.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                }),
                new OpenLayers.Control.Attribution(),
                new OpenLayers.Control.Zoom(),
                new OpenLayers.Control.ScaleLine({
                    maxWidth: 150,
                    bottomOutUnits: "",
                    bottomInUnits: ""
                })
            ],
            maxExtent: new OpenLayers.Bounds(-10, -50, 1000000, 50),
            minResolution: 0.001,
            maxResolution: 0.1,
            projection: "EPSG:404000",
            units: "m"
        };
        // create map 'map' is the id of div
        var map = new OpenLayers.Map('map',options);
        // create wmsLayer to be added
        var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                "http://192.168.111.148:8080/geoserver/sakai/wms",
                {
                    // ,でレイヤを分割する、スペースが入るとおかしくなる
                    layers: 'sakai_1,sakai_2,sakai_3',
                    format: 'image/png',
                    tiled: true,
                    transparent: false,
                    isBaseLayer: true
                } );
        // add Layer
        map.addLayer(wmsLayer);
        // 見えるようにmapの中心値をセットする、geoserverにてlayer previewを使って座標を確認しておく
        map.setCenter(new OpenLayers.LonLat(47.62695, 1.60855));
    </script>
</body>
</html>

GeoWebCache設定

todo

How to integrate Standalone GeowebCache with Geoserver on different machine
http://gis.stackexchange.com/questions/143220/how-to-integrate-standalone-geowebcache-with-geoserver-on-different-machine

8
8
1

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
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?