⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agsinternetproxy.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.web.tasks.filter;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import com.esri.adf.web.ags.data.AGSMapFunctionality;
import com.esri.adf.web.ags.data.AGSMapResource;
import com.esri.adf.web.ags.util.AGSUtil;
import com.esri.adf.web.data.WebLayerInfo;
import com.esri.adf.web.data.geometry.WebGeometry;
import com.esri.adf.web.data.query.QueryResult;
import com.esri.adf.web.data.query.WebQuery;
import com.esri.arcgisws.EsriFieldType;
import com.esri.arcgisws.EsriSearchOrder;
import com.esri.arcgisws.EsriSpatialRelEnum;
import com.esri.arcgisws.Field;
import com.esri.arcgisws.Fields;
import com.esri.arcgisws.Geometry;
import com.esri.arcgisws.MapLayerInfo;
import com.esri.arcgisws.MapServerPort;
import com.esri.arcgisws.Record;
import com.esri.arcgisws.RecordSet;
import com.esri.arcgisws.SpatialFilter;
import com.esri.adf.web.ags.data.AGSLocalMapResource;

public class AGSInternetProxy {
	private static Logger logger = Logger.getLogger(AGSInternetProxy.class.getName());

	public LinkedHashMap<String, String> getAgsFieldList(Object resource, String id, int lyrId){
		try{
			if (!(resource instanceof AGSMapResource)) return null;
			AGSMapResource agsMapResource = (AGSMapResource)resource;
			AGSMapFunctionality agsMapFunc = (AGSMapFunctionality)(agsMapResource).getFunctionality("map");
			MapLayerInfo mapLayer = agsMapFunc.getLayerInfo(lyrId);
			
			if (mapLayer.isHasAttributes()) {
				LinkedHashMap<String, String> fieldList = new LinkedHashMap<String, String>();
				
				Fields fields = mapLayer.getFields();
				
				if (fields != null) {
					Field[] flds = fields.getFieldArray();
					
					for (int i = 0; i < flds.length; i++) {
						Field fld = flds[i];
						String alias = fld.getAliasName();
						if (alias == null || alias.equalsIgnoreCase("")) alias = fld.getName();
						int fldType = 4;
						if (fld.getType() == EsriFieldType.esriFieldTypeString) fldType = 12;
						
						//TODO: Change this code to check the field type, not the field
						//      name.
						if (!fld.getName().equalsIgnoreCase("SHAPE"))
							fieldList.put(fld.getName() + "!" + fldType, alias);
					}
					
					return fieldList;
				}
				else {
					logger.warn("Service: " + agsMapResource.getEndPointURL() + ", Layer Name: " +
						mapLayer.getName() + " layer fields property was null, ignoring");
				}
			}
			else {
				logger.warn("Service: " + agsMapResource.getEndPointURL() + ", Layer Name: " +
						mapLayer.getName() + " has no attribute fields, ignoring");
			}
		}
		catch (Exception e) {
			logger.log(Priority.ERROR, "EXCEPTION: Unable to get ags field list", e);
		}
		
		return null;
	}

