com.vividsolutions.jts.geom.GeometryCollection Java Examples
The following examples show how to use
com.vividsolutions.jts.geom.GeometryCollection.
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: JTSHelper.java From xyz-hub with Apache License 2.0 | 6 votes |
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 File: WKTWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Converts a <code>GeometryCollection</code> to <GeometryCollectionText> * 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 #3
Source File: KMLWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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 #4
Source File: WKBWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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 #5
Source File: Distance3DOp.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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 #6
Source File: SameStructureTester.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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 #7
Source File: Distance3DOp.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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 #8
Source File: ShapefileHeader.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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 #9
Source File: Projection.java From gama with GNU General Public License v3.0 | 6 votes |
@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 #10
Source File: LayerRenderer.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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 #11
Source File: GeometryPainter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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 #12
Source File: OraGeom.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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 #13
Source File: JTSHelper.java From xyz-hub with Apache License 2.0 | 6 votes |
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 #14
Source File: GamaShape.java From gama with GNU General Public License v3.0 | 6 votes |
@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 #15
Source File: GeometryTreeModel.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static GeometryNode create(Geometry geom, GeometryContext context) { if (geom instanceof GeometryCollection) return new GeometryCollectionNode((GeometryCollection) geom, context); if (geom instanceof Polygon) return new PolygonNode((Polygon) geom, context); if (geom instanceof LineString) return new LineStringNode((LineString) geom, context); if (geom instanceof LinearRing) return new LinearRingNode((LinearRing) geom, context); if (geom instanceof Point) return new PointNode((Point) geom, context); return null; }
Example #16
Source File: BufferValidator.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private void addContainsTest() { addTest(new Test("Contains Test") { public void test() throws Exception { if (getOriginal().getClass() == GeometryCollection.class) { return; } com.vividsolutions.jts.util.Assert.isTrue(getOriginal().isValid()); if (bufferDistance > 0) { Assert.assertTrue( supplement("Expected buffer to contain original"), contains(getBuffer(), getOriginal())); } else { Assert.assertTrue( supplement("Expected original to contain buffer"), contains(getOriginal(), getBuffer())); } } private boolean contains(Geometry a, Geometry b) { //JTS doesn't currently handle empty geometries correctly [Jon Aquino // 10/29/2003] if (b.isEmpty()) { return true; } boolean isContained = a.contains(b); return isContained; } }); }
Example #17
Source File: BufferValidator.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private Geometry getBuffer() throws ParseException { if (buffer == null) { buffer = getOriginal().buffer(bufferDistance, QUADRANT_SEGMENTS_1); if (getBuffer().getClass() == GeometryCollection.class && getBuffer().isEmpty()) { try { //contains doesn't work with GeometryCollections [Jon Aquino // 10/29/2003] buffer = wktReader.read("POINT EMPTY"); } catch (ParseException e) { com.vividsolutions.jts.util.Assert.shouldNeverReachHere(); } } } return buffer; }
Example #18
Source File: CacheKeyServiceTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testOtherContextImpl() { CacheContext context = new MyCacheContext(); String cacheKey1 = cacheKeyService.getCacheKey(context); context.put("bla", "bla"); String cacheKey2 = cacheKeyService.getCacheKey(context); GeometryFactory geometryFactory = new GeometryFactory(); context.put("geom", new GeometryCollection(new Geometry[] {}, geometryFactory)); String cacheKey3 = cacheKeyService.getCacheKey(context); System.out.println("keys " + cacheKey1 + " " + cacheKey2 + " " + cacheKey3); Assert.assertFalse(cacheKey1.equals(cacheKey2)); Assert.assertFalse(cacheKey2.equals(cacheKey3)); Assert.assertFalse(cacheKey3.equals(cacheKey1)); }
Example #19
Source File: DefaultVmlDocument.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private void initDefaultWriters() { registerWriter(Point.class, new PointWriter()); registerWriter(LineString.class, new LineStringWriter()); registerWriter(LinearRing.class, new LineStringWriter()); registerWriter(Polygon.class, new PolygonWriter()); registerWriter(MultiPoint.class, new MultiPointWriter()); registerWriter(MultiLineString.class, new MultiLineStringWriter()); registerWriter(MultiPolygon.class, new MultiPolygonWriter()); registerWriter(GeometryCollection.class, new GeometryCollectionWriter()); }
Example #20
Source File: GeometryCollectionWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Writes a <code>GeometryCollection</code> object. * * @param o The <code>LineString</code> to be encoded. */ public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException { GeometryCollection coll = (GeometryCollection) o; document.writeElement("vml:shape", asChild); document.writeAttribute("fill-rule", "evenodd"); document.writeAttributeStart("path"); for (int i = 0; i < coll.getNumGeometries(); i++) { } document.writeAttributeEnd(); }
Example #21
Source File: GeometryCollectionWriter.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Writes a <code>GeometryCollection</code> object. * * @param o The <code>LineString</code> to be encoded. */ public void writeObject(Object o, GraphicsDocument document, boolean asChild) throws RenderException { GeometryCollection coll = (GeometryCollection) o; document.writeElement("path", asChild); document.writeAttribute("fill-rule", "evenodd"); document.writeAttributeStart("d"); for (int i = 0; i < coll.getNumGeometries(); i++) { document.writeObject(coll.getGeometryN(i), true); // TODO delegate to appropriate writers, is this correct? } document.writeAttributeEnd(); }
Example #22
Source File: DefaultSvgDocument.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private void initDefaultWriters() { registerWriter(Bbox.class, new BboxWriter()); registerWriter(Point.class, new PointWriter()); registerWriter(LineString.class, new LineStringWriter()); registerWriter(LinearRing.class, new LineStringWriter()); registerWriter(Polygon.class, new PolygonWriter()); registerWriter(MultiPoint.class, new MultiPointWriter()); registerWriter(MultiLineString.class, new MultiLineStringWriter()); registerWriter(MultiPolygon.class, new MultiPolygonWriter()); registerWriter(GeometryCollection.class, new GeometryCollectionWriter()); }
Example #23
Source File: JTSHelper.java From xyz-hub with Apache License 2.0 | 5 votes |
/** * 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 #24
Source File: MiscellaneousTest.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public void testBoundaryOfEmptyGeometry() throws Exception { assertTrue(geometryFactory.createPoint((Coordinate)null).getBoundary().getClass() == GeometryCollection.class); assertTrue(geometryFactory.createLinearRing(new Coordinate[] { }).getBoundary().getClass() == MultiPoint.class); assertTrue(geometryFactory.createLineString(new Coordinate[] { }).getBoundary().getClass() == MultiPoint.class); assertTrue(geometryFactory.createPolygon(geometryFactory.createLinearRing(new Coordinate[] { }), new LinearRing[] { }).getBoundary().getClass() == MultiLineString.class); assertTrue(geometryFactory.createMultiPolygon(new Polygon[] { }).getBoundary().getClass() == MultiLineString.class); assertTrue(geometryFactory.createMultiLineString(new LineString[] { }).getBoundary().getClass() == MultiPoint.class); assertTrue(geometryFactory.createMultiPoint(new Point[] { }).getBoundary().getClass() == GeometryCollection.class); try { geometryFactory.createGeometryCollection(new Geometry[] { }).getBoundary(); assertTrue(false); } catch (IllegalArgumentException e) { } }
Example #25
Source File: WKTWriter.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Converts a <code>Geometry</code> to <Geometry Tagged Text> format, * then appends it to the writer. * *@param geometry the <code>Geometry</code> to process *@param writer the output writer to append to */ private void appendGeometryTaggedText(Geometry geometry, int level, Writer writer) throws IOException { indent(level, writer); if (geometry instanceof Point) { Point point = (Point) geometry; appendPointTaggedText(point.getCoordinate(), level, writer, point.getPrecisionModel()); } else if (geometry instanceof LinearRing) { appendLinearRingTaggedText((LinearRing) geometry, level, writer); } else if (geometry instanceof LineString) { appendLineStringTaggedText((LineString) geometry, level, writer); } else if (geometry instanceof Polygon) { appendPolygonTaggedText((Polygon) geometry, level, writer); } else if (geometry instanceof MultiPoint) { appendMultiPointTaggedText((MultiPoint) geometry, level, writer); } else if (geometry instanceof MultiLineString) { appendMultiLineStringTaggedText((MultiLineString) geometry, level, writer); } else if (geometry instanceof MultiPolygon) { appendMultiPolygonTaggedText((MultiPolygon) geometry, level, writer); } else if (geometry instanceof GeometryCollection) { appendGeometryCollectionTaggedText((GeometryCollection) geometry, level, writer); } else { Assert.shouldNeverReachHere("Unsupported Geometry implementation:" + geometry.getClass()); } }
Example #26
Source File: GeoServiceTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void transformGeometryEmptyResultOnException() throws Exception { GeometryFactory geometryFactory = new GeometryFactory(); WKTReader reader = new WKTReader( geometryFactory ); Point point = (Point) reader.read("POINT (1 1)"); Geometry geometry = geoService.transform(point, new ThrowingTransform()); Assert.assertEquals(Point.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); LineString lineString = (LineString) reader.read("LINESTRING (0 1,1 1)"); geometry = geoService.transform(lineString, new ThrowingTransform()); Assert.assertEquals(LineString.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); Polygon polygon = (Polygon) reader.read("POLYGON ((0 0,1 1,0 1,0 0))"); geometry = geoService.transform(polygon, new ThrowingTransform()); Assert.assertEquals(Polygon.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); MultiPoint multipoint = (MultiPoint) reader.read("MULTIPOINT ((1 1),(2 1))"); geometry = geoService.transform(multipoint, new ThrowingTransform()); Assert.assertEquals(MultiPoint.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); MultiLineString multilineString = (MultiLineString) reader.read("MULTILINESTRING ((0 1,1 1),(0 2,2 2))"); geometry = geoService.transform(multilineString, new ThrowingTransform()); Assert.assertEquals(MultiLineString.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); MultiPolygon multipolygon = (MultiPolygon) reader.read("MULTIPOLYGON (((0 0,1 1,0 1,0 0)),((0 0,2 2,0 2,0 0)))"); geometry = geoService.transform(multipolygon, new ThrowingTransform()); Assert.assertEquals(MultiPolygon.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); Geometry collection = (GeometryCollection) reader.read("GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10)) "); geometry = geoService.transform(collection, new ThrowingTransform()); Assert.assertEquals(GeometryCollection.class, geometry.getClass()); Assert.assertTrue(geometry.isEmpty()); }
Example #27
Source File: WKBWriter.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private void writeGeometryCollection(int geometryType, GeometryCollection gc, OutStream os) throws IOException { writeByteOrder(os); writeGeometryType(geometryType, gc, os); writeInt(gc.getNumGeometries(), os); for (int i = 0; i < gc.getNumGeometries(); i++) { write(gc.getGeometryN(i), os); } }
Example #28
Source File: Distance3DOp.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private void computeMinDistanceOneMulti(Geometry g0, Geometry g1, boolean flip) { if (g1 instanceof GeometryCollection) { int n = g1.getNumGeometries(); for (int i = 0; i < n; i++) { Geometry g = g1.getGeometryN(i); computeMinDistanceOneMulti(g0, g, flip); if (isDone) return; } } else { computeMinDistance(g0, g1, flip); } }
Example #29
Source File: OraReaderCreateTest.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public void testRawGeometryCollectionWithPoint() throws Exception { final GeometryFactory geometryFactory = new GeometryFactory(); final OraReader oraReader = new OraReader(geometryFactory); // Geometry type is a 'collection'. final int gType = 2004; // A collection of a 'line' and a 'point'/ // The 'line' is starting at ordinate offset 1. // The 'point' is starting at ordinate offset 5. final int[] elemInfo = new int[] {1, 2, 1, 5, 1, 1}; // 6 ordinates. // 'line' (1, 1, 2, 2). // 'point' (3, 3). final double[] ordinates = new double[] {1, 1, 2, 2, 3, 3}; // Made 'create' method package private to enable test. final Geometry actual = oraReader.read(new OraGeom(gType, 0, elemInfo, ordinates)); // Preparing expected result. final LineString lineString = geometryFactory.createLineString(new Coordinate[] {new Coordinate(1, 1), new Coordinate(2, 2)}); final Point point = geometryFactory.createPoint(new Coordinate(3, 3)); final List<Geometry> geometries = new ArrayList<Geometry>(); geometries.add(lineString); geometries.add(point); final GeometryCollection expected = geometryFactory.createGeometryCollection(GeometryFactory.toGeometryArray(geometries)); assertEquals(expected, actual); }
Example #30
Source File: BufferByUnionFunctions.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public static Geometry componentBuffers(Geometry g, double distance) { List bufs = new ArrayList(); for (Iterator it = new GeometryCollectionIterator(g); it.hasNext(); ) { Geometry comp = (Geometry) it.next(); if (comp instanceof GeometryCollection) continue; bufs.add(comp.buffer(distance)); } return FunctionsUtil.getFactoryOrDefault(g) .createGeometryCollection(GeometryFactory.toGeometryArray(bufs)); }