WebGIS总结

一、webGIS技术使得人们通过浏览器使用地理信息系统


二、架构:
浏览器
    
www服务器
    
mapserver/argisserver
    
GIS空间数据库或文件
    

三、第三层介绍

其中mapserver是连接用户和数据的桥梁,他提供两种工作方式,

CGI方式(适用于CGI、AJAX、FLEX开发人员)和MapScript方式(适用于

Php、Java、 C#、Python开发人员)。两种方式都是用相同的配置文件:
MapFile文件将各种地图要素组织成具有层次关系的对象系统。

数据来源,使用的数据格式,用户交互和对OGC协议的支持也在MapFile中定义。

我们可以根据官方的语法规则手写mapfile,也可以利用QGIS等工具生成。



当浏览器通过URL告知Web Server调用MapServer CGI模块时(http://localhost/cgi-bin/
mapserv.exe?LAYERS=polyline&MAP=I:/my.map),Web Server就为CGI模块创建一个进程;
CGI模块运行并加载URL指定的MapFile文件,读取MapFile文件中的TEMPLATE文件(HTML文件),
并将TEMPLATE文件中CGI 变量的替换变量(template substitutions)替换成具体的值
;处理完TEMPLATE文件后,CGI模块将TEMPLATE文件处理结果(HTML文件)返回给Web Server,
Web Server在将HTML文件输出到用户浏览器上。这时TEMPLATE文件(HTML文件)就作为用户的交互界面。


直接通过CGI请求,得到的是一幅静态地图,为了实现地图的缩放、漫游,我们选用Openlayers地图客户端。 
通过OpenLayers.Layer.WMS可以直接调用MapServer地图服务,测试代码如下: 
var ms_layer = new OpenLayers.Layer.WMS( 
   "polyline", //OpenLayers中的图层名 
   "/cgi-bin/mapserv.exe", //MapServer地图服务器的路径 
   { layers: 'polyline', //Mapfile中定义的图层名 
     map: 'I:/cn_data/my.map', //Mapfile文件的绝对路径,注意必须使用'/'而不是'/',使用相对路径无法显示地图 
     format: 'gif' }, 
   { reproject: false, 
     'numZoomLevels': 20, 
     gutter: 15, 
     buffer: 0 }  
); 


PHP以CGI程序安装在Web Server中,把MapScript模块放置在PHP安装路径的extensions下,
配置php.int文件支持使用MapScript模块,就完成PHP/Mapscript安装。
在*.php文件或*.phtml文件中使用函数:dl(“MapScript模块名称”)就可以加载MapScript模块了。
由MapScript模块提供的API是基于对象的,它将MapFile中对象组织成对象接口。

在*.php文件或*.phtml文件中可以调用对象的属性和方法。


安装运行方法:为了方便我们可以选择使用ms4w,他集成了apache、php、mapserver等,并且同时有

安装版和绿色版。绿色版的解压后,运行apache-install.bat安装环境,并运行apache-restart.bat

来运行环境。把自己的web项目放到C:\ms4w\Apache\htdocs中,就可以用回环测试地址来访问

这个项目了。



四、第四层介绍

空间数据库我们采用的是postgresSQL+postGIS扩展

文件采用的是矢量地图shapefile,可以导入到上面的数据库。


五、Mapfile例子

# Mapfile文件必须以MAP开头 
MAP 
# Map的名字 test 
NAME test 
STATUS ON 
# 地图大小 
SIZE 800 600 
# Projection definition 
# Projections are not currenlty supported. If desired, add your own # projection information based on Mapserver documentation. 
# Map的坐标系 
PROJECTION "init=epsg:4326" 
END 


# Map的全图范围 
EXTENT 75 15 140 55 
# Map的坐标单位 DD表示经纬度 
UNITS DD 
# Map的背景颜色 白色 
IMAGECOLOR 255 255 255 
# 生成的图片类型,常用gif或png 
IMAGETYPE gif 
# shp文件的路径,请使用绝对路径 
SHAPEPATH "I://cn_data" 
#
# Start of web interface definition. Only the TEMPLATE parameter # must be specified to display a map. See Mapserver documentation
# MapServer内置了地图客户端功能,此处是Web客户端相关设置。 
# 由于我们使用Openlayers作为地图客户端,MapServer做为地图服务器,此处不做设置 
WEB 
# HEADER 
# TEMPLATE
# FOOTER
# 最小、最大比例尺等级 
MINSCALE 1 
MAXSCALE 13 
# 设置IMAGEPATH,默认路径如下,请使用绝对路径 
IMAGEPATH 'I:/ms4w/Apache/htdocs/tmp' 
# 设置IMAGEURL,默认路径如下 
IMAGEURL '/tmp/' 
END 
# 设置图层,一个Map下可以包含多个LAYER 
LAYER NAME polyline  # 图层名称,MapServer使用该名称 
TYPE LINE # 几何类型 
STATUS ON 
DATA "roa_4m" # shp文件名,不需要带扩展名,路径在前面的SHAPEPATH项中指定 
CLASS NAME "roa_4m" # 类名 
# TEMPLATE
COLOR 112 0 0 # 颜色 
END 
END 
END # Map File 

六、OpenLayers例子

window.onload = function() {
     
    var map = new OpenLayers.Map("map");


    var ol_wms = new OpenLayers.Layer.WMS(
        "OpenLayers WMS",
        "http://vmap0.tiles.osgeo.org/wms/vmap0",
        {layers: "basic"}
    );


    var dm_wms = new OpenLayers.Layer.WMS(
        "Canadian Data",
        "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap",
        {
            layers: "bathymetry,land_fn,park,drain_fn,drainage," +
                    "prov_bound,fedlimit,rail,road,popplace",
            transparent: "true",
            format: "image/png"
        },
        {isBaseLayer: false, visibility: false}
    );


    map.addLayers([ol_wms, dm_wms]);
    map.addControl(new OpenLayers.Control.LayerSwitcher());
    map.zoomToMaxExtent();
}


七、PHP的MapScript例子

<?php
//
// This example opens a regular MapServer .MAP file, renders the main
// Map image (with the default layers enabled), the legend and the 
// scale bar, and displays them in the HTML output.
//


//
// Load MapScript module.
//
if (PHP_OS == "WINNT" || PHP_OS == "WIN32")
{
  dl("php_mapscript.dll");
}
else
{
  dl("php_mapscript.so");
}


// 
// Load MapServer .map file
//
// You can download the MapServer demo data from http://mapserver.gis.umn.edu/
//
$map = ms_newMapObj("demo.map");


// print $map->numlayers;
// phpinfo();
 
//
// RENDER MAIN MAP
//
// Note: If you get errors with the saveWebImage() call below, then make sure
// that the directory specified by IMAGEPATH in the .MAP file exists and is
// writable by the httpd user.
//
$img = $map->draw();


$url = $img->saveWebImage();
printf("<IMG SRC=%s WIDTH=%d HEIGHT=%d>\n", $url, $map->width, $map->height);
 
//
// LEGEND
//
$img = $map->drawLegend();
$url = $img->saveWebImage();
printf("<P><IMG SRC=%s>\n", $url);
 
//
// SCALE BAR
//
$img = $map->drawScaleBar();
$url = $img->saveWebImage();
printf("<P><IMG SRC=%s>\n", $url);
 
?>


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值