Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use python to realize osm slice calculation

Shulou Source: shulou.com Published: 2022-06-01 06:34:13 09月22日 Update

This article mainly introduces "how to use python to achieve osm slice calculation". In daily operation, I believe many people have doubts about how to use python to achieve osm slice calculation. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubt of "how to use python to achieve osm slice calculation". Next, please follow the editor to study!

General maps are displayed by publishing slices in the background and read by the front-end engine. Some of the map slices are cut by longitude and latitude, and some are cut by Google's Mercator, so according to a certain coordinate range and zoom level, the horizontal and vertical order of the slices can be calculated, and detailed z (zoom), x (horizontal), y (vertical) numbers can be obtained, and then according to the basic server url. This slice can be downloaded to the local, multiple slices merged into one, given coordinate information, it will become a map image, the general map download tools are also downloaded and generated in accordance with this principle.

OSM is an open source map. Its map slices are cut according to longitude and latitude, that is, EPSG:4326. When calculating the slices of longitude and latitude, there is no need to convert the coordinates into web Mercator coordinates. Here is a code (python) to calculate the order of slices based on longitude and latitude coordinates:

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)

Input longitude and latitude coordinates and zoom level, you can find which slice the coordinates are on, and the direction of longitude is equal, which is relatively simple in the calculation. The latitude narrows at the distance of high latitude, so, to calculate through a complex mathematical formula, the higher the grade, the more the number of slices, the more slices will be downloaded, and the number of slices will increase according to the number of squares.

The downloaded slice coordinate range is not necessarily the same as the incoming coordinate range, so the map downloader is sometimes the same, and the merged image is not the four incoming ranges, which requires a certain amount of map clipping at a later stage.

A downloaded slice can be merged with libraries such as gdal, which is very convenient for merging and calculating the merged map.

At this point, the study on "how to use python to achieve osm slice calculation" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Maps coordinates longitude and latitude range learning time help images quantity is in more grade order Mercator the more complex practical the same and then Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Docker MySQL Microsoft Shulou Information