Examples of GeometryCollection


Examples of com.vividsolutions.jts.geom.GeometryCollection

     * @param g
     * @return
     */
    public Geometry getCentroid(Geometry g) {
        if (g instanceof GeometryCollection) {
            GeometryCollection gc = (GeometryCollection) g;
            Coordinate[] pts = new Coordinate[gc.getNumGeometries()];

            for (int t = 0; t < gc.getNumGeometries(); t++) {
                pts[t] = gc.getGeometryN(t).getCentroid().getCoordinate();
            }

            return g.getFactory().createMultiPoint(pts);
        } else {
            return g.getCentroid();
View Full Code Here

Examples of com.vividsolutions.jts.geom.GeometryCollection

            start("description");
            cdata(AtomUtils.getFeatureDescription(feature));
            end("description");
           
            GeometryCollection col = feature.getDefaultGeometry() instanceof GeometryCollection
                ? (GeometryCollection) feature.getDefaultGeometry()
                : null;

            if (geometryEncoding == GeometryEncoding.LATLONG
                || (col == null && feature.getDefaultGeometry() != null)) {
                geometryEncoding.encode((Geometry)feature.getDefaultGeometry(), this);
                end("item");
            } else {
                geometryEncoding.encode(col.getGeometryN(0), this);
                end("item");

                for (int i = 1; i < col.getNumGeometries(); i++){
                    encodeRelatedGeometryItem(col.getGeometryN(i), title, link, i);
                }
            }
        }
View Full Code Here

Examples of com.vividsolutions.jts.geom.GeometryCollection

            if (feature.getDefaultGeometry() != null) {
                Geometry g = (Geometry) feature.getDefaultGeometry();

                //handle case of multi geometry with a single geometry in it
                if (g instanceof GeometryCollection) {
                    GeometryCollection mg = (GeometryCollection) g;

                    if (mg.getNumGeometries() == 1) {
                        g = mg.getGeometryN(0);
                    }
                }

                geometryEncoding.encode(g, this);
            }
View Full Code Here

Examples of com.vividsolutions.jts.geom.GeometryCollection

                start("georss:where");
                geometryEncoding.encode((Geometry)feature.getDefaultGeometry(), this);
                end("georss:where");
                end("entry");
            } else {
                GeometryCollection col = (GeometryCollection)feature.getDefaultGeometry();
                start("georss:where");
                geometryEncoding.encode(col.getGeometryN(0), this);
                end("georss:where");
                end("entry");

                for (int i = 1; i < col.getNumGeometries(); i++){
                    encodeRelatedGeometryEntry(col.getGeometryN(i), feature.getID(), link, link + "#" + i);
                }
            }
        }
View Full Code Here

