I’m here showing how you can use GDAL2Tiles to generate map tiles of Tom Patterson’s Natural Earth II. This is a beautiful raster map that portrays the world environment in an idealised manner with little human influence. The map can be downloaded on this page. I’m here using version 2C.

I start by using gdal_translate to georeference the map image:

gdal_translate -a_srs EPSG:4326 -gcp 0 0 -180 90 -gcp 16200 0 180 90 -gcp 16200 8100 180 -90 NE2_modis3.jpg NE2_modis3.tif

The image should now have the correct projection (EPSG:4326), but GDAL2Tiles was not generating the KML SuperOverlay before ran this command:

gdalwarp -t_srs EPSG:4326 NE2_modis3.tif NE2_modis3_4326.tif

The original raster map is 16,200 x 8,100 pixels. Each map tile image is 256 x 256 pixels. This table shows the number of tiles generated for each zoom level:

For my purpose, 5 zoom levels are enough. I therefore reduced the map image to 8192 x 4096 pixels:

gdal_translate -outsize 8192 4096 NE2_modis3_4326.tif NE2_modis3_4326_5.tif

Finally, I used GDAL2Tiles to generate the map tiles:

gdal2tiles -title "Natural Earth II" -publishurl http://www.thematicmapping.org/maptiles/ -v NE2_modis3_4326_5.tif naturalearth

See the result as a KML SuperOverlay in Google Earth or in Open Layers. There seems to be a problem that OpenLayers can’t georeference TMS map tiles. It is therefore difficult to combine a map tile layer with other map layers.


UPDATE 2 APRIL 2008: The OpenLayers example above is now working properly thanks toChristopher Schmidt.

http://www.gdal.org/gdal_translate.html---可以查看gdal的帮助文档。查看那个命令的帮助直接替换了gdal_translate就可以了

另一种方法:

Step 1: Download and install GDAL

Begin by downloading and installing the GDAL as detailed here.

Step 2: Download an image

You can use any image. There are a number of sources of geographic data on the web. You can use any of them, but you should know the boundaries of the image—the latitude and longitude of each of the corners of the image. This tutorial uses a NASA Blue Marble image, available for download from NASA's website. These images were taken in 2004 and present a beautiful image of the Earth from space. Choose one of the files in the lower right of the right navigation bar.

If you're using your own image and know that it is already georectified, then you can skip to Step 5. Otherwise, proceed with Step 3.

Step 3: Get information about the image

Once you've installed the GDAL libraries and selected the image, you need to get some information about the image so that you can georeference it. Specifically, you need the pixel and line positions of each corner of the image. If you imagine the image as a table, with columns and rows, the pixels are the columns, and the lines are rows.

GDAL provides a handy utility, gdalinfo, for capturing this information. At the command line, simply typegdalinfo filename, replacing filename with the path to the file. You should get output that looks like this:

