Package com.vividsolutions.jts.geom

Examples of com.vividsolutions.jts.geom.GeometryCollection


  }

    public final Geometry decimateTransformGeneralize(Geometry geometry,
      MathTransform transform) throws TransformException {
    if (geometry instanceof GeometryCollection) {
      GeometryCollection collection = (GeometryCollection) geometry;
      final int length = collection.getNumGeometries();
      boolean cloned = false;
      Class elementType = null;
            Geometry[] elements = null;
      for (int i = 0; i < length; i++) {
        Geometry source = collection.getGeometryN(i);
                Geometry generalized = decimateTransformGeneralize(source,
            transform);
               
                // lazily handle the case where we need to deep clone
                if(generalized != source) {
                    cloned = true;
                    if(elements == null) {
                        elements = new Geometry[collection.getNumGeometries()];
                        for (int j = 0; j < i; j++) {
                            Geometry element = source.getGeometryN(j);
                            elements[j] = element;
                            accumulateGeometryType(elementType, element);
                        }
                    }
                }
                if(cloned) {
                    elements[i] = generalized;
                    elementType = accumulateGeometryType(elementType, generalized);
                }
      }
      if(cloned) {
          if(elementType == Point.class) {
              Point[] points = new Point[elements.length];
              System.arraycopy(elements, 0, points, 0, elements.length);
                    return collection.getFactory().createMultiPoint(points);
                } else if (elementType == LineString.class) {
                    LineString[] lines = new LineString[elements.length];
                    System.arraycopy(elements, 0, lines, 0, elements.length);
                    return collection.getFactory().createMultiLineString(lines);
                } else if (elementType == Polygon.class) {
                    Polygon[] polys = new Polygon[elements.length];
                    System.arraycopy(elements, 0, polys, 0, elements.length);
                    return collection.getFactory().createMultiPolygon(polys);
                } else {
                    return collection.getFactory().createGeometryCollection(elements);
          }
      } else {
          return collection;
      }
    } else if (geometry instanceof Point) {
View Full Code Here


    if (geom instanceof GeometryCollection) {
      // TODO check geometry and if its bbox is too small turn it into a
      // 1-2 point geom
      // takes a bit of work because the geometry will need to be
      // recreated.
      GeometryCollection collection = (GeometryCollection) geom;
      final int numGeometries = collection.getNumGeometries();
      for (int i = 0; i < numGeometries; i++) {
        decimate(collection.getGeometryN(i));
      }
    } else if (geom instanceof LineString) {
      LineString line = (LineString) geom;
      LiteCoordinateSequence seq = (LiteCoordinateSequence) line
          .getCoordinateSequence();
View Full Code Here

        g[0] = gf.createPoint(new Coordinate(0, 0));
        g[1] = gf.createPoint(new Coordinate(0, 10));
        g[2] = gf.createPoint(new Coordinate(10, 0));
        g[3] = gf.createPoint(new Coordinate(10, 10));

        GeometryCollection gc = gf.createGeometryCollection(g);
        SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();
        tb.setName( "bounds" );
        tb.setCRS(null);
        tb.add("p1", Point.class);
        tb.add("p2", Point.class);
        tb.add("p3", Point.class);
        tb.add("p4", Point.class);
        SimpleFeatureType t = tb.buildFeatureType();
       
        SimpleFeature f = SimpleFeatureBuilder.build(t, g, null);
        assertEquals(gc.getEnvelopeInternal(), f.getBounds());

        g[1].getCoordinate().y = 20;
        g[2].getCoordinate().x = 20;
        f.setAttribute(1, g[1]);
        f.setAttribute(2, g[2]);
        gc = gf.createGeometryCollection(g);
        assertEquals(gc.getEnvelopeInternal(), f.getBounds());
    }
View Full Code Here

                inverted[count] = (Polygon) invertGeometryCoordinates(multiPolygon
                        .getGeometryN(count));
            }
            return geometryFactory.createMultiPolygon(inverted);
        } else if (geom instanceof GeometryCollection) {
            GeometryCollection collection = (GeometryCollection) geom;
            Geometry[] inverted = new Geometry[collection.getNumGeometries()];
            for (int count = 0; count < collection.getNumGeometries(); count++) {
                inverted[count] = invertGeometryCoordinates(collection
                        .getGeometryN(count));
            }
            return geometryFactory.createGeometryCollection(inverted);
        }
        throw new IllegalArgumentException("Unknown geometry type: "
View Full Code Here

            "}");

        SimpleFeature f1 = fjson.readFeature(json);
        assertNotNull(f1.getDefaultGeometry());

        GeometryCollection gc = (GeometryCollection) f1.getDefaultGeometry();
        assertEquals(2, gc.getNumGeometries());

        WKTReader wkt = new WKTReader();
        assertTrue(wkt.read("POINT (4 6)").equals(gc.getGeometryN(0)));
        assertTrue(wkt.read("LINESTRING (4 6, 7 10)").equals(gc.getGeometryN(1)));

        assertEquals("fid-7205cfc1_138e7ce8900_-7ffe", f1.getID());
        assertEquals("Name123", f1.getAttribute("name"));
        assertEquals("Label321", f1.getAttribute("label"));
        assertEquals("[1,2,3]", f1.getAttribute("roles"));
