예제 #1
0
  /**
   * Adds a mitre join connecting the two reflex offset segments. The mitre will be beveled if it
   * exceeds the mitre ratio limit.
   *
   * @param offset0 the first offset segment
   * @param offset1 the second offset segment
   * @param distance the offset distance
   */
  private void addMitreJoin(
      final Coordinate p,
      final LineSegment offset0,
      final LineSegment offset1,
      final double distance) {
    boolean isMitreWithinLimit = true;
    Coordinate intPt = null;

    /**
     * This computation is unstable if the offset segments are nearly collinear. Howver, this
     * situation should have been eliminated earlier by the check for whether the offset segment
     * endpoints are almost coincident
     */
    try {
      intPt = HCoordinate.intersection(offset0.p0, offset0.p1, offset1.p0, offset1.p1);

      final double mitreRatio = distance <= 0.0 ? 1.0 : intPt.distance(p) / Math.abs(distance);

      if (mitreRatio > m_bufferParams.getMitreLimit()) isMitreWithinLimit = false;
    } catch (final NotRepresentableException ex) {
      intPt = new Coordinate(0, 0);
      isMitreWithinLimit = false;
    }

    if (isMitreWithinLimit) {
      m_bufferBuilder.addVertices(intPt);
    } else {
      addLimitedMitreJoin(distance, m_bufferParams.getMitreLimit());
    }
  }
 @Test
 public void testGetCoordinateCopy() throws Exception {
   // geom independance: changing returned coordinate does not change sequence.
   Coordinate co = testSeq2D.getCoordinateCopy(1);
   co.x = co.x + 1;
   assertFalse(co.equals(testSeq2D.getCoordinateCopy(1)));
 }
예제 #3
0
  /**
   * Extract the coordinate of a FeatureCollection in a HashMap with an ID as a key.
   *
   * @param nStaz
   * @param collection
   * @throws Exception if a fiel of elevation isn't the same of the collection
   */
  private LinkedHashMap<Integer, Coordinate> getCoordinate(
      int nStaz, SimpleFeatureCollection collection, String idField) throws Exception {
    LinkedHashMap<Integer, Coordinate> id2CoordinatesMap = new LinkedHashMap<Integer, Coordinate>();
    FeatureIterator<SimpleFeature> iterator = collection.features();
    Coordinate coordinate = null;
    try {
      while (iterator.hasNext()) {
        SimpleFeature feature = iterator.next();
        int name = ((Number) feature.getAttribute(idField)).intValue();
        coordinate = ((Geometry) feature.getDefaultGeometry()).getCentroid().getCoordinate();
        double z = 0;
        if (fPointZ != null) {
          try {
            z = ((Number) feature.getAttribute(fPointZ)).doubleValue();
          } catch (NullPointerException e) {
            pm.errorMessage(msg.message("kriging.noPointZ"));
            throw new Exception(msg.message("kriging.noPointZ"));
          }
        }
        coordinate.z = z;
        id2CoordinatesMap.put(name, coordinate);
      }
    } finally {
      iterator.close();
    }

    return id2CoordinatesMap;
  }
예제 #4
0
 /** Returns a copy of the instance of the class. */
 @Override
 public Infestation clone() {
   Infestation occ = new Infestation();
   occ.ageOfInfestation = ageOfInfestation;
   if (disperser != null) {
     occ.disperser = disperser.clone();
   }
   occ.infested = infested;
   occ.stageOfInfestation = stageOfInfestation;
   occ.maxInfestation = maxInfestation;
   occ.maxControl = maxControl;
   occ.wasControlled = wasControlled;
   occ.wasInfested = wasInfested;
   occ.species = species;
   occ.parent = parent;
   occ.freezeManagement = freezeManagement;
   List<Coordinate> propagules_c = new ArrayList<Coordinate>();
   for (Coordinate c : propagules) {
     propagules_c.add((Coordinate) c.clone());
   }
   for (ControlType s : controls.keySet()) {
     occ.controls.put(s, controls.get(s).longValue());
   }
   occ.propagules = propagules_c;
   return occ;
 }
