背景
應用狀況
- GIS用作CMAQ或其他模式模擬結果的顯示界面,雖然有些大材小用,也有其應用上的必要性。
- GIService在提供遠端使用者地理資訊的過程中,為不可或缺的重要伺服器。常用的免費軟體有MapServer 及GeoServer等2款。前者適用大型數據如NASA就是其最早的支持者、後者則為中小型機構所愛用。
- GeoServer可以直接讀取自帶網格經緯度座標的nc檔
- 目前運作的案例多為UCAR的氣候檔案分析以及NetCDF Java之toolsUI、
- 也可以自nc檔中地理座標相關屬性計算網格座標,並將格柵資訊、在指定範圍、指定解析度,進行圖磚製作,啟動WMS或向量檔的TMS服務,前者格式如png,jpeg,後者格式也包括了geojson等等。
- 尚無WRF、CMAQ等模式IO之應用。主要的理由是GIS系統的約定是LL網格系統,等間距的格柵檔案需要轉換格點系統(resampling or regrid)。
資源需求及限制
- GeoServer基本上是平行化接受使用者(也包括本地圖磚製作)的呼叫,使用超過一個以上的核心、也可以限定平行作業的上限數。實則java只是使用單一個pid進行運送,並沒有傳統同步運作的形式。
- 記憶體需求量大。
- 以IMac 16GB記憶體而言,執行node.js再執行geoserver的start.jar,記憶體就可以達到8成,將會對其他記憶體較大的作業造成排擠。
- 以node03 DEC工作站而言,平時記憶體最大6G、加上start.jar會再加上1.5G,對於夜間下載分析工作(get_all.cs)而言,平時記憶體(Cach)使用即超過9成,geoserver工作不適合放在夜間運作時段。
下載與啟動
install
- 通用start.jar
- MacOS: brew install geoserver
startup
- modify start.ini
- Connector port to listen on:
jetty.http.port=8080
- Connector host/address to bind to:
jetty.http.host=125.229.149.182
- Connector port to listen on:
$ cat ~/MyPrograms/geoserver/geoserv.cs
n=$(ps -ef|grep start.jar|grep java|wc -l)
if ! [[ $n -eq 1 ]];then
GEOSERVER_HOME=~/MyPrograms/geoserver/bin
cd $GEOSERVER_HOME
d=$(date +%Y%m%d)
./startup.sh >& $GEOSERVER_HOME/../logs/$d.log
fi
crontab
# geoserver
0 * * * * ~/MyPrograms/geoserver/geoserv.cs
authentication
- first time: admin/geoserver
重要工具
NetCDF plugin
- How to install NetCDF plugin to GeoServer
- gis.stackexchange
- copyprogramming
- 目前wrf/CMAQ等nc檔皆為等間距座標系統,不符合GIS之等經緯度系統(網格點的經緯度必須為1維),無法應用。
There was an error trying to connect to store PM25.nc. Do you want to save it anyway?
Original exception error:
Failed to create reader from file:///nas2/cmaqruns/2022fcst/grid09/cctm.fcst/daily/PM25.nc and hints Hints: LENIENT_DATUM_SHIFT = true REPOSITORY = org.geoserver.catalog.CatalogRepository@44015fa4 FORCE_AXIS_ORDER_HONORING = http GRID_COVERAGE_FACTORY = GridCoverageFactory TILE_ENCODING = null COMPARISON_TOLERANCE = 1.0E-8 STYLE_FACTORY = StyleFactoryImpl FEATURE_FACTORY = org.geotools.feature.LenientFeatureFactoryImpl@646811d6 FILTER_FACTORY = FilterFactoryImpl EXECUTOR_SERVICE = java.util.concurrent.ThreadPoolExecutor@5434c827[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0] FORCE_LONGITUDE_FIRST_AXIS_ORDER = true
toolsUI
- toolsUI是UCAR提供的NetCDF Java程式庫之一
- NetCDF Java 程式庫的目標在於實現數據的通用化,即通用數據模型(CDM),用於將 netCDF 文件與各種數據格式(例如 netCDF、HDF、GRIB)進行轉換對接。除了基本數據的訪問,CDM使用檔案中的 metadata(元數據、數據的描述信息)來提供更高層次的接口、充分使用檔案中的屬性數據,以便使用地球科學特定功能,特別是在座標空間中提供地理定位、和切割出特定空間的數據子集等。
- toolsUI-5.5.3.jar:下載點
- 目前適用格式以COARDS協定為主、不適用m3 convention。
nc2tiff
- 使用python对NetCDF数据批处理并生成Geotiff文件
- NetCDF to GeoTIFF using Python, Pratiman, 01 August 2020
- nc2gtiff.py,詳見說明
- tiffinfo的差異
- PM25.tiff
TIFFReadDirectory: Warning, Unknown field with tag 34264 (0x85d8) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34735 (0x87af) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34736 (0x87b0) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34737 (0x87b1) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 42112 (0xa480) encountered.
TIFF Directory at offset 0xc0 (192)
Image Width: 92 Image Length: 131
Tile Width: 512 Tile Length: 512
Bits/Sample: 64
Sample Format: IEEE floating point
Compression Scheme: None
Photometric Interpretation: min-is-black
Samples/Pixel: 1
Planar Configuration: single image plane
Tag 34264: 0.030598,0.000000,0.000000,119.226797,0.000000,0.027813,0.000000,21.775621,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,1.000000
Tag 34735: 1,1,0,7,1024,0,1,2,1025,0,1,1,2048,0,1,4326,2049,34737,7,0,2054,0,1,9102,2057,34736,1,1,2059,34736,1,0
Tag 34736: 298.257224,6378137.000000
Tag 34737: WGS 84|
Tag 42112: <GDALMetadata>
<Item name="DESCRIPTION" sample="0" role="description">pm</Item>
</GDALMetadata>
- sf:sfdem
TIFFReadDirectory: Warning, Unknown field with tag 33550 (0x830e) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 33922 (0x8482) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34735 (0x87af) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34737 (0x87b1) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 42112 (0xa480) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 42113 (0xa481) encountered.
=== TIFF directory 0 ===
TIFF Directory at offset 0x4d9ce (317902)
Image Width: 634 Image Length: 477
Tile Width: 256 Tile Length: 256
Bits/Sample: 32
Sample Format: IEEE floating point
Compression Scheme: AdobeDeflate
Photometric Interpretation: min-is-black
Samples/Pixel: 1
Planar Configuration: single image plane
Tag 33550: 30.000000,30.000000,0.000000
Tag 33922: 0.000000,0.000000,0.000000,589980.000000,4928010.000000,0.000000
Tag 34735: 1,1,0,7,1024,0,1,1,1025,0,1,1,1026,34737,33,0,2049,34737,8,33,2054,0,1,9102,3072,0,1,26713,3076,0,1,9001
Tag 34737: UTM Zone 13, Northern Hemisphere|clark66|
GDAL Metadata: <GDALMetadata>
<Item name="COLOR_TABLE_RULES_COUNT" sample="0">5</Item>
<Item name="COLOR_TABLE_RULE_RGB_0" sample="0">0.000000e+000 1.000000e+003 255 255 255 0 255 0</Item>
<Item name="COLOR_TABLE_RULE_RGB_1" sample="0">1.000000e+003 1.200000e+003 0 255 0 255 255 0</Item>
<Item name="COLOR_TABLE_RULE_RGB_2" sample="0">1.200000e+003 1.400000e+003 255 255 0 255 127 0</Item>
<Item name="COLOR_TABLE_RULE_RGB_3" sample="0">1.400000e+003 1.600000e+003 255 127 0 191 127 63</Item>
<Item name="COLOR_TABLE_RULE_RGB_4" sample="0">1.600000e+003 2.000000e+003 191 127 63 0 0 0</Item>
</GDALMetadata>
GDAL NoDataValue: -9.99999993381581251e+36
Predictor: none 1 (0x1)
- PM25.tiff圖形(詳下述)
圖磚之產生
时间序列栅格数据
- 使用图像镶嵌插件组织并发布时间序列栅格数据
- tutorial
- How to add date and time to a geotiff to enable time dimension in geoserver?
- Geoserver offers the Image Mosaic plugins, which allows either mosaicing or making time series. This pages shows how to build such a time series:
- Basically, it consists in having all the tif in a single repository, and creating at least two configuration files:
- timeregex.properties defining the rules for extracting the date from the filename, and
- indexer.properties indicating to geoserver how to create the index table.
- The third file is needed only to create entries in PostGIS (else geoserver will create a shapefile).
- Creating a new datastore is quite straightforward. A time parameter can then be passed to the WMS to select a specific image.
RESTful calling geoserver
- Importer REST API examples
- Mass configuring a directory of shapefile
- by curl
publish a GeoTiff file in GeoServer with curl tool
- gis.stackexchange(2018)
- create a coveragestore
curl -u admin:geoserver -v -H 'Content-type: application/xml' -d \
'<coverageStore>\
<name>input</name>\
<workspace>LGHAP</workspace>\
<enabled>true</enabled>\
<type>GeoTIFF</type>\
<url>/home/QGIS/Data/dtm/taiwan2.tiff</url>
</coverageStore>' \
http://200.200.31.47:8080/geoserver/rest/workspaces/LGHAP/coveragestores
- put tiff
curl -u admin:geoserver -v -XPUT -H "Content-type: image/tiff" \
--data-binary @taiwan2.tif \
http://200.200.31.47:8080/geoserver/rest/workspaces/LGHAP/coveragestores/input
geoserver內部設定
- 雖然geoserver並不是為了展示成果,而是對外提供圖檔服務,然而檢視過程仍然需要使用正確的顏色設定。
raster顏色的設定
- 基本上geoserver內raster等值區間、顏色等等、是由具有個別命名的style檔案所控制的。
- 由主畫面Data->Style進入
Manage the Styles published by GeoServer
,可以新增、刪除、產生、複製、上傳既有style、或直接修改既有的設定。 - raster範例如dem,格式為SLD(StyledLayerDescriptor)
<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>gtopo</Name>
<UserStyle>
<Name>dem</Name>
<Title>Simple DEM style</Title>
<Abstract>Classic elevation color progression</Abstract>
<FeatureTypeStyle>
<Rule>
<RasterSymbolizer>
<Opacity>1.0</Opacity>
<ColorMap>
<ColorMapEntry color="#AAFFAA" quantity="0" label="values" />
<ColorMapEntry color="#00FF00" quantity="1000"/>
<ColorMapEntry color="#FFFF00" quantity="1200" label="values" />
<ColorMapEntry color="#FF7F00" quantity="1400" label="values" />
<ColorMapEntry color="#BF7F3F" quantity="1600" label="values" />
<ColorMapEntry color="#000000" quantity="2000" label="values" />
</ColorMap>
</RasterSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
level | color | name |
---|---|---|
1 | AAFFAA | Mint Green/淡綠色 |
2 | 00FF00 | 鮮绿色/綠色/Ford Green |
3 | FFFF00 | Yellow/鮮黃 |
4 | FF7F00 | Dark Orange/橙色 |
5 | BF7F3F | shade of brown/Brandy Punch |
6 | 000000 | Black/黑 |
leaflet.js 之呼叫
xml parsing
格式紀錄在GetCapabilities內:Welcome -> GeoServer Web Map Tile Service -> WMTS(內部ip)
...
{TileMatrixSet}
<ows:WGS84BoundingBox>
<ows:LowerCorner>-103.87100615361031 44.37021187004215</ows:LowerCorner>
<ows:UpperCorner>-103.62932676908186 44.50162561960653</ows:UpperCorner>
</ows:WGS84BoundingBox>
<TileMatrixSet>EPSG:900913</TileMatrixSet>
<TileMatrix>EPSG:900913:30</TileMatrix>
<ResourceURL format="image/jpeg" resourceType="tile" template="http://200.200.31.47:8080/geoserver/gwc/service/wmts/rest/sf:sfdem/{style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}?format=image/jpeg"/>
- substute into index.js
- {style}:dem
- {TileMatrixSet} = EPSG:900913
- {TileMatrix} = EPSG:900913:30
- {z}=30
java
- demo instance sf:sfdem
var osm = L.tileLayer('http://200.200.31.47:8080/geoserver/gwc/service/wmts/rest/sf:sfdem/EPSG:900913/EPSG:900913:{z}/{y}/{x}?format=image/jpeg', {
attribution: 'Map data © 2013 OpenStreetMap contributors'
});
var map = L.map('map', {
center: [44.4, -103.7,],
zoom: 13
}).addLayer(osm);
- AQM:newCV instance
var osm = L.tileLayer('http://200.200.31.47:8080/geoserver/gwc/service/wmts/rest/AQM:newCV/AQM:PM25/EPSG:900913/EPSG:900913:{z}/{y}/{x}?format=image/png'
- 注意
- EPSG:4326似乎與leaflet不合,無法計算出正確的x,y值,必須使用EPSG:900913
- 中心點(lat,lon)必須精確到小數點1位,可以由geoserver->Tile Caching->Tile Layers之預覽由滑鼠得到。
- 測試之網頁:http://200.200.31.47/Leaflet.FileLayer/docs/a.html
Time Support in GeoServer WMS
- within a single Layer see support
- may use relative time, and Reduced accuracy times
post a vector file on leaflet map
- How do I add my own map layers to Leaflet
- Loading external GeoJSON file into Leaflet map?
- download4
leaflet.ajax.min.js
to local dir. and invoked in html and index.js
<script src="leaflet.ajax.min.js"></script>
var geojsonLayer = new L.GeoJSON.AJAX("COUNTY_MOI_1090820.geojson");
var myStyle =
{
color: 'black',
weight: 3
};
geojsonLayer.setStyle(myStyle).addTo(map);
- Notes
- setStyle seems useless
- (TODO) line color, line width, transparaency need further modifications
- (TODO) mouse hovers and clicks may be further defined.
-
Global Mercury Observation System Spatial Data Infrastructure (SDI),in presentation of Nicola Pirrone(2011) ↩
-
Zhang, C., Di, L., Sun, Z., Lin, L., Yu, E., Gaigalas, J. (2019). Exploring cloud-based Web Processing Service: A case study on the implementation of CMAQ as a Service. Environmental Modelling and Software 113. https://doi.org/10.1016/j.envsoft.2018.11.019 ↩
-
UPCOM, KARTEKO, ARTEMIS, AUTH (2021). Report on the design of technical framework and system architecture of the ICARUS DSS, WP7: Motivating citizens towards the vision in Integrated Climate forcing and Air Pollution Reduction in Urban Systems(ICURAS). ↩