Java com.vividsolutions.jts.geom.GeometryCollection 代码实例

・12 分钟阅读

以下是展示如何使用com.vividsolutions.jts.geom.GeometryCollection的最佳示例。 我们使用了代码质量辨别算法从开源项目中提取出了最佳的优秀示例。

实例 1


public static final Collection<PolygonWithHolesXZ>
        polygonsXZFromJTSGeometry(Geometry geometry) {
        Collection<PolygonWithHolesXZ> result =
                new ArrayList<PolygonWithHolesXZ>(1);
        if (geometry instanceof Polygon) {
                if (geometry.getNumPoints() > 2) {
                        try {
                                result.add(polygonXZFromJTSPolygon((Polygon)geometry));
                        } catch (InvalidGeometryException e) {
                                //don't add the broken polygon
                        }
                }
        } else if (geometry instanceof GeometryCollection) {
                GeometryCollection collection = (GeometryCollection)geometry;
                for (int i = 0; i < collection.getNumGeometries(); i++) {
                        result.addAll(polygonsXZFromJTSGeometry(collection.getGeometryN(i)));
                }
        } else {
                System.err.println("unhandled geometry type: " + geometry.getClass());
        }
        return result;
}
 

实例 2


/**
 *
 * @param geomCollection
 * @return
 * @throws SharkKBException
 */
private List<Geometry> divideGeometryCollection(GeometryCollection geomCollection) throws SharkKBException {
    List<Geometry> tempGeomList = new ArrayList();
    int numberOfGeoms = geomCollection.getNumGeometries();
    for (int i = 0; i < numberOfGeoms; i++) {
        tempGeomList.add(geomCollection.getGeometryN(i));
    }
    return tempGeomList;
}
 

实例 3


private JSONBuilder writeGeomCollection(GeometryCollection collection) throws JSONException {
    this.key("geometries");
    this.array();
    for (int i = 0, n = collection.getNumGeometries(); i < n; i++) {
        writeGeom(collection.getGeometryN(i));
    }
    return this.endArray();
}
 

实例 4


protected static Geometry transformGeometryCollection(CoordinateTransform ct, GeometryCollection geometryCollection)
    throws Exception {
    Geometry[] geometry = new Geometry[geometryCollection.getNumGeometries()];
    for (int i = 0; i < geometry.length; ++i) {
        geometry[i] = transformGeometry(ct, geometryCollection.getGeometryN(i));
    }
    return geometryCollection.getFactory().createGeometryCollection(geometry);
}
 

实例 5


/**
 * Saves a shapefile to the output stream.
 * 
 * @param coordDimension  2=x,y ; 3=x,y,m ; 4=x,y,z,m
 */
public void write(GeometryCollection geometries, int coordDimension)
    throws IOException, Exception {
  EndianDataOutputStream outStream = getOutputStream();
  ShapefileHeader header = new ShapefileHeader(geometries,
      coordDimension);
  header.write(outStream);
  int pos = 50; // header length in WORDS
  //records;
  //body;
  //header;
  int numShapes = geometries.getNumGeometries();
  ShapeHandler handler;
  if (geometries.getNumGeometries() == 0) {
    handler = new PointHandler(); //default
  } else {
    handler = Shapefile.getShapeHandler(geometries.getGeometryN(0),
        coordDimension);
  }
  for (int i = 0; i < numShapes; i++) {
    Geometry body = geometries.getGeometryN(i);
    outStream.writeIntBE(i + 1);
    outStream.writeIntBE(handler.getLength(body));
    pos += 4; // length of header in WORDS
    handler.write(body, outStream);
    pos += handler.getLength(body); // length of shape in WORDS
  }
  outStream.flush();
  outStream.close();
}
 

实例 6


public static MultiGeometryType convertToMultiGeometryType(GeometryCollection multiGeometry,
        String srsName) {
    final MultiGeometryType multiGeometryType = GML320_OBJECT_FACTORY.createMultiGeometryType();
    for (int index = 0; index < multiGeometry.getNumGeometries(); index++) {
        final Geometry geometry = multiGeometry.getGeometryN(index);
        multiGeometryType.getGeometryMember()
                .add(createGeometryPropertyType(geometry, srsName));
    }
    return multiGeometryType;
}
 

实例 7


