Beispiel #1
0
    public final Geometry edit(Geometry geometry, GeometryFactory factory) {
      if (geometry instanceof LinearRing) {
        return factory.createLinearRing(edit(geometry.getCoordinates(), geometry));
      }

      if (geometry instanceof LineString) {
        return factory.createLineString(edit(geometry.getCoordinates(), geometry));
      }

      if (geometry instanceof Point) {
        Coordinate[] newCoordinates = edit(geometry.getCoordinates(), geometry);

        return factory.createPoint((newCoordinates.length > 0) ? newCoordinates[0] : null);
      }

      return geometry;
    }
  /**
   * Returns: <br>
   * 2 for 2d (default) <br>
   * 4 for 3d - one of the oordinates has a non-NaN z value <br>
   * (3 is for x,y,m but thats not supported yet) <br>
   *
   * @param g geometry to test - looks at 1st coordinate
   */
  public int guessCoorinateDims(Geometry g) {
    Coordinate[] cs = g.getCoordinates();

    for (int t = 0; t < cs.length; t++) {
      if (!(Double.isNaN(cs[t].z))) {
        return 4;
      }
    }

    return 2;
  }
  public void write(Geometry geometry, EndianDataOutputStream file) throws IOException {
    if (geometry.isEmpty()) {
      file.writeIntLE(0);
      return;
    }
    file.writeIntLE(getShapeType());
    Coordinate c = geometry.getCoordinates()[0];
    file.writeDoubleLE(c.x);
    file.writeDoubleLE(c.y);

    if (myShapeType == 11) {
      if (Double.isNaN(c.z)) // nan means not defined
      file.writeDoubleLE(0.0);
      else file.writeDoubleLE(c.z);
    }
    if ((myShapeType == 11) || (myShapeType == 21)) {
      file.writeDoubleLE(-10E40); // M
    }
  }