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

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

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

    Flyingis

    Talking and thinking freely !
    Flying in the world of GIS !
    隨筆 - 156, 文章 - 16, 評論 - 589, 引用 - 0
    數據加載中……

    AE92 SDK for Java 最小示例學習

    ??? 作者:Flyingis

    ??? 初學ArcEngine開發,看到這么多的類和接口有點讓人望而生畏,不好好整理思路容易讓人發暈,其實熟悉了ArcGIS各組件的功能,了解了各種操作的設計思路,拿著各種文檔順藤摸瓜,還是可以迅速進入開發角色的。整個SDK結構組成的分析留到后面,我們先學習一個最小的開發示例,例子來源于ArcEngine開發文檔(HelloCentroid)。

    ??? 例子的功能:

    ??? 返回某shapefile文件第一個feature質心的坐標。

    ??? 引用的包:

    import?com.esri.arcgis.datasourcesfile.ShapefileWorkspaceFactory;
    import?com.esri.arcgis.geodatabase.*;
    import?com.esri.arcgis.geometry.*;
    import?com.esri.arcgis.system.*;

    ??? 每個包的具體用途與功能先不管,以后的學習中會慢慢涉及到并加以分析。

    ??? 從文件路徑中捕獲shapefile特征類:

    private?FeatureClass?getShapefileFeatureClass(String?path,?String?name)?throws?IOException?{
    ??FeatureClass?featureClass?
    =?null;
    ??
    try?{
    ????ShapefileWorkspaceFactory?shapefileWorkspaceFactory?
    =?new?ShapefileWorkspaceFactory();
    ????Workspace?workspace?
    =?(Workspace)?shapefileWorkspaceFactory.openFromFile(path,?0);
    ????featureClass?
    =?new?FeatureClass(workspace.openFeatureClass(name));
    ??}

    ??
    catch?(IOException?ex)?{
    ????System.out.println(
    "Could?not?open?shapefile:?"?+?name);
    ????
    throw?ex;
    ??}

    ??
    return?featureClass;
    }

    ??? 調用ShapefileWorkspaceFactory工廠類的對象的方法openFromFile,將指定的路徑列為工作空間,然后打開工作空間中指定名稱的特征類,參數傳入FeatureClass的構造方法中,返回FeatureClass對象。

    ??? ShapefileWorkspaceFactory工廠類除了可以返回指定的工作空間外,還可以創建、移動、復制工作空間,以及得到工作空間相關的基本信息。

    ??? 在com.esri.arcgis.geodatabase包中可以找到Workspace類,它的方法有許多,涉及和工作空間相關的許多功能,例如連接到工作空間的數據庫名稱、用戶名稱,開始/停止編輯工作空間,創建和刪除注記類、特征類、特征數據集、關聯類,判斷工作空間中某種操作能否執行,工作空間的基本信息,判斷對象是否注冊為版本等等。代碼中所用到的openFeatureClass用于打開已存在的特征類并返回為IFeatureClass。

    ??? FeatureClass類的構造方法接收workspace.openFeatureClass返回的參數,將對象的引用賦給featureClass對象并返回。

    ??? 這個方法的核心應該關注Workspace類,它把握著Geodatabase數據的整體框架與功能導向,FeatureClass是Workspace組成部分,包含了FeatureClass特定的功能與方法。

    ??? 得到特征類的質心位置:

    private?void?printFirstFeatureCentroid(FeatureClass?featureClass)?throws?IOException?{
    ??
    //
    ??
    //?Get?the?first?feature?in?the?feature?class.
    ??
    //
    ??IFeature?feature?=?featureClass.getFeature(0);
    ??
    //
    ??
    //?Get?the?shape?of?the?feature,?and?if?the?shape?is?a?polygon?or?ring,?
    ??
    //?get?its?centroid?by?casting?it?to?the?interface?common?to?both?of?them?(IArea),
    ??
    //?which?interface?defines?the?getCentroid?method.
    ??
    //
    ??IGeometry?shape?=?feature.getShape();
    ??
    if?(!(shape?instanceof?Polygon?||?shape?instanceof?Ring))?{
    ????System.out.println(
    "Feature's?shape?is?neither?a?polygon?nor?a?ring.??No?centroid?available.");
    ????
    return;
    ??}

    ??IArea?area?
    =?(IArea)?shape;
    ??IPoint?centroid?
    =?area.getCentroid();
    ??System.out.println(
    "Centroid:?"?+?centroid.getX()?+?",?"?+?centroid.getY());
    }

    ??? featureClass對象的getFeature(0)方法得到特征類中第一個feature,通過判斷確定該feature為區或環,將該feature所對應的shape uppercast為IArea類型,由getCentroid方法得到area對象的質心點,getX()和getY()輸出該點的坐標。IGeometry、IArea、IPoint都是com.esri.arcgis.geometry包中的接口,指定了不同的幾何類型。由printFirstFeatureCentroid方法,我們可以擴展學習com.esri.arcgis.geometry包中典型接口的使用,例如示例中用到的接口,其包含的方法都很簡單。

    ??? main方法:

    public?static?void?main(String[]?args)?{
    ??
    if?(args.length?!=?2)?{
    ????System.out.println(
    "Usage:?HelloCentroid?shapefilePath?shapefileName");
    ????System.exit(
    1);
    ??}

    ??System.out.println(
    "Hello,?Centroid!");
    ??AoInitialize?aoInitializer?
    =?null;
    ??
    try?{
    ????EngineInitializer.initializeEngine();
    ????aoInitializer?
    =?new?AoInitialize();
    ????aoInitializer.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
    ????HelloCentroid?thisApp?
    =?new?HelloCentroid();
    ????
    //
    ????
    //?Get?the?feature?class?for?the?path?and?name?specified,?
    ????
    //?and?get?its?first?feature's?centroid.
    ????
    //
    ????FeatureClass?featureClass?=?thisApp.getShapefileFeatureClass(args[0],?args[1]);
    ??????
    if?(featureClass?!=?null)?{
    ????????thisApp.printFirstFeatureCentroid(featureClass);
    ??????}

    ??}

    ??
    catch?(IOException?ex)?{
    ????ex.printStackTrace();
    ????System.out.println(
    "App?failed.");
    ??}

    ??
    finally?{
    ????
    try?{
    ??????aoInitializer.shutdown();
    ????}

    ????
    catch?(IOException?ex)?{
    ??????ex.printStackTrace();
    ????}

    ??}

    }

    ??? 從前面的四行代碼可以看出,java解釋器運行該類文件編譯后的字節碼需要兩個參數,一個是featureclass所在的路徑,一個是該路徑下featureclass名稱。需要注意的是這三行代碼:

    EngineInitializer.initializeEngine();
    aoInitializer?
    =?new?AoInitialize();
    aoInitializer.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);

    ??? com.esri.arcgis.system.EngineInitializer.initializeEngine(),在原始AO組件和Java Class之間建立聯系,如果要使用ArcGIS Visual JavaBeans進行圖形操作,則應使用initializeVisualBeans靜態方法進行初始化。aoInitializer對象決定不同的授權和擴展,ESRI License Product codes參考下列表:

    ESRI-License-Product-codes.gif

    ??? Eclipse運行測試,需要在"運行"中輸入兩個"自變量"作為參數,采用ArcGIS自帶的數據,分別為

    ??? "ArcGISHome\ArcTutor\Getting_Started\project\City_share\land"、"parcel_1"

    ??? 測試的結果,控制臺輸出為:

    ??? Hello, Centroid!
    ??? Centroid: 479049.62060511723, 3771922.345004217

    ??? 這個例子描述了一個最簡單AE開發的整個過程,從初始化、授權,到Workspace類、FeatureClass類方法,到com.esri.arcgis.geometry包中典型接口的使用,最后得到我們需要的結果,過程清晰明了,初學者可以通過這個例子順藤摸瓜,敲開AE開發的大門,說的有點玄乎:)

    posted on 2007-03-08 16:21 Flyingis 閱讀(3645) 評論(0)  編輯  收藏 所屬分類: ArcEngine

    主站蜘蛛池模板: 中文字幕在线免费观看| 特级aaaaaaaaa毛片免费视频| A国产一区二区免费入口| www.亚洲色图.com| 猫咪免费人成在线网站 | 精品乱子伦一区二区三区高清免费播放| 暖暖日本免费在线视频| 久久精品亚洲日本波多野结衣| 天天摸夜夜摸成人免费视频| 亚洲免费观看在线视频| 美女视频黄的全免费视频网站| 亚洲av无码片区一区二区三区| 最近中文字幕免费mv视频7| 中文字幕亚洲情99在线| 国产成人免费ā片在线观看| 水蜜桃视频在线观看免费| 久久久精品国产亚洲成人满18免费网站 | baoyu122.永久免费视频| 亚洲电影中文字幕| 久久久久av无码免费网| 亚洲精品第一综合99久久| 国产美女无遮挡免费视频| 国产精品永久免费| 久久精品国产亚洲av高清漫画| 成年在线观看网站免费| 日本系列1页亚洲系列| 亚洲小说区图片区另类春色| 100部毛片免费全部播放完整| 手机在线免费视频| 牛牛在线精品观看免费正| 亚洲av无码专区国产乱码在线观看| 免费国产黄网站在线观看可以下载| 久久久久亚洲AV无码专区网站| 久久青草免费91线频观看不卡| 亚洲七七久久精品中文国产| 免费污视频在线观看| 亚洲日本va一区二区三区| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 美景之屋4在线未删减免费| 国产亚洲精品xxx| 好吊妞788免费视频播放|