Examples of com.vividsolutions.jts.geom.GeometryCollection

     */
    Coordinate geometryCentroid(Geometry g) {
        // TODO: should the collection case return the centroid of the
        // multi point?
        if (g instanceof GeometryCollection) {
            GeometryCollection gc = (GeometryCollection) g;

            // check for case of single geometry
            if (gc.getNumGeometries() == 1) {
                g = gc.getGeometryN(0);
            } else {
                double maxAreaSoFar = gc.getGeometryN(0).getArea();
                Coordinate centroidToReturn =
                    gc.getGeometryN(0).getCentroid().getCoordinate();

                for (int t = 0; t < gc.getNumGeometries(); t++) {
                    double area = gc.getGeometryN(t).getArea();
                    if (area > maxAreaSoFar) {
                        maxAreaSoFar = area;
                        centroidToReturn =
                            gc.getGeometryN(t).getCentroid().getCoordinate();
                    }
                }

                return centroidToReturn;
            }
View Full Code Here

Examples of com.vividsolutions.jts.geom.GeometryCollection

       * @throws IOException if an error occurs during encoding
       */
      protected void writeMultiFeature(SimpleFeature ft,Style style,FeatureTypeStyle[] fts) throws IOException {
        reset(ft);
        if(processStyle(ft,style,fts)) {
          GeometryCollection geomCollection = (GeometryCollection) ft.getDefaultGeometry();
          for (int i = 0; i < geomCollection.getNumGeometries(); i++) {
            try {
                  startElement(ft,"."+i);       
                  startGeometry(geomCollection.getGeometryN(i));
                  writeGeometry(geomCollection.getGeometryN(i),buffer);
                  endGeometry(geomCollection.getGeometryN(i));       
                  endElement(ft);
                  commitBuffer();
            } catch(IOException e) {
              buffer=new StringBuffer();
              if(LOGGER.isLoggable(Level.WARNING))
View Full Code Here

Examples of com.vividsolutions.jts.geom.GeometryCollection

       * @throws IOException if an error occurs during encoding
       */
      protected void writeFeature(SimpleFeature ft,Style style,FeatureTypeStyle[] fts) throws IOException {
        reset(ft);
       
        GeometryCollection geomCollection = (GeometryCollection) ft.getDefaultGeometry();
       
        for (int i = 0; i < geomCollection.getNumGeometries(); i++) {
          Geometry geom=geomCollection.getGeometryN(i);
         
                Class<?> gtype = geom.getClass();

                // retrieves the right feature writer (based on the current geometry type)
                delegateWriter = (HTMLImageMapFeatureWriter) writers.get(gtype);
View Full Code Here

Examples of com.vividsolutions.jts.geom.GeometryCollection

     * @param geom
     * @throws IOException
     */
    private void writeGeometry(String layer, String ownerHandle, Geometry geom) throws IOException {
        if (geom instanceof GeometryCollection) {
            GeometryCollection coll = (GeometryCollection) geom;
            for (int count = 0; count < coll.getNumGeometries(); count++)
                writeGeometry(layer, ownerHandle, coll.getGeometryN(count));
        } else if (geom instanceof Polygon) {
            Polygon p = (Polygon) geom;
            writeGeometry(layer, ownerHandle, p.getExteriorRing());
            for (int count = 0; count < p.getNumInteriorRing(); count++)
                writeGeometry(layer, ownerHandle, p.getInteriorRingN(count));
View Full Code Here

Examples of com.vividsolutions.jts.geom.GeometryCollection

    final double x2 = this.defaultViewEnvelope.getMinX() + (2 * expectedScreenX2);
    final double y2 = this.defaultViewEnvelope.getMinY() + (2 * expectedScreenY2);
    Point point = this.geometryFactory.createPoint( new Coordinate( x1, y1 ) );
    LineString line = this.geometryFactory.createLineString( LimbGeneratorTest.Utils.createCoords( "" + x1 + " " + y1 +", " + x2 + " " + y2 ) );
    MultiLineString multiLine = this.geometryFactory.createMultiLineString( new LineString[]{ line, line } );
    GeometryCollection innerCollection = this.geometryFactory.createGeometryCollection( new Geometry[]{ point, line } );
    GeometryCollection outerCollection = this.geometryFactory.createGeometryCollection( new Geometry[]{ multiLine, innerCollection } );
    // It's important to re-use the same line object multiple times.
    // We're then able to verify that the cloning process takes a deep copy of the geometry collection.
    // A shallow copy will result in the transform being applied several times to the same line object.
    // (Interestingly, outerCollection.clone() takes a deep copy
    //  but GeometryFactory::createGeometry( outerCollection ) takes a shallow copy.)
   
    Limb limb = new Limb();
    limb.setIntersection( outerCollection );
   
    Options options = new Options();
    options.setScreenSize( this.halfScreenSize );
   
    PositionAssignmentLimbRefiner testObj = new PositionAssignmentLimbRefiner();
    testObj.refine( limb, this.defaultView, options );
   
    assertTrue( limb.getPosition() instanceof GeometryCollection );
    GeometryCollection position = (GeometryCollection)limb.getPosition();
    assertTrue( position.getGeometryN( 0 ) instanceof MultiLineString );
    MultiLineString position1 = (MultiLineString)position.getGeometryN( 0 );
    assertTrue( position1.getGeometryN( 0 ) instanceof LineString );
    LineString multiLine1 = (LineString)position1.getGeometryN( 0 );
    assertEquals( expectedScreenX1, multiLine1.getCoordinateN( 0 ).x, DOUBLE_TOLERANCE );
    assertEquals( expectedScreenY1, multiLine1.getCoordinateN( 0 ).y, DOUBLE_TOLERANCE );
    assertEquals( expectedScreenX2, multiLine1.getCoordinateN( 1 ).x, DOUBLE_TOLERANCE );
    assertEquals( expectedScreenY2, multiLine1.getCoordinateN( 1 ).y, DOUBLE_TOLERANCE );
    assertTrue( position1.getGeometryN( 1 ) instanceof LineString );
    LineString multiLine2 = (LineString)position1.getGeometryN( 1 );
    assertEquals( expectedScreenX1, multiLine2.getCoordinateN( 0 ).x, DOUBLE_TOLERANCE );
    assertEquals( expectedScreenY1, multiLine2.getCoordinateN( 0 ).y, DOUBLE_TOLERANCE );
    assertEquals( expectedScreenX2, multiLine2.getCoordinateN( 1 ).x, DOUBLE_TOLERANCE );
    assertEquals( expectedScreenY2, multiLine2.getCoordinateN( 1 ).y, DOUBLE_TOLERANCE );
    assertTrue( position.getGeometryN( 1 ) instanceof GeometryCollection );
    GeometryCollection position2 = (GeometryCollection)position.getGeometryN( 1 );
    assertTrue( position2.getGeometryN( 0 ) instanceof Point );
    Point point1 = (Point)position2.getGeometryN( 0 );
    assertEquals( expectedScreenX1, point1.getX(), DOUBLE_TOLERANCE );
    assertEquals( expectedScreenY1, point1.getY(), DOUBLE_TOLERANCE );
    assertTrue( position2.getGeometryN( 1 ) instanceof LineString );
    LineString line1 = (LineString)position2.getGeometryN( 1 );
    assertEquals( expectedScreenX1, line1.getCoordinateN( 0 ).x, DOUBLE_TOLERANCE );
    assertEquals( expectedScreenY1, line1.getCoordinateN( 0 ).y, DOUBLE_TOLERANCE );
    assertEquals( expectedScreenX2, line1.getCoordinateN( 1 ).x, DOUBLE_TOLERANCE );
    assertEquals( expectedScreenY2, line1.getCoordinateN( 1 ).y, DOUBLE_TOLERANCE );
  }
View Full Code Here

Examples of com.vividsolutions.jts.geom.GeometryCollection

   
    Geometry line = this.geometryFactory.createLineString( new Coordinate[]{ new Coordinate( 34.474, 843.487 ),
                                                                             new Coordinate( 942.42, 4.47452 ),
                                                                             new Coordinate( 3562.4, 95633.1 ) } );
   
    GeometryCollection geometryCollection = this.geometryFactory.createGeometryCollection( new Geometry[]{ polygon, point, line } );
    this.geoJsonWriter.value( geometryCollection );
   
    assertEquals( "{\"type\":\"GeometryCollection\",\"geometries\":[{\"type\":\"Polygon\",\"coordinates\":[[[0,0],[0,5],[5,5],[5,0],[0,0]],[[1,1],[1,2],[2,2],[2,1],[1,1]],[[3,3],[3,4],[4,4],[4,3],[3,3]]]},{\"type\":\"Point\",\"coordinates\":[50.6,124.59]},{\"type\":\"LineString\",\"coordinates\":[[34.474,843.487],[942.42,4.47452],[3562.4,95633.1]]}]}", this.geoJsonBuffer.toString() );
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.