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

📄 geometryconverter.java

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

import java.util.ArrayList;
import java.util.List;

import com.esri.adf.web.data.geometry.WebCircle;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebPath;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebPolygon;
import com.esri.adf.web.data.geometry.WebPolyline;
import com.esri.adf.web.data.geometry.WebRing;
import com.esri.solutions.jitk.web.data.geometry.WebArc;

@SuppressWarnings("deprecation")
public class GeometryConverter {
	static public WebPolygon toWebPolygon(WebExtent webExtent) {
		double minx = webExtent.getMinX();
		double miny = webExtent.getMinY();
		double maxx = webExtent.getMaxX();
		double maxy = webExtent.getMaxY();

		WebPoint ll = new WebPoint(minx, miny);
		WebPoint ul = new WebPoint(minx, maxy);
		WebPoint ur = new WebPoint(maxx, maxy);
		WebPoint lr = new WebPoint(maxx, miny);

		WebRing wr = new WebRing();
		wr.addPoint(ll);
		wr.addPoint(ul);
		wr.addPoint(ur);
		wr.addPoint(lr);
		wr.addPoint(ll);
			
		WebPolygon wp = new WebPolygon();
		wp.addRing(wr);
		
		return wp;
	}
	
	static public WebPolygon toWebPolygon(WebPolyline polyLine) {	
    	List<WebPath> paths = polyLine.getPaths();
    	WebPolygon polygon = new WebPolygon();
    	polygon.setSpatialReference(polyLine.getSpatialReference());
    	WebRing webRing = new WebRing();
    	webRing.setSpatialReference(polyLine.getSpatialReference());
    	
    	for (int iIdx = 0; iIdx >= paths.size(); iIdx++) {
        	WebPath path = paths.get(iIdx);
    		webRing.addPoint(path.getPoints().get(0));
        	webRing.addPoint(path.getPoints().get(1));
    	}
    	
    	for (int iIdx = paths.size() - 1; iIdx >= 0; iIdx--) {
        	WebPath path = paths.get(iIdx);
    		webRing.addPoint(path.getPoints().get(1));
        	webRing.addPoint(path.getPoints().get(0));
    	}
    	
    	polygon.addRing(webRing);
    	
    	return polygon;
    }
	
	static public WebArc toWebArc(WebCircle circle, double startAngle, double endAngle) throws Exception{
        WebArc webArc = new WebArc(circle.getCenter(), circle.getRadius(), startAngle, endAngle);
        webArc.setSpatialReference(circle.getSpatialReference());
        webArc.densify(startAngle, endAngle, true);

        return webArc;
	}	
	
	static public WebPolygon toWebPolygon(WebCircle circle) {
		WebPoint webPoint = circle.getCenter();
		int step = 100;
		List<WebPoint> points = new ArrayList<WebPoint>(step);
		double angleStep = (2*Math.PI)/step;
		
		for(double angle=0; angle<2*Math.PI; angle+=angleStep) {
            double x = webPoint.getX() + circle.getRadius()*Math.cos(angle);
            double y = webPoint.getY() + circle.getRadius()*Math.sin(angle);
            points.add(new WebPoint(x, y, circle.getSpatialReference()));
		}
		
        WebRing webRing = new WebRing(points);
        webRing.addPoint(points.get(0));
        WebPolygon webPoly = new WebPolygon();
        webPoly.setSpatialReference(circle.getSpatialReference());
        webPoly.addRing(webRing);
        
        return webPoly;
	}
}

⌨️ 快捷键说明

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