ArcGIS API for Android 案例教程 12

來源:互聯網
上載者:User
I. 幾何對象操作與地理處理

幾何對象(Geometry)的操作和地理處理(GeoProcessing/GP)是在地圖基礎上實現更複雜GIS能力的必要功能,在這一章中讓我們來看看在ArcGIS Android API中的如何對幾何對象進行操作和如何使用GP服務。

幾何對象的操作

ArcGIS Android API對幾何對象的操作和其它ArcGIS的Web API有很大區別,它並不是依賴ArcGIS Sever的Geometry Service,而是在API庫中本身就包含了對幾何對象的定義和處理。

如果我們相對一個幾何對象進行buffer操作,這時不需要再指定一個Geometry Service的地址了,而是使用ArcGIS Android API提供的GeometryEngine類就可以實現這些類似的功能。

比如下面的代碼實現了一個buffer的功能:

map.setOnLongPressListener(new OnLongPressListener() {

public void onLongPress(float x, float y) {

Point pt = map.toMapPoint(new Point(x, y));

Polygon pg = GeometryEngine.buffer(pt, map

.getSpatialReference(), 1000000, null); //null表示採用地圖單位

Graphic g = new Graphic();

g.setGeometry(pg);

AgsGeometryEngine.this.gLayer.addGraphic(g);

AgsGeometryEngine.this.gLayer.postInvalidate();

}

});

這樣,當我在地圖上長按時,程式會捕捉到地圖上的座標,然後通過GeometryEngine的靜態方法buffer對這個點進行一個緩衝操作,最後把結果繪製到GraphicsLayer上去,這個程式執行的效果是這個樣子的:

圖 29 使用GeometryEngine對點進行緩衝的結果

如果我還想對產生的這個多邊形進行一下裁剪,依然可以使用GeometryEngine實現:

map.setOnLongPressListener(new OnLongPressListener() {

public void onLongPress(float x, float y) {

Point pt = map.toMapPoint(new Point(x, y));

Polygon pg = GeometryEngine.buffer(pt, map

.getSpatialReference(), 2000000, null);

Geometry geo = GeometryEngine.clip(pg, map.getExtent(), map

.getSpatialReference());//用當前地圖範圍進行裁剪

Graphic g = new Graphic();

g.setGeometry(geo);

AgsGeometryEngine.this.gLayer.addGraphic(g);

AgsGeometryEngine.this.gLayer.postInvalidate();

}

});

這樣,當我在程式左上方邊界附近處長按螢幕產生一個圓形的多邊形後,程式還會調用GeometryEngine進行一個clip操作,通過這個操作多邊形將只保留在當前程式視窗內的部分,所以,如果再拖動一下地圖就可以看到,這個多邊形已經成為了一個餅狀的圖形, 30。

圖 30 使用GeometryEngine對一個多邊形進行裁剪後的結果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.