티스토리 뷰

728x90
반응형

 

openstreetmap을 사용할 때 아래와 같은 식으로 url을 사용하게 되지요!

tile.openstreetmap.org/{z}/{x}/{y}.png

 

여기서 {z}는 zoom, {x}, {y}는 타일의 좌표(tile number)라고 말할 수 있습니다.

만약 타일의 좌표(tile number)만 알고 있는데 wgs84 좌표계의 x,y 위경도를 알고싶다거나,

혹은 wgs84 좌표계의 x,y 위경도만 알고 있는데 이 좌표의 OSM 타일의 좌표를 알고 싶을 때!

서로 변환할 수 있는 코드가 존재합니다.

 

wgs84 좌표계 x,y를 tile number로 변환하는 경우,

wgs84 좌표계 x,y에 해당되는 tile number의 왼쪽 상단점 (x,y) tile number를 리턴 받게되고,

 

tile number를 wgs84 좌표계 x,y 위경도로 변환하는 경우,

tile의 왼쪽 상단점 (x,y)을 wgs84좌표계 위경도를 리턴받게 됩니다.

 

 

아래의 개발자 문서에서도 0,0을 가리키고 있죠.

주어진 확대/축소 수준에서 특정 타일은 지도의 왼쪽 상단에서 시작하는 0,0의 직교 좌표로 식별할 수 있습니다.

https://developers.planet.com/tutorials/slippy-maps-101/

 

Slippy maps 101

A Slippy Map is an architecture for building mapping applications on the web. It was popularized the Open Street Map (OSM). http://wiki.openstreetmap.org/wiki/Slippy_Map A core component of Slippy Maps is that the images should be served as tiles on a grid

developers.planet.com

 

 

 

 

1. wgs84 좌표계 x,y 를 tile number로 변환하기     
(Lon./lat. to tile numbers)

import math
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.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
  return (xtile, ytile)

 

deg2num 파라미터로 x, y, z(zoom)을 넣으면 되구요,

 


2. tile number를 wgs84 좌표계 x,y 위경도로 변환하기    
(Tile numbers to lon./lat.)

import math
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)

num2deg 파라미터로 {x},{y},{Z}를 넣으면 된답니다!

 

 

 

더 자세한 내용을 보시려면 아래 링크를 참조해주세요~!

https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Lon..2Flat._to_tile_numbers_2

 

Slippy map tilenames - OpenStreetMap Wiki

Tile numbering for zoom=2 This article describes the file naming conventions for the Slippy Map application. Tiles are 256 × 256 pixel PNG files Each zoom level is a directory, each column is a subdirectory, and each tile in that column is a file Filename

wiki.openstreetmap.org

 

728x90
반응형
댓글