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=YCbCrINTERLEAVE=PIXELCOMPRESSION=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=RedImage Structure Metadata:COMPRESSION=JPEG
Band 2 Block=21600x1 Type=Byte, ColorInterp=GreenImage Structure Metadata:COMPRESSION=JPEG
Band 3 Block=21600x1 Type=Byte, ColorInterp=BlueImage 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. GDAL源码剖析(五)之Python命令行程序

    一. GDAL Python工具 本文主要介绍的是GDAL工具集中的Python脚本命令,需要的环境必须是有Python环境和GDAL的Python版本.这是必须的,否则这些工具都不能用.对于已经安装 ...

  2. 软件经验|GDAL空间数据开源库开发介绍

    GDAL(Geospatial Data Abstraction Library)是使用C/C++语言编写的用于读写空间数据的一套跨平台开源库.GDAL库可以读取.写入.转换.处理各种栅格数据格式,它 ...

  3. 原创程序|基于GDAL的遥感影像批量处理工具介绍(三)

    本文主要介绍基于C#+GDAL-Python实用工具开发的遥感影像批量处理工具,该工具目前主要包括影像批量切片生成KML文件和影像批量切片生成Tiles文件.该工具.Net框架版本为4.0,GDAL版 ...

  4. 部分GDAL工具功能简介

    部分GDAL工具功能简介 gdalinfo.exe 显示GDAL支持的各种栅格文件的信息. gdal_translate.exe 在不同的格式间进行转换.同时,潜在的执行了一些切割.重采样和使像素比例 ...

  5. python rasterio库和gdal库匹配与冲突问题安装办法

    前言 近期在对栅格数据进行处理的过程中需要用到rasterio库,在使用pycharm安装的过程中出现了各种问题,pycharm无法安装成功.切换了各种网络环境(包括使用代理)都无法解决.后来还是使用 ...

  6. GDAL综合整理--7:GDAL实用工具简介

    在网上看到这篇文章写得非常全面,而且是中文的,就转过来了,学习一下 其中有部分内容是重复的,不过不影响,非常好的资料 主要转自http://blog.csdn.net/liminlu0314?view ...

  7. java实现gdal栅格矢量化_gdal栅格矢量化 - osc_lfs4vsih的个人空间 - OSCHINA - 中文开源技术交流社区...

    #include "gdal_alg.h" 栅格矢量化功能用于将栅格数据生成矢量数据,通常用于分类图像.GDAL库中使用函数GDALPolygonize()或者函数GDALFPol ...

  8. 开源影像tif切图工具gdal2tiles部署以及切图

    切片效果图 安装python,这个网上很多教程,参照网上教程安装即可,这里不再描述. python安装python版本的gdal,以我本机python3.7版本为例: 下载gdal的whl文件安装包, ...

  9. python安装gdal包_python安装gdal的两种方法

    1.不用手动下载文件,直接执行以下命令即可 conda install gdal 2.首先,下载gdal的whl文件  链接, 官网下载比较慢,GDAL-2.2.4-cp27-cp27m-win_am ...

最新文章

  1. python文件信息排序_python文件排序的方法总结
  2. Android/Ophone中的悬浮对话框和即点即关对话框
  3. Java 里的 abstract 和 final 关键字
  4. 受大厂们青睐的Web前端工程师需要掌握的3项能力!
  5. [转] .NET 3.5中MSChart组件的ImageLocation属性含义
  6. 简约至上,美炸天的Vue圆环菜单组件
  7. 从零开始学PowerShell(8)创建一个进度条
  8. Linux网络监控工具nethogs
  9. Python 小入坑
  10. C语言 文件操作| 文件关闭 |文件写入 |文件读取
  11. 零基础学python用哪本书好-零基础想要学习Python编程 ,不知道看哪本书?
  12. hanlp提取文本关键词的使用方法记录
  13. iOS 实现快速切换主题详细教程(附上源码)
  14. 【产品经验谈】详解Axure中的默认元件库
  15. 国科大学习资料--矩阵分析与应用(李保滨)--2017年期末考试试卷
  16. java excel下拉框_Java设置Excel下拉列表
  17. 在抖音追剧要付费了,微短剧能成字节新财富密码吗?
  18. 基于Microhard P900无人机PIX飞控远距离数传解决方案
  19. 第二周 计算圆的面积
  20. 华科_图形学笔记_09_奇妙的真实感_片元着色01_01

热门文章

  1. Windows自带虚拟机的使用方法
  2. matlab用方程的解赋值,Matlab隐式符号方程求解和赋值
  3. R语言:逆变换法生成随机数
  4. Android 微信双开
  5. Python Selenium破解滑块验证码最新版!
  6. cannot enlist more than one non-XA resource
  7. 董事长 CEO 总裁 总经理 区别
  8. 建表错误:ParseException line 1:55 cannot recognize input near ‘)‘ ‘rowformat‘ ‘delimited‘ in column type
  9. 怎么给领导做项目汇报
  10. 人间哪知星空遥:荣耀30系列的巡天计划