版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、實驗12空間分析任務(wù)調(diào)用(一)-2010211894 盛華英一、實驗目的1、掌握 QueryTask、IdentifyTask、Geocode 的開發(fā)。2、掌握擴展 AsyncTask 的 onPreExecute、doInBackground、onPostExecute 實現(xiàn)異步任務(wù)的調(diào)用。3、掌握通過使用IdentifyTask實現(xiàn)查詢?nèi)蝿?wù)。4、掌握通過使用Locator實現(xiàn)地址解析服務(wù)。二、實驗數(shù)據(jù) HYPERLINK /ArcGIS/rest/services/Demographic /ArcGIS/rest/services/Demographic s/USA_Average_Hou
2、sehold_Size/MapServer HYPERLINK /ArcGIS/rest/services/World_Street_ /ArcGIS/rest/services/World_Street_ Map/MapServer三、實驗內(nèi)容1、QueryTask 開發(fā)(1)界面代碼: 3.5 /(2)后臺代碼:public class AttributeQuery extends Activity /* Called when the activity is first created. */MapView mv;GraphicsLayer gl;Graphic graphic;Grap
3、hic fillGraphic;Button querybt;String targetServerURL = HYPERLINK /ArcGIS/rest/services/Demographics/USA_Ave /ArcGIS/rest/services/Demographics/USA_Ave rage_Household_Size/MapServer;boolean blQuery = true;ProgressDialog progress;final static int HAS_RESULTS = 1;final static int NO_RESULT = 2;final s
4、tatic int CLEAR_RESULT = 3;public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.main);mv = (MapView) findViewById(R.id.map);mv.setOnStatusChangedListener(new OnStatusChangedListener() private static final long serialVersionUID = 1L;public void on
5、StatusChanged(Object source, STATUS status) if (source = mv & status = STATUS.INITIALIZED) gl = new GraphicsLayer();SimpleRenderer sr = new SimpleRenderer(new SimpleFillSymbol(Color.RED);gl.setRenderer(sr);mv.addLayer(gl);boolean doQuery = false;for (Layer lv : mv.getLayers() if (lv instanceof ArcGI
6、STiledMapServiceLayer) ArcGISTiledMapServiceLayer tLayer = (ArcGISTiledMapServiceLayer) lv;if (tLayer.getUrl().equals(targetServerURL) doQuery = true;break;if (!doQuery) Toast toast = Toast.makeText(AttributeQuery.this, URL for query does not exist any more, Toast.LENGTH_LONG);toast.show(); else que
7、rybt.setEnabled(true); );querybt = (Button) findViewById(R.id.queryButton);querybt.setOnClickListener(new View.OnClickListener() public void onClick(View v) if (blQuery) String targetLayer = targetServerURL.concat(/3);String queryParams = targetLayer, AVGHHSZ_CY3.5 ; AsyncQueryTask ayncQuery = new A
8、syncQueryTask(); ayncQuery.execute(queryParams); else gl.removeAll();blQuery = true;querybt.setText(Average Household 3.5););/* Query Task executes asynchronously.*/private class AsyncQueryTask extends AsyncTask protected void onPreExecute() progress = ProgressDialog.show(AttributeQuery.this, Please
9、 wait.query task is executing);/*First member in parameter array is the query URL; second member isthe where clause.*/protected FeatureSet doInBackground(String. queryParams) if (queryParams = null | queryParams.length 0) gl.addGraphics(grs); message = (grs.length = 1 ? 1 result has : Integer .toStr
10、ing(grs.length) + results have ) + come back;progress.dismiss();Toast toast = Toast.gkeText(AttributeQuery.this, message, Toast.LENGTH_LONG);toast.show();querybt.setText(Clear graphics);blQuery = false;Overrideprotected void onPause() super.onPause();mv.pause();Overrideprotected void onResume() supe
11、r.onResume();mv.unpause();2、IdentifyTask 開發(fā)界面代碼:后臺代碼:public class Identify extends Activity MapView map = null;IdentifyParameters params;/* Called when the activity is first created. */public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);map = new MapView(this);ArcGISTi
12、ledMapServiceLayer basemap = new ArcGISTiledMapServiceLayer( HYPERLINK /ArcGIS/rest/services/World_Street_Map/M /ArcGIS/rest/services/World_Street_Map/M apServer);map.addLayer(basemap);ArcGISTiledMapServiceLayer layer = new ArcGISTiledMapServiceLayer( HYPERLINK /ArcGIS/rest/services/Demographics/USA
13、 /ArcGIS/rest/services/Demographics/USA _Average_Household_Size/MapServer);map.addLayer(layer);/ Create an extent for initial extentEnvelope env = new Envelope(-19332033.11, -3516.27, -1720941.80,11737211.28);/ Set the MapView initial extentmap.setExtent(env);setContentView(map);params = new Identif
14、yParameters();params.setTolerance(20);params.setDPI(98);params.setLayers(new int 4 );params.setLayerMode(IdentifyParameters.ALL_LAYERS);map.setOnSingleTapListener(new OnSingleTapListener() private static final long seriaLVersionUID = 1L;public void onSingleTap(final float x, final float y) if (!map.
15、isLoaded() return;/ establish the identify parametersPoint identifyPoint = map.toMapPoint(x, y);params.setGeometry(identifyPoint);params.setSpatialReference(map.getSpatialReference();params.setMapHeight(map.getHeight();params.setMapWidth(map.getWidth();Envelope env = new Envelope();map.getExtent().q
16、ueryEnvelope(env);params.setMapExtent(env);MyIdentifyTask mTask = new MyIdentifyTask(identifyPoint); mTask.execute(params););private ViewGroup createIdentifyContent(final List results) LinearLayout layout = new LinearLayout(this);layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, Lay
17、outParams. WRAP_CONTENT);layout.setOrientation(LinearLayout. HORIZONTAL);IdentifyResultSpinner spinner = new IdentifyResultSpinner(this, (List) results);spinner.setClickable(true);MyIdentifyAdapter adapter = new MyIdentifyAdapter(this, results); spinner.setAdapter(adapter);spinner.setLayoutParams(ne
18、w LayoutParams(LayoutParams.FItL_PAREN, LayoutParams.WRAP_CONTENT );layout.addView(spinner);return layout;/*This class allows the user to customize the string shown in the callout.By default its the display field name.*/public class MyIdentifyAdapter extends IdentifyResultSpinnerAdapter String m_sho
19、w = null;List resultList;int currentDataViewed = -1;Context m_context;public MyIdentifyAdapter(Context context, List results) super(context, results);this.resultList = results;this.m_context = context;/ This is the view that will get added to the callout/ Create a text view and assign the text that
20、should beisible in the/ calloutpublic View getView(int position, View convertView, ViewGroup parent) String outputVal = null;TextView txtView;IdentifyResult curResult = this.resultList.get(position);if (curResult.getAttributes().containsKey(Name) outputVal = curResult.getAttributes().get(Name).toStr
21、ing(); txtView = new TextView(this.m_context);txtView.setText(outputVal);txtView.setTextColor(Color.BLACK);txtView.setLayoutParams(new ListView.LayoutParams(LayoutParams.FILL PARENT, LayoutParams. WRAP_CONTENT);txtView.setGravity(Gravity.CENTER_VERTICAL);return txtView; protected void onPause() supe
22、r.onPause(); map.pause();Overrideprotected void onResume() super.onResume(); map.unpause();private class MyIdentifyTask extendsAsyncTask IdentifyTask mIdentifyTask;Point mAnchor;MyIdentifyTask(Point anchorPoint) mAnchor = anchorPoint; Overrideprotected IdentifyResult doInBackground(IdentifyParameter
23、s. params) IdentifyResult mResult = null;if (params != null & params.length 0) IdentifyParameters mParams = params0; try mResult = mIdentifyTask.execute(mParams); catch (Exception e) / TODO Auto-generated catch block e.printStackTrace();return mResult;Overrideprotected void onPostExecute(IdentifyRes
24、ult results) / TODO Auto-generated method stubArrayList resultList = new ArrayList();for (int index = 0; index results.length; index+) if (resultsindex.getAttributes().get( resultsindex.getDisplayFieldName() != null) resultList.add(resultsindex);/ map.getCallout().show(map.toMapPoint(x,y),/ createId
25、entifyContent(resultList); map.getCallout().show(mAnchor, createIdentifyContent(resultList);Overrideprotected void onPreExecute() / mIdentifyTask = new/IdentifyTask( HYPERLINK /ArcGIS/rest/services/Ea /ArcGIS/rest/services/Ea rthquakes/EarthquakesFromLastSevenDays/MapServer);mIdentifyTask = new Iden
26、tifyTask( HYPERLINK /ArcGIS/rest/services/Demographics/USA /ArcGIS/rest/services/Demographics/USA _Average_Household_Size/MapServer);3、Geocode 開發(fā)(1)界面代碼: (2)后臺代碼:public class GeocodeActivity extends Activity / create arcgis objectsMapView mMapView;ArcGISTiledMapServiceLayer basemap;GraphicsLayer loc
27、ationLayer;Locator locator;/ create UI componentsstatic ProgressDialog dialog;static Handler handler;/ Label instructing input for EditText TextView geocodeLabel;/ Text box for entering addressEditText addressText;Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceSt
28、ate);setContentView(R.layout.main);/ create handler to update the UI handler = new Handler();/ Set the geocodeLabel with instructionsgeocodeLabel = (TextView) findViewById(R.id.geocodeLabel);geocodeLabel.setText(getString(R.string.geocode_LabeL);/ Get the addressText component addressText = (EditTex
29、t) findViewById(R.id.addressText);/ Retrieve the map and initial extent from XML layout mMapView = (MapView) findViewById(R.id.map);/* create a ArcGISTiledMapServiceLayer */basemap = newArcGISTiledMapServiceLayer(this.getResources().getString( R.string.basemap_url );/ Add tiled layer to MapView mMap
30、View.addLayer(basemap);/ Add location layerlocationLayer = new GraphicsLayer();mMapView.addLayer(locationLayer);/ attribute ESRI logo to map mMapView.setEsriLogoVisible(true);/*Submit address for geocoding*/SuppressWarnings(unused)public void locate(View view) / remove any previous graphics location
31、Layer.removeAll();/ obtain address from text boxString address = addressText.getText().toString(); / send address to conversion method address2Pnt(address);/*Convert input address into geocoded point*/private void address2Pnt(String address) try / create Locator parameters from single line address s
32、tring LocatorFindParameters findParams = new LocatorFindParameters( address);/ set the search country to USA findParams.setSourceCountry(USA);/ limit the results to 2findParams.setMaxLocations(2);/ set address spatial reference to match map findParams.setOutSR(mMapView.getSpatialReference();/ execut
33、e async task to geocode address new Geocoder().execute(findParams); catch (Exception e) e.printStackTrace();/*(non-Javadoc)*see android.app.Activity#onPause()*/Overrideprotected void onPause() super.onPause();mMapView.pause();/*(non-Javadoc)*see android.app.Activity#onResume()*/Overrideprotected voi
34、d onResume() super.onResume();mMapView.unpause();/*Dismiss dialog when geocode task completes*/static public class MyRunnable implements Runnable public void run() dialog .dismiss。;/*AsyncTask to geocode an address to a point location Draw resulting pointlocation on the map with matching address*/pr
35、ivate class Geocoder extendsAsyncTaskLocatorFindParameters, Void, List / The result of geocode task is passed as a parameter to map the/ resultsprotected void onPostExecute(List result) if (result = null | result.size() = 0) / update UI with notice that no results were found Toast toast = Toast.make
36、Text(GeocodeActivity.this, No result found., Toast.LENGTH_LONG);toast.show();) else / show progress dialog while geocoding addressdialog = ProgressDialog.show(mMapView.getContext(), Geocoder,Searching for address .);/ get return geometry from geocode resultGeometry resultLocGeom = result.get(0).getLocation();/ create marker symbol to represent location SimpleMarkerSymbol resultSymbol = new SimpleMarkerSymbol( Color.BLUE, 20, SimpleMarkerSymbol.STYLE.CIRCLE);/ create graphic object for resulting locationGraphic resultLocation = new Graphic(r
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2026年本地配送合同
- 等保測評技術(shù)服務(wù)合同
- 2025年水利設(shè)施智能管理系統(tǒng)可行性研究報告
- 2025年新型物流倉儲設(shè)施建設(shè)可行性研究報告
- 2025年數(shù)字鄉(xiāng)村發(fā)展與應用項目可行性研究報告
- 港口運輸合同范本
- 田地退租合同范本
- 產(chǎn)后消費協(xié)議書
- 高考全國二卷英語題庫題庫(含答案)
- 人力資源培訓師課程設(shè)計能力測試題含答案
- 2025年廣東省第一次普通高中學業(yè)水平合格性考試(春季高考)英語試題(含答案詳解)
- 2026年合同全生命周期管理培訓課件與風險防控手冊
- 特殊兒童溝通技巧培訓
- 理賠管理經(jīng)驗分享
- 中國馬克思主義與當代2024版教材課后思考題答案
- 2026年日歷表(每月一頁、可編輯、可備注)
- DB44∕T 1297-2025 聚乙烯單位產(chǎn)品能源消耗限額
- 2025年歷城語文面試題目及答案
- 裝修合同三方協(xié)議范本
- 講給老年人聽的助聽器
- 大清包勞務(wù)合同樣本及條款解讀
評論
0/150
提交評論