Example #1
0
  public void testMultiPointRead() throws SAXException, IOException, ParserConfigurationException {
    FileReader fr = new FileReader(TEST_DIR + "multipoints.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++) {
      MultiPoint p = (MultiPoint) gc.getGeometryN(i);
      assertNotNull(p);
    }
  }
Example #2
0
  public void testLineStringRead() throws SAXException, IOException, ParserConfigurationException {
    FileReader fr = new FileReader(TEST_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 #3
0
 public static void computeDistance(Geometry geom, Coordinate pt, PointPairDistance ptDist) {
   if (geom instanceof LineString) {
     computeDistance((LineString) geom, pt, ptDist);
   } else if (geom instanceof Polygon) {
     computeDistance((Polygon) geom, pt, ptDist);
   } else if (geom instanceof GeometryCollection) {
     GeometryCollection gc = (GeometryCollection) geom;
     for (int i = 0; i < gc.getNumGeometries(); i++) {
       Geometry g = gc.getGeometryN(i);
       computeDistance(g, pt, ptDist);
     }
   } else { // assume geom is Point
     ptDist.setMinimum(geom.getCoordinate(), pt);
   }
 }
Example #4
0
  private GeometryCollection editGeometryCollection(
      GeometryCollection collection, GeometryEditorOperation operation) {
    // first edit the entire collection
    // MD - not sure why this is done - could just check original collection?
    GeometryCollection collectionForType = (GeometryCollection) operation.edit(collection, factory);

    // edit the component geometries
    ArrayList geometries = new ArrayList();
    for (int i = 0; i < collectionForType.getNumGeometries(); i++) {
      Geometry geometry = edit(collectionForType.getGeometryN(i), operation);
      if (geometry == null || geometry.isEmpty()) {
        continue;
      }
      geometries.add(geometry);
    }

    if (collectionForType.getClass() == MultiPoint.class) {
      return factory.createMultiPoint((Point[]) geometries.toArray(new Point[] {}));
    }
    if (collectionForType.getClass() == MultiLineString.class) {
      return factory.createMultiLineString((LineString[]) geometries.toArray(new LineString[] {}));
    }
    if (collectionForType.getClass() == MultiPolygon.class) {
      return factory.createMultiPolygon((Polygon[]) geometries.toArray(new Polygon[] {}));
    }
    return factory.createGeometryCollection((Geometry[]) geometries.toArray(new Geometry[] {}));
  }