예제 #5
0
  /**
   * Adds points for a circular fillet arc between two specified angles. The start and end point for
   * the fillet are not added - the caller must add them if required.
   *
   * @param direction is -1 for a CW angle, 1 for a CCW angle
   * @param radius the radius of the fillet
   */
  private void addFillet(
      final Coordinate p,
      final double startAngle,
      final double endAngle,
      final int direction,
      final double radius) {
    final int directionFactor = direction == CGAlgorithms.CLOCKWISE ? -1 : 1;

    final double totalAngle = Math.abs(startAngle - endAngle);
    final int nSegs = (int) (totalAngle / m_filletAngleQuantum + 0.5);

    if (nSegs < 1) return; // no segments because angle is less than increment - nothing to do!

    double initAngle, currAngleInc;

    // choose angle increment so that each segment has equal length
    initAngle = 0.0;
    currAngleInc = totalAngle / nSegs;

    double currAngle = initAngle;
    final Coordinate pt = new Coordinate();
    while (currAngle < totalAngle) {
      final double angle = startAngle + directionFactor * currAngle;
      pt.x = p.x + radius * Math.cos(angle);
      pt.y = p.y + radius * Math.sin(angle);
      m_bufferBuilder.addVertices(pt);
      currAngle += currAngleInc;
    }
  }
 static PolygonBuilder mutatePolygonBuilder(PolygonBuilder pb) {
   if (randomBoolean()) {
     pb = polyWithOposingOrientation(pb);
   } else {
     // change either point in shell or in random hole
     LineStringBuilder lineToChange;
     if (randomBoolean() || pb.holes().size() == 0) {
       lineToChange = pb.shell();
     } else {
       lineToChange = randomFrom(pb.holes());
     }
     Coordinate coordinate = randomFrom(lineToChange.coordinates(false));
     if (randomBoolean()) {
       if (coordinate.x != 0.0) {
         coordinate.x = coordinate.x / 2;
       } else {
         coordinate.x = randomDoubleBetween(-180.0, 180.0, true);
       }
     } else {
       if (coordinate.y != 0.0) {
         coordinate.y = coordinate.y / 2;
       } else {
         coordinate.y = randomDoubleBetween(-90.0, 90.0, true);
       }
     }
   }
   return pb;
 }
예제 #7
0
 @Override
 public void getCoordinate(int index, Coordinate coord) {
   Point point = get(index);
   coord.x = point.get0();
   coord.y = point.get1();
   coord.z = point.get2();
 }
예제 #8
0
 @Override
 public boolean equals(final Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null) {
     return false;
   }
   if (getClass() != obj.getClass()) {
     return false;
   }
   final Edge other = (Edge) obj;
   if (end == null) {
     if (other.end != null) {
       return false;
     }
   } else if (!end.equals(other.end)) {
     return false;
   }
   if (start == null) {
     if (other.start != null) {
       return false;
     }
   } else if (!start.equals(other.start)) {
     return false;
   }
   return true;
 }
예제 #9
0
  private LinkedHashMap<Integer, Coordinate> getCoordinate(GridGeometry2D grid) {
    LinkedHashMap<Integer, Coordinate> out = new LinkedHashMap<Integer, Coordinate>();
    int count = 0;
    RegionMap regionMap = CoverageUtilities.gridGeometry2RegionParamsMap(grid);
    cols = regionMap.getCols();
    rows = regionMap.getRows();
    south = regionMap.getSouth();
    west = regionMap.getWest();
    xres = regionMap.getXres();
    yres = regionMap.getYres();

    outWR = CoverageUtilities.createDoubleWritableRaster(cols, rows, null, null, null);

    double northing = south;
    double easting = west;
    for (int i = 0; i < cols; i++) {
      easting = easting + xres;
      for (int j = 0; j < rows; j++) {
        northing = northing + yres;
        Coordinate coordinate = new Coordinate();
        coordinate.x = west + i * xres;
        coordinate.y = south + j * yres;
        out.put(count, coordinate);
        count++;
      }
    }

    return out;
  }
예제 #10
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = (prime * result) + ((end == null) ? 0 : end.hashCode());
   result = (prime * result) + ((start == null) ? 0 : start.hashCode());
   return result;
 }
  public Coordinate projectInverse(double xyx, double xyy, Coordinate out) {
    double c;

    out.y = MapMath.asin(xyy / C_y);
    out.x = xyx / (C_x * ((c = Math.cos(out.y)) - 0.5));
    out.y = MapMath.asin((out.y + Math.sin(out.y) * (c - 1.)) / C_p);
    return out;
  }
예제 #12
0
 /**
  * Forward projects a point.
  *
  * @param lat the latitude of the point to project, in RADIANS
  * @param lat the longitude of the point to project, in RADIANS
  * @param storage a place to store the result
  * @return The projected point. Same object as <code>storage</code>
  */
 protected Coordinate forwardPointRaw(double lon, double lat, Coordinate storage) {
   double sinPhi = StrictMath.sin(lat);
   double cosPhi = StrictMath.cos(lat);
   double kPrime = 1 / (_sinPhi0 * sinPhi + _cosPhi0 * cosPhi * StrictMath.cos(lon - _lambda0));
   storage.x = _a * kPrime * cosPhi * StrictMath.sin(lon - _lambda0);
   storage.y =
       _a * kPrime * (_cosPhi0 * sinPhi - _sinPhi0 * cosPhi * StrictMath.cos(lon - _lambda0));
   return storage;
 }
예제 #13
0
 /**
  * Returns a hash value for this envelope. This value need not remain consistent between different
  * implementations of the same class.
  */
 @Override
 public int hashCode() {
   // Algorithm from Effective Java by Joshua Bloch [Jon Aquino]
   int result = super.hashCode();
   result = 37 * result + Coordinate.hashCode(minz);
   result = 37 * result + Coordinate.hashCode(maxz);
   int code = result ^ (int) serialVersionUID;
   return code;
 }
예제 #14
0
 /**
  * Removes the common coordinate bits from a Geometry. The coordinates of the Geometry are
  * changed.
  *
  * @param geom the Geometry from which to remove the common coordinate bits
  * @return the shifted Geometry
  */
 public Geometry removeCommonBits(Geometry geom) {
   if (commonCoord.x == 0.0 && commonCoord.y == 0.0) return geom;
   Coordinate invCoord = new Coordinate(commonCoord);
   invCoord.x = -invCoord.x;
   invCoord.y = -invCoord.y;
   Translater trans = new Translater(invCoord);
   geom.apply(trans);
   geom.geometryChanged();
   return geom;
 }
예제 #15
0
 @SuppressWarnings("unused")
 private void checkDD(
     Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2, Coordinate intPt) {
   Coordinate intPtDD = CGAlgorithmsDD.intersection(p1, p2, q1, q2);
   boolean isIn = isInSegmentEnvelopes(intPtDD);
   System.out.println("DD in env = " + isIn + "  --------------------- " + intPtDD);
   if (intPt.distance(intPtDD) > 0.0001) {
     System.out.println("Distance = " + intPt.distance(intPtDD));
   }
 }
 @Override
 public void filter(CoordinateSequence seq, int i) {
   Coordinate coord = seq.getCoordinate(i);
   PixelPos pixelPos = geoCoding.getPixelPos(new GeoPos(coord.y, coord.x), null);
   // rounding needed because closed geometries yield errors if their first and last coordinate
   // do not exactly match
   double x = Math.round(pixelPos.x * 10000) / 10000;
   double y = Math.round(pixelPos.y * 10000) / 10000;
   coord.setCoordinate(new Coordinate(x, y));
   count++;
 }
