免费视频|新人指南|投诉删帖|广告合作|地信网APP下载

查看: 3039|回复: 1
收起左侧

[技术交流] 研究了两天才把google的投影和Openlayers搞一致

[复制链接]

296

主题

3740

铜板

50

好友

地信学员

Rank: 12Rank: 12Rank: 12

积分
3471

斑竹勋章

发表于 2010-3-14 16:25 | 显示全部楼层 |阅读模式
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:
[pre]var layer = new OpenLayers.Layer.Google("Google", {"sphericalMercator": true});
[/pre]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:
[pre]            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)
};
[/pre]The projection in question can be expressed in proj4 as:
[pre]   +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
[/pre]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:
[pre]   <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
[/pre]If, for whatever reason, you can't edit your system PROJ.4 definitions (i.e., don't have root), you can use the CONFIG &quotROJ_LIB" option to the map object in MapServer, as described in the docs.
In GeoServer, you can define the Spherical Mercator projection as:
[pre]     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"]]
[/pre]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:
[pre]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');
[/pre]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
http://blog.myspace.cn/e/405020229.htm

1145

主题

10万

铜板

2

好友

传奇会员

Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30Rank: 30

积分
21817

灌水勋章活跃勋章冰雪节勋章

QQ
发表于 2013-11-17 18:52 | 显示全部楼层
进来看看,谢谢分享。

评分

参与人数 1铜板 +1 收起 理由
admin + 1 亲,你好快哦~~~

查看全部评分

加强科技支撑和引领  实现地质找矿新突破 。     
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

在线客服
快速回复 返回顶部 返回列表