研究了两天才把google的投影和Openlayers搞一致

http://www.cnblogs.com/mimi001/articles/1355080.html

The world is not quite a sphere -- but the commercial mapping APIs tend to disbelieve that. They use a Mercator projection with an earth-as-a-sphere assumption. crschmidt is working on a document that goes into this in further detail: http://crschmidt.net/~crschmidt/spherical_mercator.html

In order to interact with them, in OpenLayers 2.5 and beyond, you will create a layer with a sphericalMercator option set to true:

var layer = new OpenLayers.Layer.Google("Google", {"sphericalMercator": true});

This is the best way to overlay data on top of the Google Maps API in OpenLayers, and other alternatives may eventually not be supported. (This includes the 'reproject: true' option on WMS layers.)

The options you should use with this configuration are:

            var options = {

projection: new OpenLayers.Projection("EPSG:900913"),

units: "m",

maxResolution: 156543.0339,

maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,

20037508.34, 20037508.34)

};

The projection in question can be expressed in proj4 as:

   +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 +no_defs

See http://proj.maptools.org/faq.html#sphere_as_wgs84 for more information on why this is.

This can be added to /usr/share/epsg/proj, and thus MapServer, GDAL, etc. by adding the following line to the file:

   <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 +no_defs

If, for whatever reason, you can't edit your system PROJ.4 definitions (i.e., don't have root), you can use the CONFIG "PROJ_LIB" option to the map object in MapServer, as described in the docs.

In GeoServer, you can define the Spherical Mercator projection as:

     900913=PROJCS["WGS84 / Simple Mercator", GEOGCS["WGS 84",

DATUM["WGS_1984", SPHEROID["WGS_1984", 6378137.0, 298.257223563]],

PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295],

AXIS["Longitude", EAST], AXIS["Latitude", NORTH]],

PROJECTION["Mercator_1SP_Google"],

PARAMETER["latitude_of_origin", 0.0], PARAMETER["central_meridian", 0.0],

PARAMETER["scale_factor", 1.0], PARAMETER["false_easting", 0.0],

PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["x", EAST],

AXIS["y", NORTH], AUTHORITY["EPSG","900913"]]

Note that GeoServer versions 1.5.4 and above already include this definition, so no additional server side configuration is needed to overlay on OpenLayers as long as you are using the latest versions.

Note that GeoServer's WKT uses a special PROJECTION parameter which will probably not be supported by other software.

In PostGIS, you can run this sql script to add the correct projection setting:

INSERT into spatial_ref_sys (srid, auth_name, auth_srid, srtext, proj4text) values (900913 ,'EPSG',900913,'GEOGCS["WGS 84", DATUM["World Geodetic System

1984", SPHEROID["WGS 84", 6378137.0, 298.257223563,AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], NIT["degree",0.017453292519943295], AXIS["Longitude", EAST], AXIS["Latitude", NORTH],AUTHORITY["EPSG","4326"]], PROJECTION["Mercator_1SP"],PARAMETER["semi_minor", 6378137.0],

PARAMETER["latitude_of_origin",0.0], PARAMETER["central_meridian", 0.0], PARAMETER["scale_factor",1.0], PARAMETER["false_easting", 0.0], PARAMETER["false_northing", 0.0],UNIT["m", 1.0], AXIS["x", EAST], AXIS["y", NORTH],AUTHORITY["EPSG","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 +no_defs');

WMS/other Services Supporting EPSG:900913 ¶

Service Link Layer
Nexrad WMS Weather Feed 
(updated every 5 minutes):
http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi nexrad-n0r-900913
CIA Factbook: http://world.freemap.in/cgi-bin/mapserv?map=/www/freemap.in/world/map/world-overlay.map





EPSG:4326(WGS84) WMS in Openlayers and EPSG:900913 Google Map

周二, 2009-05-12 01:32 — leelight

In SUAS Map Server I used Openlayers to display WMS layers in EPSG:4326 SRS with Google Map, I found the WMS overlays are always be transformed, now i kown the reason. EPSG:4326 != EPSG:900913

The world is not quite a sphere -- but the commercial mapping APIs tend
to disbelieve that. They use a Mercator projection with an
earth-as-a-sphere assumption. crschmidt is working on a document that
goes into this in further detail: http://crschmidt.net/~crschmidt/spherical_mercator.html

In order to interact with them, in OpenLayers 2.5 and beyond, you will create a layer with a sphericalMercator option set to true:

var layer = new OpenLayers.Layer.Google("Google", {"sphericalMercator": true});

    

This is the best way to overlay data on top of the Google Maps API in OpenLayers, and other alternatives may eventually not be supported. (This includes the 'reproject: true' option on WMS layers.)

The options you should use with this configuration are:

            var options = {

    projection: new OpenLayers.Projection("EPSG:900913"),

    units: "m",

    maxResolution: 156543.0339,

    maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34,

    20037508.34, 20037508.34)

    };

    

The projection in question can be expressed in proj4 as:

   +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 +no_defs

    

See http://proj.maptools.org/faq.html#sphere_as_wgs84 for more information on why this is.

This can be added to /usr/share/epsg/proj, and thus MapServer, GDAL, etc. by adding the following line to the file:

   <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 +no_defs

    

If, for whatever reason, you can't edit your system PROJ.4 definitions
(i.e., don't have root), you can use the CONFIG "PROJ_LIB" option to
the map object in MapServer, as described in the docs.

In GeoServer, you can define the Spherical Mercator projection as:

     900913=PROJCS["WGS84 / Simple Mercator", GEOGCS["WGS 84",

    DATUM["WGS_1984", SPHEROID["WGS_1984", 6378137.0, 298.257223563]],

    PRIMEM["Greenwich", 0.0], UNIT["degree", 0.017453292519943295],

    AXIS["Longitude", EAST], AXIS["Latitude", NORTH]],

    PROJECTION["Mercator_1SP_Google"],

    PARAMETER["latitude_of_origin", 0.0], PARAMETER["central_meridian", 0.0],

    PARAMETER["scale_factor", 1.0], PARAMETER["false_easting", 0.0],

    PARAMETER["false_northing", 0.0], UNIT["m", 1.0], AXIS["x", EAST],

    AXIS["y", NORTH], AUTHORITY["EPSG","900913"]]

    

Note that GeoServer versions 1.5.4 and above already include this
definition, so no additional server side configuration is needed to
overlay on OpenLayers as long as you are using the latest versions.

Note that GeoServer's WKT uses a special PROJECTION parameter which will probably not be supported by other software.

In PostGIS, you can run this sql script to add the correct projection setting:

INSERT into spatial_ref_sys (srid, auth_name, auth_srid, srtext, proj4text) values (900913 ,'EPSG',900913,'GEOGCS["WGS 84", DATUM["World Geodetic System

    1984", SPHEROID["WGS 84", 6378137.0, 298.257223563,AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], NIT["degree",0.017453292519943295], AXIS["Longitude", EAST], AXIS["Latitude", NORTH],AUTHORITY["EPSG","4326"]], PROJECTION["Mercator_1SP"],PARAMETER["semi_minor", 6378137.0],

    PARAMETER["latitude_of_origin",0.0], PARAMETER["central_meridian", 0.0], PARAMETER["scale_factor",1.0], PARAMETER["false_easting", 0.0], PARAMETER["false_northing", 0.0],UNIT["m", 1.0], AXIS["x", EAST], AXIS["y", NORTH],AUTHORITY["EPSG","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 +no_defs');

    

WMS/other Services Supporting EPSG:900913 ¶

Service Link Layer
Nexrad WMS Weather Feed 
(updated every 5 minutes):
http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi nexrad-n0r-900913
CIA Factbook: http://world.freemap.in/cgi-bin/mapserv?map=/www/freemap.in/world/map/world-overlay.map world

 

Ref:
http://trac.openlayers.org/wiki/SphericalMercator
http://spin.mohawkcollege.ca/courses/jackgibb/newmapping/googleWMS.html


http://www.easywms.com/easywms/?q=zh-hans/node/3592

你可能感兴趣的:(OpenLayers)