webpolygonconverter.java

来自「esri的ArcGIS Server超级学习模板程序(for java)」· Java 代码 · 共 69 行

JAVA
69
字号
package com.esri.solutions.jitk.data.gml;

import java.util.Collections;
import java.util.List;

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

import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.geometry.WebGeometry;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebPolygon;
import com.esri.adf.web.data.geometry.WebRing;
import com.esri.solutions.jitk.common.geometry.WebRingInspector;
import com.esri.solutions.jitk.datasources.ogc.gml.GMLLinearRing;
import com.esri.solutions.jitk.datasources.ogc.gml.GMLPolygon;
import com.esri.solutions.jitk.datasources.ogc.gml.IGMLGeometry;

public class WebPolygonConverter implements IWebGeometryConverter {
	private static final Logger _logger = LogManager.getLogger(WebPolygonConverter.class);
	protected WebContext _wContext = null;
	
	public WebPolygonConverter(WebContext wContext) {
		_wContext = wContext;
	}
	
	public IGMLGeometry toGMLGeometry(WebGeometry geometry) {
		WebPolygon polygon = (WebPolygon) geometry;
		GMLPolygon gmlPoly = new GMLPolygon();
		StringBuilder ringPath = new StringBuilder();
		WebRingInspector inspector = null;
		
		for (WebRing ring : polygon.getRings()) {
			GMLLinearRing lr = new GMLLinearRing();
			
			
			try {
				List<WebPoint> vertices = ring.getPoints();				
				WebRing screenCoordRing = ring.fromMapGeometry(_wContext.getWebMap());
				inspector = new WebRingInspector(screenCoordRing);
				
				//GML Polygons sent to ArcGIS Server require outer rings to have a
				//clockwise orientation. Since the web ADF does not distinguish between
				//outer and inner rings, the orientation of all counter clockwise rings 
				//are reversed.
				if (!inspector.isClockwise()) {
					Collections.reverse(vertices);
				}
			} catch (Exception ex) {
				_logger.warn("Clockwise orientation of ring could not be determined, orientation left unchanged");
			}
			
			for (WebPoint point : ring.getPoints()) {
				if (ringPath.length() > 0) {
					ringPath.append(" ");
				}
				
				ringPath.append(String.valueOf(point.getY()));
				ringPath.append(" ");
				ringPath.append(String.valueOf(point.getX()));
			}
			
			lr.setPostList(ringPath.toString());
			gmlPoly.addRing(lr);
		}
		
		return gmlPoly;
	}
}

⌨️ 快捷键说明

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