パイクラおじさんの日記

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

3x3倍する

np.repeat(array, repeats, axis)という関数(?)で各要素を指定倍数だけ増やせるらしい。

全体を5x5倍すると確認するのにえらいことになる(処理に20時間以上かかる)ので、まずは3次メッシュを3x3くらいして見ようと思う。

xmlnpy.pyを元に最後に配列を縦横にrepeatする部分をつけてxmlnpy3x3.pyとして保存。

# coding: utf-8

import xml.etree.ElementTree as ET
import numpy as np
import sys

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

NPY_DIR = "/Users/pycra/Desktop"
NPY_FILE = "npydata-{0:04d}-{1:02d}-{2:02d}.npy"

if len(sys.argv) < 4:
    print("xmlnpy3x3.py mesh1 mesh2 mesh3")
    exit(-1)

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

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:
    print("{http://www.opengis.net/gml/3.2}tupleList is not found")
    exit(-1)

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:
    print("{http://www.opengis.net/gml/3.2}startPoint is not found")
    exit(-1)

(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

data_array = array.reshape((150, 225))
print(data_array.shape)
print(data_array)
data3_array = np.repeat(data_array, 3, axis=0)
print(data3_array.shape)
print(data3_array)
data3x3_array = np.repeat(data3_array, 3, axis=1)
print(data3x3_array.shape)
print(data3x3_array)
np.save(NPY_DIR+"/"+NPY_FILE.format(mesh1, mesh2, mesh3), data3x3_array)

で、マイクラ内でloadnpy.pyをそのまま実行。

f:id:pycra:20170920022453p:plain
3x3版の外房有料道路
f:id:pycra:20170920022550p:plain
3x3版の外房有料道路(地上から)

ドット感がかなりある。

アンチエイリアス処理をする?