Java Code Examples for com.vividsolutions.jts.geom.GeometryCollection

The following examples show how to use com.vividsolutions.jts.geom.GeometryCollection. These examples are extracted from open source projects. 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 Project: xyz-hub   Author: heremaps   File: JTSHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static GeometryCollection toGeometryCollection(com.here.xyz.models.geojson.implementation.GeometryCollection geometryCollection) {
  if (geometryCollection == null) {
    return null;
  }

  List<GeometryItem> geometries = geometryCollection.getGeometries();
  int len = geometries.size();
  Geometry[] jtsGeometries = new Geometry[len];

  for (int i = 0; i < len; i++) {
    jtsGeometries[i] = toGeometry(geometries.get(i));
  }

  return new GeometryCollection(jtsGeometries, factory);

}
 
Example #2
Source Project: xyz-hub   Author: heremaps   File: JTSHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static com.here.xyz.models.geojson.implementation.GeometryCollection fromGeometryCollection(
    GeometryCollection jtsGeometryCollection) {
  if (jtsGeometryCollection == null) {
    return null;
  }

  com.here.xyz.models.geojson.implementation.GeometryCollection geometryCollection = new com.here.xyz.models.geojson.implementation.GeometryCollection();

  int len = jtsGeometryCollection.getNumGeometries();
  List<com.here.xyz.models.geojson.implementation.GeometryItem> geometries = new ArrayList<>();

  for (int i = 0; i < len; i++) {
    geometries.add(fromGeometry(jtsGeometryCollection.getGeometryN(i)));
  }

  return geometryCollection.withGeometries(geometries);
}
 
Example #3
Source Project: gama   Author: gama-platform   File: GamaShape.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setInnerGeometry(final Geometry geom) {
	if (geom == null) {
		geometry = null;
		return;
	}
	if (geom.isEmpty()) {
		// See Issue 725
		return;
	}
	if (geom instanceof GeometryCollection && geom.getNumGeometries() == 1) {
		geometry = geom.getGeometryN(0);
	} else {
		geometry = geom;
	}
}
 
Example #4
Source Project: gama   Author: gama-platform   File: Projection.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public Geometry transform(final Geometry g) {
	// Remove uselessly complicated multigeometries
	if (g instanceof GeometryCollection && g.getNumGeometries() == 1) { return transform(g.getGeometryN(0)); }
	Geometry geom = GeometryUtils.GEOMETRY_FACTORY.createGeometry(g);
	if (transformer != null) {
		try {
			geom = transformer.transform(geom);
		} catch (final TransformException e) {
			e.printStackTrace();
		}
	}
	translate(geom);
	convertUnit(geom);
	return geom;
}
 
Example #5
Source Project: jts   Author: metteo   File: KMLWriter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private void writeGeometry(Geometry g, int level, StringBuffer buf) {
  String attributes = "";
  if (g instanceof Point) {
    writePoint((Point) g, attributes, level, buf);
  } else if (g instanceof LinearRing) {
    writeLinearRing((LinearRing) g, attributes, true, level, buf);
  } else if (g instanceof LineString) {
    writeLineString((LineString) g, attributes, level, buf);
  } else if (g instanceof Polygon) {
    writePolygon((Polygon) g, attributes, level, buf);
  } else if (g instanceof GeometryCollection) {
    writeGeometryCollection((GeometryCollection) g, attributes, level, buf);
  }
  else 
    throw new IllegalArgumentException("Geometry type not supported: " + g.getGeometryType());
}
 
Example #6
Source Project: jts   Author: metteo   File: LayerRenderer.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private void renderGeometryCollection(Graphics2D g, Viewport viewport, 
    GeometryCollection gc,
    Style style
    ) 
throws Exception
{
  /**
   * Render each element separately.
   * Otherwise it is not possible to render both filled and non-filled
   * (1D) elements correctly.
   * This also allows cancellation.
   */
  for (int i = 0; i < gc.getNumGeometries(); i++) {
  	render(g, viewport, gc.getGeometryN(i), style);
    if (isCancelled) return;
  }
}
 
