版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、實(shí)驗(yàn)12空間分析任務(wù)調(diào)用(一)-2010211894 盛華英一、實(shí)驗(yàn)?zāi)康?、掌握 QueryTask、IdentifyTask、Geocode 的開(kāi)發(fā)。2、掌握擴(kuò)展 AsyncTask 的 onPreExecute、doInBackground、onPostExecute 實(shí)現(xiàn)異步任務(wù)的調(diào)用。3、掌握通過(guò)使用IdentifyTask實(shí)現(xiàn)查詢(xún)?nèi)蝿?wù)。4、掌握通過(guò)使用Locator實(shí)現(xiàn)地址解析服務(wù)。二、實(shí)驗(yàn)數(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三、實(shí)驗(yàn)內(nèi)容1、QueryTask 開(kāi)發(fā)(1)界面代碼: 3.5 /(2)后臺(tái)代碼: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 開(kāi)發(fā)界面代碼:后臺(tái)代碼: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 開(kāi)發(fā)(1)界面代碼: (2)后臺(tái)代碼: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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年綠色生態(tài)建筑農(nóng)民工勞動(dòng)合同示范3篇
- 二零二五年度防盜門(mén)行業(yè)市場(chǎng)分析報(bào)告合同2篇
- 二零二五版加油站智能監(jiān)控與數(shù)據(jù)分析合同3篇
- 二零二五白云區(qū)觀白活力中心房地產(chǎn)合作開(kāi)發(fā)投資框架合同2篇
- 二零二五年度智能家電產(chǎn)品研發(fā)與銷(xiāo)售合同3篇
- 二零二五版養(yǎng)殖企業(yè)與個(gè)體養(yǎng)牛戶(hù)合作合同3篇
- 二零二五版數(shù)據(jù)中心機(jī)房租賃及數(shù)據(jù)備份服務(wù)合同2篇
- 基于2025年度5G網(wǎng)絡(luò)技術(shù)研發(fā)合作合同2篇
- 二零二五版拌和站產(chǎn)品質(zhì)量追溯與售后服務(wù)合同2篇
- 二零二五版建筑工程土方中介合同糾紛調(diào)解機(jī)制3篇
- 課題申報(bào)書(shū):GenAI賦能新質(zhì)人才培養(yǎng)的生成式學(xué)習(xí)設(shè)計(jì)研究
- 外配處方章管理制度
- 2025年四川長(zhǎng)寧縣城投公司招聘筆試參考題庫(kù)含答案解析
- 駱駝祥子-(一)-劇本
- 《工程勘察設(shè)計(jì)收費(fèi)標(biāo)準(zhǔn)》(2002年修訂本)
- 全國(guó)醫(yī)院數(shù)量統(tǒng)計(jì)
- 【MOOC】PLC技術(shù)及應(yīng)用(三菱FX系列)-職教MOOC建設(shè)委員會(huì) 中國(guó)大學(xué)慕課MOOC答案
- 2023七年級(jí)英語(yǔ)下冊(cè) Unit 3 How do you get to school Section A 第1課時(shí)(1a-2e)教案 (新版)人教新目標(biāo)版
- 泌尿科主任述職報(bào)告
- 2024年醫(yī)美行業(yè)社媒平臺(tái)人群趨勢(shì)洞察報(bào)告-醫(yī)美行業(yè)觀察星秀傳媒
- 第六次全國(guó)幽門(mén)螺桿菌感染處理共識(shí)報(bào)告-
評(píng)論
0/150
提交評(píng)論