View Full Code Here

            "}");
       
        SimpleFeature f1 = fjson.readFeature(json);
        assertNotNull(f1.getDefaultGeometry());

        GeometryCollection gc = (GeometryCollection) f1.getDefaultGeometry();
        assertEquals(2, gc.getNumGeometries());

        WKTReader wkt = new WKTReader();
        assertTrue(wkt.read("POLYGON ((-28.1107 142.998, -28.1107 148.623, -30.2591 148.623, -30.2591 142.998, -28.1107 142.998))").equals(gc.getGeometryN(0)));
        assertTrue(wkt.read("POLYGON((-27.1765 142.998, -25.6811 146.4258, -27.1765 148.5352, -27.1765 142.998))").equals(gc.getGeometryN(1)));

        assertEquals("fid-397164b3_13880d348b9_-7a5c", f1.getID());
        assertEquals("", f1.getAttribute("name"));
        assertEquals("x_2000a", f1.getAttribute("caseSN"));
        assertEquals(2l, f1.getAttribute("siteNum"));
View Full Code Here

                inverted[count] = (Polygon) invertGeometryCoordinates(multiPolygon
                        .getGeometryN(count));
            }
            return geometryFactory.createMultiPolygon(inverted);
        } else if (geom instanceof GeometryCollection) {
            GeometryCollection collection = (GeometryCollection) geom;
            Geometry[] inverted = new Geometry[collection.getNumGeometries()];
            for (int count = 0; count < collection.getNumGeometries(); count++) {
                inverted[count] = invertGeometryCoordinates(collection
                        .getGeometryN(count));
            }
            return geometryFactory.createGeometryCollection(inverted);
        }
        throw new IllegalArgumentException("Unknown geometry type: "
View Full Code Here

                        "    'type': 'GeometryCollection'" +
                        "  }");
    }

    GeometryCollection collection() {
        GeometryCollection gcol = gf.createGeometryCollection(new Geometry[]{
           gf.createPoint(new Coordinate(100.1,0.1)),
           gf.createLineString(array(new double[][]{{101.1, 0.1}, {102.1, 1.1}}))
        });
        return gcol;
    }
View Full Code Here

            "    ]"+
            "  }");
    }

    GeometryCollection collection3d() {
        GeometryCollection gcol = gf.createGeometryCollection(new Geometry[]{
           gf.createPoint(new Coordinate(100.1,0.1, 10.2)),
           gf.createLineString(array(new double[][]{{101.1, 0.1, 10.2}, {102.1, 1.1, 11.2}}))
        });
        return gcol;
    }
View Full Code Here

    public void testGeometryCollectionReadTypeLast() throws IOException {
        Object obj = gjson.read(collectionTypeLastText());
        assertTrue(obj instanceof GeometryCollection);

        GeometryCollection gc = (GeometryCollection) obj;
        assertEquals(2, gc.getNumGeometries());

        assertTrue(gc.getGeometryN(0) instanceof Point);
        assertTrue(gc.getGeometryN(1) instanceof LineString);
    }
View Full Code Here

TOP

Related Classes of com.vividsolutions.jts.geom.GeometryCollection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.