public void testPoint1() throws Exception { String WKT = "POINT (80 340)"; Object geometry = parser.parse(WKT); assertNotNull(geometry); assertTrue(geometry instanceof Point); Point point = (Point) geometry; assertNotNull(point.getDirectPosition()); assertEquals(80, point.getDirectPosition().getOrdinate(0), 0.0); assertEquals(340, point.getDirectPosition().getOrdinate(1), 0.0); }
public void testPoint2() throws Exception { String WKT = "POINT (320.324 180.234)"; Object geometry = parser.parse(WKT); assertNotNull(geometry); assertTrue(geometry instanceof Point); Point point = (Point) geometry; assertEquals(320.324, point.getDirectPosition().getOrdinate(0), 0.0); assertEquals(180.234, point.getDirectPosition().getOrdinate(1), 0.0); }
public void testPoint3() throws Exception { String WKT = "POINT (260.01 -360.55)"; Object geometry = parser.parse(WKT); assertNotNull(geometry); assertTrue(geometry instanceof Point); Point point = (Point) geometry; assertEquals(260.01, point.getDirectPosition().getOrdinate(0), 0.0); assertEquals(-360.55, point.getDirectPosition().getOrdinate(1), 0.0); }
/** * Converts a list of points into a geotools-based bounding box. * * @param points List of points, should only include the 'upper-left' and 'lower-right' points in that order. * Code will not look at any other points that are passed in. * @return BoundingBox if transformation works, null otherwise. */ public static BoundingBox pointsToBBox(List<org.opengis.geometry.primitive.Point> points) { BoundingBox bbox = null; if (!points.isEmpty()) { org.opengis.geometry.primitive.Point point1 = points.get( 0 ); org.opengis.geometry.primitive.Point point2 = points.get( 1 ); bbox = new ReferencedEnvelope(point1.getDirectPosition().getCoordinate()[0], point2.getDirectPosition().getCoordinate()[0], point1.getDirectPosition().getCoordinate()[1], point2.getDirectPosition().getCoordinate()[1], DefaultGeographicCRS.WGS84 ); } return bbox; }
/** * Converts a point to a WKT-based string. * * @param point Point to convert to WKT. * @return WKT String. */ public static String pointToWKT(org.opengis.geometry.primitive.Point point) { return JTS.toGeometry(point.getDirectPosition()).toText(); }
@Test public void testNewEmptyPoint() { Point point = new JTSPoint(); assertNotNull(point.getCoordinateReferenceSystem()); DirectPosition position = point.getDirectPosition(); assertNotNull(position); }
@Test public void testNewPointHere() { DirectPosition here = new GeneralDirectPosition(CommonCRS.WGS84.normalizedGeographic()); here.setOrdinate(0, 48.44); here.setOrdinate(1, -123.37); // 48.44,-123.37 Point point = new JTSPoint(here); assertNotNull(point.getCoordinateReferenceSystem()); assertEquals(here.getCoordinateReferenceSystem(), point .getCoordinateReferenceSystem()); assertEquals(here, point.getDirectPosition()); assertEquals(here.hashCode(), point.getDirectPosition().hashCode()); }
@Test public void testNewFactoryPointHere() { PositionFactory gFact = new JTSPositionFactory( CommonCRS.WGS84.normalizedGeographic()); double[] ords = { 48.44, -123.37 }; DirectPosition here = gFact.createDirectPosition(ords); Point point = new JTSPoint(here); assertNotNull(point.getCoordinateReferenceSystem()); assertEquals(here.getCoordinateReferenceSystem(), point .getCoordinateReferenceSystem()); assertEquals(here, point.getDirectPosition()); assertEquals(here.hashCode(), point.getDirectPosition().hashCode()); }
@Test public void testWSG843DPoint(){ // Do actually test stuff double[] ords = { 48.44, -123.37, 0.0 }; PositionFactory factory = new JTSPositionFactory(AbstractCRS.castOrCopy(CommonCRS.WGS84.geographic3D()).forConvention(AxesConvention.RIGHT_HANDED)); assertNotNull(factory); DirectPosition here = factory.createDirectPosition(ords); Point point = new JTSPoint(here); assertNotNull(point.getCoordinateReferenceSystem()); assertEquals(here.getCoordinateReferenceSystem(), point .getCoordinateReferenceSystem()); assertEquals(here, point.getDirectPosition()); assertEquals(here.hashCode(), point.getDirectPosition().hashCode()); }