パイクラおじさんの日記

MinecraftでPythonを勉強するおじさんの日記です。

データ数が少ないエリア(2)

左上が海になっているエリア(534020, 534010)のデータをダウンロードして、<gml:startPoint>が0 0以外のデータに対応させた。 (ついでに、534021, 534011もダウンロードした。)

基盤地図情報ダウンロードサービス

f:id:pycra:20170918044407p:plain
左上に海があるエリア

実行結果はFig. 20。

f:id:pycra:20170918044632p:plain
Fig. 20

最新のplotall.pyは次の通り。

# coding: utf-8

import xml.etree.ElementTree as ET
import numpy as np
import matplotlib.pyplot as plot
import sys

GEO_DIR = "FG-GML-{0:04d}-{1:02d}-DEM5A"
GEO_XML = "FG-GML-{0:04d}-{1:02d}-{2:02d}-DEM5A-20161001.xml"

def xml2array(mesh1, mesh2, mesh3):
    dir = GEO_DIR.format(mesh1, mesh2)
    fname = GEO_XML.format(mesh1, mesh2, mesh3)

    tree = ET.parse(dir+"/"+fname)
    root = tree.getroot()

    tl = root.find('./{http://fgd.gsi.go.jp/spec/2008/FGD_GMLSchema}DEM/{http://fgd.gsi.go.jp/spec/2008/FGD_GMLSchema}coverage/{http://www.opengis.net/gml/3.2}rangeSet/{http://www.opengis.net/gml/3.2}DataBlock/{http://www.opengis.net/gml/3.2}tupleList')
    if tl is None:
        raise Exception("{http://www.opengis.net/gml/3.2}tupleList is not found")

    sp = root.find('./{http://fgd.gsi.go.jp/spec/2008/FGD_GMLSchema}DEM/{http://fgd.gsi.go.jp/spec/2008/FGD_GMLSchema}coverage/{http://www.opengis.net/gml/3.2}coverageFunction/{http://www.opengis.net/gml/3.2}GridFunction/{http://www.opengis.net/gml/3.2}startPoint')
    if sp is None:
        raise Exception("{http://www.opengis.net/gml/3.2}startPoint is not found")

    (spx, spy) = sp.text.split()

    lines = tl.text.split()
    array = np.zeros(33750)
    array.fill(-9)
    i = int(spx) + int(spy) * 225
    for l in lines:
        (t, h) = l.split(",")
        hval = float(h)
        if hval == -9999:
            array[i] = -9
        else:
            array[i] = hval
        i += 1

    return array.reshape((150, 225))


# ここからスタート

if len(sys.argv) < 3:
    print("plotall.py mesh1 mesh2")
    exit(-1)

mesh1 = int(sys.argv[1])
mesh2 = int(sys.argv[2])

yarray = None
for y in range(10):
    xarray = None
    for x in range(10):
        try:
            mesh3 = y * 10 + x
            array = xml2array(mesh1, mesh2, mesh3)
        except Exception as err:
            print(err)
            array = np.zeros((150, 225))
            array.fill(-10)
        finally:
            if xarray is None:
                xarray = array
            else:
                xarray = np.concatenate((xarray, array), axis=1)
        
    if yarray is None:
        yarray = xarray
    else:
        yarray = np.concatenate((xarray, yarray), axis=0)

print(yarray.shape)

plot.imshow(yarray)
plot.colorbar()
plot.show()