Example #7
Source Project: jts   Author: metteo   File: GeometryPainter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void paint(Graphics2D g, Viewport viewport, Geometry geometry, Style style)
throws Exception
{
  if (geometry == null)
    return;

  // cull non-visible geometries
  if (! viewport.intersectsInModel(geometry.getEnvelopeInternal())) 
    return;

  if (geometry instanceof GeometryCollection) {
    GeometryCollection gc = (GeometryCollection) geometry;
    /**
     * Render each element separately.
     * Otherwise it is not possible to render both filled and non-filled
     * (1D) elements correctly
     */
    for (int i = 0; i < gc.getNumGeometries(); i++) {
      paint(g, viewport, gc.getGeometryN(i), style);
    }
    return;
  }
  
  style.paint(geometry, viewport, g);
}
 
Example #8
Source Project: jts   Author: metteo   File: OraGeom.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the GTYPE GEOM_TYPE code
 * corresponding to the geometry type.
 * 
 * @see OraGeom.GEOM_TYPE
 *
 * @param geom the geometry to compute the GEOM_TYPE for
 * @return geom type code, if known, or UNKNOWN
 */
static int geomType(Geometry geom) {
  if (geom == null) {
      return OraGeom.GEOM_TYPE.UNKNOWN_GEOMETRY; 
  } else if (geom instanceof Point) {
      return OraGeom.GEOM_TYPE.POINT;
  } else if (geom instanceof LineString) {
      return OraGeom.GEOM_TYPE.LINE;
  } else if (geom instanceof Polygon) {
      return OraGeom.GEOM_TYPE.POLYGON;
  } else if (geom instanceof MultiPoint) {
      return OraGeom.GEOM_TYPE.MULTIPOINT;
  } else if (geom instanceof MultiLineString) {
      return OraGeom.GEOM_TYPE.MULTILINE;
  } else if (geom instanceof MultiPolygon) {
      return OraGeom.GEOM_TYPE.MULTIPOLYGON;
  } else if (geom instanceof GeometryCollection) {
      return OraGeom.GEOM_TYPE.COLLECTION;
  }
  return OraGeom.GEOM_TYPE.UNKNOWN_GEOMETRY; 
}
 
Example #9
Source Project: jts   Author: metteo   File: ShapefileHeader.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public ShapefileHeader(GeometryCollection geometries,int dims) throws Exception
{
    ShapeHandler handle;
    if (geometries.getNumGeometries() == 0)
    {
        handle = new PointHandler(); //default
    }
    else
    {
           handle = Shapefile.getShapeHandler(geometries.getGeometryN(0),dims);
    }
    int numShapes = geometries.getNumGeometries();
    shapeType = handle.getShapeType();
    version = Shapefile.VERSION;
    fileCode = Shapefile.SHAPEFILE_ID;
    bounds = geometries.getEnvelopeInternal();
    fileLength = 0;
    for(int i=0;i<numShapes;i++){
        fileLength+=handle.getLength(geometries.getGeometryN(i));
        fileLength+=4;//for each header
    }
    fileLength+=50;//space used by this, the main header
    indexLength = 50+(4*numShapes);
}
 
Example #10
Source Project: jts   Author: metteo   File: Distance3DOp.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private void computeMinDistanceMultiMulti(Geometry g0, Geometry g1, boolean flip) {
	if (g0 instanceof GeometryCollection) {
		int n = g0.getNumGeometries();
		for (int i = 0; i < n; i++) {
			Geometry g = g0.getGeometryN(i);
			computeMinDistanceMultiMulti(g, g1, flip);
			if (isDone)	return;
		}
	}
	else {
		// handle case of multigeom component being empty
		if (g0.isEmpty())
			return;
		
		// compute planar polygon only once for efficiency
		if (g0 instanceof Polygon) {
			computeMinDistanceOneMulti(polyPlane(g0), g1, flip);
		}
		else 
			computeMinDistanceOneMulti(g0, g1, flip);
	}
}
 