Driver: JPEG/JPEG JFIF
Files: world_200401.jpg
Size is 21600, 10800
Coordinate System is `'
Image Structure Metadata:
SOURCE_COLOR_SPACE=YCbCr
INTERLEAVE=PIXEL
COMPRESSION=JPEG
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0,10800.0)
Upper Right (21600.0, 0.0)
Lower Right (21600.0,10800.0)

Center (10800.0, 5400.0)
Band 1 Block=21600x1 Type=Byte, ColorInterp=Red
Image Structure Metadata:
COMPRESSION=JPEG
Band 2 Block=21600x1 Type=Byte, ColorInterp=Green
Image Structure Metadata:
COMPRESSION=JPEG
Band 3 Block=21600x1 Type=Byte, ColorInterp=Blue
Image Structure Metadata:
COMPRESSION=JPEG

The important information for this tutorial is the Upper Left, Lower Left, Upper Right, Lower Right lines. These tell you the pixel and line values of each corner. The Upper Left, in this case, is at 0,0, and the Lower Right is at 21600,10800.

Step 4: Georeference the Image

Georeferencing in this case means to create metadata describing the geographic position of each of the corners of the image. Using the information gained in Step 3 and gdal_translate, you can assign georeference information to the file. This creates a VRT file from world_200401.jpg image, bluemarble1.vrt. VRT files are XML files that contain the information about a particular transformation, in this case the gdal_translate step. You will use it again in the next step to create your final set of tiles. gdal_translate allows you to do multiple file output types including major image file formats. Using VRT outputs allows you to essentially put off making output files until the last step. This increases efficiency and decreases your wait time for individual steps if you're doing the command line. Here's the command you would run:

gdal_translate -of VRT -a_srs EPSG:4326 -gcp 0 0 -180 90 -gcp 21600 0 180 90 -gcp 21600 10800 180 -90 world_200401.jpg bluemarble1.vrt

There's a lot of information on that line, so here it is broken out:

  • -of is output format, in this case VRT.
  • -a_srs assigns a spatial reference system to the file. That tells any application consuming it what coordinate system is being used. In this case, it is using EPSG:4326, which is the same as WGS84, the coordinate system used by Google Earth.
  • -gcp, or ground control point, assigns coordinates to positions in the file. In this case, you actually only need three points, since the image is a rectangle and therefore the fourth point can be easily identified. For -gcp, define the gcp by setting the pixel and then line number, and then the longitude and latitude. Each of those is separated by a space.
  • The last two parameters are the origin file and the target file.

Step 5: Warp the Image

The original image wasn't created for a round globe, it was created to appear to lie flat. In GIS terms, it is projected, which means that it is a two-dimensional representation of a three-dimensional object. Projection requires distorting the image so that it appears how you would expect a flat image of the Earth to look.

In order to get it to look right, you have to warp the image it to fit the globe. Fortunately GDAL provides a great tool for that too. Simply type gdalwarp -of VRT -t_srs EPSG:4326 bluemarble1.vrt bluemarble2.vrt. This will create a new file, bluemarble2.vrt, which provides metadata about the warping procedure.

Step 6: Create the Tiles

You're almost done, but this part will take the longest. To create the tiles, type in gdal2tiles.py -p geodetic -k bluemarble2.vrt. The -k forces a KML output. This will create a directory structure with a super-overlay. As each of those image files has to be created separately, it takes awhile to run. For large images, you can now go, get a cup of coffee, take a nap, maybe get a light meal. When you're done, open up doc.kml and observe the results!

也可以使用gdal_retile.py形成切片 发不到geoserver上

gdal_retile.py -levels 3 -ps 2048 2048 -co "TILED=YES" -co "BLOCKXSIZE=256" -co "BLOCKYSIZE=256" -s_srs EPSG:4326 -targetDir bmpyramid bluemarble2.vrt

Conclusion

This tutorial just scratches the surface of what GDAL can do, but it does provide a convenient mechanism for generating tiles. The core GDAL libraries are written in C++, but they provide bindings for Perl, Python, VB6, R, Ruby, Java, and C#/.NET, meaning you can easily incorporate GDAL into your own applications. Also, many of the utilities, including gdal2tiles, are written in Python, making them easy to incorporate into Python applications.gdal2tiles also has the ability to generate Google Maps API and OpenLayers pages.

欢迎大家来我的新家看一看 3wwang个人博客-记录走过的技术之路

gdal gdal2tiles.py 的使用的更多相关文章

  1. 瓦片切图工具gdal2tiles.py改写为纯c++版本

    gdal2tiles.py是GDAL库中用于生成TMS瓦片的python代码,支持谷歌墨卡托EPSG:3857与经纬度EPSG:4326两种瓦片,输出png格式图像. gdal2tiles.py Mo ...

  2. 瓦片切图工具gdal2tiles.py改写为纯c++版本(二)

    python这么火,C++/C#的程序员都生存不下去了,为啥还要干把python转写成c++的这种反动的事? 项目需要呗... gdal2tiles.py文件中有两个类是计算全球墨卡托与WGS84两种 ...

  3. 部分GDAL工具功能简介

    主要转自http://blog.csdn.net/liminlu0314?viewmode=contents 部分GDAL工具功能简介 gdalinfo.exe 显示GDAL支持的各种栅格文件的信息. ...

  4. window 安装gdal和python

    进入 http://www.gisinternals.com/release.php 中下载下图(也可以不是这个版本但是下载的python和gdal一定要版本对应) 1.点击下图中release-17 ...

  5. 【GIS】使用GDAL为Leaflet切图

    一.参考资料 https://commenthol.github.io/leaflet-rastercoords/ https://github.com/commenthol/gdal2tiles-l ...

  6. C++代码利用pthread线程池与curl批量下载地图瓦片数据

    项目需求编写的程序,稳定性有待进一步测试. 适用场景:在网络地图上,比如天地图与谷歌地图,用户用鼠标在地图上拉一个矩形框,希望下载该矩形框内某一层级的瓦片数据,并将所有瓦片拼接成一个完整的,包含地理坐 ...

  7. linux下gdal的python包的安装

    由于python包是从C++包编译出来的,所以需要先下载源码进行编译安装.1. gdal下载http://download.osgeo.org/gdal/CURRENT/sudo ./configur ...

  8. gdal_merge.py

    1 gdal_merge.py: 合并(Merge)/镶嵌(Mosaic)工具.要求图像必须是相同坐标系统.具有相同的波段数:可以不同分辨率,可以有重叠区域(后加入图像覆盖先加入的图像). 注意:只能 ...

  9. Centos7.3 编译安装GDAL以及Python的GDAL包

    参考: https://cryolite.iteye.com/blog/176382 https://blog.csdn.net/a13326021319/article/details/782505 ...

随机推荐

  1. shiro 会话管理

  2. 学JS的心路历程-for of和for in

    我们在刚入门JS时候,说到要跑出数组的每个值肯定都是这样子: var arr = [1,2,3,4,5,6]: for(let i = 0:i < arr.length:i++){ consol ...

  3. JAVA&PYTHON

  4. centos7.5下yum 安装mariadb数据库

    前言 mariadb 和mysql就像亲兄弟的关系,各种语法.驱动啥的,在mysql上能上的,在mariadb上基本都可以直接使用.更多的细节在此不多说. 1.删除旧版本 centos7下默认安装有m ...

  5. 微信小程序----搜索框input回车搜索事件

    在微信小程序里的搜索框,按软键盘回车键触发搜索事件. <input type="text"  placeholder="搜索" value="{ ...

  6. MySql介绍

    MySql介绍 标签(空格分隔): MySql MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 ...

  7. Oracle数据导出导入

    总结了几种Oracle导入导出的命令方法,方便以后使用.      数据导出: 1. 将数据库test完全导出,用户名system 密码manager 导出到d:/daochu.dmp中        ...

  8. style标签下的CSS代码的显示与实时编辑

    style标签也是标签 首先设置body style的样式 body style{ display:block; padding:0.6em 0.8em; border:1px dashed #ccc ...

  9. python 读取文件第一列 空格隔开的数据

    file=open('6230hand.log','r') result=list() for c in file.readlines(): c_array=c.split(" " ...

  10. Shc 应用

    1.说明 shc是一个加密shell脚本的工具, 它的作用是把shell脚本转换为一个可执行的二进制文件 2.安装 下载 # mget  http://www.datsi.fi.upm.es/~fro ...