posts - 41,  comments - 90,  trackbacks - 0
            2010年11月24日

          Android老大哥安迪魯賓近日在發(fā)布2.3姜餅系統(tǒng)和Nexus S的時(shí)候曾演示了最新版本的Google Maps 5.0手機(jī)地圖,最大的變化就是采用了全3D地圖。

          在新版手機(jī)地圖中,矢量圖將替換原本的2D畫(huà)面為用戶(hù)呈現(xiàn)出全新的3D界面,用戶(hù)可以自由的轉(zhuǎn)動(dòng)和縮放。此外用戶(hù)還將會(huì)獲得離線(xiàn)地圖瀏覽功能,不用在瀏覽地圖時(shí)保持在線(xiàn)狀態(tài)。

          Google現(xiàn)在在其官方手機(jī)頻道又放出了一段用Nexus S運(yùn)行新版Maps應(yīng)用的全功能演示,這款軟件將會(huì)隨Nexus S上市,之后提供其他設(shè)備更新,但是對(duì)手機(jī)硬件有一定的要求,新款800MHz至1GHz處理器且配有專(zhuān)用圖形核心的手機(jī)才能支持3D視圖。



          原文見(jiàn)驅(qū)動(dòng)之家
          http://news.mydrivers.com/1/181/181818.htm
          posted @ 2010-12-12 21:54 天狼 閱讀(611) | 評(píng)論 (1)編輯 收藏
          天地圖官方網(wǎng)站提供的二次開(kāi)發(fā)文檔和例子過(guò)于簡(jiǎn)單,很多關(guān)鍵信息沒(méi)有給予說(shuō)明,例如給出了WFS服務(wù)接口,卻沒(méi)有提供詳細(xì)的開(kāi)發(fā)文檔。
          不過(guò)這并不影響我們的使用,因?yàn)镺GC WFS規(guī)范包含元數(shù)據(jù)查詢(xún)命令,通過(guò)發(fā)送getCapabilities請(qǐng)求,我們可以得知服務(wù)器提供哪些WFS服務(wù)。

          獲取WFS服務(wù)器元數(shù)據(jù)
          http://search.tianditu.com/wfs?request=getCapabilities
          返回信息如下:
          <WFS_Capabilities version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengeospatial.net//wfs/1.0.0/WFS-capabilities.xsd">
          <Service>
          <Name>GeoGlobe WFS</Name>
          <Title>GeoGlobe網(wǎng)絡(luò)要素服務(wù)器</Title>
          <Abstract>武大吉奧信息技術(shù)有限公司GeoGlobe網(wǎng)絡(luò)要素服務(wù)器</Abstract>
          <KeywordList/>
          <OnlineResource>http://search.tianditu.com:80/wfs</OnlineResource>
          </Service>
          <Capability>
          <Request>
          <GetCapabilities>
          <DCPType>
          <HTTP>
          <Get onlineResource="http://search.tianditu.com:80/wfs"/>
          </HTTP>
          </DCPType>
          </GetCapabilities>
          <GetFeature>
          <ResultFormat>
          <GML2/>
          </ResultFormat>
          <DCPType>
          <HTTP>
          <Get onlineResource="http://search.tianditu.com:80/wfs"/>
          <Post onlineResource="http://search.tianditu.com:80/wfs"/>
          </HTTP>
          </DCPType>
          </GetFeature>
          <DescribeFeatureType>
          <SchemaDescriptionLanguage>
          <XMLSCHEMA/>
          </SchemaDescriptionLanguage>
          <DCPType>
          <HTTP>
          <Get onlineResource="http://search.tianditu.com:80/wfs"/>
          </HTTP>
          </DCPType>
          </DescribeFeatureType>
          </Request>
          <VendorSpecificCapabilities/>
          </Capability>
          <FeatureTypeList>
          <Operations>
          <Query/>
          </Operations>
          <FeatureType>
          <Name>DOMAIN_POI_NEW</Name>
          <Title>DOMAIN_POI_NEW</Title>
          <Abstract>DOMAIN_POI_NEW</Abstract>
          <Keywords>DOMAIN_POI_NEW</Keywords>
          <SRS>EPSG:4326</SRS>
          <LatLongBoundingBox minx="-180.0" miny="-90.0" maxx="180.0" maxy="90.0"/>
          </FeatureType>
          <FeatureType>
          <Name>iso19112:SI_Gazetteer</Name>
          <Title>iso19112:SI_Gazetteer</Title>
          <SRS>EPSG:4326</SRS>
          <LatLongBoundingBox minx="-180.0" miny="-90.0" maxx="180.0" maxy="90.0"/>
          </FeatureType>
          </FeatureTypeList>
          <ogc:Filter_Capabilities>
          <ogc:Spatial_Capabilities>
          <ogc:Spatial_Operators>
          <ogc:BBOX/>
          <ogc:Equals/>
          <ogc:Disjoint/>
          <ogc:Intersect/>
          <ogc:Touches/>
          <ogc:Crosses/>
          <ogc:Within/>
          <ogc:Contains/>
          <ogc:Overlaps/>
          <ogc:Beyond/>
          </ogc:Spatial_Operators>
          </ogc:Spatial_Capabilities>
          <ogc:Scalar_Capabilities>
          <ogc:Logical_Operators/>
          <ogc:Comparison_Operators>
          <ogc:Simple_Comparisons/>
          <ogc:Like/>
          <ogc:Between/>
          </ogc:Comparison_Operators>
          </ogc:Scalar_Capabilities>
          </ogc:Filter_Capabilities>
          </WFS_Capabilities>

          返回信息包含了WFS服務(wù)器的開(kāi)發(fā)單位(武大吉奧),WFS圖層的名稱(chēng)(DOMAIN_POI_NEW和iso19112:SI_Gazetteer),支持的邏輯操作符和空間操作符。

          繼續(xù)測(cè)試
          http://search.tianditu.com/wfs?request=GetFeature&version=1.0.0&typeName=DOMAIN_POI_NEW&BBOX=105.99,29.99,106,30
          返回
          <wfs:FeatureCollection xsi:schemaLocation="http://www.opengis.net/wfs WFS_Basic.xsd http://www.geostart.com.cn/geoglobe describe.xsd">
          <gml:boundedBy>
          <gml:Box>
          <gml:coordinates>-180.0,-90.0 180.0,90.0</gml:coordinates>
          </gml:Box>
          </gml:boundedBy>
          <gml:featureMember>
          <DOMAIN_POI_NEW>
          <OID>6764930</OID>
          <Geometry>
          <gml:Point srsName="-1">
          <gml:coordinates>105.999183,29.995258</gml:coordinates>
          </gml:Point>
          </Geometry>
          <DOMAINNAME>梅子村</DOMAINNAME>
          <DOMAINCODE>1CHN50022400000130172</DOMAINCODE>
          <NLEVEL>16</NLEVEL>
          <X>105.999183</X>
          <Y>29.995258</Y>
          <COLDATE/>
          <NAMETIME/>
          <ENDTIME/>
          <CLASSID/>
          <STANDARDNAME>亞洲中國(guó)重慶市銅梁縣梅子村</STANDARDNAME>
          <TELEPHONE/>
          <ADDRESS/>
          <KIND>BB80</KIND>
          <ZIPCODE/>
          <ADMINCODE>500224</ADMINCODE>
          <POI_ID>5000000130172</POI_ID>
          <PID/>
          <DATATYPE>chinapoi</DATATYPE>
          <FENAME/>
          <locationType>
          <SI_LocationType>
          <name>DOMAIN_POI_NEW</name>
          </SI_LocationType>
          </locationType>
          </DOMAIN_POI_NEW>
          </gml:featureMember>
          </wfs:FeatureCollection>

          分析返回的GML數(shù)據(jù),可知DOMAIN_POI_NEW是地名圖層,包含名稱(chēng)、代碼、類(lèi)別碼等屬性字段。

          將圖層改為iso19112:SI_Gazetteer,沒(méi)有返回任何信息,google ISO19112,得到如下解釋?zhuān)?br /> DIN EN ISO 19112-2005 地理信息.通過(guò)地理標(biāo)識(shí)符的空間定位 標(biāo)準(zhǔn)號(hào): DIN EN ISO 19112-2005 標(biāo)準(zhǔn)名稱(chēng): 地理信息.通過(guò)地理標(biāo)識(shí)符的空間定位

          得到以上信息后,我們嘗試使用Openlayers獲取,即全國(guó)地名數(shù)據(jù)庫(kù)。

          通過(guò)URL(GET方式)訪(fǎng)問(wèn)“天地圖”WFS服務(wù),可以使用OpenLayers.Request.GET類(lèi),示例代碼如下:
             //使用FEATUREID查詢(xún)

             new OpenLayers.Request.GET( {
                  url : "http://search.tianditu.com/wfs?request=GetFeature",
                  params: {
                      typeName: "DOMAIN_POI_NEW",
                      FEATUREID: "DOMAIN_POI_NEW.6649356"
                  },
                  callback : handler
              });


             //使用BBOX查詢(xún)

              new OpenLayers.Request.GET( {
                  url : "http://search.tianditu.com/wfs?request=GetFeature",
                  params: {
                      typeName: "DOMAIN_POI_NEW",
                      BBOX: "105.99,29.99,106,30"  //map.getExtent().toBBOX()
                  },
                  callback : handler
              });


          說(shuō)明:
          url WFS服務(wù)器地址,必須加上?request=GetFeature
          typeName 圖層名稱(chēng)
          FEATUREID WFS的圖元ID,采用標(biāo)準(zhǔn)格式: [圖層名].[OID編號(hào)]
          BBOX 指定區(qū)域查詢(xún),注意不要設(shè)置過(guò)大,否則瀏覽器可能失去響應(yīng)。

          通過(guò)POST方式訪(fǎng)問(wèn)“天地圖”WFS服務(wù),可以使用OpenLayers.Request.POST類(lèi),示例代碼如下:

              var xmlPara = "<?xml version='1.0' encoding='UTF-8'?>"
                      + "<wfs:GetFeature maxFeatures='100' service='WFS' version='1.0.0' "
                      + "xmlns:wfs='http://www.opengis.net/wfs' "
                      + "xmlns:gml='http://www.opengis.net/gml' "
                      + "xmlns:ogc='http://www.opengis.net/ogc' "
                      + "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "
                      + "xsi:schemaLocation='http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd'>"
                      + "<wfs:Query typeName='iso19112:SI_Gazetteer' srsName='EPSG:4326'>"
                      + "<ogc:Filter xmlns:ogc='http://www.opengis.net/ogc'>"
                      + "<ogc:And><ogc:PropertyIsLike wildCard='*' singleChar='.' escape='!'>"
                      + "<ogc:PropertyName>STANDARDNAME</ogc:PropertyName>"
                      + "<ogc:Literal>*解放碑*</ogc:Literal>"
                      + "</ogc:PropertyIsLike></ogc:And></ogc:Filter>"
                      + "</wfs:Query></wfs:GetFeature>";
              
              var request = OpenLayers.Request.POST( {
                  url : "http://search.tianditu.com/wfs?",
                  data : xmlPara,
                  callback : handler
              });
          };

          說(shuō)明:

          url WFS服務(wù)器地址

          data WFS請(qǐng)求正文,返回的GML由回調(diào)函數(shù)handler處理

          handler負(fù)責(zé)處理服務(wù)端返回的GML數(shù)據(jù),也就是矢量化的地圖數(shù)據(jù),根據(jù)應(yīng)用需求編寫(xiě)代碼,獲取feature的通用代碼如下:
          var g = new OpenLayers.Format.GML();
          var features = g.read(req.responseText);
          for ( var i = 0; i < features.length; ++i) {
             var feature = features[i];
             var geometry = feature.geometry;
             var attributes = feature.attributes;
          }

          定義過(guò)濾條件時(shí)請(qǐng)使用STANDARDNAME字段,不要使用DOMAINNAME字段,前者應(yīng)該有索引支持,而后者沒(méi)有,查詢(xún)速度差別很大。

          經(jīng)過(guò)測(cè)試,typeName="DOMAIN_POI_NEW"和typeName="iso19112:SI_Gazetteer"都能返回結(jié)果。由于缺少官方文檔說(shuō)明,不知道這兩個(gè)圖層有何區(qū)別。

          嘗試使用OpenLayers.Protocol.WFS無(wú)法訪(fǎng)問(wèn)“天地圖”WFS服務(wù),服務(wù)器返回: 請(qǐng)求參數(shù)[REQUEST]的值為空或不正確。

          提醒: 使用POST查詢(xún)時(shí),頁(yè)面文件或代碼文件務(wù)必保存為utf-8編碼,如果使用gbk、gb2312編碼,漢字地名會(huì)變成亂碼,導(dǎo)致javascript代碼錯(cuò)誤。

          posted @ 2010-12-10 16:22 天狼 閱讀(5943) | 評(píng)論 (3)編輯 收藏
          國(guó)家測(cè)繪局2010年10月21日正式發(fā)布中國(guó)公眾版國(guó)家地理信息公共服務(wù)平臺(tái)“天地圖”,作為中國(guó)境內(nèi)數(shù)據(jù)資源最全的地理信息服務(wù)網(wǎng)站,“天地圖”將為公眾提供權(quán)威、可信、統(tǒng)一的地理信息資源。

          “天地圖”公開(kāi)開(kāi)放了地圖數(shù)據(jù)服務(wù)接口,第三方使用者可以直接通過(guò)互聯(lián)網(wǎng)獲取地圖數(shù)據(jù),無(wú)需授權(quán)認(rèn)證,在公眾服務(wù)信息公開(kāi)方面可以說(shuō)是一次非常大的進(jìn)步。
          “天地圖”的在線(xiàn)服務(wù)數(shù)據(jù)近10TB,以下是“天地圖”提供的在線(xiàn)地理信息數(shù)據(jù)資源:

          數(shù)據(jù)類(lèi)型

          數(shù)據(jù)源

          級(jí)別

          服務(wù)地址

          線(xiàn)劃地圖

          全球1:100萬(wàn)地理底圖

          2-10級(jí)

          http://tile0.tianditu.com/services/A0512_EMap

          http://tile0.tianditu.com/services/AB0512_Anno

          全國(guó)1:25萬(wàn)公開(kāi)版數(shù)字地形圖

          11-12級(jí)

          http://tile0.tianditu.com/services/B0627_EMap1112

          全國(guó)車(chē)載導(dǎo)航

          13-18級(jí)

          http://tile0.tianditu.com/services/siwei0608

          衛(wèi)星影像

          全球250米衛(wèi)星影像 (MODIS)

          2-7級(jí)

          http://tile0.tianditu.com/services/sbsm0210

          全國(guó)15米衛(wèi)星影像 (ETM)

          8-10級(jí)

          全國(guó)2.5米衛(wèi)星影像 (P5)

          11-14級(jí)

          http://tile0.tianditu.com/services/e11

          http://tile0.tianditu.com/services/e12
          http://tile0.tianditu.com/services/e13
          http://tile0.tianditu.com/services/eastdawnall

          地級(jí)城市0.6米衛(wèi)星影像

           (QuickBird、WorldView I、WorldView II)

          15-18級(jí)

          http://tile0.tianditu.com/services/sbsm1518

          數(shù)字高程模型

          全球90X90米數(shù)字高程模型

           

          http://tile0.tianditu.com/services/J07098

          地名地址

          全球1:100萬(wàn)地名地址

           

          http://search.tianditu.com/wfs

          全國(guó)1:25萬(wàn)地名地址


          全國(guó)車(chē)載導(dǎo)航地名地址


          除地名地址數(shù)據(jù)使用OGC WFS協(xié)議發(fā)布外,其他數(shù)據(jù)全部采用基于OGC WMS-C協(xié)議的分級(jí)瓦片形式發(fā)布,工作原理類(lèi)似于谷歌地圖和OSM(OpenStreetMap)。

          類(lèi)似谷歌地圖,“天地圖”為互聯(lián)網(wǎng)開(kāi)發(fā)人員提供了二次開(kāi)發(fā)API(武大吉奧開(kāi)發(fā)的GeoGlobe二維地圖API)。

          通過(guò)分析GeoGlobe API代碼,發(fā)現(xiàn)它源自O(shè)penlayers,大部分代碼除了把Openlayers換成GeoSurf外,沒(méi)有任何變化。不知道Openlayers項(xiàng)目組就此作何感想。
          正因?yàn)槿绱?,我們可以參考OpenLayers.Layer.TileCache和OpenLayers.Layer.XYZ類(lèi),編寫(xiě)一個(gè)專(zhuān)用于讀取“天地圖”的TDTLayer類(lèi),使Openlayers能夠直接訪(fǎng)問(wèn)“天地圖”的在線(xiàn)地圖數(shù)據(jù)。

          “天地圖”采用256×256像素,png格式的地圖瓦片文件,讀取單個(gè)文件需要四個(gè)參數(shù):T、X、Y、L
          T=瓦片(Tile)名稱(chēng),X=瓦片橫向編碼,Y=瓦片縱向編碼,L=瓦片級(jí)別
          這個(gè)是一個(gè)完整的請(qǐng)求示例:http://tile0.tianditu.com/DataServer?T=AB0512_Anno&X=50&Y=12&L=6

          天地圖”地理信息數(shù)據(jù)資源列表將地圖瓦片分為16級(jí)(L=2-18),其中L=2級(jí)比例尺最小,對(duì)應(yīng)全球地圖。
          L=2級(jí)只有8個(gè)瓦片文件,分別是

           X= 0 1 2 3 0 1 2 3
           Y= 0 0 0 0 1 1 1 1
          L=3級(jí)有32個(gè)瓦片文件,分別是:
           X= 0-7
           Y= 0-3
          L=4級(jí)有128個(gè)瓦片文件,分別是:
           X= 0-15
           Y= 0-7
          其余各級(jí)以此類(lèi)推,每級(jí)的瓦片文件數(shù)比前一級(jí)增加4倍,其中線(xiàn)劃地圖10級(jí)以上,衛(wèi)星地圖8級(jí)以上只提供中國(guó)境內(nèi)的數(shù)據(jù),沒(méi)有覆蓋全球。

          查看
          GeoGlobe API主代碼GeoSurfJSAPI.js文件(相當(dāng)于Openlayers.js,可以了解X(x_num)、Y(y_num)、L(level)的生成方法,偽代碼如下:
          level=getLevelForResolution(map.getResolution()); //計(jì)算瓦片級(jí)別
          coef=TopTileSize.w/Math.pow(2,level); //中間系數(shù)
          x_num=this.pyramid.topTileFromX<this.pyramid.topTileToX?Math.round((bounds.left-this.pyramid.topTileFromX)/coef):Math.round((this.pyramid.topTileFromX-bounds.right)/coef);
          y_num=this.pyramid.topTileFromY<this.pyramid.topTileToY?Math.round((bounds.bottom-this.pyramid.topTileFromY)/coef):Math.round((this.pyramid.topTileFromY-bounds.top)/coef);
          根據(jù)當(dāng)前分辨率計(jì)算地圖瓦片級(jí)別
          function getLevelForResolution(res){
          var ratio=map.getMaxResolution()/res;
          if(ratio<1)return 0;
          for(var level=0;ratio/2>=1;)
          {level++;ratio/=2;}
          return level;
          }

          經(jīng)過(guò)簡(jiǎn)單測(cè)試,“天地圖”和谷歌地圖在數(shù)據(jù)上差別不大,二次開(kāi)發(fā)方面借助于強(qiáng)大的Openlayers地圖客戶(hù)端引擎不會(huì)弱于Google Map API,唯獨(dú)在速度上與谷歌地圖存在較大差距,特別是地圖放大到13級(jí)-18級(jí)時(shí),延遲變得非常明顯,有時(shí)甚至無(wú)法顯示。
          使用Firebug跟蹤運(yùn)行發(fā)現(xiàn),大約1/3的地圖瓦片請(qǐng)求超時(shí),導(dǎo)致客戶(hù)端讀取失敗。
          “天地圖”目前還處于測(cè)試階段,希望相關(guān)單位繼續(xù)改進(jìn)和提升服務(wù)器端性能,快速穩(wěn)定的響應(yīng)大量客戶(hù)端發(fā)出的并發(fā)請(qǐng)求。
          測(cè)試中發(fā)現(xiàn),“天地圖”開(kāi)放的地圖數(shù)據(jù)服務(wù)接口從tile0.tianditu.com一直到tile7.tianditu.com。依次ping 這8個(gè)服務(wù)接口,tile1到tile7的響應(yīng)速度相對(duì)較快。修改客戶(hù)端js代碼,將瓦片地圖請(qǐng)求平均發(fā)送給tile0到tile7 八個(gè)服務(wù)接口,可以有效加快地圖顯示速度。“天地圖”提供的GeoSurfJSAPI.js中已經(jīng)包含相關(guān)代碼,通過(guò)給Layer的mirrorUrl屬性賦值,可以均衡讀取指定的多個(gè)服務(wù)接口,代碼如下:
                                  var layer3 = new GeoSurf.Layer.GlobeTile("siwei0608", "http://tile6.tianditu.com/services/siwei0608", {
                                          transitionEffect: "resize",
                                          topLevel: 13,
                                          bottomLevel: 18,
                                          maxExtent: new GeoSurf.Bounds(100, 27, 110, 34),
                                          mirrorUrls: [
                                              "http://tile1.tianditu.com/services/siwei0608",
                                              "http://tile2.tianditu.com/services/siwei0608",
                                              "http://tile3.tianditu.com/services/siwei0608",
                                              "http://tile4.tianditu.com/services/siwei0608",
                                              "http://tile5.tianditu.com/services/siwei0608",
                                              "http://tile6.tianditu.com/services/siwei0608"
                                          ]
                                      });

          客戶(hù)端使用上述讀取策略后,即便放大到17-18級(jí),整幅地圖也能夠完全顯示,速度有明顯的提升。


          posted @ 2010-12-06 14:06 天狼 閱讀(8603) | 評(píng)論 (5)編輯 收藏
          發(fā)布WFS矢量地圖

          OGC WFS協(xié)議定義了地圖客戶(hù)端查詢(xún)和傳送矢量數(shù)據(jù)的方法,在查詢(xún)、分析、動(dòng)態(tài)繪圖等實(shí)際應(yīng)用中非常有用。MapServer支持OGC WFS 1.0.0和1.1.0規(guī)范。

          重新定義一個(gè)Mapfile文件,命名為ext2.map,內(nèi)容如下:
          MAP

            NAME "vector"
              SHAPEPATH "I://cn_data"
              
              FONTSET fonts.txt
              IMAGECOLOR 255 255 255
              IMAGETYPE agg

              SIZE 800 600
              STATUS ON
              UNITS DD
              EXTENT 115.275 39.2204 117.475 40.9462
             
              OUTPUTFORMAT
                  NAME agg
                  DRIVER AGG/PNG
                  IMAGEMODE RGB
                  FORMATOPTION "INTERLACE=false"
                  MIMETYPE "image/png"
              END

              PROJECTION
                  "init=epsg:4326"
              END

              WEB
                  METADATA
                      "wms_title"                       "road wms"
                      "wfs_title"                       "road wfs"
                      "wms_onlineresource"              "http://192.98.151.23/cgi-bin/mapserv.exe?"  #mapserver服務(wù)器的url
                      "wms_srs"                         "EPSG:4326"   #地圖坐標(biāo)系        
                  END
              END

              LAYER
                  NAME "road"
                  METADATA
                      "wms_title"                       "road"
                      "wfs_title"                       "road"
                      "wms_srs"                         "EPSG:4326"  #圖層坐標(biāo)系
                      "gml_include_items"             "all"
                      "gml_featureid"                 "id" #必須指定id
                  END
                  STATUS ON
                  DATA "roa_4m.shp"
                  TYPE line
                  DUMP TRUE
                  CLASS
                      STYLE
                          COLOR "#00FF00"
                      END
                  END
              END

          END

          該文件中有兩組METADATA標(biāo)簽,是WFS(WMS) Server所需要的,分別是MAP的METADATA標(biāo)簽和LAYER的METADATA標(biāo)簽。
          前者是針對(duì)整個(gè)地圖的全局定義,后者是每個(gè)圖層的元數(shù)據(jù)定義。

          保存Mapfile文件,打開(kāi)瀏覽器進(jìn)行測(cè)試
          http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetCapabilities
          正常情況下,可以看到以下返回信息
          <WFS_Capabilities version="1.0.0" updateSequence="0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-capabilities.xsd">
          <!--
           MapServer version 5.2.1 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=PDF OUTPUT=SWF OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS=THREADS SUPPORTS=GEOS SUPPORTS=RGBA_PNG INPUT=JPEG INPUT=POSTGIS INPUT=ORACLESPATIAL INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE
          -->
          <Service>
          <Name>MapServer WFS</Name>
          <Title>road wfs</Title>
          <OnlineResource>
          http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&
          </OnlineResource>
          </Service>
          <Capability>
          <Request>
          <GetCapabilities>
          <DCPType>
          <HTTP>
          <Get onlineResource="http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&"/>
          </HTTP>
          </DCPType>
          <DCPType>
          <HTTP>
          <Post onlineResource="http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&"/>
          </HTTP>
          </DCPType>
          </GetCapabilities>
          <DescribeFeatureType>
          <SchemaDescriptionLanguage>
          <XMLSCHEMA/>
          </SchemaDescriptionLanguage>
          <DCPType>
          <HTTP>
          <Get onlineResource="http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&"/>
          </HTTP>
          </DCPType>
          <DCPType>
          <HTTP>
          <Post onlineResource="http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&"/>
          </HTTP>
          </DCPType>
          </DescribeFeatureType>
          <GetFeature>
          <ResultFormat>
          <GML2/>
          </ResultFormat>
          <DCPType>
          <HTTP>
          <Get onlineResource="http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&"/>
          </HTTP>
          </DCPType>
          <DCPType>
          <HTTP>
          <Post onlineResource="http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&"/>
          </HTTP>
          </DCPType>
          </GetFeature>
          </Request>
          </Capability>
          <FeatureTypeList>
          <Operations>
          <Query/>
          </Operations>
          <FeatureType>
          <Name>road</Name>
          <Title>road</Title>
          <SRS>EPSG:4326</SRS>
          <LatLongBoundingBox minx="80.3869" miny="18.2823" maxx="132.515" maxy="49.6272"/>
          </FeatureType>
          </FeatureTypeList>
          <ogc:Filter_Capabilities>
          <ogc:Spatial_Capabilities>
          <ogc:Spatial_Operators>
          <ogc:Equals/>
          <ogc:Disjoint/>
          <ogc:Touches/>
          <ogc:Within/>
          <ogc:Overlaps/>
          <ogc:Crosses/>
          <ogc:Intersect/>
          <ogc:Contains/>
          <ogc:DWithin/>
          <ogc:BBOX/>
          </ogc:Spatial_Operators>
          </ogc:Spatial_Capabilities>
          <ogc:Scalar_Capabilities>
          <ogc:Logical_Operators/>
          <ogc:Comparison_Operators>
          <ogc:Simple_Comparisons/>
          <ogc:Like/>
          <ogc:Between/>
          </ogc:Comparison_Operators>
          </ogc:Scalar_Capabilities>
          </ogc:Filter_Capabilities>
          </WFS_Capabilities>

          在OpenLayers中加載WFS圖層

          OpenLayers是一個(gè)功能強(qiáng)大的Web地圖客戶(hù)端引擎。

          接下來(lái),我們利用OpenLayers的OpenLayers.Protocol.WFS類(lèi),顯示剛才發(fā)布的WFS圖層,代碼如下

                 var protocol = OpenLayers.Protocol.WFS({
                              url: "http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&", //mapserver地圖服務(wù)器的url,加上mapfi了文件的路徑
                              featureType: "road", //layer的名稱(chēng)
                              srsName: "EPSG:4326", //layer的坐標(biāo)系
                              geometryName: "msGeometry", //geometry字段的名稱(chēng)
                              featurePrefix: "ms"
                          });

          以下是全部javascript代碼:
                  window.onload = function() {
                          var map = new OpenLayers.Map('mapdiv', {
                              projection: "EPSG:4326",
                              units: "degree"
                          });
                          
                          var roads = new OpenLayers.Layer.WMS("road", "http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&", {
                              layers: 'road',
                              transparent: 'true',
                              format: 'image/png'
                          }, {
                              isBaseLayer: false,
                              visibility: true,
                              buffer: 0
                          });
                          
                          
                          var empty = new OpenLayers.Layer("empty", {
                              isBaseLayer: true
                          });
                          
                          var select = new OpenLayers.Layer.Vector("Selection", {
                              styleMap: new OpenLayers.Style(OpenLayers.Feature.Vector.style["select"]),
                              displayInLayerSwitcher: false
                          });
                          
                          var hover = new OpenLayers.Layer.Vector("Hover", {
                              displayInLayerSwitcher: false
                          });
                          
                          map.addLayers([roads, hover, select, empty]);
                          
                          var protocol = OpenLayers.Protocol.WFS({
                              url: "http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&",
                              featureType: "road",
                              srsName: "EPSG:4326",
                              geometryName: "msGeometry",
                              featurePrefix: "ms"
                          });
                          
                          var control = new OpenLayers.Control.GetFeature({
                              protocol: protocol,
                              box: true,
                              hover: true,
                              multipleKey: "shiftKey",
                              toggleKey: "ctrlKey"
                          });
                          
                          control.events.register("featureselected", this, function(e){
                              select.addFeatures([e.feature]);
                          });
                          control.events.register("featureunselected", this, function(e){
                              select.removeFeatures([e.feature]);
                          });
                          control.events.register("hoverfeature", this, function(e){
                              hover.addFeatures([e.feature]);
                          });
                          
                          control.events.register("outfeature", this, function(e){
                              hover.removeFeatures([e.feature]);
                          });
                          
                          map.addControl(control);
                          control.activate();
                          
                          map.addControl(new OpenLayers.Control.LayerSwitcher());
                          map.addControl(new OpenLayers.Control.MousePosition());
                          
                          if (!map.getCenter()) {
                              map.zoomToMaxExtent();
                          }

                      }

          在瀏覽器中運(yùn)行html頁(yè)面,國(guó)道數(shù)據(jù)將以矢量方式傳送到客戶(hù)端,由openlayers動(dòng)態(tài)繪制,鼠標(biāo)移動(dòng)到道路上或者選中道路,道路將實(shí)時(shí)改變顏色,在Web上實(shí)現(xiàn)與傳統(tǒng)桌面GIS應(yīng)用類(lèi)似的體驗(yàn)效果。

          posted @ 2010-12-01 15:00 天狼 閱讀(2524) | 評(píng)論 (0)編輯 收藏
          在今年的FOSS4G國(guó)際大會(huì)上,geoserver項(xiàng)目組發(fā)布了2.1beta1版本。
          新版本增加了多項(xiàng)引人注目的功能,原文如下:

          WMS Cascading

          Something users have asked for since the addition of WMS support itself is cascading, the ability of GeoServer to proxy for another remote WMS server like MapServer or another GeoServer. This feature has many uses such as pulling in a remote base layer and overlaying local vector data onto it or securing a locally unsecured map server. Special thanks to the University of Perugia for sponsoring this feature.

          Read more about WMS cascading.

          Virtual Services

          Anyone who has published a large number of layers or feature types with GeoServer has probably at some point been annoyed by the fact that every single layer is published by a single global service. WMS has the ability to group and nest layers but WFS and WCS have no such equivalent. Well now with virtual services one can create multiple service endpoints within a single physical geoserver instance.

          Special thanks to Landgate for funding this work.

          Read more about virtual services.

          Layers from SQL

          GeoServer has always been good at publishing a flat database table. But users often need to do more such as pre filter the data in a table, or join two tables together, or generate column values on the fly with a function. Before this feature the recommendation was to create a view. However views can be a maintenance burden and are at times problematic.

          Now one can create a layer directly from an SQL query. And on top of that query definitions can be parameterized which allows one to create dynamic queries on the fly. These parameters can be restricted with regular expressions in order to prevent an SQL injection security hole.

          Special thanks to Andrea for spending much of his personal time on this one. And also to OBIS who provided the funding for the parametric component of the work.

          Read more about SQL layers.

          WPS

          With 2.1 and the arrival of WPS we welcome a new OGC service to the family. The Web Processing Service is an OGC service for performing geospatial analysis functions over the web. The specification is extensible in nature and allows for simple processes like buffering a geometry to more complex processes such as image processing.

          Historically GeoServer has been focused primarily on data delivery without any tools for performing analysis of spatial data. WPS fills that gap making GeoServer a more compete solution for geospatial web services.

          Thanks to Refractions Research for the initial contribution of the WPS module and to Andrea once again for taking personal time to bring WPS support to its current state.

          Read more about WPS. Download the WPS extension now to try it out.

          Unit of Measure

          Support for units in SLD allows one to specify values in measurements other than pixels such as feet or meters. This adds a very powerful capability to SLD that in many cases alleviates the need for multiple scale dependent rendering rules. This has the upside of greatly simplifying complex SLD documents.

          Special thanks to Milton Jonathan who did the initial GeoTools work to make unit of measure support possible and to Andrea for working with Milton to improve the initial patch. Note that this feature has also been backported to the stable 2.0.x branch. Thanks to SWECO and Malmö City of Sweden for sponsoring the backport.

          Read more about UOM support.

          DPI Scaling

          By default GeoServer renders images at a resolution of 90 DPI. While this is acceptable for the standard screen it is not acceptable for print which requires a higher resolution. Now it is possible to supply a format option to a WMS request on the fly that controls the DPI setting.

          Special thanks again to SWECO and to Malmö City of Sweden for sponsoring this work. Note also that this feature has also been backported to the stable 2.0.x branch.

          Read more about DPI scaling.



          posted @ 2010-12-01 10:42 天狼 閱讀(1764) | 評(píng)論 (0)編輯 收藏
          為MapServer添加瓦片緩存服務(wù)

          國(guó)際上有兩個(gè)比較流行的開(kāi)源地圖瓦片緩存服務(wù)器:geowebcache和tilecache。
          geowebcache基于J2EE架構(gòu),具有完整的Web圖形管理界面,支持多進(jìn)程并發(fā)切圖,可以隨時(shí)查看切圖進(jìn)度和剩余時(shí)間,搭配geoserver非常合適。
          titlecache采用python編寫(xiě),CGI工作模式,非常小巧,2.11版本只有令人驚訝的68K!(這一點(diǎn)很像MapServer)。
          titlecache采用SHELL或DOS命令行方式運(yùn)行切圖程序,實(shí)時(shí)輸出切圖進(jìn)度信息。
          mapserver選擇titlecache作為地圖切片緩存服務(wù)器,在ms4w_3.0beta10中包含了tilecache插件,由于beta版本存在問(wèn)題,
          我們?cè)趍s4w_2.3.1正式版中手工加入tilecache服務(wù)器,具體步驟如下:

          1、從tilecache官方網(wǎng)站下載安裝包tilecache-2.11.tar.gz,該安裝包適用于所有操作系統(tǒng),我們使用Windows XP。
          2、解壓安裝包,將其中的tilecache-2.11目錄整體復(fù)制到ms4w的apps目錄下。
          3、進(jìn)入ms4w的http.d目錄,新建一個(gè)名為httpd_tilecache.conf的文本文件,內(nèi)容如下:
          Alias /tilecache/ "/ms4w/apps/tilecache-2.11/"
          <Directory "/ms4w/apps/tilecache-2.11/">
            AllowOverride None
            Options ExecCGI
            Order allow,deny
            Allow from all
          </Directory>
          addHandler cgi-script .cgi .py
          4、進(jìn)入ms4w/apps/tilecache-2.11目錄,打開(kāi)tilecache.cgi文件,修改第一行的python編譯器路徑,例如
          #!E:\Python25\python.exe
          5、打開(kāi)該目錄下的tilecache.cfg文件,修改cache標(biāo)簽,指定本地磁盤(pán)緩存目錄,例如
          [cache]
          type=Disk
          base=F:/tmp/tilecache
          添加一個(gè)road標(biāo)簽,指定地圖服務(wù)類(lèi)型,服務(wù)地址,mapfile文件路徑,圖層名稱(chēng),柵格格式,空間參考系統(tǒng)編碼,例如
          [road]
          type=WMS
          url=http://127.0.0.1/cgi-bin/mapserv.exe?map=I:/cn_data/c2.map&transparent=true&
          layers=road
          extension=png
          srs=EPSG:4326
          6、重新啟動(dòng)Apache
          7、打開(kāi)tilecache下的index.html文件,根據(jù)實(shí)際情況修改openlayers.js的路徑,例如
          <script src="/openlayers/OpenLayers.js"></script>
          修改layer參數(shù),例如
          layer = new OpenLayers.Layer.WMS( "road", "tilecache.cgi?", {layers: 'road', format: 'image/png' } );

          使用瀏覽器訪(fǎng)問(wèn)http://127.0.0.1/tilecache,Web頁(yè)面上將顯示經(jīng)過(guò)tilecache處理的地圖,客戶(hù)端瀏覽過(guò)的地圖切片文件被保存在tilecache.cfg文件指定的臨時(shí)目錄下,這里是F:/tmp/tilecache目錄,如果其中包含客戶(hù)端正在請(qǐng)求的地圖,這些地圖將不再通過(guò)MapServer動(dòng)態(tài)生成,而是直接從緩存目錄讀取靜態(tài)圖片文件。對(duì)于大用戶(hù)量、高并發(fā)的地圖訪(fǎng)問(wèn),瓦片緩存機(jī)制可以非常有效的提高客戶(hù)端讀取、顯示地圖的速度。

          通過(guò)執(zhí)行tilecache_seed.py腳本,可以手動(dòng)生成地圖切片,下面的命令給road圖層發(fā)布0到6級(jí)的地圖切片文件。
          python "F:\ms4w\apps\tilecache-2.11\tilecache_seed.py" road 0 6
          等待執(zhí)行完畢,進(jìn)入緩存目錄可以找到剛才發(fā)布的地圖切片文件。


          posted @ 2010-11-26 15:45 天狼 閱讀(3282) | 評(píng)論 (5)編輯 收藏
          連接Oracle Spatial

          前面的測(cè)試中我們使用shape文件作為地圖數(shù)據(jù)源,下面我們將從Oracle Spatial空間數(shù)據(jù)庫(kù)讀取地理數(shù)據(jù)。

          mapserver提供兩種方式連接oracle空間數(shù)據(jù)庫(kù),native oracle spatial和ogr。安裝包提供了支持native oracle spatial的二進(jìn)制文件,ogr方式需要自行編譯源代碼。借用以往項(xiàng)目的Oracle 10.2.0.3數(shù)據(jù)庫(kù),MapServer采用ms4w_2.3.1已編譯包,地圖服務(wù)器安裝Oracle10.2客戶(hù)端,進(jìn)行本地網(wǎng)絡(luò)配置,測(cè)試連接正常。

          關(guān)閉Apache MS4W Web Server服務(wù),進(jìn)入\ms4w\Apache\cgi-bin\ignored-libmap\oracle11g目錄,將libmap.dll復(fù)制粘貼到\ms4w\Apache\cgi-bin目錄,替換原有文件,啟動(dòng)Apache MS4W Web Server服務(wù)。

          新建一個(gè)Mapfile文件,LAYER部分如下
          LAYER
              NAME "road"
              TYPE LINE
              CONNECTION "geouser/123456@geodb" #數(shù)據(jù)庫(kù)連接字符串
              CONNECTIONTYPE oraclespatial      #連接類(lèi)型為oracle spatial
              DATA "GEOLOC FROM NAV_ROAD1 USING SRID 4326"  #此處GEOLOC為GEOMETRY字段名,NAV_ROAD1為表名
              PROJECTION
                 "init=epsg:4326" #必須指定SRS編碼
              END
              DUMP TRUE
              CLASS
                  STYLE
                      COLOR 0 128 128
                  END
              END
          END

          DATA標(biāo)簽使用如下格式
          "[geom_column]
          FROM
          [table]| [(SELECT [...]
          FROM [table]|[Spatial Operator]
          [WHERE condition] )]
          [USING [UNIQUE column]| [SRID #srid]| [FUNCTION]| [VERSION #version]
          ]"
          注意:不要在FROM之前加入屬性字段名,屬性字段可添加在FROM后的子查詢(xún)中,如下所示



          GEOLOC FROM (SELECT MI_PRINX AS OID, NAME AS ONAME, COLOR AS COLOR, GEOLOC AS GEOLOC FROM NAV_ROAD1) USING SRID 4326



          LABEL或STYLE用到的屬性字段必須包含在SELECT子查詢(xún)中。







          修改openlayers客戶(hù)端代碼



          var ms_layer = new OpenLayers.Layer.WMS(



                          "Test Map",
                          "/cgi-bin/mapserv.exe",
                          {   
                              layers: 'road',
                              map: 'I:/cn_data/c2.map',
                              format: 'png'
                          },
                          {
                              reproject: false,
                              'numZoomLevels': 20,
                              gutter: 15,
                              buffer: 0
                          }
                      );

          打開(kāi)瀏覽器,查看效果。

          為圖層添加標(biāo)注(Label)


          在地圖上標(biāo)注文字,必然涉及到字體,MapServer采用與操作系統(tǒng)無(wú)關(guān)的設(shè)計(jì),不能自動(dòng)獲知當(dāng)前操作系統(tǒng)下安裝了哪些字體,必須手工創(chuàng)建字體集FONTSET文件。
          該文件的格式非常簡(jiǎn)單,每行配置一個(gè)字體,左邊是字體名(可自由命名),右邊是字體文件的路徑(請(qǐng)使用絕對(duì)路徑),如下所示:
          arial   C:\WINDOWS\Fonts\arial.ttf
          sans    C:\WINDOWS\Fonts\SIMSUN.TTC
          將以上內(nèi)容保存為文本文件,文件名和擴(kuò)展名不限,例如保存為fonts.txt

          在Mapfile的Map標(biāo)簽下添加一行
          FONTSET fonts.txt #指明字體集文件,可以包含路徑

          在Mapfile的Layer標(biāo)簽中添加一行
          LABELITEM "NAME"  #指明標(biāo)注所用的字段名

          在Layer下的CLASS標(biāo)簽中添加以下內(nèi)容
          LABEL
              COLOR  0 0 0
              OUTLINECOLOR 255 255 255
              FONT "sans"  #此處sans對(duì)應(yīng)宋體SIMSUN.TTC
              TYPE truetype
              SIZE 6
              POSITION AUTO
              PARTIALS FALSE
              ENCODING GBK #此處為文字編碼,如果不設(shè)置該值,中文將不能正確顯示。對(duì)于中文Windows系統(tǒng),操作系統(tǒng)的默認(rèn)編碼為GBK。
          END

          注意:ms4w_3.0beta11屬于開(kāi)發(fā)版本,支持shape文件數(shù)據(jù)源配置label標(biāo)簽,不支持oracle spatial數(shù)據(jù)源配置label標(biāo)簽。
          為了讀取oracle空間表中的屬性生成標(biāo)簽,我們換用ms4w_2.3.1正式版,系統(tǒng)工作正常。

          使用動(dòng)態(tài)樣式(STYLE)

          實(shí)際應(yīng)用中對(duì)地圖的渲染有很多要求,MapServer支持動(dòng)態(tài)設(shè)置STYLE,修改Mapfile文件LAYER的STYLE,例如:
          STYLE
              COLOR [COLOR]
          END
          每條道路的顏色由道路表的屬性字段COLOR決定,與之類(lèi)似,可以從數(shù)據(jù)庫(kù)取值填充SYMBOL,SIZE,ANGLE等標(biāo)簽。
          提示:MapServer的顏色碼可以使用[r] [g] [b]十進(jìn)制格式,也可以使用Web開(kāi)發(fā)中常用的RRGGBB十六進(jìn)制格式,例如:#FF0000


          posted @ 2010-11-26 12:16 天狼 閱讀(2809) | 評(píng)論 (1)編輯 收藏
          MapServer簡(jiǎn)介
              在開(kāi)源WebGIS領(lǐng)域,MapServer的歷史和名氣都超過(guò)GeoServer(20世紀(jì)90年代中期,由明尼蘇達(dá)大學(xué)研制),很早就被列入OSGeo項(xiàng)目組。
          與GeoServer不同,MapServer用C語(yǔ)言編寫(xiě),采用傳統(tǒng)的CGI架構(gòu),融合了Pro4j、GDAL等開(kāi)源項(xiàng)目。對(duì)比J2EE架構(gòu)的GeoServer,MapServer顯得非常精巧,5.6版本的核心部分只有33KB,源代碼只有2.2M,包括Apache、Php、Pro4j、GDAL、MapScript在內(nèi)的完整安裝包也只有35M。

          安裝過(guò)程
              和Java一樣,C具有良好的跨平臺(tái)特性,MapServer支持Windows、Linux、Mac OS X等操作系統(tǒng)。

              官方網(wǎng)站對(duì)Unix和Windows平臺(tái)下的源代碼安裝步驟給出了詳細(xì)說(shuō)明。根據(jù)說(shuō)明下載需要的第三方庫(kù),然后在Shell命令行模式下編譯源代碼,對(duì)于缺少Unix Shell或DOS操作經(jīng)驗(yàn)的用戶(hù), 這是一件比較頭疼的事情。好在MapServer已經(jīng)考慮到不習(xí)慣命令行操作的Windows用戶(hù),給出了Windows下的已編譯安裝包ms4w,目前最新版本是3.0beta11。
             
              ms4w的安裝過(guò)程很簡(jiǎn)單,下載ms4w,解壓縮到硬盤(pán)任意目錄(目錄名最好不要包含中文字符),打開(kāi)命令提示符窗口,切換到ms4w所在目錄,鍵入apache-install即可。(提示:如果機(jī)器上安裝有Apache或IIS,運(yùn)行apache-install之前,請(qǐng)將它們關(guān)閉。ms4w安裝后不會(huì)和原有的Apache沖突。)

          看到如下信息,說(shuō)明安裝成功。
          Installing the Apache MS4W Web Server service
          The Apache MS4W Web Server service is successfully installed.
          Testing httpd.conf....
          Errors reported here must be corrected before the service
          can be started.
          The Apache MS4W Web Server service is starting.
          The Apache MS4W Web Server service was started successfully.

          安裝完成后,使用瀏覽器訪(fǎng)問(wèn) http://127.0.0.1/cgi-bin/mapserv.exe,MapServer返回如下提示信息
          No query information to decode. QUERY_STRING is set, but empty.

          發(fā)布地圖數(shù)據(jù)
              類(lèi)似于Arcgis Server和GeoServer,MapServer采用零代碼編寫(xiě)的配置文件方式管理地圖發(fā)布,配置文件被稱(chēng)為Mapfile,后綴名為map。

              Mapfile有三種編寫(xiě)方式:
              1、參考官方文檔Mapfile章節(jié),手工編寫(xiě)
              這種方式要求開(kāi)發(fā)人員對(duì)Mapfile的編寫(xiě)規(guī)則非常熟悉,否則很容易出錯(cuò)。
              2、類(lèi)似Arcgis Server和GeoServer提供的Web圖形化配置界面,MapServer有一個(gè)對(duì)應(yīng)的開(kāi)源項(xiàng)目MapLab,提供基于Web的圖形化配置界面
              不過(guò)個(gè)人感覺(jué),MapLab的易用性遠(yuǎn)遜于Arcgis Server和GeoServer。
              3、使用開(kāi)源桌面平臺(tái)QGIS,自動(dòng)生成Mapfile文件
              對(duì)于新手,推薦使用第三種方式。

          以下是測(cè)試用的Mapfile文件,MapServer對(duì)Mapfile文件的存放位置沒(méi)有特殊要求,可以存放在不同的計(jì)算機(jī)上。

          # Mapfile文件必須以MAP開(kāi)頭
          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的坐標(biāo)系
          PROJECTION "init=epsg:4326"
          END

          # Map的全圖范圍
          EXTENT 75 15 140 55
          # Map的坐標(biāo)單位 DD表示經(jīng)緯度
          UNITS DD
          # Map的背景顏色 白色
          IMAGECOLOR 255 255 255
          # 生成的圖片類(lèi)型,常用gif或png
          IMAGETYPE gif
          # shp文件的路徑,請(qǐng)使用絕對(duì)路徑
          SHAPEPATH "I://cn_data"
          #
          # Start of web interface definition. Only the TEMPLATE parameter # must be specified to display a map. See Mapserver documentation
          # MapServer內(nèi)置了地圖客戶(hù)端功能,此處是Web客戶(hù)端相關(guān)設(shè)置。
          # 由于我們使用Openlayers作為地圖客戶(hù)端,MapServer做為地圖服務(wù)器,此處不做設(shè)置
          WEB
          # HEADER
          # TEMPLATE
          # FOOTER
          # 最小、最大比例尺等級(jí)
          MINSCALE 1
          MAXSCALE 13
          # 設(shè)置IMAGEPATH,默認(rèn)路徑如下,請(qǐng)使用絕對(duì)路徑
          IMAGEPATH 'I:/ms4w/Apache/htdocs/tmp'
          # 設(shè)置IMAGEURL,默認(rèn)路徑如下
          IMAGEURL '/tmp/'
          END
          # 設(shè)置圖層,一個(gè)Map下可以包含多個(gè)LAYER
          LAYER NAME polyline  # 圖層名稱(chēng),MapServer使用該名稱(chēng)
          TYPE LINE # 幾何類(lèi)型
          STATUS ON
          DATA "roa_4m" # shp文件名,不需要帶擴(kuò)展名,路徑在前面的SHAPEPATH項(xiàng)中指定
          CLASS NAME "roa_4m" # 類(lèi)名
          # TEMPLATE
          COLOR 112 0 0 # 顏色
          END
          END
          END # Map File

          客戶(hù)端測(cè)試
              接下來(lái)測(cè)試剛才建立的Mapfile,在瀏覽器地址欄中輸入 http://127.0.0.1/cgi-bin/mapserv.exe?LAYERS=polyline&MAP=I:/ms4w/Apache/htdocs/my.map&FORMAT=gif&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=75,15,140,55&WIDTH=800&HEIGHT=600
          大約0.5秒后(初次加載),瀏覽器顯示出中國(guó)1:400萬(wàn)道路網(wǎng),地圖發(fā)布成功! 熟悉OGC標(biāo)準(zhǔn)的朋友可能已經(jīng)發(fā)現(xiàn),上面的URL是WMS地圖請(qǐng)求。

          直接通過(guò)CGI請(qǐng)求,得到的是一幅靜態(tài)地圖,為了實(shí)現(xiàn)地圖的縮放、漫游,我們選用Openlayers地圖客戶(hù)端。 通過(guò)OpenLayers.Layer.WMS可以直接調(diào)用MapServer地圖服務(wù),測(cè)試代碼如下:
          var ms_layer = new OpenLayers.Layer.WMS(
             "polyline", //OpenLayers中的圖層名
             "/cgi-bin/mapserv.exe", //MapServer地圖服務(wù)器的路徑
             { layers: 'polyline', //Mapfile中定義的圖層名
               map: 'I:/cn_data/my.map', //Mapfile文件的絕對(duì)路徑,注意必須使用'/'而不是'\',使用相對(duì)路徑無(wú)法顯示地圖
               format: 'gif' },
             { reproject: false,
               'numZoomLevels': 20,
               gutter: 15,
               buffer: 0 }
          );

          滾動(dòng)鼠標(biāo)滾輪,地圖的刷新速度保持在0.5秒以?xún)?nèi)。MapServer繼承了C語(yǔ)言的特點(diǎn),地圖渲染效率很高。

          寫(xiě)在最后
              MapServer提供兩種工作方式,CGI方式(適用于CGI、AJAX、FLEX開(kāi)發(fā)人員)和MapScript方式(適用于Php、Java、C#、Python開(kāi)發(fā)人員)。以原生CGI方式效率最高,配合TileCache,可以快速生成大范圍的地圖瓦片數(shù)據(jù)。比較基于.Net和J2EE的商業(yè)或開(kāi)源平臺(tái),MapServer更適合高負(fù)荷的大型互聯(lián)網(wǎng)地圖應(yīng)用。

          posted @ 2010-11-24 17:39 天狼 閱讀(6709) | 評(píng)論 (5)編輯 收藏
          主站蜘蛛池模板: 安平县| 石阡县| 汶川县| 赤峰市| 莱芜市| 凤冈县| 桦南县| 台东县| 饶平县| 张掖市| 金湖县| 四会市| 宁陕县| 子长县| 天镇县| 陈巴尔虎旗| 吉首市| 桐乡市| 巢湖市| 双辽市| 庄河市| 东光县| 珲春市| 汝南县| 延吉市| 项城市| 津南区| 新绛县| 多伦县| 辛集市| 云南省| 兴业县| 阳西县| 五大连池市| 固阳县| 大邑县| 红桥区| 威海市| 望谟县| 霍城县| 濉溪县|