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

The following examples show how to use com.vividsolutions.jts.geom.MultiPolygon#getNumGeometries() . 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: GamaShape.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public GamaShape getExteriorRing(final IScope scope) {

	// WARNING Only in 2D
	Geometry result = getInnerGeometry();
	if (result instanceof Polygon) {
		result = ((Polygon) result).getExteriorRing();
	} else

	if (result instanceof MultiPolygon) {
		final MultiPolygon mp = (MultiPolygon) result;
		final LineString lines[] = new LineString[mp.getNumGeometries()];
		for (int i = 0; i < mp.getNumGeometries(); i++) {
			lines[i] = ((Polygon) mp.getGeometryN(i)).getExteriorRing();
		}
		result = GEOMETRY_FACTORY.createMultiLineString(lines);

	}
	return new GamaShape(result);
}
 
Example 2
Source File: WKTWriter.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 *  Converts a <code>MultiPolygon</code> to &lt;MultiPolygon Text&gt; format,
 *  then appends it to the writer.
 *
 *@param  multiPolygon  the <code>MultiPolygon</code> to process
 *@param  writer        the output writer to append to
 */
private void appendMultiPolygonText(MultiPolygon multiPolygon, int level, Writer writer)
  throws IOException
{
  if (multiPolygon.isEmpty()) {
    writer.write("EMPTY");
  }
  else {
    int level2 = level;
    boolean doIndent = false;
    writer.write("(");
    for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
      if (i > 0) {
        writer.write(", ");
        level2 = level + 1;
        doIndent = true;
      }
      appendPolygonText((Polygon) multiPolygon.getGeometryN(i), level2, doIndent, writer);
    }
    writer.write(")");
  }
}
 
Example 3
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 4
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 5
Source File: JTSHelper.java    From xyz-hub with Apache License 2.0 5 votes vote down vote up
/**
 * Create MultiPolygon coordinates.
 */
public static MultiPolygonCoordinates createMultiPolygonCoordinates(MultiPolygon geom) {
  if (geom == null) {
    return null;
  }

  int len = geom.getNumGeometries();
  MultiPolygonCoordinates multiPolygonCoordinates = new MultiPolygonCoordinates(len);

  for (int i = 0; i < len; i++) {
    multiPolygonCoordinates.add(createPolygonCoordinates((Polygon) geom.getGeometryN(i)));
  }

  return multiPolygonCoordinates;
}
 
Example 6
Source File: GamaKmlExport.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public void addMultiPolygon(final Placemark pm, final MultiPolygon mpoly, final double height) {
	final int ng = mpoly.getNumGeometries();
	final MultiGeometry mg = pm.createAndSetMultiGeometry();
	for (int gx = 0; gx < ng; gx++) {
		final de.micromata.opengis.kml.v_2_2_0.Polygon kmlpoly = mg.createAndAddPolygon();
		fillPolygon(kmlpoly, (Polygon) mpoly.getGeometryN(gx), height);
	}
}
 
Example 7
Source File: PdfContext.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void drawGeometry(Geometry g, SymbolInfo symbol) {
	if (g instanceof MultiPolygon) {
		MultiPolygon mpoly = (MultiPolygon) g;
		for (int i = 0; i < mpoly.getNumGeometries(); i++) {
			drawGeometry(mpoly.getGeometryN(i), symbol);
		}
	} else if (g instanceof MultiLineString) {
		MultiLineString mline = (MultiLineString) g;
		for (int i = 0; i < mline.getNumGeometries(); i++) {
			drawGeometry(mline.getGeometryN(i), symbol);
		}
	} else if (g instanceof MultiPoint) {
		MultiPoint mpoint = (MultiPoint) g;
		for (int i = 0; i < mpoint.getNumGeometries(); i++) {
			drawGeometry(mpoint.getGeometryN(i), symbol);
		}
	} else if (g instanceof Polygon) {
		Polygon poly = (Polygon) g;
		LineString shell = poly.getExteriorRing();
		int nHoles = poly.getNumInteriorRing();
		drawPathContent(shell.getCoordinates());
		for (int j = 0; j < nHoles; j++) {
			drawPathContent(poly.getInteriorRingN(j).getCoordinates());
		}
		template.closePathEoFillStroke();
	} else if (g instanceof LineString) {
		LineString line = (LineString) g;
		drawPathContent(line.getCoordinates());
		template.stroke();
	} else if (g instanceof Point) {
		Point point = (Point) g;
		drawPoint(point.getCoordinate(), symbol);
		template.fillStroke();
	}
}
 
Example 8
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;
}