EPSG:900913 与 EPSG:4326 转换方法

EPSG:900913 与 EPSG:4326 转换方法

前提条件是安装了Mapserver for Windows ms4w 软件包中已经包含 


1. 设置环境变量 
set GDAL_DATA=\ms4w\gdaldata 
path=%path%;\ms4w\tools\gdal-ogr;\ms4w\Apache\cgi-bin 

设置坐标系,EPSG:90013 
在Dos下执行这个命令: 
echo ^<900913^> +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs ^<^> >> \ms4w\proj\nad\epsg 

2. 转换Arcgis 的 SHP 文件(用ogr2ogr实现) 
G:\>ogr2ogr 

Usage: ogr2ogr [–help-general] [-skipfailures] [-append] [-update] 
               [-select field_list] [-where restricted_where] 
               [-sql <sql statement>] 
               [-spat xmin ymin xmax ymax] [-preserve_fid] [-fid FID] 
               [-a_srs srs_def] [-t_srs srs_def] [-s_srs srs_def] 
               [-f format_name] [-overwrite] [[-dsco NAME=VALUE] …] 
               dst_datasource_name src_datasource_name 
               [-lco NAME=VALUE] [-nln name] [-nlt type] [layer [layer …]] 

可以用ogrinfo 查看shp 信息 
F:\ms4w\apps\webgis\data2>ogrinfo -summary . rivers_region 
INFO: Open of `.’ 
      using driver `ESRI Shapefile’ successful. 

Layer name: rivers_region 
Geometry: Polygon 
Feature Count: 8370 
Extent: (112.980256, 22.538197) – (114.054200, 23.923092) 
Layer SRS WKT: 
GEOGCS[“Lat Long WGS84”, 
    DATUM[“WGS84”, 
        SPHEROID[“World_Geodetic_System_of_1984”,6378137,298.257223563]], 
    PRIMEM[“Greenwich”,0], 
    UNIT[“Degree”,0.017453292519943295]] 
序号: String (10.0) 
编号: String (10.0) 
名称: String (30.0) 
类型: String (15.0) 
LAT_HI: Real (10.6) 
LONG_HI: Real (11.6) 
LAT_LOW: Real (10.6) 
LONG_LOW: Real (11.6) 

现在是LonLat的坐标系,下面我们来转换: 
命令格式: 
ogr2ogr -t_srs EPSG:900913 <to_file.shp> <from_shape_file.shp> 

>ogr2ogr -t_srs EPSG:900913 out_river.shp rivers_region.shp 

执行后得到的结果是: 

F:\ms4w\apps\webgis\data2>ogrinfo -summary . out_river 
INFO: Open of `.’ 
      using driver `ESRI Shapefile’ successful. 

Layer name: out_river 
Geometry: Polygon 
Feature Count: 8370 
Extent: (12576904.567614, 2576266.091130) – (12696455.466834, 2744039.331212) 
Layer SRS WKT: 
PROJCS[“Google Maps Global Mercator”, 
    GEOGCS[“GCS_WGS_1984”, 
        DATUM[“WGS_1984”, 
            SPHEROID[“WGS_1984”,6378137,298.257223563]], 
        PRIMEM[“Greenwich”,0], 
        UNIT[“Degree”,0.017453292519943295]], 
    PROJECTION[“Mercator_2SP”], 
    PARAMETER[“standard_parallel_1”,0], 
    PARAMETER[“latitude_of_origin”,0], 
    PARAMETER[“central_meridian”,0], 
    PARAMETER[“false_easting”,0], 
    PARAMETER[“false_northing”,0], 
    UNIT[“Meter”,1], 
    EXTENSION[“PROJ4”,”+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 
x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs”]] 
序号: String (10.0) 
编号: String (10.0) 
名称: String (30.0) 
类型: String (15.0) 
LAT_HI: Real (10.6) 
LONG_HI: Real (11.6) 
LAT_LOW: Real (10.6) 
LONG_LOW: Real (11.6) 

3.Raster 文件的转换方式。 
Raster 文件通过是用GeoTiff的格式,中间包含了地理信息。 
命令格式: 
gdalwarp -s_srs EPSG:4326 -t_srs EPSG:900913 <from_file.tif> <to_file.tif> 

