📄 featurecounter.java
字号:
package com.intellegent;
import java.rmi.RemoteException;
import com.esri.adf.web.ags.ADFAGSException;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.WebExtent;
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.MapServerPort;
import com.esri.arcgisws.SpatialFilter;
public class FeatureCounter {
private WebContext context;
private int countedFeatures;
public String countFeaturesInRectangle(MapEvent event) {
//Get the chosen extent
WebMap webMap = context.getWebMap();
WebExtent chosenExent = (WebExtent) event.getWebGeometry()
.toMapGeometry(webMap);
//Delegate to countFeatures()
this.countFeatures(chosenExent);
//Don't want to navigate to another page
return null;
}
public String countFeaturesInFullExtent() {
//Get the full extent
WebExtent fullExtent = context.getWebMap().getFullExtent();
//Delegate to countFeatures()
this.countFeatures(fullExtent);
//Don't want to navigate to another page
return null;
}
private void countFeatures(WebExtent extent) {
// Get the MapServerPort so we can execute methods through ArcGIS Server API
AGSMapResource agsMap = (AGSMapResource) context.getResources().get(
"ags0");
MapServerPort mapServer = agsMap.getMapServer();
// Make a new envelope from the web extent
EnvelopeN env = new EnvelopeN(extent.getMinX(), extent.getMinY(),
extent.getMaxX(), extent.getMaxY(), null, null, null, null,
null);
// Setup a spatial filter for an Intersection relationship
SpatialFilter spatialFilter = new SpatialFilter();
spatialFilter
.setSpatialRel(EsriSpatialRelEnum.esriSpatialRelIntersects);
spatialFilter.setWhereClause("");
spatialFilter.setSearchOrder(EsriSearchOrder.esriSearchOrderSpatial);
spatialFilter.setSpatialRelDescription("");
spatialFilter.setGeometryFieldName("");
// Set the envelope as the geometry
spatialFilter.setFilterGeometry(env);
// MapServer::queryFeatureCount() executes on the server and can throw a
// RemoteException
try {
// Count features in 4th layer which intersect with the envelope
int layerId = 3;
this.countedFeatures = mapServer.queryFeatureCount(mapServer
.getDefaultMapName(), layerId, spatialFilter);
} catch (RemoteException rme) {
// Rethrow this as ADFAGSException so that it can participate in the
// exception framework
throw new ADFAGSException(
"Could not execute MapServer::queryFeatureCount()", rme);
}
}
public WebContext getContext() {
return context;
}
public void setContext(WebContext context) {
this.context = context;
}
public int getCountedFeatures() {
return countedFeatures;
}
public void setCountedFeatures(int countedFeatures) {
this.countedFeatures = countedFeatures;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -