private int estimateLineString(LineString geom) {
   if (geom == null || geom.getNumGeometries() == 0) {
     return 0;
   } else {
     return 4
         + 8
             * getCoordSequenceDim(geom.getCoordinateSequence())
             * geom.getCoordinateSequence().size();
   }
 }
Ejemplo n.º 2
0
  Map<String, Object> createLine(LineString line) {
    LinkedHashMap obj = new LinkedHashMap();

    obj.put("type", "LineString");
    obj.put("coordinates", new CoordinateSequenceEncoder(line.getCoordinateSequence(), scale));
    return obj;
  }
Ejemplo n.º 3
0
  /**
   * Converts a JTS {@link Polygon}, which represents a ROI, int an AWT {@link java.awt.Polygon} by
   * means of the provided {@link MathTransform}.
   *
   * <p>It also stores the points for this polygon into the provided {@link List}.
   *
   * @param roiInput the input ROI as a JTS {@link Polygon}.
   * @param worldToGridTransform the {@link MathTransform} to apply to the input ROI.
   * @param points a {@link List} that should hold the transformed points.
   * @return an AWT {@link java.awt.Polygon}.
   * @throws TransformException in case the provided {@link MathTransform} chokes.
   */
  public static java.awt.Polygon convertPolygonToPointArray(
      final Polygon roiInput, MathTransform worldToGridTransform, List<Point2D> points)
      throws TransformException {
    final boolean isIdentity = worldToGridTransform.isIdentity();
    final double coords[] = new double[2];
    final LineString exteriorRing = roiInput.getExteriorRing();
    final CoordinateSequence exteriorRingCS = exteriorRing.getCoordinateSequence();
    final int numCoords = exteriorRingCS.size();
    final java.awt.Polygon retValue = new java.awt.Polygon();
    for (int i = 0; i < numCoords; i++) {
      // get the actual coord
      coords[0] = exteriorRingCS.getX(i);
      coords[1] = exteriorRingCS.getY(i);

      // transform it
      if (!isIdentity) worldToGridTransform.transform(coords, 0, coords, 0, 1);

      // send it back to the returned polygon
      final int x = (int) (coords[0] + 0.5d);
      final int y = (int) (coords[1] + 0.5d);
      if (points != null) points.add(new Point2D.Double(coords[0], coords[1]));

      // send it back to the returned polygon
      retValue.addPoint(x, y);
    }

    // return the created polygon.
    return retValue;
  }
Ejemplo n.º 4
0
  /** decimates JTS geometries. */
  public final Geometry decimate(Geometry geom) {
    GeometryFactory gFac = new GeometryFactory(geom.getPrecisionModel(), geom.getSRID());
    if (spanx == -1) return geom;
    if (geom instanceof MultiPoint) {
      // TODO check geometry and if its bbox is too small turn it into a 1
      // point geom
      return geom;
    }
    if (geom instanceof GeometryCollection) {
      // TODO check geometry and if its bbox is too small turn it into a
      // 1-2 point geom
      // takes a bit of work because the geometry will need to be
      // recreated.
      GeometryCollection collection = (GeometryCollection) geom;
      Geometry[] result = new Geometry[collection.getDimension()];
      final int numGeometries = collection.getNumGeometries();
      for (int i = 0; i < numGeometries; i++) {
        result[i] = decimate(collection.getGeometryN(i));
      }
      return gFac.createGeometryCollection(result);

    } else if (geom instanceof LineString) {
      LineString line = (LineString) geom;
      CoordinateSequence seq = (CoordinateSequence) line.getCoordinateSequence();
      LiteCoordinateSequence lseq = new LiteCoordinateSequence(seq.toCoordinateArray());

      if (decimateOnEnvelope(line, lseq)) {
        if (lseq.size() >= 2) return gFac.createLineString(lseq);
      }
      if (lseq.size() >= 2) return gFac.createLineString(decimate(lseq));
      return null;
    } else if (geom instanceof Polygon) {
      Polygon line = (Polygon) geom;
      Coordinate[] exterior = decimate(line.getExteriorRing()).getCoordinates();
      forceClosed(exterior);
      if (exterior.length > 3) {
        LinearRing ring = gFac.createLinearRing(exterior);

        final int numRings = line.getNumInteriorRing();
        List<LinearRing> rings = new ArrayList<LinearRing>();

        for (int i = 0; i < numRings; i++) {
          Coordinate[] interior = decimate(line.getInteriorRingN(i)).getCoordinates();
          forceClosed(interior);
          if (interior.length > 3) rings.add(gFac.createLinearRing(interior));
        }
        return gFac.createPolygon(ring, rings.toArray(new LinearRing[] {}));
      }
      return null;
    }
    return geom;
  }
  static DirectPosition[] positions(LineString line) {
    CoordinateSequence coordinates = line.getCoordinateSequence();
    DirectPosition[] dps = new DirectPosition[coordinates.size()];

    double x;
    double y;

    for (int i = 0; i < dps.length; i++) {
      x = coordinates.getOrdinate(i, 0);
      y = coordinates.getOrdinate(i, 1);
      dps[i] = new DirectPosition2D(x, y);
    }

    return dps;
  }
Ejemplo n.º 6
0
  public Geometry densify(double segLength) {
    newCoords = new CoordinateList();

    CoordinateSequence seq = inputLine.getCoordinateSequence();

    Coordinate p0 = new Coordinate();
    Coordinate p1 = new Coordinate();
    seq.getCoordinate(0, p0);
    newCoords.add(new Coordinate(p0));

    for (int i = 0; i < seq.size() - 1; i++) {
      seq.getCoordinate(i, p0);
      seq.getCoordinate(i + 1, p1);
      densify(p0, p1, segLength);
    }
    Coordinate[] newPts = newCoords.toCoordinateArray();
    return inputLine.getFactory().createLineString(newPts);
  }
Ejemplo n.º 7
0
  /**
   * @param ls
   * @param at
   * @param generalize
   * @param maxDistance
   * @return
   */
  private void _init(LineString ls, AffineTransform at, boolean generalize, float maxDistance) {
    if (at == null) {
      at = NO_TRANSFORM;
    }

    this.at = at;
    coordinates = ls.getCoordinateSequence();
    coordinateCount = coordinates.size();
    isClosed = ls instanceof LinearRing;

    this.generalize = generalize;
    this.maxDistance = maxDistance;
    done = false;
    currentCoord = 0;

    oldX = Float.NaN;
    oldY = Float.NaN;
  }
 private void writeLineString(LineString geom, ValueSetter dest) {
   dest.setInt(geom.getNumPoints());
   writeCoordinates(geom.getCoordinateSequence(), getCoordDim(geom), dest);
 }
Ejemplo n.º 9
0
 /**
  * Transforms a {@link LineString} geometry.
  *
  * @param geom
  * @param parent
  * @return
  */
 protected Geometry transformLineString(LineString geom, Geometry parent) {
   // should check for 1-point sequences and downgrade them to points
   return factory.createLineString(transformCoordinates(geom.getCoordinateSequence(), geom));
 }