Java Code Examples for com.vividsolutions.jts.geom.MultiPolygon#getGeometryN()

The following examples show how to use com.vividsolutions.jts.geom.MultiPolygon#getGeometryN() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiPolygonWriter.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Writes the body for a <code>MultiPolygon</code> object. MultiPolygons are
 * encoded into SVG path elements. This function writes the different
 * polygons in one d-attribute of an SVG path element, separated by an 'M'
 * character. (in other words, it calls the super.writeBody for each
 * polygon).
 *
 * @param o The <code>MultiPolygon</code> to be encoded.
 */
public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException {
	document.writeElement("vml:shape", asChild);
	document.writeAttribute("fill-rule", "evenodd");
	document.writeAttributeStart("path");
	MultiPolygon mpoly = (MultiPolygon) o;
	for (int i = 0; i < mpoly.getNumGeometries(); i++) {
		Polygon poly = (Polygon) mpoly.getGeometryN(i);
		LineString shell = poly.getExteriorRing();
		int nHoles = poly.getNumInteriorRing();
		document.writeClosedPathContent(shell.getCoordinates());

		for (int j = 0; j < nHoles; j++) {
			document.writeClosedPathContent(poly.getInteriorRingN(j).getCoordinates());
		}
	}
	document.writeAttributeEnd();
}
 
Example 2
Source File: MultiPolygonWriter.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Writes the body for a <code>MultiPolygon</code> object. MultiPolygons are
 * encoded into SVG path elements. This function writes the different
 * polygons in one d-attribute of an SVG path element, separated by an 'M'
 * character. (in other words, it calls the super.writeBody for each
 * polygon).
 *
 * @param o The <code>MultiPolygon</code> to be encoded.
 */
public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException {
	document.writeElement("path", asChild);
	document.writeAttribute("fill-rule", "evenodd");
	document.writeAttributeStart("d");
	MultiPolygon mpoly = (MultiPolygon) o;
	for (int i = 0; i < mpoly.getNumGeometries(); i++) {
		Polygon poly = (Polygon) mpoly.getGeometryN(i);
		LineString shell = poly.getExteriorRing();
		int nHoles = poly.getNumInteriorRing();
		document.writeClosedPathContent(shell.getCoordinates());

		for (int j = 0; j < nHoles; j++) {
			document.writeClosedPathContent(poly.getInteriorRingN(j).getCoordinates());
		}
	}
	document.writeAttributeEnd();
}
 
Example 3
Source File: GeometryConverterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void dtoMultiPolygonToJts() throws GeomajasException {
	// Test DTO MultiPolygon to JTS:
	MultiPolygon multiPolygon = (MultiPolygon) converter.toInternal(createDtoMultiPolygon());
	Polygon polygon = (Polygon) multiPolygon.getGeometryN(1);
	Assert.assertEquals(dtoC6.getX(), polygon.getInteriorRingN(0).getCoordinateN(1).x);
}
 
Example 4
Source File: TopologicalOverlay.java    From geowe-core with GNU General Public License v3.0 4 votes vote down vote up
public List<String> getOverlay(final Geometry layer1,
		final Geometry layer2, final int op) {
	final List<String> resultLayer = new ArrayList<String>();
	Geometry geomContorno = null;

	switch (op) {
	case OverlayOp.INTERSECTION:
		geomContorno = EnhancedPrecisionOp.intersection(
				layer1.buffer(TOLERANCIA), layer2.buffer(TOLERANCIA));
		break;
	case OverlayOp.DIFFERENCE:
		geomContorno = EnhancedPrecisionOp.difference(
				layer1.buffer(TOLERANCIA), layer2.buffer(TOLERANCIA));
		break;
	case OverlayOp.SYMDIFFERENCE:
		geomContorno = EnhancedPrecisionOp.symDifference(
				layer1.buffer(TOLERANCIA), layer2.buffer(TOLERANCIA));
		break;
	default:
		break;
	}

	if (geomContorno != null) {

		if (geomContorno instanceof Polygon) {
			resultLayer.add(geomContorno.toText());
		} else if (geomContorno instanceof MultiPolygon) {

			final MultiPolygon multiPolygon = (MultiPolygon) geomContorno;
			for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
				final Polygon pol = (Polygon) multiPolygon.getGeometryN(i);
				resultLayer.add(pol.toText());
			}
		} else if (geomContorno instanceof GeometryCollection) {

			final GeometryCollection gc = (GeometryCollection) geomContorno;
			for (int i = 0; i < gc.getNumGeometries(); i++) {
				final Geometry geom = gc.getGeometryN(i);
				resultLayer.add(geom.toText());
			}
		}
	}

	return resultLayer;
}