Example #11
Source Project: jts   Author: metteo   File: Distance3DOp.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
private void computeMinDistanceOneMulti(PlanarPolygon3D poly, Geometry geom, boolean flip) {
	if (geom instanceof GeometryCollection) {
		int n = geom.getNumGeometries();
		for (int i = 0; i < n; i++) {
			Geometry g = geom.getGeometryN(i);
			computeMinDistanceOneMulti(poly, g, flip);
			if (isDone)	return;
		}
	}
	else {
		if (geom instanceof Point) {
			computeMinDistancePolygonPoint(poly, (Point) geom, flip);
			return;
		}
		if (geom instanceof LineString) {
			computeMinDistancePolygonLine(poly, (LineString) geom, flip);
			return;
		}
		if (geom instanceof Polygon) {
			computeMinDistancePolygonPolygon(poly, (Polygon) geom, flip);
			return;
		}
	}
}
 
Example #12
Source Project: jts   Author: metteo   File: WKBWriter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Writes a {@link Geometry} to an {@link OutStream}.
 *
 * @param geom the geometry to write
 * @param os the out stream to write to
 * @throws IOException if an I/O error occurs
 */
public void write(Geometry geom, OutStream os) throws IOException
{
  if (geom instanceof Point)
    writePoint((Point) geom, os);
  // LinearRings will be written as LineStrings
  else if (geom instanceof LineString)
    writeLineString((LineString) geom, os);
  else if (geom instanceof Polygon)
    writePolygon((Polygon) geom, os);
  else if (geom instanceof MultiPoint)
    writeGeometryCollection(WKBConstants.wkbMultiPoint, 
        (MultiPoint) geom, os);
  else if (geom instanceof MultiLineString)
    writeGeometryCollection(WKBConstants.wkbMultiLineString,
        (MultiLineString) geom, os);
  else if (geom instanceof MultiPolygon)
    writeGeometryCollection(WKBConstants.wkbMultiPolygon,
        (MultiPolygon) geom, os);
  else if (geom instanceof GeometryCollection)
    writeGeometryCollection(WKBConstants.wkbGeometryCollection,
        (GeometryCollection) geom, os);
  else {
    Assert.shouldNeverReachHere("Unknown Geometry type");
  }
}
 
Example #13
Source Project: jts   Author: metteo   File: WKTWriter.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 *  Converts a <code>GeometryCollection</code> to &lt;GeometryCollectionText&gt;
 *  format, then appends it to the writer.
 *
 *@param  geometryCollection  the <code>GeometryCollection</code> to process
 *@param  writer              the output writer to append to
 */
private void appendGeometryCollectionText(GeometryCollection geometryCollection, int level,
    Writer writer)
  throws IOException
{
  if (geometryCollection.isEmpty()) {
    writer.write("EMPTY");
  }
  else {
    int level2 = level;
    writer.write("(");
    for (int i = 0; i < geometryCollection.getNumGeometries(); i++) {
      if (i > 0) {
        writer.write(", ");
        level2 = level + 1;
      }
      appendGeometryTaggedText(geometryCollection.getGeometryN(i), level2, writer);
    }
    writer.write(")");
  }
}
 
Example #14
Source Project: jts   Author: metteo   File: SameStructureTester.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public static boolean isSameStructure(Geometry g1, Geometry g2)
{
  if (g1.getClass() != g2.getClass())
    return false;
  if (g1 instanceof GeometryCollection)
    return isSameStructureCollection((GeometryCollection) g1, (GeometryCollection) g2);
  else if (g1 instanceof Polygon)
    return isSameStructurePolygon((Polygon) g1, (Polygon) g2);
  else if (g1 instanceof LineString)
    return isSameStructureLineString((LineString) g1, (LineString) g2);
  else if (g1 instanceof Point)
    return isSameStructurePoint((Point) g1, (Point) g2);

  Assert.shouldNeverReachHere(
      "Unsupported Geometry class: " + g1.getClass().getName());
  return false;
}
 
Example #15
Source Project: xyz-hub   Author: heremaps   File: JTSHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a JTS Geometry from the provided GeoJSON geometry.
 */
