自己今天一步一步做的,總結(jié)如下。 0. 檢查 檢查當前MS4W是否支持OGC WMS服務 使用DOS命令行進入MS4W的安裝路徑(如D:\ms4w\Apache\cgi-bin), 執(zhí)行mapserv -v C:\ms4w\Apache\cgi-bin>mapserv-v MapServerversion 5.2.1 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=PDF OUTPUT=SWF OUTPUT=SVG SUPPORTS=PROJSUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=ICO NVSUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENTSUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUP PORTS=THREADSSUPPORTS=GEOS SUPPORTS=RGBA_PNG INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE 1. 安裝qgis 下載osgeo4w-setup.exe 最新版,直接運行,選擇桌面GIS即可 安裝完成后如下
2. 運行QGIS,生成*.map文件 在插件選項中,添加 mapserver export 插件 打開幾個shp圖層,右擊每個圖層,在屬性中設置使用oldsymbology,否則不能導出到mapserver
選了3個圖層,生成的map文件如下: # Map file created from QGIS project file I:/GIS/freeGIS/QGIS/chianmap_final.qgs # Edit this file to customize for your map interface # (Created with PyQgis MapServer Export plugin) MAP NAME"QGIS-MAP" # Map image size SIZE 1200 800 UNITS meters
EXTENT 49.189774-3.159989 173.282634 76.327090 FONTSET'fontset.txt' SYMBOLSET'symbols.txt' PROJECTION 'proj=longlat' 'ellps=WGS84' 'towgs84=0,0,0,0,0,0,0' 'no_defs' END
# Backgroundcolor for the map canvas -- change as desired IMAGECOLOR 255255 255 IMAGEQUALITY 95 IMAGETYPE agg
OUTPUTFORMAT NAME agg DRIVER AGG/PNG IMAGEMODE RGB END # Legend LEGEND IMAGECOLOR255 255 255 STATUS ON KEYSIZE 18 12 LABEL TYPE BITMAP SIZE MEDIUM COLOR 0 0 89 END END
# Web interfacedefinition. Only the template parameter # is required todisplay a map. See MapServer documentation WEB # Set IMAGEPATHto the path where MapServer should # write itsoutput. IMAGEPATH'/tmp/'
# Set IMAGEURLto the url that points to IMAGEPATH # as defined inyour web server configuration IMAGEURL'/tmp/'
# WMS serversettings METADATA 'ows_title' 'QGIS-MAP' 'ows_onlineresource' 'http://192.168.1.94:8080/cgi-bin/mapserv.exe?map=I:/GIS/freeGIS/QGIS/tt.map' 'ows_srs' 'EPSG:4326' END
#Scale range atwhich web interface will operate # Template andheader/footer settings # Only thetemplate parameter is required to display a map. See MapServer documentation TEMPLATE'fooOnlyForWMSGetFeatureInfo' END
LAYER NAME 'bou2_4p' TYPE POLYGON DUMP true TEMPLATEfooOnlyForWMSGetFeatureInfo EXTENT 49.189774-3.159989 173.282634 76.327090 DATA'I:\GIS\maps\chinamap_final\bou2_4p.shp' METADATA 'ows_title' 'bou2_4p' END STATUS OFF TRANSPARENCY100 PROJECTION 'proj=longlat' 'ellps=WGS84' 'towgs84=0,0,0,0,0,0,0' 'no_defs' END CLASS NAME'bou2_4p' STYLE WIDTH 1 OUTLINECOLOR 0 0 0 COLOR 21091 200 END END END
LAYER NAME'chinaMapL' TYPE LINE DUMP true TEMPLATEfooOnlyForWMSGetFeatureInfo EXTENT 49.189774-3.159989 173.282634 76.327090 DATA'I:\GIS\maps\chinamap_final\chinaMapL.shp' METADATA 'ows_title''chinaMapL' END STATUS OFF TRANSPARENCY100 PROJECTION 'proj=longlat' 'ellps=WGS84' 'towgs84=0,0,0,0,0,0,0' 'no_defs' END CLASS NAME'chinaMapL' STYLE WIDTH 1 COLOR 182134 241 END END END
LAYER NAME 'railway' TYPE LINE DUMP true TEMPLATEfooOnlyForWMSGetFeatureInfo EXTENT 49.189774-3.159989 173.282634 76.327090 DATA'I:\GIS\maps\chinamap_final\railway.shp' METADATA 'ows_title''railway' END STATUS OFF TRANSPARENCY100 PROJECTION 'proj=longlat' 'ellps=WGS84' 'towgs84=0,0,0,0,0,0,0' 'no_defs' END CLASS NAME'railway' STYLE WIDTH 1 COLOR 13595 134 END END END
END
注意需要把里面的WIDTH 改為1,之前是0.91,否則會出錯 在apache目錄的htdocs下新建一map文件夾,將字體、symbols等文件
并且把map文件里面的FONTSET 和SYMBOLSET修改如下: FONTSET 'fontset.txt' SYMBOLSET 'symbols.txt'
3. 用瀏覽器訪問地圖服務
4. 更改apache的設置 在\Apache\cgi-bin復制mapserv.exe一份,改名xmap.exe 打開ms4w安裝目錄\Apache\conf\httpd.conf編輯 最后一行添加:
#用于碰到url中有/cgi-bin/xmap.exe,就調(diào)用../htdocs/map/test.map作為地圖 SetEnvIf Request_URI "/cgi-bin/xmap.exe"MS_MAPFILE=../htdocs/map/test.map 然后使用瀏覽器訪問 http://192.168.1.94:8080/cgi-bin/xmap.exe?LAYERS=ALL&MODE=MAP 結(jié)果如下:
5. 在openlayers 中調(diào)用 在調(diào)用自己的mapserver發(fā)布的wms服務時,地圖的option中,單位需要與wms的單位一致,如 units : "dd",否則距離量算不準確。 最大最小分辨率決定了地圖在最小最大縮放時的大小
必須設置一個圖層為基層圖層,其他圖層為非基基礎圖層,并且透明度設置為true,如下: var layer1 = new OpenLayers.Layer.WMS("layer1", "http://localhost:8080/cgi-bin/xmap.exe?",{ layers: 'railway',transparent: "true",IMAGETYPE: 'PNG'}, { isBaseLayer: false}); var layer2 = new OpenLayers.Layer.WMS("layer2", "http://localhost:8080/cgi-bin/xmap.exe?",{ layers: 'chinaMapL',transparent: "true",IMAGETYPE: 'PNG'}, { isBaseLayer: false}); var layer3 = new OpenLayers.Layer.WMS("layer3", "http://localhost:8080/cgi-bin/xmap.exe?",{ layers: 'bou2_4p',IMAGETYPE: 'PNG'}, { isBaseLayer: true}); map.addLayers([layer1,layer2,layer3]); 如下:
6. Qgis中可以設置地圖顯示樣式,比如polygon對象的顏色分級,label標注字段、字體,圖層的顯示比例尺范圍等。 設置好以后,還是直接導出為mapserver所需的*.map文件,注意修改里面的 FONTSET 'fontset.txt' 以及WIDTH為1. 就可以用了,實時渲染就是非常慢,本機都慢。
7. 下一步用mapserver發(fā)布WFS。
add: symbols.txt的內(nèi)容如下,直接拷貝即可: Symbol
fontset.txt內(nèi)容如下: simhei Fonts\simhei.ttf Fonts文件夾內(nèi)容如下,你只拷貝fontset.txt中的字體文件進去即可:
|
|