예제 #17
0
  public boolean onToolTouchEvent(MotionEvent event) {
    if (mapView == null || mapView.isClickable()) {
      return false;
    }

    Projection pj = mapView.getProjection();
    // handle drawing
    float currentX = event.getX();
    float currentY = event.getY();
    int deltaPixels = 100;

    int action = event.getAction();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
      case MotionEvent.ACTION_MOVE:
        GeoPoint currentGeoPoint = pj.fromPixels(round(currentX), round(currentY));
        GeoPoint plusPoint =
            pj.fromPixels(round(currentX + deltaPixels), round(currentY + deltaPixels));

        double touchLon = currentGeoPoint.getLongitude();
        double touchLat = currentGeoPoint.getLatitude();
        double lonPlus = plusPoint.getLongitude();
        double latPlus = plusPoint.getLatitude();
        double deltaX = Math.abs(touchLon - lonPlus);
        double deltaY = Math.abs(touchLat - latPlus);
        Coordinate touchCoord = new Coordinate(touchLon, touchLat);
        Envelope queryEnvelope = new Envelope(touchCoord);
        queryEnvelope.expandBy(deltaX, deltaY);

        List<GpsLogInfo> result = gpsLogInfoTree.query(queryEnvelope);
        if (result.size() == 0) {
          return true;
        } else {
          GpsLogInfo nearest = null;
          double minDist = Double.POSITIVE_INFINITY;
          for (GpsLogInfo info : result) {
            double dist = touchCoord.distance(info.pointXYZ);
            if (dist < minDist) {
              minDist = dist;
              nearest = info;
            }
          }
          gpsLogInfo = nearest;
        }
        break;
      case MotionEvent.ACTION_UP:
        gpsLogInfo = null;
        break;
    }
    EditManager.INSTANCE.invalidateEditingView();
    return true;
  }
예제 #18
0
  Geometry toShape(List<LineSegment> path, double h) {
    // TODO: take into account letter alignment
    // turn the path into a single polygon by generating points orthogonal
    // to the individual line segments
    GeomBuilder gb = new GeomBuilder();

    LinkedList<Coordinate> top = new LinkedList<Coordinate>();
    for (int i = 0; i < path.size(); i++) {
      LineSegment seg = path.get(i);
      Coordinate p0 = seg.p0;
      Coordinate p1 = seg.p1;
      double theta = seg.angle();

      gb.points(p0.x, p0.y);

      // generate the perpendicular point at a distance of h
      Coordinate p2 = new Coordinate();

      if (theta > 0) {
        if (theta <= HALFPI) {
          // ne
          double phi = Math.PI - (HALFPI + theta);
          p2.x = (Math.cos(phi) * h - p0.x) * -1;
          p2.y = Math.sin(phi) * h + p0.y;
        } else {
          // nw
          double phi = Math.PI - theta;
          p2.x = Math.cos(phi) * h + p0.x;
          p2.y = Math.sin(phi) * h + p0.y;
        }
      } else {
        theta = Math.abs(theta);
        if (theta < HALFPI) {
          double phi = HALFPI - theta;
          p2.x = (Math.cos(phi) * h + p0.x);
          p2.y = (Math.sin(phi) * h + p0.y);
        } else {
          double phi = theta = HALFPI;
          p2.x = Math.cos(phi) * h + p0.x;
          p2.y = (Math.sin(phi) * h - p0.y) * -1;
        }
      }

      top.add(p2);
      if (i == path.size() - 1) {
        gb.points(p1.x, p1.y);
        top.add(new Coordinate(p1.x + p2.x - p0.x, p1.y + p2.y - p0.y));
      }
    }

    for (Iterator<Coordinate> it = top.descendingIterator(); it.hasNext(); ) {
      Coordinate c = it.next();
      gb.points(c.x, c.y);
    }

    return gb.toPolygon();
  }
 private static Coordinate average(Coordinate[] pts) {
   Coordinate avg = new Coordinate();
   int n = pts.length;
   for (int i = 0; i < pts.length; i++) {
     avg.x += pts[i].x;
     avg.y += pts[i].y;
   }
   if (n > 0) {
     avg.x /= n;
     avg.y /= n;
   }
   return avg;
 }