	public List<QueryResult> doQuery(Object resource, WebQuery webQuery, FilterCriteria qbc, WebLayerInfo webLayerInfo){
		List<QueryResult> results = new ArrayList<QueryResult>();
		try{
			int lyrId = webLayerInfo.getId();
			if (!(resource instanceof AGSMapResource)) return null;
			
			AGSMapResource agsMapResource = (AGSMapResource)resource;
			AGSMapFunctionality agsMapFunc = (AGSMapFunctionality)(agsMapResource).getFunctionality("map");
			//String mapName = agsMapFunc.getMapDescription().getName();

			MapLayerInfo mapLayer = agsMapFunc.getLayerInfo(lyrId);
			Field[] flds = mapLayer.getFields().getFieldArray();

			MapServerPort mapServer = agsMapResource.getMapServer();
			SpatialFilter spatialFilter = new SpatialFilter();
			spatialFilter.setSpatialRel(EsriSpatialRelEnum.esriSpatialRelIntersects);
			spatialFilter.setWhereClause(qbc.getWhereClause());
			spatialFilter.setSearchOrder(EsriSearchOrder.esriSearchOrderSpatial);
			spatialFilter.setGeometryFieldName("");
			spatialFilter.setSpatialReferenceFieldName("");
			spatialFilter.setSpatialRelDescription("");

			spatialFilter.setFilterGeometry(AGSUtil.toAGSGeometry(qbc.getWebGeometry()));
			RecordSet recordSet = mapServer.queryFeatureData(mapServer.getDefaultMapName(), lyrId, spatialFilter);
			Record[] records = recordSet.getRecords();
			int maxRecords = qbc.getMaxRecordCount();
			int size = (maxRecords < records.length) && (maxRecords > 0) ? maxRecords : records.length;
			for (int i = 0; i < size; i++){
				Object[] objs = records[i].getValues();
				Map<String, Object> details = new LinkedHashMap<String, Object>();
				WebGeometry adfGeom = null;
				String displayName = "";
				for (int j = 0; j < flds.length; j++){
					details.put(flds[j].getName(), objs[j]);
					if (flds[j].getType() == EsriFieldType.esriFieldTypeGeometry){
						adfGeom = AGSUtil.fromAGSGeometry((Geometry)objs[j]);
					}
					if (flds[j].getType() == EsriFieldType.esriFieldTypeOID){
						Integer val = (Integer)objs[j];
						displayName = val.toString();
					}
				}
				QueryResult queryResult = new QueryResult(webLayerInfo, displayName, webQuery, details, null, adfGeom);
				results.add(queryResult);
			}
		}
		catch (Exception e){
			logger.log(Priority.ERROR, "Unable to do query", e);
		}
		return results;
	}
	
	public LinkedHashMap<String, String> getLayerName(AGSMapResource agsMapResource, MapLayerInfo mapLayer, String resourceId, int lyrId)
	{
		if(agsMapResource != null){
			
			LinkedHashMap<String, String> newLayerList = new LinkedHashMap<String, String>();	
			
			String mapSourceName = agsMapResource.getAlias();
			
			if (agsMapResource instanceof AGSLocalMapResource){
				mapSourceName = ((AGSLocalMapResource)agsMapResource).getServerObjectName();
			}
			Fields fields = mapLayer.getFields();
			
			if (mapLayer.isHasAttributes() && (fields != null)) {
				newLayerList.put(resourceId + "!" + mapLayer.getLayerID(),
						mapSourceName + "." + mapLayer.getName());
			}
			else {						
				logger.log(Priority.DEBUG, "Service: " + agsMapResource.getEndPointURL() + 
						", Layer: " + mapLayer.getName() + ", has no attributes.");
			}	
			return newLayerList;
		}	
		
		return null;
	}
	
	public LinkedHashMap<String, String> getServiceLayerList(AGSMapResource agsMapResource, String resourceId){
		try{
			LinkedHashMap<String, String> newLayerList = new LinkedHashMap<String, String>();	
			if(agsMapResource != null){
				AGSMapFunctionality agsMapFunc = (AGSMapFunctionality)(agsMapResource).getFunctionality("map");
				MapLayerInfo[] mapLayers = agsMapFunc.getLayerInfos();
				
				String mapSourceName = agsMapResource.getAlias();
				
				if (agsMapResource instanceof AGSLocalMapResource){
					mapSourceName = ((AGSLocalMapResource)agsMapResource).getServerObjectName();
				}
				for (int i = 0; i < mapLayers.length; i++){
					MapLayerInfo mapLayer = mapLayers[i];
					Fields fields = mapLayer.getFields();
					
					if (mapLayer.isHasAttributes() && (fields != null)) {
						newLayerList.put(resourceId + "!" + mapLayer.getLayerID(),
								mapSourceName + "." + mapLayer.getName());
					}
					else {						
						logger.log(Priority.DEBUG, "Service: " + agsMapResource.getEndPointURL() + 
								", Layer: " + mapLayer.getName() + ", has no attributes.");
					}					
				}
			}	
			return newLayerList;
		}
		catch(Exception e){
			logger.log(Priority.ERROR, "Unable to get service layer list", e);
		}
		return null;
	}		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -