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

The following examples show how to use com.vividsolutions.jts.geom.GeometryCollection#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: GeometryUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static IList<IShape> voronoi(final IScope scope, final IList<GamaPoint> points) {
	final IList<IShape> geoms = GamaListFactory.create(Types.GEOMETRY);
	final VoronoiDiagramBuilder dtb = new VoronoiDiagramBuilder();
	dtb.setClipEnvelope(scope.getSimulation().getEnvelope());
	dtb.setSites(points);
	final GeometryCollection g = (GeometryCollection) dtb.getDiagram(GEOMETRY_FACTORY);
	final int nb = g.getNumGeometries();
	for (int i = 0; i < nb; i++) {
		final Geometry gg = g.getGeometryN(i);
		geoms.add(new GamaShape(gg.intersection(scope.getSimulation().getInnerGeometry())));
	}
	return geoms;
}
 
Example 2
Source File: GeometryUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static IList<IShape> voronoi(final IScope scope, final IList<GamaPoint> points, final IShape clip) {
	final IList<IShape> geoms = GamaListFactory.create(Types.GEOMETRY);
	final VoronoiDiagramBuilder dtb = new VoronoiDiagramBuilder();
	dtb.setClipEnvelope(clip.getEnvelope());
	dtb.setSites(points);
	final GeometryCollection g = (GeometryCollection) dtb.getDiagram(GEOMETRY_FACTORY);
	final int nb = g.getNumGeometries();
	for (int i = 0; i < nb; i++) {
		final Geometry gg = g.getGeometryN(i);
		geoms.add(new GamaShape(gg));
	}
	return geoms;
}
 
Example 3
Source File: GeometryUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static IList<IShape> triangulation(final IScope scope, final IList<IShape> lines) {
	final IList<IShape> geoms = GamaListFactory.create(Types.GEOMETRY);
	final ConformingDelaunayTriangulationBuilder dtb = new ConformingDelaunayTriangulationBuilder();

	final Geometry points = GamaGeometryType.geometriesToGeometry(scope, lines).getInnerGeometry();
	dtb.setSites(points);
	dtb.setConstraints(points);
	final GeometryCollection tri = (GeometryCollection) dtb.getTriangles(GEOMETRY_FACTORY);
	final int nb = tri.getNumGeometries();
	for (int i = 0; i < nb; i++) {
		final Geometry gg = tri.getGeometryN(i);
		geoms.add(new GamaShape(gg));
	}
	return geoms;
}
 
Example 4
Source File: GeometryUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private static IList<IShape> filterGeoms(final GeometryCollection geom, final Geometry clip, final double sizeTol,
		final boolean approxClipping) {
	if (geom == null) { return null; }
	final double elevation = getContourCoordinates(clip).averageZ();
	final boolean setZ = elevation != 0.0;
	final IList<IShape> result = GamaListFactory.create(Types.GEOMETRY);
	final Geometry bufferClip = sizeTol != 0.0 ? clip.buffer(sizeTol, 5, 0) : clip;
	final PreparedGeometry buffered = PREPARED_GEOMETRY_FACTORY.create(bufferClip);
	final Envelope3D env = Envelope3D.of(buffered.getGeometry());
	try {
		for (int i = 0; i < geom.getNumGeometries(); i++) {
			final Geometry gg = geom.getGeometryN(i);
			if (!clip.covers(gg.getCentroid())) continue;
			final Coordinate[] coord = gg.getCoordinates();
			boolean cond = env.covers(gg.getCentroid().getCoordinate());
			cond = cond && (approxClipping
					? buffered.covers(gg.getCentroid()) && buffered.covers(GEOMETRY_FACTORY.createPoint(coord[0]))
							&& buffered.covers(GEOMETRY_FACTORY.createPoint(coord[1]))
							&& buffered.covers(GEOMETRY_FACTORY.createPoint(coord[2]))
					: bufferClip.covers(gg));
			if (cond) {
				if (setZ) {
					final ICoordinates cc = getContourCoordinates(gg);
					cc.setAllZ(elevation);
					gg.geometryChanged();
				}
				result.add(new GamaShape(gg));
			}
		}
	} finally {
		env.dispose();
	}
	/*
	 * applyToInnerGeometries(geom, (gg) -> { final ICoordinates cc = getContourCoordinates(gg); if
	 * (cc.isCoveredBy(env) && buffered.covers(gg)) {
	 *
	 * } });
	 */
	return result;
}
 
