OpenStreetMap Server
Aug 22, 2020 16:03:37 GMT 1
Post by alexfish on Aug 22, 2020 16:03:37 GMT 1
HI All
as part of the on going XCB cairo / surfaces
it will be map enabled Hence this bit
How to get the tiles from openstreet map
You will need curl.bac From HERE
The FUNCTIONS + a sample in Main
objective Create the Zoom Directory , create Zoom level Directories
how to identity where the png are
read from the terminal
EXAMPLE
Screenshot ::
London latitude 51.5074° N, 0.1278° W
actual cords
as part of the on going XCB cairo / surfaces
it will be map enabled Hence this bit
How to get the tiles from openstreet map
You will need curl.bac From HERE
The FUNCTIONS + a sample in Main
objective Create the Zoom Directory , create Zoom level Directories
how to identity where the png are
read from the terminal
EXAMPLE
INCLUDE "curl.bac"
DEF FN ASINH = asinh
DEF FN ATAN = atan
'radius at equater
DEF FN OSM_EQ_RADIUS = 6378137.0
DEF FN ISNAN = isnan
DECLARE OSMDIR$ TYPE STRING
' https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
' source$ server [a,b,c]
' ========================================================
' ========================================================
FUNCTION LONG_TO_PIX(int ZOOM, double longditude) TYPE int
LOCAL TILE_X TYPE int
TILE_X = (int)(FLOOR(( longditude +180.0) /360 *(1 << ZOOM)))
RETURN TILE_X
END FUNCTION
' =====================================================
FUNCTION LAT_TO_PIX(int ZOOM, double latitude) TYPE int
LOCAL TILE_Y TYPE int
LOCAL LAT_RAD TYPE double
LAT_RAD = latitude * PI / 180
TILE_Y = (int)FLOOR( (1.0 - ASINH(TAN(LAT_RAD)) / PI) / 2.0 * (1 << ZOOM))
RETURN TILE_Y
END FUNCTION
' =====================================================
FUNCTION TILE_X_TO_LONG(int x, int z) TYPE double
RETURN x / (double)(1 << z) * 360.0 - 180
END FUNCTION
' =====================================================
FUNCTION TILE_Y_TO_LAT(int y, int z) TYPE double
LOCAL n TYPE double
n = PI - 2.0 * PI * y / (double)(1 << z)
RETURN 180.0 / PI * ATAN(0.5 * (exp(n) - exp(-n)))
END FUNCTION
' =====================================================
FUNCTION CHECK_NAN(float numb) TYPE STRING
IF ( ISNAN(numb)) THEN
RETURN "NAN"
ELSE
RETURN STR$(numb)
END IF
END FUNCTION
' =====================================================
FUNCTION OSM_GET_TILE$ (int ZOOM, double longditude, double latitude, STRING source$) TYPE STRING
LOCAL filename$ TYPE STRING
filename$ =OSMDIR$ & STR$(ZOOM)
LOCAL TILE$ TYPE STRING
LOCAL TILE_X, TILE_Y TYPE int
LOCAL LAT_RAD TYPE double
TILE_X = LONG_TO_PIX(ZOOM,longditude)
TILE_Y = LAT_TO_PIX(ZOOM,latitude)
TILE$ = "https://" & source$ & ".tile.openstreetmap.org/" & STR$(ZOOM) & "/" & STR$(TILE_X) & "/" & STR$(TILE_Y) & ".png"
MAKEDIR OSMDIR$ & STR$(ZOOM) & "/" & STR$(TILE_X)
filename$ =OSMDIR$ & STR$(ZOOM) & "/" & STR$(TILE_X) & "/" & STR$(TILE_Y) & ".png"
IF ( NOT(FILEEXISTS (filename$ ))) THEN
'PRINT "GET TILE:" ,TILE$
OPEN filename$ FOR WRITING AS download
easyhandle = curl_easy_init()
curl_global_init(CURL_GLOBAL_ALL)
curl_easy_setopt(easyhandle, CURLOPT_USERAGENT, "bacon-osm-map")
curl_easy_setopt(easyhandle, CURLOPT_SSL_VERIFYHOST, 2L)
curl_easy_setopt(easyhandle, CURLOPT_URL,TILE$)
curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, NULL)
'curl_easy_setopt(easyhandle, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, download)
success = curl_easy_perform(easyhandle)
' Cleanup
curl_easy_cleanup(easyhandle)
' Close filehandle
CLOSE FILE download
RETURN filename$
ELSE
RETURN filename$
END IF
END FUNCTION
' ========================================================
SUB SET_OSM_DIRECTORY()
HOME$ = GETENVIRON$("HOME")
OSMDIR$ = HOME$ & "/bacon-osm-maps/"
'PRINT OSMDIR$
'MAKEDIR OSMDIR$
FOR t = 1 TO 19
MAKEDIR OSMDIR$ & STR$(t)
OPEN OSMDIR$ & STR$(t) & "/zoom" FOR WRITING AS myfile
WRITELN "bacon-osm-" & STR$(t) TO myfile
CLOSE FILE myfile
NEXT
END SUB
' MAIN EXAMPLE =============================================
LOCAL TILE$
LOCAL SERVER_SOURCE$ TYPE STRING
LOCAL lat, lon TYPE double
LOCAL nan$ TYPE STRING
SET_OSM_DIRECTORY()
lon = -0.1278
lat = 51.5074
' normaly algos may return a nan on float a nan can couse seg fault check for is nan
nan$ = CHECK_NAN(lat)
IF nan$ = "NAN" THEN END
nan$ = CHECK_NAN(lon)
IF nan$ = "NAN" THEN END
' discriptor source$ server [a,b,c].tile
SERVER_SOURCE$ = "a"
'get tile ZOOM , LONGITUDE , LATITUDE oms server discriptor
' London tile zoom 10 longitude latitude
TILE$ = OSM_GET_TILE$(10,lon,lat,"a")
'TILE$ = OSM_GET_TILE$(10,-4.01,51.4934,"b")
'TILE$ = OSM_GET_TILE$(10,-4.01,51.4934,"c")
' Lat SOUTH - 0 + NORTH
' Long WEST - 0 + EAST IE greenwich london 51.4934° N, 0.0098° E
PRINT TILE$
Screenshot ::
London latitude 51.5074° N, 0.1278° W
actual cords
zoom 10
lon = -0.1278
lat = 51.5074