Java Code Examples for com.vividsolutions.jts.geom.Geometry#getCoordinate()

The following examples show how to use com.vividsolutions.jts.geom.Geometry#getCoordinate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractIndexedLineTest.java    From jts with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void runOffsetTest(String inputWKT,
      String testPtWKT, double offsetDistance, String expectedPtWKT)
//        throws Exception
    {
      Geometry input = read(inputWKT);
      Geometry testPoint = read(testPtWKT);
      Geometry expectedPoint = read(expectedPtWKT);
      Coordinate testPt = testPoint.getCoordinate();
      Coordinate expectedPt = expectedPoint.getCoordinate();
      Coordinate offsetPt = extractOffsetAt(input, testPt, offsetDistance);
      
      boolean isOk = offsetPt.distance(expectedPt) < TOLERANCE_DIST;
      if (! isOk)
        System.out.println("Expected = " + expectedPoint + "  Actual = " + offsetPt);
      assertTrue(isOk);
    }
 
Example 2
Source File: GeoUtil.java    From fiware-cepheus with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Transform a Geometry to NGSI location coordinates (two comma separated double numbers using point as decimal separator).
 * First number is latitude, second is longitude. Ex: "49.2323, 1.334".
 * @param geometry
 * @return
 */
public static String toNGSIString(Geometry geometry) throws IllegalArgumentException {
    if (geometry instanceof Point) {
        Coordinate coordinate = geometry.getCoordinate();
        return coordinate.getOrdinate(Coordinate.Y) + ", " + coordinate.getOrdinate(Coordinate.X);
    }
    throw new IllegalArgumentException("cannot output geometry, only Point is supported");
}
 
Example 3
Source File: CGAlgorithmFunctions.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static int orientationIndex(Geometry segment, Geometry ptGeom) {
  if (segment.getNumPoints() != 2 || ptGeom.getNumPoints() != 1) {
    throw new IllegalArgumentException("A must have two points and B must have one");
  }
  Coordinate[] segPt = segment.getCoordinates();
  
  Coordinate p = ptGeom.getCoordinate();
  int index = CGAlgorithms.orientationIndex(segPt[0], segPt[1], p);
  return index;
}
 
Example 4
Source File: CGAlgorithmFunctions.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static int orientationIndexDD(Geometry segment, Geometry ptGeom) {
  if (segment.getNumPoints() != 2 || ptGeom.getNumPoints() != 1) {
    throw new IllegalArgumentException("A must have two points and B must have one");
  }
  Coordinate[] segPt = segment.getCoordinates();
  
  Coordinate p = ptGeom.getCoordinate();
  int index = CGAlgorithmsDD.orientationIndex(segPt[0], segPt[1], p);
  return index;
}
 
Example 5
Source File: AbstractIndexedLineTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void runIndexOfAfterTest(String inputStr,
      String testPtWKT)
//        throws Exception
    {
      Geometry input = read(inputStr);
      Geometry testPoint = read(testPtWKT);
      Coordinate testPt = testPoint.getCoordinate();
      boolean resultOK = indexOfAfterCheck(input, testPt);
      assertTrue(resultOK);
    }
 
Example 6
Source File: AbstractIndexedLineTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void runIndexOfAfterTest(String inputStr,
      String testPtWKT, String afterPtWKT)
//        throws Exception
    {
      Geometry input = read(inputStr);
      Geometry testPoint = read(testPtWKT);
      Coordinate testPt = testPoint.getCoordinate();
      Geometry afterPoint = read(afterPtWKT);
      Coordinate afterPt = afterPoint.getCoordinate();
      boolean resultOK = indexOfAfterCheck(input, testPt, afterPt);
      assertTrue(resultOK);
    }
 
Example 7
Source File: WKTReaderExpTest.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void readGoodCheckCoordinate(String wkt, double x, double y)
    throws IOException, ParseException
{
  Geometry g = rdr.read(wkt);
  Coordinate pt = g.getCoordinate();
  assertEquals(pt.x, x, 0.0001);
  assertEquals(pt.y, y, 0.0001);
}
 
Example 8
Source File: GamaPoint.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see msi.gama.common.interfaces.IGeometry#setInnerGeometry(com.vividsolutions.jts.geom.Geometry)
 */
@Override
public void setInnerGeometry(final Geometry point) {
	final Coordinate p = point.getCoordinate();
	setLocation(p.x, p.y, p.z);
}