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

📄 pointbuffertaskutil.java

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

import java.util.Iterator;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebGeometry;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebPolyline;
import com.esri.adf.web.data.geometry.WebPolygon;
import com.esri.adf.web.data.geometry.WebPath;
import com.esri.adf.web.data.geometry.WebRing;
import com.esri.adf.web.data.symbol.WebSimpleMarkerSymbol;
import com.esri.adf.web.data.symbol.WebSimpleLineSymbol;
import com.esri.adf.web.data.symbol.WebSimplePolygonSymbol;
import com.esri.adf.web.data.GraphicElement;
import org.apache.log4j.Logger;

/**
 * This utility class creates buffer geometry. 
 */
public class PointBufferTaskUtil {
	private static Logger _logger = Logger.getLogger(PointBufferTaskUtil.class.getName());
	private static final int SHAPE_WIDTH = 3;
	private static final String COLOR = "255,0,0";

	@SuppressWarnings("deprecation")
	public static GraphicElement setSymbol(WebGeometry webGeom, String color) {
		if (color == null) {
			color = COLOR;
		}
		
		try {
			if (webGeom instanceof WebPoint) {
				WebSimpleMarkerSymbol pSymbol = new WebSimpleMarkerSymbol();
				pSymbol.setColor(color);
				pSymbol.setMarkerType(WebSimpleMarkerSymbol.CIRCLE);
				pSymbol.setWidth(SHAPE_WIDTH * SHAPE_WIDTH);

				GraphicElement graphicElem = new GraphicElement();
				graphicElem.setGeometry(webGeom);
				graphicElem.setSymbol(pSymbol);
				
				return graphicElem;
			}
			
			if (webGeom instanceof WebPolyline) {
				WebSimpleLineSymbol pSymbol = new WebSimpleLineSymbol();
				pSymbol.setColor(color);
				pSymbol.setJoinType(WebSimpleLineSymbol.MITER);
				pSymbol.setLineType(WebSimpleLineSymbol.SOLID);
				pSymbol.setWidth(SHAPE_WIDTH);
				GraphicElement graphicElem = new GraphicElement();
				graphicElem.setGeometry(graphicElem.getGeometry());
				graphicElem.setSymbol(pSymbol);
				
				return graphicElem;
			}
			
			if (webGeom instanceof WebPolygon) {
				WebSimplePolygonSymbol pSymbol = new WebSimplePolygonSymbol();
				pSymbol.setFillColor(color);
				pSymbol.setBoundaryColor(color);
				pSymbol.setBoundaryWidth(SHAPE_WIDTH);
				GraphicElement graphicElem = new GraphicElement();
				graphicElem.setGeometry(graphicElem.getGeometry());
				graphicElem.setSymbol(pSymbol);
				
				return graphicElem;
			}
		}
		catch (Exception e) {
			_logger.error("Unable to set symbol", e);
		}
		
		return null;
	}

	private static WebExtent getPointEnvelope(WebGeometry webGeom) {
		try {
			WebPoint webPoint = (WebPoint)webGeom;
			
			return new WebExtent(webPoint.getX(), webPoint.getY(), webPoint.getX(), webPoint.getY());
		}
		catch(Exception e) {
			_logger.error("Unable to get point envelope", e);
		}
		
		return null;
	}

	@SuppressWarnings("unchecked")
	private static WebExtent getLineEnvelope(WebGeometry webGeom) {
		try {
			WebPolyline webLine = (WebPolyline)webGeom;
			Iterator rit = webLine.getPaths().iterator();
			WebExtent webExt = new WebExtent() ;
			boolean firstElm = false;
			
			while (rit.hasNext()) {
				WebPath path = (WebPath)rit.next();
				Iterator pit = path.getPoints().iterator();
				
				while (pit.hasNext()) {
					WebPoint webPoint = (WebPoint)pit.next();
					
					if (!firstElm) {
						webExt.setMinX(webPoint.getX());
						webExt.setMaxX(webPoint.getX());
						webExt.setMinY(webPoint.getY());
						webExt.setMaxY(webPoint.getY());
						firstElm = true;
					}
					
					if (webPoint.getX() < webExt.getMinX()) webExt.setMinX(webPoint.getX());
					if (webPoint.getX() > webExt.getMaxX()) webExt.setMaxX(webPoint.getX());
					if (webPoint.getY() < webExt.getMinY()) webExt.setMinY(webPoint.getY());
					if (webPoint.getY() > webExt.getMaxY()) webExt.setMaxY(webPoint.getY());
				}
			}
			
			return webExt;
		}
		catch(Exception e) {
			_logger.error("Unable to get line envelope", e);
		}
		
		return null;
	}

	@SuppressWarnings("unchecked")
	private static WebExtent getPolyEnvelope(WebGeometry webGeom) {
		try {
			WebPolygon webPoly = (WebPolygon)webGeom;
			Iterator rit = webPoly.getRings().iterator();
			WebExtent webExt = new WebExtent();
			boolean firstElm = false;
			
			while (rit.hasNext()) {
				WebRing ring = (WebRing)rit.next();
				Iterator pit = ring.getPoints().iterator();
				
				while (pit.hasNext()) {
					WebPoint webPoint = (WebPoint)pit.next();
					
					if (!firstElm) {
						webExt.setMinX(webPoint.getX());
						webExt.setMaxX(webPoint.getX());
						webExt.setMinY(webPoint.getY());
						webExt.setMaxY(webPoint.getY());
						firstElm = true;
					}
					
					if (webPoint.getX() < webExt.getMinX()) webExt.setMinX(webPoint.getX());
					if (webPoint.getX() > webExt.getMaxX()) webExt.setMaxX(webPoint.getX());
					if (webPoint.getY() < webExt.getMinY()) webExt.setMinY(webPoint.getY());
					if (webPoint.getY() > webExt.getMaxY()) webExt.setMaxY(webPoint.getY());
				}
			}
			
			return webExt;
		}
		catch(Exception e) {
			_logger.error("Unable to get polygon envelope", e);
		}
		
		return null;
	}

	public static WebExtent getGeometryEnvelope(WebGeometry webGeom) {
		try {
			if (webGeom instanceof WebPoint) return getPointEnvelope(webGeom);
			if (webGeom instanceof WebPolyline) return getLineEnvelope(webGeom);
			if (webGeom instanceof WebPolygon) return getPolyEnvelope(webGeom);
		}
		catch(Exception e) {
			_logger.error("Unable to get geometry envelope", e);
		}
		
		return null;
	}	
}

⌨️ 快捷键说明

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