예제 #20
0
  Coordinate coord(List list) {
    ensureSize(list, 2);

    double x = number(list.get(0));
    double y = number(list.get(1));
    double z = list.size() > 2 ? number(list.get(2)) : Double.NaN;

    Coordinate c = new Coordinate(x, y);
    if (!Double.isNaN(z)) {
      c.z = z;
    }
    return c;
  }
예제 #21
0
 /**
  * Normalize the supplied coordinates so that their minimum ordinate values lie at the origin.
  * NOTE: this normalization technique appears to cause large errors in the position of the
  * intersection point for some cases.
  *
  * @param n1
  * @param n2
  * @param n3
  * @param n4
  * @param normPt
  */
 @SuppressWarnings("unused")
 private void normalizeToMinimum(
     Coordinate n1, Coordinate n2, Coordinate n3, Coordinate n4, Coordinate normPt) {
   normPt.x = smallestInAbsValue(n1.x, n2.x, n3.x, n4.x);
   normPt.y = smallestInAbsValue(n1.y, n2.y, n3.y, n4.y);
   n1.x -= normPt.x;
   n1.y -= normPt.y;
   n2.x -= normPt.x;
   n2.y -= normPt.y;
   n3.x -= normPt.x;
   n3.y -= normPt.y;
   n4.x -= normPt.x;
   n4.y -= normPt.y;
 }
  protected boolean indexOfAfterCheck(Geometry linearGeom, Coordinate testPt) {
    LocationIndexedLine indexedLine = new LocationIndexedLine(linearGeom);

    // check locations are consecutive
    LinearLocation loc1 = indexedLine.indexOf(testPt);
    LinearLocation loc2 = indexedLine.indexOfAfter(testPt, loc1);
    if (loc2.compareTo(loc1) <= 0) return false;

    // check extracted points are the same as the input
    Coordinate pt1 = indexedLine.extractPoint(loc1);
    Coordinate pt2 = indexedLine.extractPoint(loc2);
    if (!pt1.equals2D(testPt)) return false;
    if (!pt2.equals2D(testPt)) return false;

    return true;
  }
예제 #23
0
 @Override
 public int hashCode() {
   final int prime = 31;
   int result = 1;
   result = prime * result + ((coor == null) ? 0 : coor.hashCode());
   return result;
 }
예제 #24
0
 public void computeIntersection(Coordinate p, Coordinate p1, Coordinate p2) {
   isProper = false;
   // do between check first, since it is faster than the orientation test
   if (Envelope.intersects(p1, p2, p)) {
     if ((CGAlgorithms.orientationIndex(p1, p2, p) == 0)
         && (CGAlgorithms.orientationIndex(p2, p1, p) == 0)) {
       isProper = true;
       if (p.equals(p1) || p.equals(p2)) {
         isProper = false;
       }
       result = POINT_INTERSECTION;
       return;
     }
   }
   result = NO_INTERSECTION;
 }
예제 #25
0
  public void findEdge(List dirEdgeList) {
    /**
     * Check all forward DirectedEdges only. This is still general, because each edge has a forward
     * DirectedEdge.
     */
    for (Iterator i = dirEdgeList.iterator(); i.hasNext(); ) {
      DirectedEdge de = (DirectedEdge) i.next();
      if (!de.isForward()) continue;
      checkForRightmostCoordinate(de);
    }

    /**
     * If the rightmost point is a node, we need to identify which of the incident edges is
     * rightmost.
     */
    Assert.isTrue(
        minIndex != 0 || minCoord.equals(minDe.getCoordinate()),
        "inconsistency in rightmost processing");
    if (minIndex == 0) {
      findRightmostEdgeAtNode();
    } else {
      findRightmostEdgeAtVertex();
    }
    /** now check that the extreme side is the R side. If not, use the sym instead. */
    orientedDe = minDe;
    int rightmostSide = getRightmostSide(minDe, minIndex);
    if (rightmostSide == Position.LEFT) {
      orientedDe = minDe.getSym();
    }
  }
예제 #26
0
  private Coordinate intersectionWithNormalization(
      Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) {
    Coordinate n1 = new Coordinate(p1);
    Coordinate n2 = new Coordinate(p2);
    Coordinate n3 = new Coordinate(q1);
    Coordinate n4 = new Coordinate(q2);
    Coordinate normPt = new Coordinate();
    normalizeToEnvCentre(n1, n2, n3, n4, normPt);

    Coordinate intPt = safeHCoordinateIntersection(n1, n2, n3, n4);

    intPt.x += normPt.x;
    intPt.y += normPt.y;

    return intPt;
  }
예제 #27
0
 /**
  * Make sure the network doesn't have any problems
  *
  * @param n - the network to be tested
  */
 static void testNetworkForIssues(Network n) {
   System.out.println("testing");
   for (Object o : n.allNodes) {
     GeoNode node = (GeoNode) o;
     for (Object p : n.getEdgesOut(node)) {
       sim.field.network.Edge e = (sim.field.network.Edge) p;
       LineString ls = (LineString) ((MasonGeometry) e.info).geometry;
       Coordinate c1 = ls.getCoordinateN(0);
       Coordinate c2 = ls.getCoordinateN(ls.getNumPoints() - 1);
       GeoNode g1 = (GeoNode) e.getFrom();
       GeoNode g2 = (GeoNode) e.getTo();
       if (c1.distance(g1.geometry.getCoordinate()) > 1) System.out.println("found you");
       if (c2.distance(g2.geometry.getCoordinate()) > 1) System.out.println("found you");
     }
   }
 }
예제 #28
0
  @Test
  public void toGeometry_Shape_Poly() {
    Shape shape = new Polygon(XPOINTS, YPOINTS, NPOINTS);
    Geometry geom = JTS.toGeometry(shape);
    assertTrue(geom instanceof LinearRing);

    Coordinate[] coords = geom.getCoordinates();
    assertEquals(NPOINTS + 1, coords.length);

    CoordList list = new CoordList(coords);
    Coordinate c = new Coordinate();
    for (int i = 0; i < NPOINTS; i++) {
      c.x = XPOINTS[i];
      c.y = YPOINTS[i];
      assertTrue(list.contains(c));
    }
  }
예제 #29
0
  /**
   * Get the stacked point closest to the provided coordinate
   *
   * @param result
   * @param coordinate
   * @param i
   * @param j
   */
  private SimpleFeature getResultPoint(SimpleFeatureCollection result, Coordinate testPt) {
    /** Find closest point to loc pt, then check that the attributes match */
    double minDist = Double.MAX_VALUE;

    // find nearest result to testPt
    SimpleFeature closest = null;
    for (SimpleFeatureIterator it = result.features(); it.hasNext(); ) {
      SimpleFeature f = it.next();
      Coordinate outPt = ((Point) f.getDefaultGeometry()).getCoordinate();
      double dist = outPt.distance(testPt);
      if (dist < minDist) {
        closest = f;
        minDist = dist;
      }
    }

    return closest;
  }
예제 #30
0
  /**
   * Added this test after a bug was reported in JTS.transform for converting between WGS84 (2D) and
   * DefaultGeocentric.CARTESIAN (3D).
   */
  @Test
  public void transformCoordinate2DCRSTo3D() throws Exception {
    CoordinateReferenceSystem srcCRS = DefaultGeographicCRS.WGS84;
    CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN;
    MathTransform transform = CRS.findMathTransform(srcCRS, targetCRS);

    Coordinate srcCoord = new Coordinate(0, 0);
    Coordinate dest0 = JTS.transform(srcCoord, null, transform);

    srcCoord.x = 180;
    Coordinate dest180 = JTS.transform(srcCoord, null, transform);

    // Only a perfunctory check on the return values - mostly we
    // just wanted to make sure there was no exception
    assertEquals(dest0.x, -dest180.x, TOL);
    assertEquals(dest0.y, dest180.y, TOL);
    assertEquals(dest0.z, dest180.z, TOL);
  }