private static void addElemInfo(List elemInfoList, GeometryCollection geoms,
    final int STARTING_OFFSET, final int GTYPE) {
    Geometry geom;
    int offset = STARTING_OFFSET;
    int LEN = D(GTYPE) + L(GTYPE);
    for (int i = 0; i < geoms.getNumGeometries(); i++) {
        geom = geoms.getGeometryN(i);
        elemInfo(elemInfoList, geom, offset, GTYPE);
        if( geom instanceof Polygon && isRectangle( (Polygon) geom )){
            offset += (2 * LEN);                
        }
        else {
            offset += (geom.getNumPoints() * LEN);                
        }                        
    }
}
 

实例 8


private static void addCoordinates(List list, GeometryCollection geoms) {
    Geometry geom;
    for (int i = 0; i < geoms.getNumGeometries(); i++) {
        geom = geoms.getGeometryN(i);
        if (geom instanceof Point) {
            addCoordinates(list, (Point) geom);
        } else if (geom instanceof LineString) {
            addCoordinates(list, (LineString) geom);
        } else if (geom instanceof Polygon) {
            addCoordinates(list, (Polygon) geom);
        } else if (geom instanceof MultiPoint) {
            addCoordinates(list, (MultiPoint) geom);
        } else if (geom instanceof MultiLineString) {
            addCoordinates(list, (MultiLineString) geom);
        } else if (geom instanceof MultiPolygon) {
            addCoordinates(list, (MultiPolygon) geom);
        } else if (geom instanceof GeometryCollection) {
            addCoordinates(list, (GeometryCollection) geom);
        }
    }
}
 

实例 9


/**
 * @param gc
 * @param at
 */
public void init(GeometryCollection gc, AffineTransform at, boolean generalize, double maxDistance) {
       this.gc = gc;
       this.at = at==null?new AffineTransform():at;
       this.generalize = generalize;
       this.maxDistance = maxDistance;
       currentGeom = 0;
       done = false;
       currentIterator = gc.isEmpty() ? EmptyIterator.INSTANCE : getIterator(gc.getGeometryN(0));
}
 

实例 10


private Geometry reducePoints(Geometry geometry, double tolerance)
{        
    if (geometry instanceof GeometryCollection)
    {
        GeometryFactory geoFac = geometry.getFactory();
        GeometryCollection gc = (GeometryCollection) geometry;
        Geometry[] geos = new Geometry[gc.getNumGeometries()];
        if (!gc.isEmpty())
        {
            for (int i = 0; i < gc.getNumGeometries(); i++)
            {
                geos[i] = reduceGeo(gc.getGeometryN(i), tolerance);
            }                
            return new GeometryCollection(geos, geoFac);
        }
        else
        {
            return geometry;
        }
    }
    else
    {
        return reduceGeo(geometry, tolerance);
    }        
}
 

实例 11


/**
 * @param gc
 * @param at
 */
public void init(GeometryCollection gc, AffineTransform at, boolean generalize, double maxDistance) {
       this.gc = gc;
       this.at = at==null?new AffineTransform():at;
       this.generalize = generalize;
       this.maxDistance = maxDistance;
       currentGeom = 0;
       done = false;
       currentIterator = gc.isEmpty() ? EmptyIterator.INSTANCE : getIterator(gc.getGeometryN(0));
}
 

实例 12


/**
 * @param gc
 * @param at
 */
public void init(GeometryCollection gc, AffineTransform at, boolean generalize, double maxDistance) {
       this.gc = gc;
       this.at = at==null?new AffineTransform():at;
       this.generalize = generalize;
       this.maxDistance = maxDistance;
       currentGeom = 0;
       done = false;
       currentIterator = gc.isEmpty() ? EmptyIterator.INSTANCE : getIterator(gc.getGeometryN(0));
}
 

实例 13


/**
 * 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(")");
    }
}
 

实例 14


/**
 *  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(")");
  }
}
 

实例 15


/**
 * @param gc
 * @param at
 */
public void init(GeometryCollection gc, AffineTransform at) {
    this.gc = gc;
    this.at = at == null ? new AffineTransform() : at;
    currentGeom = 0;
    done = false;
    currentIterator = gc.isEmpty() ? EmptyIterator.INSTANCE : getIterator(gc.getGeometryN(0));
}
 
讨论
淘淘あ西西 profile image