Example 5
Source File: GeometryUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static void applyToInnerGeometries(final GeometryCollection g, final GeometryFilter f) {
	final int geoms = g.getNumGeometries();
	if (geoms == 0) { return; }
	for (int i = 0; i < geoms; i++) {
		final Geometry sub = g.getGeometryN(i);
		sub.apply(f);
	}
}
 
Example 6
Source File: GMLReaderTestCase.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testPointRead() throws SAXException, IOException, ParserConfigurationException{
	Reader fr = TestFiles.getReader(TestFiles.GML_DIR + "points.xml");
	
	GMLReader gr = new GMLReader();
	Geometry g = gr.read(fr,geometryFactory);
	
	GeometryCollection gc = (GeometryCollection)g;
	assertTrue(gc.getNumGeometries() == 25);
	
	for(int i=0;i<25;i++){
		Point p = (Point) gc.getGeometryN(i);
		assertNotNull(p);
	}
}
 
Example 7
Source File: GMLReaderTestCase.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testLineStringRead() throws SAXException, IOException, ParserConfigurationException{
	Reader fr = TestFiles.getReader(TestFiles.GML_DIR + "linestrings.xml");
	
	GMLReader gr = new GMLReader();
	Geometry g = gr.read(fr,geometryFactory);
	
	GeometryCollection gc = (GeometryCollection)g;
	assertTrue(gc.getNumGeometries() == 25);
	
	for(int i=0;i<25;i++){
		LineString ls = (LineString) gc.getGeometryN(i);
		assertNotNull(ls);
	}
}
 
Example 8
Source File: GMLReaderTestCase.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testPolygonRead() throws SAXException, IOException, ParserConfigurationException{
	Reader fr = TestFiles.getReader(TestFiles.GML_DIR + "polygons.xml");
	
	GMLReader gr = new GMLReader();
	Geometry g = gr.read(fr,geometryFactory);
	
	GeometryCollection gc = (GeometryCollection)g;
	assertTrue(gc.getNumGeometries() == 25);
	
	for(int i=0;i<25;i++){
		Polygon p = (Polygon) gc.getGeometryN(i);
		assertNotNull(p);
	}
}
 
Example 9
Source File: GMLReaderTestCase.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testMultiPointRead() throws SAXException, IOException, ParserConfigurationException{
	Reader fr = TestFiles.getReader(TestFiles.GML_DIR + "multipoints.xml");
	
	GMLReader gr = new GMLReader();
	Geometry g = gr.read(fr,geometryFactory);
	
	GeometryCollection gc = (GeometryCollection)g;
	assertTrue(gc.getNumGeometries() == 25);
	
	for(int i=0;i<25;i++){
		MultiPoint p = (MultiPoint) gc.getGeometryN(i);
		assertNotNull(p);
	}
}
 
Example 10
Source File: GMLReaderTestCase.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testMultiLineStringRead() throws SAXException, IOException, ParserConfigurationException{
	Reader fr = TestFiles.getReader(TestFiles.GML_DIR + "multilinestrings.xml");
	
	GMLReader gr = new GMLReader();
	Geometry g = gr.read(fr,geometryFactory);
	
	GeometryCollection gc = (GeometryCollection)g;
	assertTrue(gc.getNumGeometries() == 25);
	
	for(int i=0;i<25;i++){
		MultiLineString ls = (MultiLineString) gc.getGeometryN(i);
		assertNotNull(ls);
	}
}
 
Example 11
Source File: GMLReaderTestCase.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testMultiPolygonRead() throws SAXException, IOException, ParserConfigurationException{
	Reader fr = TestFiles.getReader(TestFiles.GML_DIR + "multipolygons.xml");
	
	GMLReader gr = new GMLReader();
	Geometry g = gr.read(fr,geometryFactory);
	
	GeometryCollection gc = (GeometryCollection)g;
	assertTrue(gc.getNumGeometries() == 25);
	
	for(int i=0;i<25;i++){
		MultiPolygon p = (MultiPolygon) gc.getGeometryN(i);
		assertNotNull(p);
	}
}
 
Example 12
Source File: ValidClosedRingTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testBadGeometryCollection()
{
  GeometryCollection gc = (GeometryCollection) fromWKT("GEOMETRYCOLLECTION ( POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (1 1, 2 1, 2 2, 1 2, 1 1) )), POINT(0 0) )");
  Polygon poly = (Polygon) gc.getGeometryN(0);
  updateNonClosedRing((LinearRing) poly.getInteriorRingN(0));
  checkIsValid(poly, false);
}
 
Example 13
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;
}