Google Earth 图片处理

从Google Earth上抓回来的地图是4326坐标系的,JPEG 图片,没有压缩的,质量比较好。但是相应的.map文件的格式如下:

!table
OziExplorer Map Data File Version 2.2
tianhe1.jpg
C:\users\Gecapture\tianhe1.jpg
1 ,Map Code,
WGS 84,WGS 84,   0.0000,   0.0000,WGS 84
Reserved 1
Reserved 2
Magnetic Variation,,,E
Map Projection,Latitude/Longitude,PolyCal,No,AutoCalOnly,No,BSBUseWPX,No
Point01,xy,284,197,in, deg, 23, 9.028140,N, 113, 17.976480,E, grid,   ,           ,           ,
Point02,xy,8520,1970,in, deg, 23, 8.072580,N, 113, 22.894800,E, grid,   ,           ,           ,
Point03,xy,8520,4334,in, deg, 23, 6.799800,N, 113, 22.885200,E, grid,   ,           ,           ,
Point04,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point05,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point06,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point07,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point08,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point09,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point10,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point11,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point12,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point13,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point14,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point15,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point16,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point17,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point18,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point19,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point20,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point21,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point22,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point23,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point24,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point25,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point26,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point27,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point28,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point29,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Point30,xy,     ,     ,in, deg,    ,        ,,    ,        ,, grid,   ,           ,           ,
Projection Setup,,,,,,,,,,
Map Feature = MF ; Map Comment = MC     These follow if they exist
Track File = TF      These follow if they exist
Moving Map Parameters = MM?    These follow if they exist
MM0,Yes
MMPNUM,4
MMPXY,1,0,0
MMPXY,2,9088,0
MMPXY,3,9088,7092
MMPXY,4,0,7092
MMPLL,1, 113.296784, 23.152230
MMPLL,2, 113.387115, 23.152230
MMPLL,3, 113.387115, 23.088601
MMPLL,4, 113.296784, 23.088601
MM1B,1.017826
LL Grid Setup
LLGRID,No,No Grid,Yes,255,16711680,0,No Labels,0,16777215,7,1,Yes,x
Other Grid Setup
GRGRID,No,No Grid,Yes,255,16711680,No Labels,0,16777215,8,1,Yes,No,No,x
MOP,Map Open Position,0,0
IWH,Map Image Width/Height,9088,7092


需要修改成为后缀为.tab的文件才能转换。

!table
!version 300
!charset WindowsSimpChinese

Definition Table
  File "tianhe1.jpg"
  Type "RASTER"
  (113.296784, 23.152230) (0,0) Label "Pt 1",
  (113.387115, 23.152230) (9088,0) Label "Pt 2",
  (113.296784, 23.088601) (0,7092) Label "Pt 3"
  CoordSys Earth Projection 1, 104
  Units "degree"

=== set_tab.rb=====
k = 0
File.open(ARGV[0], 'r').each_line do |line|
  k = k+1
  $filename = line.chomp if k == 2
  if line[0..6] == 'MMPXY,3'
    ss = line.chomp.split(',')
    $width = ss[2]
    $height = ss[3]
  end
 
  if line[0..6] == 'MMPLL,1'
    ss = line.chomp.split(',') 
    $x0, $y0 = ss[2], ss[3]
  end

  if line[0..6] == 'MMPLL,3'
    ss = line.chomp.split(',') 
    $x1, $y1 = ss[2], ss[3]
  end
end 

puts '!version 300'
puts '!charset WindowsSimpChinese'
puts
puts 'Definition Table'
puts "  File \"#{$filename}\""
puts "  Type \"RASTER\""
puts "  (#{$x0},#{$y0}) (0,0) Label \"Pt 1\","
puts "  (#{$x1},#{$y0}) (#{$width},0) Label \"Pt 2\","
puts "  (#{$x0},#{$y1}) (0,#{$height}) Label \"Pt 3\""
puts '  CoordSys Earth Projection 1, 104'
puts '  Units "degree"'

=== end of ruby script ====

运行:liujun$ ruby set_tab.rb tianhe1.map

!version 300
!charset WindowsSimpChinese

Definition Table
  File "tianhe1.jpg"
  Type "RASTER"
  ( 113.296784, 23.152230) (0,0) Label "Pt 1",
  ( 113.387115, 23.152230) (9088,0) Label "Pt 2",
  ( 113.296784, 23.088601) (0,7092) Label "Pt 3"
  CoordSys Earth Projection 1, 104
  Units "degree"

重新定向到 ruby set_tab.rb tianhe1.map > tianhe1.tab

.tab文件准备好之后,就可以用gdalwarp 把坐标系和ERSI的信息加进去生成GeoTiff  图片了。


liujun$ gdalwarp -s_srs EPSG:4326 -of GTiff tianhe1.jpg tt.tif
Creating output file that is 9424P x 6639L.
Processing input file tianhe1.jpg.
0...10...20...30...40...50...60...70...80...90...100 - done.

然后用
liujun$ gdalinfo tt.tif
Driver: GTiff/GeoTIFF
Files: tt.tif
Size is 9424, 6639
Coordinate System is:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.2572235630016,
            AUTHORITY["EPSG","7030"]],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0],
    UNIT["degree",0.0174532925199433],
    AUTHORITY["EPSG","4326"]]
Origin = (113.296784000000031,23.152230000000014)
Pixel Size = (0.000009584844494,-0.000009584844494)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  ( 113.2967840,  23.1522300) (113d17'48.42"E, 23d 9'8.03"N)
Lower Left  ( 113.2967840,  23.0885962) (113d17'48.42"E, 23d 5'18.95"N)
Upper Right ( 113.3871116,  23.1522300) (113d23'13.60"E, 23d 9'8.03"N)
Lower Right ( 113.3871116,  23.0885962) (113d23'13.60"E, 23d 5'18.95"N)
Center      ( 113.3419478,  23.1204131) (113d20'31.01"E, 23d 7'13.49"N)
Band 1 Block=9424x1 Type=Byte, ColorInterp=Red
Band 2 Block=9424x1 Type=Byte, ColorInterp=Green
Band 3 Block=9424x1 Type=Byte, ColorInterp=Blue


然后就可以用 gdal2tiles.py 来生成cahce文件了。由于边界问题,所以还不是特别规整,这个可以尝试。

liu-juns-macbook-pro:Gecapture liujun$ gdal2tiles.py tt.tif  ./tt_out/
Generating Base Tiles:
0...10...20...30...40...50...60...70...80...90...100 - done.
Generating Overview Tiles:
0...10...20...30...40...50...60...70...80...90...100 - done.

1km的高度,就是17级的。

如果要18, 19甚至更高级别的图片就需要重新下载更详细的Google图片


如果要加到OpenLayers 里面,可以先在geoserver里面登记一下,然后再用相同的方法处理一下。

你可能感兴趣的:(Google,Ruby)