@SuppressWarnings("unchecked")
public static <X extends Geometry> X toGeometry(com.here.xyz.models.geojson.implementation.Geometry geometry) {
  if (geometry == null) {
    return null;
  }

  if (geometry instanceof com.here.xyz.models.geojson.implementation.Point) {
    return (X) toPoint(((com.here.xyz.models.geojson.implementation.Point) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.MultiPoint) {
    return (X) toMultiPoint(((com.here.xyz.models.geojson.implementation.MultiPoint) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.LineString) {
    return (X) toLineString(((com.here.xyz.models.geojson.implementation.LineString) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.MultiLineString) {
    return (X) toMultiLineString(((com.here.xyz.models.geojson.implementation.MultiLineString) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.Polygon) {
    return (X) toPolygon(((com.here.xyz.models.geojson.implementation.Polygon) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.MultiPolygon) {
    return (X) toMultiPolygon(((com.here.xyz.models.geojson.implementation.MultiPolygon) geometry).getCoordinates());
  }
  if (geometry instanceof com.here.xyz.models.geojson.implementation.GeometryCollection) {
    return (X) toGeometryCollection(((com.here.xyz.models.geojson.implementation.GeometryCollection) geometry));
  }
  return null;
}
 
Example #16
Source Project: xyz-hub   Author: heremaps   File: JTSHelper.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <X extends com.here.xyz.models.geojson.implementation.Geometry> X fromGeometry(Geometry jtsGeometry) {
  if (jtsGeometry == null) {
    return null;
  }

  if (jtsGeometry instanceof Point) {
    return (X) new com.here.xyz.models.geojson.implementation.Point().withCoordinates(createPointCoordinates((Point) jtsGeometry));
  }
  if (jtsGeometry instanceof MultiPoint) {
    return (X) new com.here.xyz.models.geojson.implementation.MultiPoint()
        .withCoordinates(createMultiPointCoordinates((MultiPoint) jtsGeometry));
  }
  if (jtsGeometry instanceof LineString) {
    return (X) new com.here.xyz.models.geojson.implementation.LineString()
        .withCoordinates(createLineStringCoordinates((LineString) jtsGeometry));
  }
  if (jtsGeometry instanceof MultiLineString) {
    return (X) new com.here.xyz.models.geojson.implementation.MultiLineString()
        .withCoordinates(createMultiLineStringCoordinates((MultiLineString) jtsGeometry));
  }
  if (jtsGeometry instanceof Polygon) {
    return (X) new com.here.xyz.models.geojson.implementation.Polygon().withCoordinates(createPolygonCoordinates((Polygon) jtsGeometry));
  }
  if (jtsGeometry instanceof MultiPolygon) {
    return (X) new com.here.xyz.models.geojson.implementation.MultiPolygon()
        .withCoordinates(createMultiPolygonCoordinates((MultiPolygon) jtsGeometry));
  }
  if (jtsGeometry instanceof GeometryCollection) {
    return (X) fromGeometryCollection((GeometryCollection) jtsGeometry);
  }

  return null;
}
 
Example #17
Source Project: geowe-core   Author: geowe   File: CoordinateUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void addCoordinateArrays(final Geometry geometry, final boolean orientPolygons,
		final List<Coordinate[]> coordArrayList) {
	if (geometry.getDimension() <= 0) {
		return;
	} else if (geometry instanceof LineString) {
		final LineString l = (LineString) geometry;
		coordArrayList.add(l.getCoordinates());
	} else if (geometry instanceof Polygon) {
		final Polygon poly = (Polygon) geometry;
		Coordinate[] shell = poly.getExteriorRing().getCoordinates();

		if (orientPolygons) {
			shell = ensureOrientation(CGAlgorithms.CLOCKWISE, shell);
		}

		coordArrayList.add(shell);

		for (int numRing = 0; numRing < poly.getNumInteriorRing(); numRing++) {
			Coordinate[] hole = poly.getInteriorRingN(numRing).getCoordinates();

			if (orientPolygons) {
				hole = ensureOrientation(
						CGAlgorithms.COUNTERCLOCKWISE, hole);
			}

			coordArrayList.add(hole);
		}
	} else if (geometry instanceof GeometryCollection) {
		final GeometryCollection gc = (GeometryCollection) geometry;

		for (int numGeom = 0; numGeom < gc.getNumGeometries(); numGeom++) {
			addCoordinateArrays(gc.getGeometryN(numGeom), orientPolygons,
					coordArrayList);
		}
	}
}
 
Example #18
Source Project: gama   Author: gama-platform   File: GamaShape.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public double getPerimeter() {
	if (geometry instanceof GeometryCollection) {
		final int[] result = new int[1];
		GeometryUtils.applyToInnerGeometries((GeometryCollection) geometry,
				(g) -> result[0] += GeometryUtils.getContourCoordinates(g).getLength());
		return result[0];
	}
	final ICoordinates seq = GeometryUtils.getContourCoordinates(geometry);
	return seq.getLength();
}
 
Example #19
Source Project: gama   Author: gama-platform   File: AWTDisplayGraphics.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public Rectangle2D drawShape(final Geometry geometry, final DrawingAttributes attributes) {
	if (geometry == null) { return null; }
	if (geometry instanceof GeometryCollection) {
		final Rectangle2D result = new Rectangle2D.Double();
		GeometryUtils.applyToInnerGeometries(geometry, (g) -> result.add(drawShape(g, attributes)));
		return result;
	}
	final boolean isLine = geometry instanceof Lineal || geometry instanceof Puntal;

	GamaColor border = isLine ? attributes.getColor() : attributes.getBorder();
	if (border == null && attributes.isEmpty()) {
		border = attributes.getColor();
	}
	if (highlight) {
		attributes.setFill(GamaColor.getInt(data.getHighlightColor().getRGB()));
		if (border != null) {
			border = attributes.getColor();
		}
	}
	final Shape s = sw.toShape(geometry);
	try {
		final Rectangle2D r = s.getBounds2D();
		currentRenderer.setColor(attributes.getColor());
		if (!isLine && !attributes.isEmpty()) {
			currentRenderer.fill(s);
		}
		if (isLine || border != null || attributes.isEmpty()) {
			if (border != null) {
				currentRenderer.setColor(border);
			}
			currentRenderer.draw(s);
		}
		return r;
	} catch (final Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
Example #20
Source Project: gama   Author: gama-platform   File: GeometryUtils.java    License: 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 #21
Source Project: gama   Author: gama-platform   File: GeometryUtils.java    License: 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 #22
Source Project: gama   Author: gama-platform   File: GeometryUtils.java    License: 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 #23
Source Project: gama   Author: gama-platform   File: GeometryUtils.java    License: 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 #24
Source Project: gama   Author: gama-platform   File: GeometryUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static ICoordinates getContourCoordinates(final Geometry g) {
	if (g instanceof Polygon) { return getContourCoordinates((Polygon) g); }
	if (g instanceof LineString) { return getContourCoordinates((LineString) g); }
	if (g instanceof Point) { return getContourCoordinates((Point) g); }
	if (g instanceof GeometryCollection) { return getContourCoordinates(g.convexHull()); }
	return ICoordinates.EMPTY;
}
 
Example #25
Source Project: gama   Author: gama-platform   File: GeometryUtils.java    License: 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 #26
Source Project: gama   Author: gama-platform   File: Envelope3D.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static Envelope3D of(final GeometryCollection g) {
	final int i = g.getNumGeometries();
	if (i == 0) { return EMPTY; }
	final Envelope3D result = of(g.getGeometryN(0));
	for (int j = 1; j < i; j++) {
		result.expandToInclude(of(g.getGeometryN(j)));
	}
	return result;
}
 
Example #27
Source Project: jts   Author: metteo   File: KMLWriter.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
private void writeGeometryCollection(GeometryCollection gc,
    String attributes, int level, StringBuffer buf) {
  startLine("<MultiGeometry>\n", level, buf);
  for (int t = 0; t < gc.getNumGeometries(); t++) {
    writeGeometry(gc.getGeometryN(t), level + 1, buf);
  }
  startLine("</MultiGeometry>\n", level, buf);
}
 
Example #28
Source Project: jts   Author: metteo   File: GMLReaderTestCase.java    License: 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 #29
Source Project: jts   Author: metteo   File: GMLReaderTestCase.java    License: 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 #30
Source Project: jts   Author: metteo   File: GMLReaderTestCase.java    License: 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);
	}
}