ArcGIS API for Android 案例教程 13

來源:互聯網
上載者:User
地理處理服務

圖 31 調用GP服務的ViewShed例子

ArcGIS Android API中示範GP服務的調用是一個很有意思的例子(ViewShed),這個例子讓使用者在螢幕上畫一個點,再通過左上方那個執行的按鈕發送一個調用GP服務的請求,當這個GP服務被調用成功後,返回給用戶端的是一些多邊形,這些多邊形表示的是如果有人站在剛才使用者畫點的位置所能看到的地區。

現在,如果你開啟這個例子的原始碼,你應該可以很容易地從左上方那個“go”按鈕的事件監聽中找到這個GP服務的調用方法:

GPFeatureRecordSetLayer gpf = new GPFeatureRecordSetLayer(

"Input_Observation_Point");

gpf.setSpatialReference(map.getSpatialReference());

gpf.setGeometryType("esriGeometryPoint");

Graphic f = new Graphic();

f.setGeometry(mappoint);

gpf.addGraphic(f);

GPLinearUnit gpl = new GPLinearUnit("Viewshed_Distance");

gpl.setUnits("esriMeters");

gpl.setDistance(8046.72);

params = new ArrayList();

params.add(gpf);

params.add(gpl);

try {

dialog = ProgressDialog.show(Viewshed.this, "",

"Loading. Please wait...", true, true);

new ViewShedQuery().execute(params);

cancelViewShed = new Timer();

cancelViewShed.schedule(new TimerTask() {

@Override

public void run() {

uiHandler.sendEmptyMessage(CANCEL_LOADING_WINDOW);

}

}, 60000);

} catch (Exception e) {

e.printStackTrace();

}

在上面的代碼中,主要做了兩件事情:第一件事情是準備GP服務執行所需要的參數ArrayList;另一件事情就是開始調用GP服務。在這個例子裡,對GP服務的調用還進行了一個封裝,而事實上核心的代碼可以從下面代碼中的高亮部分看到(代碼略有修改):

class ViewShedQuery extends

AsyncTask, Void, GPParameter[]> {

GPParameter[] outParams = null;

@Override

protected void onPostExecute(GPParameter[] result) {

…

}

@Override

protected GPParameter[] doInBackground(

ArrayList... params1) {

gp = new GeoProcessor("http://sampleserver1.arcgisonline.com/ArcGIS
/rest/services/Elevation/ESRI_Elevation_World/GPServer/Viewshed");

gp.setOutSR(map.getSpatialReference().getID());

try {

GPResultResource gprr = gp.execute(params1[0]);

outParams = gprr.getOutputParameters();

} catch (Exception e) {

e.printStackTrace();

}

return outParams;

}

很顯然,這個GP服務是一個同步執行的服務,因此,在這裡調用的是GeoProcessor對象的execute方法。如果是一個非同步執行的GP服務,那麼想來應該是執行GeoProcessor的submitJob方法,有興趣的可以自己再嘗試一下。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.