Exemplo n.º 1
0
  public void write(WriteBufferManager buffer, Object geometry) throws IOException {
    MultiLineString multi = (MultiLineString) geometry;

    Envelope box = multi.getEnvelopeInternal();
    buffer.putDouble(box.getMinX());
    buffer.putDouble(box.getMinY());
    buffer.putDouble(box.getMaxX());
    buffer.putDouble(box.getMaxY());

    int numParts = multi.getNumGeometries();

    buffer.putInt(numParts);
    int npoints = multi.getNumPoints();
    buffer.putInt(npoints);

    LineString[] lines = new LineString[numParts];
    int idx = 0;

    for (int i = 0; i < numParts; i++) {
      lines[i] = (LineString) multi.getGeometryN(i);
      buffer.putInt(idx);
      idx = idx + lines[i].getNumPoints();
    }

    Coordinate[] coords = multi.getCoordinates();

    for (int t = 0; t < npoints; t++) {
      buffer.putDouble(coords[t].x);
      buffer.putDouble(coords[t].y);
    }

    if (shapeType == ShapeType.ARCZ) {
      double[] zExtreame = JTSUtilities.zMinMax(coords);

      if (Double.isNaN(zExtreame[0])) {
        buffer.putDouble(0.0);
        buffer.putDouble(0.0);
      } else {
        buffer.putDouble(zExtreame[0]);
        buffer.putDouble(zExtreame[1]);
      }

      for (int t = 0; t < npoints; t++) {
        double z = coords[t].z;

        if (Double.isNaN(z)) {
          buffer.putDouble(0.0);
        } else {
          buffer.putDouble(z);
        }
      }
    }

    if (shapeType == ShapeType.ARCZ) {
      buffer.putDouble(-10E40);
      buffer.putDouble(-10E40);

      for (int t = 0; t < npoints; t++) {
        buffer.putDouble(-10E40);
      }
    }
  }