先查看一下图片信息: 
F:\ms4w\apps\webgis\data2>gdalinfo fg-900.TIF 
Warning 1: TIFFFetchNormalTag:ASCII value for tag “Software” does not end in nul 
l byte 
Driver: GTiff/GeoTIFF 
Files: fg-900.TIF 
Size is 2058, 1756 
Coordinate System is `’ 
Origin = (113.204516152319740,23.234743614544065) 
Pixel Size = (0.000121859844067,-0.000121859844067) 
Metadata: 
  TIFFTAG_SOFTWARE= 
  TIFFTAG_XRESOLUTION=300 
  TIFFTAG_YRESOLUTION=300 
  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch) 
Image Structure Metadata: 
  INTERLEAVE=BAND 
Corner Coordinates: 
Upper Left  ( 113.2045162,  23.2347436) 
Lower Left  ( 113.2045162,  23.0207577) 
Upper Right ( 113.4553037,  23.2347436) 
Lower Right ( 113.4553037,  23.0207577) 
Center      ( 113.3299099,  23.1277507) 
Band 1 Block=2058×3 Type=Byte, ColorInterp=Palette 
  Color Table (RGB with 256 entries) 
    0: 0,0,0,255 
    1: 128,0,0,255 
    2: 0,128,0,255 
    3: 128,128,0,255 
    4: 0,0,128,255 
    5: 128,0,128,255 
    6: 0,128,128,255 

执行转换命令: 
F:\ms4w\apps\webgis\data2>gdalwarp -s_srs EPSG:4326 -t_srs EPSG:900913 fg-900.TI 
F fg-900-n.TIF 
Warning 1: TIFFFetchNormalTag:ASCII value for tag “Software” does not end in nul 
l byte 
Copying color table from fg-900.TIF to new file. 
Creating output file that is 1983P x 1840L. 
Warning 1: TIFFFetchNormalTag:ASCII value for tag “Software” does not end in nul 
l byte 
Processing input file fg-900.TIF. 
0…10…20…30…40…50…60…70…80…90…100 – done. 

执行完成后,我们再检查一下: 
F:\ms4w\apps\webgis\data2>gdalinfo fg-900-n.TIF 
Driver: GTiff/GeoTIFF 
Files: fg-900-n.TIF 
Size is 1983, 1840 
Coordinate System is: 
PROJCS[“Google Maps Global Mercator”, 
    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″]], 
    PROJECTION[“Mercator_1SP”], 
    PARAMETER[“central_meridian”,0], 
    PARAMETER[“scale_factor”,1], 
    PARAMETER[“false_easting”,0], 
    PARAMETER[“false_northing”,0], 
    UNIT[“metre”,1, 
        AUTHORITY[“EPSG”,”9001″]]] 
Origin = (12601869.093575137000000,2660431.700036020900000) 
Pixel Size = (14.077025171240757,-14.077025171240757) 
Metadata: 
  AREA_OR_POINT=Area 
Image Structure Metadata: 
  INTERLEAVE=BAND 
Corner Coordinates: 
Upper Left  (12601869.094, 2660431.700) (113d12’16.26″E, 23d22’28.38″N) 
Lower Left  (12601869.094, 2634529.974) (113d12’16.26″E, 23d 9’34.49″N) 
Upper Right (12629783.834, 2660431.700) (113d27’19.00″E, 23d22’28.38″N) 
Lower Right (12629783.834, 2634529.974) (113d27’19.00″E, 23d 9’34.49″N) 
Center      (12615826.464, 2647480.837) (113d19’47.63″E, 23d16’1.59″N) 
Band 1 Block=1983×4 Type=Byte, ColorInterp=Palette 
  Color Table (RGB with 256 entries) 
    0: 0,0,0,255 
    1: 128,0,0,255 
    2: 0,128,0,255 
    3: 128,128,0,255 
    4: 0,0,128,255 
    5: 128,0,128,255 

END. 

转载自:https://blog.csdn.net/xyr05288/article/details/42640745

You may also like...