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

📄 wfsgetcapabilitiesadapter.java

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

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebSpatialReference;
import com.esri.solutions.jitk.datasources.ogc.gml.GMLPoint;
import com.esri.solutions.jitk.datasources.ogc.wfs.WFSCapabilities;

public class WFSGetCapabilitiesAdapter {
	private static final Logger _logger = LogManager.getLogger(WFSGetCapabilitiesAdapter.class);
	protected WFSCapabilities _cap = null;
	
	public WFSGetCapabilitiesAdapter(WFSCapabilities cap) {
		_cap = cap;
	}
	
	protected boolean isValidGMLPoint(GMLPoint point) {
		boolean isValid = true;
		double x = 0;
		double y = 0;
		
		try {
			x = Double.parseDouble(point.getX());
			y = Double.parseDouble(point.getY());
		} catch (Exception ex) {
			isValid = false;
		}
		
		if (Double.isInfinite(x) || Double.isNaN(x)) {
			isValid = false;
		}
		
		if (Double.isInfinite(y) || Double.isNaN(y)) {
			isValid = false;
		}		
		
		return isValid;
	}
	
	/**
	 * Returns full extent of the service. The full extent is calculated by returning the extent
	 * of the first service in the GetCapabilities response with an extent that has valid doubles.
	 * @param desireWsr The desired spatial reference to return the extent in
	 * @return Full extent of service
	 */
	public WebExtent getServiceFullExtent(WebSpatialReference desireWsr) {
		WebExtent extWGS1984 = new WebExtent();
		WebExtent extWfsCs = null; 
		
		try {
			// Build spatial reference from .... WGS1984
			WebSpatialReference wsr = WebSpatialReference.getWebSpatialReference(4326);
			extWGS1984.setSpatialReference(wsr);
	
			if (_cap.getFeatureTypes().size() > 0) {
				int size = _cap.getFeatureTypes().size();
				boolean validLayerExtentFound = false;
				
				for (int index = 0; index < size; index++) {
					GMLPoint lower = _cap.getFeatureTypes().get(index).getLowerCorner();
					GMLPoint upper = _cap.getFeatureTypes().get(index).getUpperCorner();
					
					if (isValidGMLPoint(lower) && isValidGMLPoint(upper)) {					
						extWGS1984.setMaxX(Double.parseDouble(upper.getX()));
						extWGS1984.setMaxY(Double.parseDouble(upper.getY()));
						extWGS1984.setMinX(Double.parseDouble(lower.getX()));
						extWGS1984.setMinY(Double.parseDouble(lower.getY()));	
						validLayerExtentFound = true;
						break;
					} else {
						_logger.warn("Invalid extent encountered for WFS feature type, moving to next feature type");
					}
				}
				
				if (validLayerExtentFound) {
					extWfsCs = extWGS1984.project(desireWsr);
					_logger.debug("WFS Extent Used:" + extWfsCs);
				} else {
					_logger.error("Service extent could not be read from WFS GetCapabilities data");
					extWfsCs = null;					
				}
			}
		} catch (Exception ex) {
			_logger.error("Service extent could not be read from WFS GetCapabilities data", ex);
			extWfsCs = null;
		}
		
		return extWfsCs;
	}	
	
	/**
	 * Returns the default spatial reference of the WFS, calculated by returning 
	 * the default spatial reference of the 1st feature type in the service.
	 * @return Default spatial reference of the service.
	 */
	public WebSpatialReference getDefaultSpatialReference() {
		WebSpatialReference wsr = null;
		String srsCode = null;
		
		// Default SRS of first layer matches that of all other layers
		if (_cap.getFeatureTypes().size() > 0) {
			srsCode = _cap.getFeatureTypes().get(0).getDefaultSrs().getCode();
			_logger.debug("SRS Code for Service is " + srsCode);
		} else {
			_logger.warn("SRS Code could not be retrieved from Service");
		}		
		
		if (srsCode != null) {
			try {
				wsr = WebSpatialReference.getWebSpatialReference(Integer.parseInt(srsCode));
			} catch (Exception ex) {
				_logger.error("Could not convert SRS Code " + srsCode + " to WebSpatialReference", ex);
				_logger.error("Defereing to super.getDefaultSpatialReference()");
			}
		}
		
		return wsr;		
	}	
}

⌨️ 快捷键说明

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