이전 동료로부터 두 개의 Python 스크립트 (조각과 비슷 함)를 상속 받았습니다. 이 코드는 고해상도 이미지 (png)를 도형 좌표 공간 (위도/경도)에서 Leaflet.js에서 사용할 수있는 확대/축소 가능 타일 (slippy-map)로 변환합니다.Python Slippy-map Tile Generation
Python (또는 GIS) 녀석이 아니기 때문에 나는 제대로 작동하도록 노력하고 있습니다. 문제가 내 지식 부족인지 코드인지 알 수 없습니다.
이 첫 번째 스크립트는 입력 이미지 (myImgMaxRez.png)에서 파생 된 점진적으로 낮은 해상도의 5 개의 이미지 파일을 생성하여 예상대로 작동합니다. 저는 이것을 '이미지 피라미드'라고 부릅니다. .png를 각각 Z [1..5]의 치수는 미끄러운 맵 타일을 생성한다 (256)
from skimage import io
from skimage import transform
import skimage
z1 = io.imread("myImgMaxRez.png", as_grey=True)
io.imsave("z1.png",skimage.img_as_uint(z1))
z2 = transform.pyramid_reduce(z1)
io.imsave("z2.png",skimage.img_as_uint(z2))
z3 = transform.pyramid_reduce(z2)
io.imsave("z3.png",skimage.img_as_uint(z3))
z4 = transform.pyramid_reduce(z3)
io.imsave("z4.png",skimage.img_as_uint(z4))
z5 = transform.pyramid_reduce(z4)
io.imsave("z5.png",skimage.img_as_uint(z5))
다음 스크립트 (int로 플로트) 형식 변환 오류 나눌 드로우한다.
import math
import os
from skimage import io
def createTiles(xStart, yStart, zoom, theData):
ncols = theData.shape[1]/256
nrows = theData.shape[0]/256
print(nrows, ncols)
topDir = "%d" % (zoom)
os.mkdir(topDir)
for i in range(0, ncols):
theDir = topDir + "/%d" % (i+xStart)
print (theDir)
os.mkdir(theDir)
for j in range(0, nrows):
theFile = topDir + "/%d/%d.png" % (i + xStart, j + yStart)
print (theFile)
io.imsave(theFile, theData[j*256:(j+1)*256, i*256(i+1)*256])
def num2deg(xtile, ytile, zoom):
n= 2.0 ** zoom
lon_deg = xtile/n *360.0 -180.0
lat_rad = math.atan(math.sinh(math.pi * (1 - 2 * ytile/n)))
lat_deg = math.degrees(lat_rad)
return (lat_deg, lon_deg)
def deg2num(lat_deg, lon_deg, zoom):
lat_rad = math.radians(lat_deg)
n= 2.0 ** zoom
xtile = int((lon_deg + 180.0)/360.0 * n)
ytile = int((1.0 - math.log(math.tan(lat_rad) + (1/math.cos(lat_rad)))/math.pi)/2.0 * n)
return (xtile, ytile)
# Take center point of interest (MCK). Since z tile is 4x3 go 1 tile up and 2 left
startZoom = 18
centerLoc = deg2num(43.533942709166325, -96.71487003564836, startZoom)
startCol = centerLoc[0]
startRow = centerLoc[1]
# Now get lat/long of upper left tile corner
geoCoord = num2deg(startCol, startRow, startZoom)
loc = deg2num(geoCoord[0], geoCoord[1],18)
# EDIT: reading the .png thanks to JH comment below
z1 = io.imread("z1.png", as_grey=True)
createTiles(loc[0], loc[1], 18, z1)
loc = deg2num(geoCoord[0], geoCoord[1],19)
# EDIT: reading the .png thanks to JH comment below
z2 = io.imread("z2.png", as_grey=True)
createTiles(loc[0], loc[1], 19, z2)
loc = deg2num(geoCoord[0], geoCoord[1],20)
# EDIT: reading the .png thanks to JH comment below
z3 = io.imread("z3.png", as_grey=True)
createTiles(loc[0], loc[1], 20, z3)
loc = deg2num(geoCoord[0], geoCoord[1],21)
# EDIT: reading the .png thanks to JH comment below
z4 = io.imread("z4.png", as_grey=True)
createTiles(loc[0], loc[1], 21, z4)
loc = deg2num(geoCoord[0], geoCoord[1],22)
# EDIT: reading the .png thanks to JH comment below
z5 = io.imread("z5.png", as_grey=True)
createTiles(loc[0], loc[1], 22, z5)
CreateTiles은() TypeError: float object cannot be interpreted as an integer
말을 라인 for i in range(0, ncols):
에 오류를 던지고있다 ... 흥미롭게도,이 오류를 던지기 전에 제 1 서브 디렉토리 18/
를 작성합니다. 다시 z [1..5] .png의 크기가 2의 제곱 수 (또는 256의 배수)임을 확인했습니다.
float를 정수로 변환 할 때이 오류가 발생하는 이유는 무엇입니까?
고맙습니다. 이것의 첫번째 부분은 매우 도움이되었습니다 ... 나는 해결책에 가깝지만 아직 거기에 없다고 느낍니다. 다시 한번 당신의 도움과 기꺼이 이것을 보아 주셔서 감사합니다 ... – Colin