📄 countfeatures.java
字号:
/*
* Copyright 2006 ESRI
*
* All rights reserved under the copyright laws of the United States
* and applicable international laws, treaties, and conventions.
*
* You may freely redistribute and use this sample code, with or
* without modification, provided you include the original copyright
* notice and use restrictions.
* See use restrictions at /arcgis/java/samples/userestrictions.
*/
package com.esri.webadf.sample;
import java.rmi.RemoteException;
import com.esri.adf.web.ags.ADFAGSException;
import com.esri.adf.web.ags.data.AGSMapFunctionality;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebLayerInfo;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.query.WebQuery;
import com.esri.adf.web.faces.event.MapEvent;
import com.esri.arcgisws.EnvelopeN;
import com.esri.arcgisws.EsriSearchOrder;
import com.esri.arcgisws.EsriSpatialRelEnum;
import com.esri.arcgisws.LayerDescription;
import com.esri.arcgisws.MapServerPort;
import com.esri.arcgisws.SpatialFilter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.model.SelectItem;
public class CountFeatures {
private WebContext webContext = null;
private int numberOfFeatures = -1;
private WebLayerInfo layer;
private AGSMapFunctionality mfunc = null;
private ArrayList layers = null;
public int getNumberOfFeatures() {
return numberOfFeatures;
}
public WebContext getWebContext() {
return webContext;
}
public void setWebContext(WebContext webContext) {
this.webContext = webContext;
}
public String countInExtent(){
WebMap webMap = webContext.getWebMap();
WebExtent webExtent = webMap.getCurrentExtent();
//this line is safe only because this is a single source application that has an AGS Source
AGSMapResource agsMap = (AGSMapResource) webContext.getResources().get("ags1");
goCount(webExtent, agsMap);
//by returning null the JSF Navigation Handler returns to the originating page
return null;
}
public void countInRectangle(MapEvent event){
WebMap webMap = webContext.getWebMap();
WebExtent webExtent = (WebExtent) event.getWebGeometry().toMapGeometry(webMap);
//this line is safe only because this is a single source application that has an AGS Source
AGSMapResource agsMap = (AGSMapResource) webContext.getResources().get("ags1");
goCount(webExtent, agsMap);
}
private void goCount(WebExtent webExtent, AGSMapResource agsMap) {
numberOfFeatures = 0;
//Get the class that handles the SOAP transactions with the server
MapServerPort mapServer = agsMap.getMapServer();
//make a new envelope from the web extent
EnvelopeN env = new EnvelopeN(webExtent.getMinX(), webExtent.getMinY(), webExtent.getMaxX(), webExtent.getMaxY(),
null, null, null, null, null);
// make a spatialfilter value object with the required parameters
SpatialFilter spatialFilter = new SpatialFilter();
spatialFilter.setFilterGeometry(env);
spatialFilter.setSpatialRel(EsriSpatialRelEnum.esriSpatialRelIntersects);
spatialFilter.setWhereClause("");
spatialFilter.setSearchOrder(EsriSearchOrder.esriSearchOrderSpatial);
spatialFilter.setSpatialRelDescription("");
spatialFilter.setGeometryFieldName("");
int layerId = -1;
if (layer != null) layerId = layer.getId();
//because queryFeatureCount is found on the MapServerPort the call to queryFeatureCount goes back
//to the server which can throw an RemoteException
try {
if(layerId != -1)
numberOfFeatures = mapServer.queryFeatureCount(mapServer.getDefaultMapName(), layerId, spatialFilter);
else {
AGSMapFunctionality func = (AGSMapFunctionality)agsMap.getFunctionality("map");
LayerDescription[] descs = func.getLayerDescriptions();
for(int i = 0; i < descs.length; i++) {
numberOfFeatures += mapServer.queryFeatureCount(mapServer.getDefaultMapName(), descs[i].getLayerID(),spatialFilter);
}
}
} catch (RemoteException e){
//By rethrowing this as an ADFAGSException it can participate in the exception frameowork of the
//ADF which will show root cause and be available in a message stack for your JSF page.
throw new ADFAGSException("Unable to count features", e);
}
}
public ArrayList getQueryLayers(){
if (layers != null) return layers;
layers = new ArrayList();
WebQuery wQuery = this.webContext.getWebQuery();
WebLayerInfo layerInfo = null;
if (wQuery != null){
List layerList = wQuery.getQueryLayers();
for (Iterator iter = layerList.iterator(); iter.hasNext(); ) {
Object item = (Object) iter.next();
if (item instanceof WebLayerInfo){
layerInfo = (WebLayerInfo)item;
layers.add(new SelectItem(layerInfo, layerInfo.getName()));
}
}
}
return layers;
}
public WebLayerInfo getLayer() {
return layer;
}
public void setLayer(WebLayerInfo layer) {
this.layer = layer;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -