如何将平面图像投影到球形墨卡托EPGS:900013以在openlayers的图像层中使用 [英] how to project a flat image to spherical mercator EPGS:900013 to use in a Image Layer in openlayers

查看:337
本文介绍了如何将平面图像投影到球形墨卡托EPGS:900013以在openlayers的图像层中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个400x400像素的平面图像,代表400x400公里的区域.我需要将此图像绘制为OpenLayers映射系统上的覆盖图.我将OpenStreetMap/Google地图用作基础图层.我想使用图像层"绘制覆盖图像,并希望将覆盖图像居中于特定的纬度/经度点.基本层的投影是EPSG:900913,实际上是OpenStreetMap和Google Maps使用的投影.

I have a flat 400x400 pixels image which represents an area of 400x400 kilometers. I need to draw this image as an overlay on my OpenLayers mapping system. I use OpenStreetMap/Google Maps as base layers. I want to draw the overlay image using an Image Layer and I want to center my overlay image at a specific lat/lon point. The projection of the base layer is EPSG:900913 which is, in fact, the projection used by OpenStreetMap and Google Maps.

我所了解的(如果我错了,请纠正我)是我不能使用平坦的未投影"图像作为图像层,但是我必须进行某种重新投影"调整符合地图投影的图像,即EPSG:900913.在这里和网上搜索,似乎我应该使用一个名为GDAL的库/工具来执行此操作,但是我对此完全陌生,请问您:

What I have understood (please correct me if I'm wrong), is that I can't use a flat, 'unprojected' image as an Image Layer, but I have to do a sort of 'reprojecting' to adjust the image to be compliant with the projection of the map, which is EPSG:900913. Searching here and the net, it seems I should use a library/tool called GDAL to do this, but whereas I am completely new to this I ask you:

  • 有人可以向我介绍如何使用它吗?
  • 您能告诉我我刚才说的话是否正确,我在这里描述的方式是否有效?
  • 如何使用gdal将未投影的平面400x400像素图像转换为以EPSG:900913投影的图像,并适合作为图像层作为叠加层放置?

谢谢.

我按要求添加了图片.

@capdragon提供的答案很有用,让我更进一步.无论如何,我仍然有一些问题.我是这样做的:

The answer provided by @capdragon was useful and let me going one step further. Anyway I have still some problems. I did this:

  1. 使用gdal_translate将GCP设置为图像的四个角和中心,如下所示:

gdal_translate -of "GTIFF" -gcp 0 0 8.6923 45.5427 -gcp 400 0 13.8149 45.5427 -gcp 200 200 11.2536 43.771702 -gcp 0 400 8.8413 41.9460 -gcp 400 400 13.6659 41.9460 quadrprod.png quadrprod_gpc.tif

这样,我得到了quadrprod_gcp.tif输出.然后.

This way I get a quadrprod_gcp.tif output. Then.

  1. 使用gdalwarp应用上面的点中设置的GCP并设置正确的投影,即EPSG:4326,如下所示:

gdalwarp -t_srs EPSG:4326 quadrprod_gcp.tif quadrprod_gcp_warped.tif

这样,我得到了最终的quadrprod_gcp_warped.tif.生成的图像不再是400x400像素,而是458x331像素.然后,如果我使用gdalinfo进行查看,就会发现:

This way I get a final quadrprod_gcp_warped.tif. The resulting image is no more 400x400 pixels but is 458x331 pixels. Then if I use gdalinfo to look at it, I found this:

gdalinfo quadrprod_gcp_warped.tif
Driver: GTiff/GeoTIFF
Files: quadrprod_gcp_warped.tif
Size is 458, 331
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (8.768046497499189,45.547291862003739)
Pixel Size = (0.010877474938832,-0.010877474938832)
Metadata:
    AREA_OR_POINT=Area
Image Structure Metadata:
    INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (   8.7680465,  45.5472919) (  8d46'4.97"E, 45d32'50.25"N)
Lower Left  (   8.7680465,  41.9468477) (  8d46'4.97"E, 41d56'48.65"N)
Upper Right (  13.7499300,  45.5472919) ( 13d44'59.75"E, 45d32'50.25"N)
Lower Right (  13.7499300,  41.9468477) ( 13d44'59.75"E, 41d56'48.65"N)
Center      (  11.2589883,  43.7470698) ( 11d15'32.36"E, 43d44'49.45"N)
Band 1 Block=458x4 Type=Byte, ColorInterp=Red
    Mask Flags: PER_DATASET ALPHA
Band 2 Block=458x4 Type=Byte, ColorInterp=Green
    Mask Flags: PER_DATASET ALPHA
Band 3 Block=458x4 Type=Byte, ColorInterp=Blue
    Mask Flags: PER_DATASET ALPHA
Band 4 Block=458x4 Type=Byte, ColorInterp=Alpha

如您所见,四个角和中心纬度/经度与我使用-gcp值设置的值不同.我的问题:

As you can see the 4 corners and the center lat/lon are different from the values I set using -gcp values. My questions:

  • 为什么gdalinfo返回的经纬度值与我在步骤1中使用-gpc设置的值不同?
  • 这是正常现象还是我做错了什么?
  • 下一步是什么?我应该再次将图像从EPSG:4326转换为EPSG:900913吗?
  • 当我将图像作为叠加层放置在openlayers中时,当创建bounds对象时,应该将在-gcp中使用的值还是在gdalinfo中看到的最终值用作西南角和东北角?

推荐答案

您所说的是正确的.

您基本上想使用gdal_translate设置一些控制点(参考点),然后使用gdalwarp扭曲图像.

You basically want to set some control points (reference points) using gdal_translate then warp the image using gdalwarp.

因此,对于粗略的投影,您可以像这样简单地使用角坐标来设置4个控制点. (这些示例使用的是EPSG:4326,但是您可以使用EPSG:900913.

So for a rough projection you could simply use the corner cordinates to set 4 control points like so. (These examples are using EPSG:4326, but you can use EPSG:900913.

gdal_translate -a_srs EPSG:4326 -gcp 0 0 -89.38939600 30.39282800 -gcp 1024 0 -87.00029400 30.01043900 -gcp 0 1250 -89.99424800 27.37030800 -gcp 1024 1250 -87.67748400 26.98606100 "originalImage.tif" "image_trans.tiff"

上面说像素x = 0和y = 0等于"-89.38939600 30.39282800"像素x = 1024且y = 0是-87.00029400 30.01043900,依此类推.

The above is saying that pixel x=0 and y=0 is equal to "-89.38939600 30.39282800" pixel x=1024 and y=0 is -87.00029400 30.01043900 and so forth.

gdalwarp -dstalpha -t_srs EPSG:4326 image_trans.tiff image_warped.tiff

如果变形效果不佳,则需要在图像上设置更多的控制点.

If the warping isn't good enough you're going to need to set more control points on the image.

我下载了您的图片并运行了您拥有的命令.一切对我来说都很好: |

I downloaded your image and ran the commands you have. Everything worked fine for me: |

    captDragon@liberatecuba:/media/Data/tmp/orthoTesting$ gdal_translate -of "GTIFF" -gcp 0 0 8.6923 45.5427 -gcp 400 0 13.8149 45.5427 -gcp 200 200 11.2536 43.771702 -gcp 0 400 8.8413 41.9460 -gcp 400 400 13.6659 41.9460 quadrprod.png quadrprod_gpc.tif
    Input file size is 400, 400
    0...10...20...30...40...50...60...70...80...90...100 - done.
captDragon@liberatecuba:/media/Data/tmp/orthoTesting$ gdalinfo quadrprod_gpc.tif 
    Driver: GTiff/GeoTIFF
    Files: quadrprod_gpc.tif
    Size is 400, 400
    Coordinate System is `'
    GCP Projection = 
    GCP[  0]: Id=1, Info=
              (0,0) -> (8.6923,45.5427,0)
    GCP[  1]: Id=2, Info=
              (400,0) -> (13.8149,45.5427,0)
    GCP[  2]: Id=3, Info=
              (200,200) -> (11.2536,43.771702,0)
    GCP[  3]: Id=4, Info=
              (0,400) -> (8.8413,41.946,0)
    GCP[  4]: Id=5, Info=
              (400,400) -> (13.6659,41.946,0)
    Image Structure Metadata:
      INTERLEAVE=PIXEL
    Corner Coordinates:
    Upper Left  (    0.0,    0.0)
    Lower Left  (    0.0,  400.0)
    Upper Right (  400.0,    0.0)
    Lower Right (  400.0,  400.0)
    Center      (  200.0,  200.0)
    Band 1 Block=400x5 Type=Byte, ColorInterp=Red
      Mask Flags: PER_DATASET ALPHA 
    Band 2 Block=400x5 Type=Byte, ColorInterp=Green
      Mask Flags: PER_DATASET ALPHA 
    Band 3 Block=400x5 Type=Byte, ColorInterp=Blue
      Mask Flags: PER_DATASET ALPHA 
    Band 4 Block=400x5 Type=Byte, ColorInterp=Alpha

这篇关于如何将平面图像投影到球形墨卡托EPGS:900013以在openlayers的图像层中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