日常應(yīng)用中無(wú)論是草圖繪制,還是外業(yè)采集都需要在移動(dòng)端進(jìn)行空間要素的繪制。而ArcGIS Runtime SDK for Android中提供了Geometry、Feature、Graphic,這三者到底如何使用,本文稍微做做解答。
空間要素(Geometry)
Geometries用以在特定地理位置上通過形狀來(lái)表達(dá)真實(shí)世界的對(duì)象。圖層范圍、視圖范圍、GPS定位都是通過Geometries表達(dá)實(shí)現(xiàn)進(jìn)一步的數(shù)據(jù)編輯、空間分析、地理處理、位置與面積量算都離不開空間要素。
Features 與 Graphics
Feature(com.esri.arcgisruntime.data.Feature),存儲(chǔ)于Feature Table中,在 Feature Layer中進(jìn)行顯示。包含的Geometry 必須同一類型。包含的屬性信息其字段信息必須相同。用以Feature Table中進(jìn)行更新、刪除等操作。
Graphic(com.esri.arcgisruntime.mapping.view. Graphic ),存儲(chǔ)于運(yùn)行內(nèi)存中,在Graphics OverLay中進(jìn)行顯示。包含的Geometry類型可以不統(tǒng)一。通過類對(duì)象直接創(chuàng)建,僅用以繪制性顯示。
創(chuàng)建 – 矩形、點(diǎn)
Envelope envelope =
new Envelope(-123.0, 33.5, -101.0, 48.0, SpatialReferences.getWgs84());
Point pt =
new Point(34.056295, -117.195800, SpatialReferences.getWgs84());
PointCollection stateCapitalsPST =
new PointCollection(SpatialReferences.getWgs84());
stateCapitalsPST.add(-121.491014, 38.579065); // Sacramento, CA
stateCapitalsPST.add(-122.891366, 47.039231); // Olympia, WA
stateCapitalsPST.add(-123.043814, 44.93326); // Salem, OR
stateCapitalsPST.add(-119.766999, 39.164885); // Carson City, NV
Multipoint multipoint = new Multipoint(stateCapitalsPST);
創(chuàng)建 – 線、面
PointCollection borderCAtoNV =
new PointCollection(SpatialReferences.getWgs84());
borderCAtoNV.add(-119.992, 41.989);
borderCAtoNV.add(-119.994, 38.994);
borderCAtoNV.add(-114.620, 35.0);
Polyline polyline = new Polyline(borderCAtoNV);
PointCollection coloradoCorners =
new PointCollection(SpatialReferences.getWgs84());
coloradoCorners.add(-109.048, 40.998);
coloradoCorners.add(-102.047, 40.998);
coloradoCorners.add(-102.037, 36.989);
coloradoCorners.add(-109.048, 36.998);
Polygon polygon = new Polygon(coloradoCorners);
空間要素繪制 – SketchEditor
繪制類型(SketchCreationMode)
- POINT
- MULTIPOINT
- POLYLINE
- POLYGON
- FREEHAND_LINE
- FREEHAND_POLYGON
初始化地圖
mainMapView = (MapView) findViewById(R.id.mainMapView);
mainBasemap = new Basemap(
TianDiTuMethodsClass.CreateTianDiTuTiledLayer(
TianDiTuMethodsClass.LayerType.TIANDITU_VECTOR_2000));
mainBasemap.getBaseLayers().add(
TianDiTuMethodsClass.CreateTianDiTuTiledLayer(
TianDiTuMethodsClass.LayerType.TIANDITU_VECTOR_ANNOTATION_CHINESE_2000));
mainArcGISMap = new ArcGISMap(mainBasemap);
mainMapView.setMap(mainArcGISMap);
mainSketchEditor = new SketchEditor();
mainSketchStyle = new SketchStyle();
mainSketchEditor.setSketchStyle(mainSketchStyle);
mainMapView.setSketchEditor(mainSketchEditor);
啟動(dòng)繪制
mPointButton = (ImageButton) findViewById(R.id.pointSketchButton);
mPointButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
//mainSketchEditor.stop();
mainSketchEditor.start(SketchCreationMode.POINT);
}
catch (Exception e)
{
e.getCause();
}
}
});
mPolylineButton = (ImageButton) findViewById(R.id.polylineSketchButton);
mPolylineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
//mainSketchEditor.stop();
mainSketchEditor.start(SketchCreationMode.POLYLINE);
}
catch (Exception e)
{
e.getCause();
}
}
});
mPolygonButton = (ImageButton) findViewById(R.id.polygonSketchButton);
mPolygonButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
//mainSketchEditor.stop();
mainSketchEditor.start(SketchCreationMode.POLYGON);
}
catch (Exception e)
{
e.getCause();
}
}
});
mPolylineFreeheadButton = (ImageButton) findViewById(R.id.polylineFreeheadSketchButton);
mPolylineFreeheadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
//mainSketchEditor.stop();
mainSketchEditor.start(SketchCreationMode.FREEHAND_LINE);
}
catch (Exception e)
{
e.getCause();
}
}
});
mPolygonFreeheadButton = (ImageButton) findViewById(R.id.polygonFreeheadSketchButton);
mPolygonFreeheadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
//mainSketchEditor.stop();
mainSketchEditor.start(SketchCreationMode.FREEHAND_POLYGON);
}
catch (Exception e)
{
e.getCause();
}
}
});
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
|