<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 41,  comments - 90,  trackbacks - 0
      2009年8月31日

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

    在新版手機地圖中,矢量圖將替換原本的2D畫面為用戶呈現出全新的3D界面,用戶可以自由的轉動和縮放。此外用戶還將會獲得離線地圖瀏覽功能,不用在瀏覽地圖時保持在線狀態。

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



    原文見驅動之家
    http://news.mydrivers.com/1/181/181818.htm
    posted @ 2010-12-12 21:54 天狼 閱讀(606) | 評論 (1)編輯 收藏
    天地圖官方網站提供的二次開發文檔和例子過于簡單,很多關鍵信息沒有給予說明,例如給出了WFS服務接口,卻沒有提供詳細的開發文檔。
    不過這并不影響我們的使用,因為OGC WFS規范包含元數據查詢命令,通過發送getCapabilities請求,我們可以得知服務器提供哪些WFS服務。

    獲取WFS服務器元數據
    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網絡要素服務器</Title>
    <Abstract>武大吉奧信息技術有限公司GeoGlobe網絡要素服務器</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服務器的開發單位(武大吉奧),WFS圖層的名稱(DOMAIN_POI_NEW和iso19112:SI_Gazetteer),支持的邏輯操作符和空間操作符。

    繼續測試
    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>亞洲中國重慶市銅梁縣梅子村</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數據,可知DOMAIN_POI_NEW是地名圖層,包含名稱、代碼、類別碼等屬性字段。

    將圖層改為iso19112:SI_Gazetteer,沒有返回任何信息,google ISO19112,得到如下解釋:
    DIN EN ISO 19112-2005 地理信息.通過地理標識符的空間定位 標準號: DIN EN ISO 19112-2005 標準名稱: 地理信息.通過地理標識符的空間定位

    得到以上信息后,我們嘗試使用Openlayers獲取,即全國地名數據庫。

    通過URL(GET方式)訪問“天地圖”WFS服務,可以使用OpenLayers.Request.GET類,示例代碼如下:
       //使用FEATUREID查詢

       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查詢

        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
        });


    說明:
    url WFS服務器地址,必須加上?request=GetFeature
    typeName 圖層名稱
    FEATUREID WFS的圖元ID,采用標準格式: [圖層名].[OID編號]
    BBOX 指定區域查詢,注意不要設置過大,否則瀏覽器可能失去響應。

    通過POST方式訪問“天地圖”WFS服務,可以使用OpenLayers.Request.POST類,示例代碼如下:

        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
        });
    };

    說明:

    url WFS服務器地址

    data WFS請求正文,返回的GML由回調函數handler處理

    handler負責處理服務端返回的GML數據,也就是矢量化的地圖數據,根據應用需求編寫代碼,獲取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;
    }

    定義過濾條件時請使用STANDARDNAME字段,不要使用DOMAINNAME字段,前者應該有索引支持,而后者沒有,查詢速度差別很大。

    經過測試,typeName="DOMAIN_POI_NEW"和typeName="iso19112:SI_Gazetteer"都能返回結果。由于缺少官方文檔說明,不知道這兩個圖層有何區別。

    嘗試使用OpenLayers.Protocol.WFS無法訪問“天地圖”WFS服務,服務器返回: 請求參數[REQUEST]的值為空或不正確。

    提醒: 使用POST查詢時,頁面文件或代碼文件務必保存為utf-8編碼,如果使用gbk、gb2312編碼,漢字地名會變成亂碼,導致javascript代碼錯誤。

    posted @ 2010-12-10 16:22 天狼 閱讀(5936) | 評論 (3)編輯 收藏
    國家測繪局2010年10月21日正式發布中國公眾版國家地理信息公共服務平臺“天地圖”,作為中國境內數據資源最全的地理信息服務網站,“天地圖”將為公眾提供權威、可信、統一的地理信息資源。

    “天地圖”公開開放了地圖數據服務接口,第三方使用者可以直接通過互聯網獲取地圖數據,無需授權認證,在公眾服務信息公開方面可以說是一次非常大的進步。
    “天地圖”的在線服務數據近10TB以下是“天地圖”提供的在線地理信息數據資源:

    數據類型

    數據源

    級別

    服務地址

    線劃地圖

    全球1:100萬地理底圖

    2-10

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

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

    全國1:25萬公開版數字地形圖

    11-12

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

    全國車載導航

    13-18

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

    衛星影像

    全球250米衛星影像 (MODIS)

    2-7

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

    全國15米衛星影像 (ETM)

    8-10

    全國2.5米衛星影像 (P5)

    11-14

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

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

    地級城市0.6米衛星影像

     (QuickBirdWorldView IWorldView II)

    15-18

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

    數字高程模型

    全球90X90米數字高程模型

     

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

    地名地址

    全球1:100萬地名地址

     

    http://search.tianditu.com/wfs

    全國1:25萬地名地址


    全國車載導航地名地址


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

    類似谷歌地圖,“天地圖”為互聯網開發人員提供了二次開發API(武大吉奧開發的GeoGlobe二維地圖API)。

    通過分析GeoGlobe API代碼,發現它源自Openlayers,大部分代碼除了把Openlayers換成GeoSurf外,沒有任何變化。不知道Openlayers項目組就此作何感想。
    正因為如此,我們可以參考OpenLayers.Layer.TileCache和OpenLayers.Layer.XYZ類,編寫一個專用于讀取“天地圖”的TDTLayer類,使Openlayers能夠直接訪問“天地圖”的在線地圖數據。

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

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

     X= 0 1 2 3 0 1 2 3
     Y= 0 0 0 0 1 1 1 1
    L=3級有32個瓦片文件,分別是:
     X= 0-7
     Y= 0-3
    L=4級有128個瓦片文件,分別是:
     X= 0-15
     Y= 0-7
    其余各級以此類推,每級的瓦片文件數比前一級增加4倍,其中線劃地圖10級以上,衛星地圖8級以上只提供中國境內的數據,沒有覆蓋全球。

    查看
    GeoGlobe API主代碼GeoSurfJSAPI.js文件(相當于Openlayers.js,可以了解X(x_num)、Y(y_num)、L(level)的生成方法,偽代碼如下:
    level=getLevelForResolution(map.getResolution()); //計算瓦片級別
    coef=TopTileSize.w/Math.pow(2,level); //中間系數
    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);
    根據當前分辨率計算地圖瓦片級別
    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;
    }

    經過簡單測試,“天地圖”和谷歌地圖在數據上差別不大,二次開發方面借助于強大的Openlayers地圖客戶端引擎不會弱于Google Map API,唯獨在速度上與谷歌地圖存在較大差距,特別是地圖放大到13級-18級時,延遲變得非常明顯,有時甚至無法顯示。
    使用Firebug跟蹤運行發現,大約1/3的地圖瓦片請求超時,導致客戶端讀取失敗。
    “天地圖”目前還處于測試階段,希望相關單位繼續改進和提升服務器端性能,快速穩定的響應大量客戶端發出的并發請求。
    測試中發現,“天地圖”開放的地圖數據服務接口從tile0.tianditu.com一直到tile7.tianditu.com。依次ping 這8個服務接口,tile1到tile7的響應速度相對較快。修改客戶端js代碼,將瓦片地圖請求平均發送給tile0到tile7 八個服務接口,可以有效加快地圖顯示速度。“天地圖”提供的GeoSurfJSAPI.js中已經包含相關代碼,通過給Layer的mirrorUrl屬性賦值,可以均衡讀取指定的多個服務接口,代碼如下:
                            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"
                                    ]
                                });

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


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

    OGC WFS協議定義了地圖客戶端查詢和傳送矢量數據的方法,在查詢、分析、動態繪圖等實際應用中非常有用。MapServer支持OGC WFS 1.0.0和1.1.0規范。

    重新定義一個Mapfile文件,命名為ext2.map,內容如下:
    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服務器的url
                "wms_srs"                         "EPSG:4326"   #地圖坐標系        
            END
        END

        LAYER
            NAME "road"
            METADATA
                "wms_title"                       "road"
                "wfs_title"                       "road"
                "wms_srs"                         "EPSG:4326"  #圖層坐標系
                "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標簽,是WFS(WMS) Server所需要的,分別是MAP的METADATA標簽和LAYER的METADATA標簽。
    前者是針對整個地圖的全局定義,后者是每個圖層的元數據定義。

    保存Mapfile文件,打開瀏覽器進行測試
    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是一個功能強大的Web地圖客戶端引擎。

    接下來,我們利用OpenLayers的OpenLayers.Protocol.WFS類,顯示剛才發布的WFS圖層,代碼如下

           var protocol = OpenLayers.Protocol.WFS({
                        url: "http://192.98.151.23/cgi-bin/mapserv.exe?map=I:/cn_data/ext2.map&", //mapserver地圖服務器的url,加上mapfi了文件的路徑
                        featureType: "road", //layer的名稱
                        srsName: "EPSG:4326", //layer的坐標系
                        geometryName: "msGeometry", //geometry字段的名稱
                        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();
                    }

                }

    在瀏覽器中運行html頁面,國道數據將以矢量方式傳送到客戶端,由openlayers動態繪制,鼠標移動到道路上或者選中道路,道路將實時改變顏色,在Web上實現與傳統桌面GIS應用類似的體驗效果。

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

    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 天狼 閱讀(1761) | 評論 (0)編輯 收藏
    為MapServer添加瓦片緩存服務

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

    1、從tilecache官方網站下載安裝包tilecache-2.11.tar.gz,該安裝包適用于所有操作系統,我們使用Windows XP。
    2、解壓安裝包,將其中的tilecache-2.11目錄整體復制到ms4w的apps目錄下。
    3、進入ms4w的http.d目錄,新建一個名為httpd_tilecache.conf的文本文件,內容如下:
    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、進入ms4w/apps/tilecache-2.11目錄,打開tilecache.cgi文件,修改第一行的python編譯器路徑,例如
    #!E:\Python25\python.exe
    5、打開該目錄下的tilecache.cfg文件,修改cache標簽,指定本地磁盤緩存目錄,例如
    [cache]
    type=Disk
    base=F:/tmp/tilecache
    添加一個road標簽,指定地圖服務類型,服務地址,mapfile文件路徑,圖層名稱,柵格格式,空間參考系統編碼,例如
    [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、重新啟動Apache
    7、打開tilecache下的index.html文件,根據實際情況修改openlayers.js的路徑,例如
    <script src="/openlayers/OpenLayers.js"></script>
    修改layer參數,例如
    layer = new OpenLayers.Layer.WMS( "road", "tilecache.cgi?", {layers: 'road', format: 'image/png' } );

    使用瀏覽器訪問http://127.0.0.1/tilecache,Web頁面上將顯示經過tilecache處理的地圖,客戶端瀏覽過的地圖切片文件被保存在tilecache.cfg文件指定的臨時目錄下,這里是F:/tmp/tilecache目錄,如果其中包含客戶端正在請求的地圖,這些地圖將不再通過MapServer動態生成,而是直接從緩存目錄讀取靜態圖片文件。對于大用戶量、高并發的地圖訪問,瓦片緩存機制可以非常有效的提高客戶端讀取、顯示地圖的速度。

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


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

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

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

    關閉Apache MS4W Web Server服務,進入\ms4w\Apache\cgi-bin\ignored-libmap\oracle11g目錄,將libmap.dll復制粘貼到\ms4w\Apache\cgi-bin目錄,替換原有文件,啟動Apache MS4W Web Server服務。

    新建一個Mapfile文件,LAYER部分如下
    LAYER
        NAME "road"
        TYPE LINE
        CONNECTION "geouser/123456@geodb" #數據庫連接字符串
        CONNECTIONTYPE oraclespatial      #連接類型為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標簽使用如下格式
    "[geom_column]
    FROM
    [table]| [(SELECT [...]
    FROM [table]|[Spatial Operator]
    [WHERE condition] )]
    [USING [UNIQUE column]| [SRID #srid]| [FUNCTION]| [VERSION #version]
    ]"
    注意:不要在FROM之前加入屬性字段名,屬性字段可添加在FROM后的子查詢中,如下所示



    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子查詢中。







    修改openlayers客戶端代碼



    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
                    }
                );

    打開瀏覽器,查看效果。

    為圖層添加標注(Label)


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

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

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

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

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

    使用動態樣式(STYLE)

    實際應用中對地圖的渲染有很多要求,MapServer支持動態設置STYLE,修改Mapfile文件LAYER的STYLE,例如:
    STYLE
        COLOR [COLOR]
    END
    每條道路的顏色由道路表的屬性字段COLOR決定,與之類似,可以從數據庫取值填充SYMBOL,SIZE,ANGLE等標簽。
    提示:MapServer的顏色碼可以使用[r] [g] [b]十進制格式,也可以使用Web開發中常用的RRGGBB十六進制格式,例如:#FF0000


    posted @ 2010-11-26 12:16 天狼 閱讀(2803) | 評論 (1)編輯 收藏
    MapServer簡介
        在開源WebGIS領域,MapServer的歷史和名氣都超過GeoServer(20世紀90年代中期,由明尼蘇達大學研制),很早就被列入OSGeo項目組。
    與GeoServer不同,MapServer用C語言編寫,采用傳統的CGI架構,融合了Pro4j、GDAL等開源項目。對比J2EE架構的GeoServer,MapServer顯得非常精巧,5.6版本的核心部分只有33KB,源代碼只有2.2M,包括Apache、Php、Pro4j、GDAL、MapScript在內的完整安裝包也只有35M。

    安裝過程
        和Java一樣,C具有良好的跨平臺特性,MapServer支持Windows、Linux、Mac OS X等操作系統。

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

    看到如下信息,說明安裝成功。
    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.

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

    發布地圖數據
        類似于Arcgis Server和GeoServer,MapServer采用零代碼編寫的配置文件方式管理地圖發布,配置文件被稱為Mapfile,后綴名為map。

        Mapfile有三種編寫方式:
        1、參考官方文檔Mapfile章節,手工編寫
        這種方式要求開發人員對Mapfile的編寫規則非常熟悉,否則很容易出錯。
        2、類似Arcgis Server和GeoServer提供的Web圖形化配置界面,MapServer有一個對應的開源項目MapLab,提供基于Web的圖形化配置界面
        不過個人感覺,MapLab的易用性遠遜于Arcgis Server和GeoServer。
        3、使用開源桌面平臺QGIS,自動生成Mapfile文件
        對于新手,推薦使用第三種方式。

    以下是測試用的Mapfile文件,MapServer對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

    客戶端測試
        接下來測試剛才建立的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秒后(初次加載),瀏覽器顯示出中國1:400萬道路網,地圖發布成功! 熟悉OGC標準的朋友可能已經發現,上面的URL是WMS地圖請求。

    直接通過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 }
    );

    滾動鼠標滾輪,地圖的刷新速度保持在0.5秒以內。MapServer繼承了C語言的特點,地圖渲染效率很高。

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

    posted @ 2010-11-24 17:39 天狼 閱讀(6706) | 評論 (5)編輯 收藏
    OpenLayers.Layer.Google
    #2493: Google layer instances with overridden methods may need to be modified, because some methods are now mixed in from OpenLayers.Layer.Google.v2. Affected API methods are
    onMapResize,
    getMapObjectBoundsFromOLBounds,
    setMapObjectCenter,
    dragPanMapObject,
    getMapObjectLonLatFromMapObjectPixel,
    getMapObjectPixelFromMapObjectLonLat,
    getMapObjectZoomFromMapObjectBounds,
    getMapObjectLonLatFromLonLat and getMapObjectPixelFromXY.
    This means that when calling any of these methods on the prototype, the code needs to be changed to call it on OpenLayers.Layer.Google.v2 instead. You would e.g. have to change
    OpenLayers.Layer.Google.prototype.onMapResize.apply(this, arguments);
    to
    OpenLayers.Layer.Google.v2.onMapResize.apply(this, arguments);
    OpenLayers.Control.Panel
    #2764: OpenLayers.Control.Panel does not change the active state of controls with a type of OpenLayers.Control.TYPE_BUTTON any more. If you want to retain the old behavior, create your panel with an overridden activateControl method like this:
    var panel = new OpenLayers.Control.Panel({ activateControl: function(control) { OpenLayers.Control.Panel.prototype.activateControl.apply(this, arguments); if (control.active &amp;&amp; control.type == OpenLayers.Control.TYPE_TOOL) { for (var i=panel.controls.length-1; i&gt;=0; --i) { panel.controls[i].type == OpenLayers.Control.TYPE_BUTTON &amp;&amp; panel.controls[i].deactivate(); } } }
    });
    New Addins
    InlineXhtml - adds support for WMS layers with SVG as image format, for SVG enabled browsers.
    posted @ 2010-09-13 12:22 天狼 閱讀(549) | 評論 (0)編輯 收藏
    openlayers是一個純javascript的web地圖客戶端框架,對開發平臺的適應性非常強,可以很容易的嵌入靜態http頁面、asp頁面、.net頁面、jsp頁面、j2ee頁面。由于openlayers采用AJAX架構,當地圖服務器與web客戶端服務器不同時,WMS中的getFeatureInfo,以及所有WFS功能接口不能正常工作。原因是各種瀏覽器禁止跨域訪問xml,解決的辦法很簡單,使用代理(Proxy)。

    根據應用系統架構的不同,代理的實現方式有很多種,包括web服務器內置代理(如Apache)、cgi方式代理、php代理、jsp代理、aspx代理等。
    openlayers官方提供了一個采用python編寫的cgi代理,推薦在Apache2.2下使用。

    openlayers官方代理安裝步驟:
    1、安裝Python2.5,記住安裝路徑。
    2、將openlayers官方提供的proxy.cgi復制到apache的cgi-bin目錄下。
    修改第一行Python25的安裝路徑,注意不要去掉最前面的#號。
    修改allowedHosts中的geoserver/mapserver ip:geoserver/mapserver port部分。
    3、打開conf目錄下的httpd.conf文件,修改cgi部分,例如:
    <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
        AllowOverride None
        Options ExecCGI
        Order allow,deny
        Allow from all
    </Directory>
    AddHandler cgi-script .cgi .py
    保存后重新啟動Apache,在瀏覽器地址欄中填入http://apache ip/cgi-bin/proxy.cgi,測試代理是否工作正常。

    以下是proxy.cgi的內容:
    #!C:\Python25\python.exe
    # -*- coding: utf-8 -*-

    import urllib2
    import cgi
    import sys, os

    # Designed to prevent Open Proxy type stuff.

    allowedHosts = ['geoserver/mapserver ip:geoserver/mapserver port',
                                    'www.openlayers.org',
                                    'openlayers.org']

    method = os.environ["REQUEST_METHOD"]

    if method == "POST":
        qs = os.environ["QUERY_STRING"]
        d = cgi.parse_qs(qs)
        if d.has_key("url"):
            url = d["url"][0]
        else:
            url = "http://www.openlayers.org"
    else:
        fs = cgi.FieldStorage()
        url = fs.getvalue('url', "http://www.openlayers.org")

    try:
        host = url.split("/")[2]
        if allowedHosts and not host in allowedHosts:
            print "Status: 502 Bad Gateway"
            print "Content-Type: text/plain"
            print
            print "This proxy does not allow you to access that location (%s)." % (host,)
            print
            print os.environ
     
        elif url.startswith("http://") or url.startswith("https://"):
      
            if method == "POST":
                length = int(os.environ["CONTENT_LENGTH"])
                headers = {"Content-Type": os.environ["CONTENT_TYPE"]}
                body = sys.stdin.read(length)
                r = urllib2.Request(url, body, headers)
                y = urllib2.urlopen(r)
            else:
                y = urllib2.urlopen(url)
          
            # print content type header
            i = y.info()
            if i.has_key("Content-Type"):
                print "Content-Type: %s" % (i["Content-Type"])
            else:
                print "Content-Type: text/plain"
            print
          
            print y.read()
          
            y.close()
        else:
            print "Content-Type: text/plain"
            print
            print "Illegal request."

    except Exception, E:
        print "Status: 500 Unexpected Error"
        print "Content-Type: text/plain"
        print
        print "Some unexpected error occurred. Error text was:", E

    備注:部署在同一個機器、不同服務器上(相同ip,不同端口號)同樣是跨域訪問。例如地圖服務器geoserver在tomcat,端口8080,應用系統在Apache或IIS,端口80),這種情況下只有IE6能夠正常訪問,條件是將ip地址加入可信站點列表,IE7、IE8、FF3.6都會禁止訪問。


    posted @ 2010-08-26 10:36 天狼 閱讀(4116) | 評論 (0)編輯 收藏
    Openlayers項目開發完成后,需要將系統從開發環境轉移到生產環境。

    開發環境下,Openlayers框架由上百個獨立的javascript程序文件組成,通過lib目錄中的Openlayers.js
    動態加載,便于各個功能模塊的開發調試。

    Openlayers是一個非常龐大的Web地圖客戶端應用框架,提供了很多功能模塊,通常在開發過程中不會用到全部模塊。
    將系統中用到的獨立javascript程序庫組織成一個Openlayers.js文件,可以減少代碼冗余,加快加載速度,
    同時也便于對代碼進行壓縮和重編碼,在一定程度上保護軟件產品。

    Openlayers提供了代碼組合和壓縮工具,在build目錄下,使用Python腳本實現。運行該工具,需要安裝Python解釋器。
    build文件夾中提供了三種預設的配置文件,它們是:
    full.cfg    組合全部代碼
    library.cfg 組合主要代碼
    lite.cfg    組合最小代碼
    項目配置文件建議使用library.cfg或lite.cfg為模板編寫。
    配置文件中定義了四種作用不同的標簽:
    [first]    最前執行的代碼文件
    [last]     最后執行的代碼文件
    [include]  在預設配置中加入的代碼文件列表
    [exclude]  從預設配置中去除的代碼文件列表
    修改[include]和[exclude]項,生成項目配置文件。

    在命令提示符下,輸入python build.py mycfg my.js(如果是windows系統,請將python.exe加入系統Path路徑)
    生成的my.js就是生產版本的Openlayers庫文件,將my.js部署到生產環境,測試各項功能是否運行正常。

    build過程對代碼文件做了壓縮處理,壓縮率在40%左右,程序結構沒有做任何改動。
    如果你想保護自己的代碼,建議使用其他工具進行二次處理,這里推薦Google的Jscompiler,Google的很多項目都使用該工具進行代碼壓縮和優化。

    Google Jscompiler的使用方法:
    從http://code.google.com/intl/zh-CN/closure/compiler/下載最新版本。
    Google Jscompiler采用Java編寫,需要安裝Java 6.0運行時或開發包,如果沒有安裝請到Oracle網站下載。
    解壓下載的zip包,生成compiler-latest目錄,其中compiler.jar是主程序,幫助包含在README中。

    執行Google Jscompiler請新打開一個命令提示符窗口,輸入:
    java -jar compiler.jar --help 顯示所有可選參數說明。
    壓縮編碼單個javascript程序文件,請使用下面的命令:
    java -jar compiler.jar --js=in.js --js_output_file=out.js
    壓縮合并多個javascript程序文件,請使用下面的命令:
    java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js

    經過Google Jscompiler處理后的Openlayers庫文件可以再減少20-30%的大小,生成的文件經過測試沒有任何問題。
    Google Jscompiler會自動對代碼進行分析,自動篩選出邏輯上不可能到達的代碼,給出提示。
    Google Jscompiler會對代碼邏輯流程重新組合和優化,提高瀏覽器上的執行效率。
    經過Google Jscompiler重新編碼后,Web客戶端的運行速度有明顯提升。

    posted @ 2010-08-04 14:44 天狼 閱讀(3498) | 評論 (1)編輯 收藏
    第三步:加入GeoTools類庫
    使用Eclipse打開example工程下的pom.xml文件,替換成以下內容并保存:
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.geotools.demo</groupId>
     <artifactId>example</artifactId>
     <packaging>jar</packaging>
     <version>1.0-SNAPSHOT</version>
     <name>example</name>
     <url>http://maven.apache.org</url>
     <properties>
      <geotools.version>2.6.3</geotools.version>
     </properties>
     <dependencies>
      <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>
       <scope>test</scope>
      </dependency>
      <dependency>
       <groupId>org.geotools</groupId>
       <artifactId>gt-main</artifactId>
       <version>${geotools.version}</version>
      </dependency>
     </dependencies>
     <repositories>
      <repository>
       <id>maven2-repository.dev.java.net</id>
       <name>Java.net repository</name>
       <url>http://download.java.net/maven/2</url>
      </repository>
      <repository>
       <id>osgeo</id>
       <name>Open Source Geospatial Foundation Repository</name>
       <url>http://download.osgeo.org/webdav/geotools/</url>
      </repository>
     </repositories>
    </project>

    不要關閉Eclipse,回到“命令提示符”窗口,在工程目錄下鍵入mvn eclipse:eclipse,
    例如: F:\project\example>mvn eclipse:eclipse
    等待執行完成。

    其間Maven會自動下載GeoTools的gt-main類庫,請保持網絡連接。

    切換到Eclipse,使用refresh命令刷新example工程,你可以看到GeoTools已經加入工程中。

    打開geotools.demo.example.App類,做如下修改:
     public static void main( String[] args )

            System.out.println( "Hello GeoTools:" + GeoTools.getVersion() );
    }

    編譯執行,如果看到 Hello GeoTools:2.6-3,恭喜你!大功告成!

    第四步:加入繪圖界面和Shape插件

    打開pom.xml文件,在 <dependencies></dependencies>之間加入以下內容:
    <dependency>
       <groupId>org.geotools</groupId>
       <artifactId>gt-shapefile</artifactId>
       <version>${geotools.version}</version>
      </dependency>
      <dependency>
       <groupId>org.geotools</groupId>
       <artifactId>gt-epsg-hsql</artifactId>
       <version>${geotools.version}</version>
      </dependency>
      <dependency>
       <groupId>org.geotools</groupId>
       <artifactId>gt-swing</artifactId>
       <version>${geotools.version}</version>
      </dependency>

    不要關閉Eclipse,回到“命令提示符”窗口,執行:F:\project\example>mvn eclipse:eclipse
    其間Maven會自動下載GeoTools類庫,請保持網絡連接。

    執行完成后,切換到Eclipse,使用refresh命令刷新example工程。
     
    運行QuickStart類,如果demo路徑中沒有找到Quickstart.java,可以自己創建。
    源文件在http://svn.osgeo.org/geotools/tags/2.6.3/demo/example/src/main/java/org/geotools/demo/Quickstart.java 直接復制代碼,編譯運行即可。

    中文亂碼問題
    用QuickStart打開shape文件,如果文件中包含中文屬性信息,中文將無法正確顯示,這是GeoTools和GeoServer的常見問題。
    在這里,不需要更改ShapefileDataStore類的源代碼,我們可以直接修改QuickStart類,
        FileDataStore store = FileDataStoreFinder.getDataStore(file);
    FeatureSource featureSource = store.getFeatureSource();
    
    更改為
        ShapefileDataStore shpDataStore=new ShapefileDataStore(file.toURL());
        shpDataStore.setStringCharset(Charset.forName("GBK"));
        FeatureSource featureSource = shpDataStore.getFeatureSource();
    即可顯示漢字。

    posted @ 2010-05-18 16:12 天狼 閱讀(3407) | 評論 (3)編輯 收藏
    Geotools官方網站上有一個很好Quickstart教程 http://geotools.org/quickstart.html
    通過學習該教程,可以快速生成開發環境,我們選擇Eclipse作為集成開發工具。

    第一步:安裝和配置Java和Maven
    這部分屬于常識性內容,Quickstart沒有詳細說明。
    下載Java SDK 1.5或1.6,運行安裝程序自動安裝。手工設置JAVA_HOME環境變量,指向Java SDK安裝目錄。
    下載Maven,當前版本是2.2.1(必須使用2.1以上版本),解壓到硬盤指定目錄。將Maven所在目錄手工添加到PATH環境變量中。

    檢查JDK和Maven是否安裝,打開“命令提示符”窗口,鍵入mvn -version,
    例如:F:\project\example>mvn -version
    如果返回以下信息,說明JDK和Maven正確安裝。
    Apache Maven 2.2.1 (r801777; 2009-08-07 03:16:01+0800)
    Java version: 1.6.0_03
    Java home: C:\Program Files\Java\jdk1.6.0_03\jre
    Default locale: zh_CN, platform encoding: GBK OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"
    如果返回錯誤信息,請檢查環境變量是否設置正確。

    第二步:設置工程文件目錄
    回到“命令提示符”窗口,轉到工程起始目錄下,鍵入mvn archetype:generate,
    例如 F:\project>mvn archetype:generate
    等待執行完畢。在此過程中Maven會創建工程文件和目錄,并自動通過互聯網下載需要的庫文件,請保持網絡連接。

    運行到快要結束時,需要填入幾個參數:
    1、輸入文檔類型:選擇默認的快速啟動文檔類型 15。注:Maven 2.2.1版本的默認值不是15,可以使用新默認值。
    2、填入以下值:
    groupId: org.geotools.demo
    artifactId: example
    version: 1.0-SNAPSHOT
    package: org.geotools.demo.example
    回到“命令提示符”窗口,按下面操作:
    F:\project>cd example
    F:\project\example>mvn eclipse:eclipse
    等待執行完成。

    啟動Eclipse,打開Windows>Preferences菜單,找到Java>Build Path>Classpath Variables配置頁面,添加一個新類路徑,鍵入名稱M2_REPO,加入類文件路徑。
    對于Windows XP在C:\Documents and Settings\<當前用戶名>\.m2\repository,對于Windows Vista在: C:\Users\<當前用戶名>\.m2\repository,
    對于Linux和Mac在: ~/.m2/repository

    導入剛才創建的example工程,選擇File>Import菜單,選“Choose Existing Projects into Workspace”, 單擊Next按鈕,選擇工程路徑F:\project\example,完成。
    posted @ 2010-05-18 16:00 天狼 閱讀(5144) | 評論 (4)編輯 收藏
    Google Maps基站定位
    (轉載至http://www.cnblogs.com/psunny/archive/2009/10/22/1587779.html)

    如果你在你的手機裝過Google Mobile Maps,你就可以發現只要你的手機能連接GPRS,即使沒有GPS功能,也能定位到你手機所在的位置, 只是精度不夠準確。在探討這個原理之前,我們需要了解一些移動知識,了解什么是MNC/LAC/Cell ID。
    • Mobile Network Code(MNC)
      移動網號碼,中國聯通CDMA系統的MNC為03,中國移動的為00。
    • Mobile Country Code(MCC)
      移動用戶所屬國家代號:460
    • Location Area Code(LAC)
      地區區域碼,用來劃分區域,一般一個小地方就一個LAC,大地方就
    • Cell Tower ID(Cell ID)
      CellID代表一個移動基站,如果你有基站數據,查CellID你就可以知道這個基站在哪里,移動公司或者警察通過這個知道你是在哪個基站范圍打的移動電話。

    這些信息有什么用呢? 通過這些信息可以知道你的手機是從哪個國家,區域和哪個基站接入移動網絡的。所以有些防盜手機丟失后,會發一些類 似"MCC:460;MNC:01;LAC:7198:CELLID:24989"內容的短信到你指定號碼就是這個用途,通過這些信息可以從移動查到你的 被盜手機在哪里出現過。不過知道了也沒用,中國人口這么密集,就是在你身邊你也不知道誰是小偷:) 

      這些信息從哪里來呢,一般的手機系統都提供相應的API來獲取這些信息(Tower Info),比如Window SmartPhone 或Mobile就是通過RIL.dll里的API來取得,每個手機操作系統不一樣,相關的信息可以查相關資料。

    得到了這些信息,如果沒有基站信息表,得到了這些信息也不知道在哪,因為只有移動運營商有相關的信息,除非你是運營商或者警察才能得到這些信息。是 不是我們就查不到相應的數據呢,當然不是,強大的Google就有,這里就要提到Google Mobile Maps API,里面囊括了比較全的基站信息,中國的也有,就是偏遠地區的有沒有就不知道了。Google Mobile Maps本身就是使用的這些信息,感興趣可以試一試,沒有GPS模塊也能定位到你手機位置,但精度不大,取決于基站的位置離你多遠。

      同樣我們自己也可以開發相應的手機應用來定位,只要調用Google現成的API(Secret API)“.

  • 首先讀取你自己手機的CellID和LAC。
  • 通過Http連接發送Post請求到http://www.google.com/glm/mmap
  • 傳入CellID和LAC參數,從API返回基站的經緯度(Latitude/Longitude)。
  • 另外有個可以參考的例子(windows mobile)http://www.codeproject.com/KB/mobile/DeepCast.aspx

       下面是通過j2me獲取手機imei號碼和cellid(基站號)的例子

    package jizhan;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;

    public class GetIMEIAndCellId extends MIDlet implements CommandListener {
        
    private Command exitCommand = new Command("exit", Command.EXIT, 1);

         Form form 
    = new Form("imei and cellid");
         Display display 
    = null;

        
    public GetIMEIAndCellId() {
             display 
    = Display.getDisplay(this);

         }


        
    protected void destroyApp(boolean arg0) {

         }


        
    protected void pauseApp() {

         }


        
    protected void startApp() throws MIDletStateChangeException {
            
    //獲取系統信息
             String info = System.getProperty("microedition.platform");
            
    //獲取到imei號碼
             String imei = "";
            
    //cellid
             String cellid = "";
            
    //lac
             String lac = "";
            
    // #if polish.vendor==Sony-Ericsson
             imei = System.getProperty("com.sonyericsson.imei");
            
    //參考 http://forums.sun.com/thread.jspa?threadID=5278668
            
    //https://developer.sonyericsson.com/message/110949
             cellid = System.getProperty("com.sonyericsson.net.cellid");
            
    //獲取索愛機子的
             lac = System.getProperty("com.sonyericsson.net.lac");
            
    // #else if polish.vendor==Nokia
             imei = System.getProperty("phone.imei");
            
    if (imei == null || "".equals(imei)) {
                 imei 
    = System.getProperty("com.nokia.IMEI");
             }

            
    if (imei == null || "".equals(imei)) {
                 imei 
    = System.getProperty("com.nokia.mid.imei");
             }

            
    //獲取到cellid
            
    //參考http://wiki.forum.nokia.com/index.php/CS000947_-_Getting_Cell_ID_in_Java_ME
            
    // #if polish.group==Series60
             cellid = System.getProperty("com.nokia.mid.cellid");
            
    // #else if polish.group==Series40
             cellid = System.getProperty("Cell-ID");
            
    // #endif
            
    // #else if polish.vendor==Siemens
             imei = System.getProperty("com.siemens.imei");
            
    // #else if polish.vendor==Motorola
             imei = System.getProperty("com.motorola.IMEI");
            
    //cellid 參考 http://web.mit.edu/21w.780/www/spring2007/guide/
             cellid = System.getProperty("CellID");
            
    // #else if polish.vendor==Samsung
             imei = System.getProperty("com.samsung.imei");
            
    // #endif

            
    if (imei == null || "".equals(imei)) {
                 imei 
    = System.getProperty("IMEI");
             }


            
    //展示出來
             form.append("platforminfo:" + info);
             form.append(
    "imei:" + imei);
             form.append(
    "cellid:" + cellid);
             form.setCommandListener(
    this);
             form.addCommand(exitCommand);
             display.setCurrent(form);
         }


        
    public void commandAction(Command cmd, Displayable item) {
            
    if (cmd == exitCommand) {
                 destroyApp(
    false);
                 notifyDestroyed();
             }

         }


    }

      需要注意的是,必須是受信任的Midlet才可以取到這些數據。也就是說Midlet必須經過簽名上述代碼才可以工作,否則獲取到的是NULL。。
    下面是從別的地方看來的,沒做過測試,供參考。
    a) Nokia = System.getProperty("com.nokia.mid.imei");
    System.getProperty("com.nokia.IMEI");
    System.getProperty("phone.imei");
    b) Samsung
    System.getProperty("com.samsung.imei");
    c) Sony-Ericsson
    System.getProperty("com.sonyericsson.imei");

    IMSI: IMSI全稱是International Mobile Subscriber Identification Number,移動用戶身份碼。當手機開機后,在接入網絡的過程中有一個注冊登記的過程,系統通過控制信道將經加密算法后的參數組傳送給客戶,手機中的 SIM卡收到參數后,與SIM卡存儲的客戶鑒權參數經同樣算法后對比,結果相同就允許接入,否則為非法客戶,網絡拒絕為此客戶服務。IMSI唯一的標志了 一個SIM卡。
    IMEI: IMEI即International Mobile Equipment Identity(國際移動設備身份)的簡稱,也被稱為串號,它唯一標志了一臺移動設備,比如手機。 IMEI碼一般由15位數字組成,絕大多數的GSM手機只要按下“*#06#”,IMEI碼就會顯示出來。其格式如下: TAC即Type Approval Code,為設備型號核準號碼。FAC即Final Assembly Code,為最后裝配號碼。 SNR即Serial Number,為出廠序號。 SP即Spare Number,為備用號碼。  

      有時候,我們在應用中需要獲取IMSI或者IMEI號用于將應用程序和手機或SIM卡綁在一起。獲取的方式在各不同廠商的各款手機上不盡相同,在motorola RAZR E6   上采用System.getProperty()獲取。相應程序代碼是:

                 String imei= System.getProperty("IMEI"); //for E6
                 if ( null == imei )
                     imei = System.getProperty("phone.IMEI");
                
                 String imsi = System.getProperty("IMSI"); //for E6
                 if ( null == imsi )
                     imei = System.getProperty("phone.IMSI");
                
                 g.drawString("IMEI: "+imei, 10, 50, Graphics.LEFT | Graphics.TOP);

                 g.drawString("IMSI: "+imsi, 10, 70, Graphics.LEFT | Graphics.TOP);

    參考地址:
    http://blog.csdn.net/phiger/archive/2009/07/22/4371922.aspx
    http://hi.baidu.com/lfcomputer/blog/item/0520e0d37a410a3c970a16c1.html
    http://wiki.forum.nokia.com/index.php/CS000947_-_Getting_Cell_ID_in_Java_ME
    posted @ 2009-12-03 16:30 天狼 閱讀(2988) | 評論 (4)編輯 收藏
    不需要安裝任何插件,使用openlayers 2.8可在Web頁面上實現高級編輯功能。

    作為一個功能強大的WebGIS客戶端,openlayers提供了添加、刪除點、線、面的功能。
    對于節點捕獲、分割、旋轉等高級編輯功能,openlayers也提供了相應的例子。

    節點捕獲的例子 http://dev.openlayers.org/releases/OpenLayers-2.8/examples/snapping.html
    分割的例子 http://dev.openlayers.org/releases/OpenLayers-2.8/examples/split-feature.html
    節點捕獲和分割的例子 http://dev.openlayers.org/releases/OpenLayers-2.8/examples/snap-split.html
    旋轉、縮放的例子 http://dev.openlayers.org/releases/OpenLayers-2.8/examples/modify-feature.html
    控制縮放的例子 http://dev.openlayers.org/releases/OpenLayers-2.8/examples/resize-features.html
    動畫旋轉的例子 http://dev.openlayers.org/releases/OpenLayers-2.8/examples/rotate-features.html



    posted @ 2009-11-20 15:14 天狼 閱讀(2204) | 評論 (0)編輯 收藏

    給圖層添加高度數據,需要根據實體幾何類型分別處理。對于面,例如行政區界或建筑物,需要創建一個高度模板文件。
    對于線(點),例如架空電纜,高程將直接從圖形數據中讀取。
    GeoServer 1.7.1及以上版本支持輸出三維面的KML(KMZ),1.7.6及以上版本支持輸出三維線(點)的KML(KMZ)。

    發布三維面圖層:

    用Geoserver發布三維面的過程非常簡單,測試中我們使用Geoserver自帶的示例圖層topp:states。

    1、用記事本新建一個文本文件(高度模板文件),命名為height.ftl
    2、在文件中加入一行腳本,格式為${ATTRIBUTE.value},ATTRIBUTE是屬性字段的名稱。
    例如states圖層有屬性字段PERSONS,記錄每個州的人口,輸入${PERSONS.value?number/100},把高度和人口數建立關系。
    3、將height.ftl復制到Geoserver的/data/featureTypes/states/目錄下
    4、進入Geoserver地圖預覽頁面,找到topp:states,選擇KML,打開Google Earth瀏覽效果。

    效果圖1



    官方原文見:http://geoserver.org/display/GEOSDOC/04-Height+Templates

    作為練習,可以根據官方文檔
    http://demo.opengeo.org:8080/display/GEOSDOC/05-Super+Overlays+and+Extrudes+with+Building+Data,
    發布紐約曼哈頓的建筑物,瀏覽三維城市效果。

    效果圖2



    發布三維線圖層:

    三維線不使用height.ftl文件,因為一條線有兩個以上的節點,每個節點可能有不同的高度值,高程直接存放在圖形數據(Geometry)的Z坐標中。
    Oracle Spatial、PostgreSQL(PostGIS)等數據庫都支持存儲三維坐標。

    Geoserver可以直接發布三維線,測試中使用Oracle Spatial(10g)和PostgreSQL(8.3)作為數據源。
    1、在Oracle Spatial(10g)或PostgreSQL(8.3)中存入包含Z坐標的三維線數據,作為測試,可用直接SQL語句插入數據。
    2、在Geoserver中發布該圖層。
    3、進入Geoserver地圖預覽頁面,找到剛才發布的圖層,選擇KML,打開Google Earth瀏覽效果。

    需要注意的是,默認KML(KMZ)在Google Earth中的實際效果是三維面。
    經過查閱KML文檔,要實現三維線,需要在KML鏈接后加上可選參數format_options=extrude:0,例如將
    http://192.98.151.200:8080/geoserver/wms/kml?layers=topp:TESTL
    改為
    http://192.98.151.200:8080/geoserver/wms/kml?layers=topp:TESTL&format_options=extrude:0

    效果圖3


    Google KML Version 2.2已經獲得OGC批準,成為國際標準的數據存儲格式。ESRI、INTERGRAPH、MAPINFO在其最新版本軟件中提供KML格式輸出支持。
    Google定義的KML不僅可以包含三維高程數據,還能加入四維時間數據。

    本文只涉及三維數據的發布和展示,相關技術文檔請參考Google KML和Geoserver KML頁面。
    Google KML頁面:http://code.google.com/apis/kml/documentation/
    Geoserver KML頁面:http://geoserver.org/display/GEOSDOC/KML+KMZ+Output http://geoserver.org/display/GEOSDOC/Google+Earth+Features
    本文涉及的軟件環境為:Geoserver 1.7.7、Geoserver 2.0、Google Earth 5.1、Oracle 10.2.0.3、PostgreSQL 8.3.7

    posted @ 2009-10-27 10:40 天狼 閱讀(6754) | 評論 (2)編輯 收藏
    2009年10月23日 Geoserver 2.0 正式發布
    posted @ 2009-10-26 15:55 天狼 閱讀(375) | 評論 (0)編輯 收藏

    一.安裝postgis

      (1)首先到postgresql的官方網站(www.postgresql.org)上下載最新版的開源數據庫postgresql,我當前下載的最新安裝包是postgresql-8.3.6-1-windows.exe

      (2)運行該exe,按照向導安裝之,在安裝過程中最好關閉防火墻,以及監控;另外最好將安裝目錄設置為NTFS分區的盤上.

      (3)安裝完成后提示你是否在退出時配置application stack builder,這里購選上它,然后點finish

      (4)進入application stack builder向導后,選擇postgresql 8.3 on port 5432,點next

      (5)在application list中溝選中你要安裝的application,這里必須溝選postgis-pg83-setup-1.3.5-1.exe

      (6)下一步,選擇下載服務器,下載完成后開始安裝相應的application

      (7)在安裝時要注意,有兩處都要設置密碼,不要設置密碼為空.

      (8)這樣根據向導就可以成功安裝postgis了

      安裝postgis過程中可能會出現"Error opening file for writing:
    c:\program files\PostgreSQL\8.3\bin\libiconv-2.dll"的提示,這里我們可以忽略之

    二.向postgis導入shapefile數據

      (1)安裝后運行pgadmin III,右擊postgresql 8.3(localhost)服務器,連接之,這里的密碼是你安裝時設置的密碼,務必牢記

      (2)連接后,我們發現postgis安裝后自動給我們生成了一個數據template_postgis,我們將要導入的數據就需要放到這個數據庫中.

      (3)運行命名提示符cmd.exe,將其轉向C:\Program Files\PostgreSQL\8.3\bin(或者將cmd.exe復制到該目錄下)如下:

        C:\Program Files\PostgreSQL\8.3\bin>

      (4)首先將shp生成對應的sql腳本,鍵入以下字符

         C:\Program Files\PostgreSQL\8.3\bin>shp2pgsql -W "GBK" D:\CampusGISProject\new_p
    ku_vector\viwpt.shp viwpt > D:\CampusGISProject\new_pku_vector\viwpt.sql

         這里的-W "GBK"代表字符編碼的轉換,D:\CampusGISProject\new_pku_vector\viwpt.shp則是要生成sql腳本的 shp文件.viwpt是創建數據表的表名,>不能少,D:\CampusGISProject\new_pku_vector \viwpt.sql則是要生成SQL文件的絕對目錄

         生成成功后命令提示符會顯示如下:

         Shapefile type: Point
         Postgis type: POINT[2]

      (5)然后我們執行sql語句,執行該SQL語句文件,導入數據到數據庫template_postgis中

         C:\Program Files\PostgreSQL\8.3\bin>psql -d template_postgis -f D:\CampusGISProj
    ect\new_pku_vector\viwpt.sql postgres

         其中 template_postgis是數據庫名,postgres是該數據庫的用戶

         執行成功后,刷新該數據庫,就可以看到新生成的數據表viwpt

       這樣viwpt.shp數據就成功導入到了postgis中了
    posted @ 2009-10-20 15:00 天狼 閱讀(838) | 評論 (0)編輯 收藏
    從MapGuide官方網站(https://mapguide.osgeo.org)下載MapGuide Open Source Windows安裝包
    MgServerSetup-2.0.2.3011.exe
    MgWebServerExtensionsSetup-2.0.2.3011.exe
    安裝包中已經包含了apache和tomcat,但是沒有包含Java SDK。需要單獨安裝Java SDK 5.0以上版本,并設置JAVA_HOME和JRE_HOME環境變量。

    安裝MapGuide Server和MapGuide Web Server Extensions,安裝時選擇Java環境,另外兩種環境是PHP和DOTNET。
    下載java環境示例文件javaviewersample.zip,解壓到 MapGuideOpenSource安裝目錄\WebServerExtensions\www 目錄下,
    在解壓后的文件夾 javaviewersample 找到文件 readme.txt,按其中的說明進行配置,注意修改路徑。
    進入 MapGuideOpenSource安裝目錄\WebServerExtensions\Tomcat\bin 目錄,執行 startup.bat,啟動Tomcat。
    如果Tomcat無法啟動,檢查Java環境變量是否正確。

    下載示例數據包 Sheboygan.mgp,復制到 MapGuideOpenSource安裝目錄\Server\Packages 目錄下。
    打開站點管理程序,地址為 http://ip:8008/mapguide/mapadmin/login.php,登錄用戶名Administrator,密碼admin,注意大小寫。
    如果輸入了正確的用戶名和密碼,仍然無法登錄,檢查MapGuide Server服務是否運行。

    選擇管理頁面左側的導航條,選擇ManagePackages,然后在右側列表選中Sheboygan.Mgp,點擊Load Package標簽,等待Package加載完成。
    注意:如果IP地址為127.0.0.1或localhost,可能無法執行Load Package命令。

    在瀏覽器中輸入 http://ip:8008/mapguide/javaviewersample/ajaxtiledviewersample.jsp, 查看運行效果。


    posted @ 2009-08-31 15:19 天狼 閱讀(1642) | 評論 (0)編輯 收藏
    主站蜘蛛池模板: 亚洲国产成人精品久久| 色老头永久免费网站| 色在线亚洲视频www| 亚洲精品制服丝袜四区| 国产伦精品一区二区三区免费迷| 暖暖免费日本在线中文| 九九九国产精品成人免费视频| 亚洲а∨天堂久久精品9966 | 亚洲av专区无码观看精品天堂| 亚洲色精品vr一区二区三区| 国产免费无遮挡精品视频| 亚洲精品动漫免费二区| 性xxxx视频免费播放直播| 久久高潮一级毛片免费| 成年免费a级毛片| 精品亚洲视频在线| 亚洲人成未满十八禁网站| 亚洲国产av一区二区三区丶| 亚洲精品自产拍在线观看动漫| 亚洲国产婷婷六月丁香| 狠狠综合久久综合88亚洲| avtt亚洲天堂| 一级毛片直播亚洲| 免费少妇a级毛片人成网| 四虎www免费人成| 日韩特黄特色大片免费视频| 一级毛片**免费看试看20分钟 | 欧美最猛性xxxxx免费| 59pao成国产成视频永久免费| 中文字幕无码免费久久| 十八禁视频在线观看免费无码无遮挡骂过 | 亚洲午夜无码片在线观看影院猛| 国产精品va无码免费麻豆| 永久免费观看的毛片的网站| 全免费一级午夜毛片| 午夜网站免费版在线观看| 免费看美女被靠到爽的视频| 日本a级片免费看| 国产gav成人免费播放视频| 又色又污又黄无遮挡的免费视| 男人的天堂亚洲一区二区三区|