/** * Constructs a position initialized to the same values than the specified point. * * @param point The position to copy. * @since 2.2 */ public GeneralDirectPosition(final DirectPosition point) { ordinates = point.getCoordinate(); // Should already be cloned. crs = point.getCoordinateReferenceSystem(); }
/** * Returns the LINESTRING representation in WKT. * * @return WKT format. */ public String toString() { String wkt = ""; for (int i = 0; i < vertices.length; i++) { wkt = wkt + vertices[i].getCoordinate()[0] + " " + vertices[i].getCoordinate()[1]; if (i != (vertices.length - 1)) { wkt = wkt + ", "; } } return "LINESTRING (" + wkt + ")"; }
/** * Test the Quadrilateral if it is a convex polygon. * * @return whether the diagonals intersects */ public boolean isConvex() { return Line2D.linesIntersect( p0.getCoordinate()[0], p0.getCoordinate()[1], p2.getCoordinate()[0], p2.getCoordinate()[1], p1.getCoordinate()[0], p1.getCoordinate()[1], p3.getCoordinate()[0], p3.getCoordinate()[1]); }
/** * Returns reduced coordinates of vertices so the first vertex has [0,0] coordinats. * * @return The List of reduced vertives */ protected List<DirectPosition> reduce() { // Coordinate[] redCoords = new Coordinate[coordinates.length]; ArrayList<DirectPosition> redCoords = new ArrayList<DirectPosition>(); for (int i = 0; i < vertices.length; i++) { redCoords.add( new DirectPosition2D( vertices[i].getCoordinateReferenceSystem(), vertices[i].getCoordinate()[0] - vertices[0].getCoordinate()[0], vertices[i].getCoordinate()[1] - vertices[0].getCoordinate()[1])); } return redCoords; }
/** * Enlarge the polygon using homothetic transformation method. * * @param scale of enlargement (when scale = 1 then polygon stays unchanged) */ protected void enlarge(double scale) { double sumX = 0; double sumY = 0; for (int i = 0; i < vertices.length; i++) { sumX = sumX + vertices[i].getCoordinate()[0]; sumY = sumY + vertices[i].getCoordinate()[1]; } // The center of polygon is calculated. sumX = sumX / vertices.length; sumY = sumY / vertices.length; // The homothetic transformation is made. for (int i = 0; i < vertices.length; i++) { vertices[i].getCoordinate()[0] = (scale * (vertices[i].getCoordinate()[0] - sumX)) + sumX; vertices[i].getCoordinate()[1] = (scale * (vertices[i].getCoordinate()[1] - sumY)) + sumY; } }
public MockDirectPosition(DirectPosition position) { assert position.getCoordinateReferenceSystem() == crs; coordinates = position.getCoordinate(); }
/** * Generates GeneralPath from the array of points. * * @param points vertices of polygon. * @return generated GeneralPath. */ protected GeneralPath generateGeneralPath(DirectPosition[] points) { GeneralPath ring = new GeneralPath(); // Set the initiakl coordinates of the general Path ring.moveTo((float) points[0].getCoordinate()[0], (float) points[0].getCoordinate()[1]); // Create the star. Note: this does not draw the star. for (int i = 1; i < points.length; i++) { ring.lineTo((float) points[i].getCoordinate()[0], (float) points[i].getCoordinate()[1]); } return ring; }
/** * Returns the CircumCicle of the this TINTriangle. * * @return Returns the CircumCicle of the this TINTriangle */ protected Circle getCircumCicle() { // DirectPosition center = new DirectPosition2D(); List<DirectPosition> reducedVertices = reduce(); CoordinateReferenceSystem crs = ((DirectPosition) reducedVertices.get(1)).getCoordinateReferenceSystem(); double x1 = ((DirectPosition) reducedVertices.get(1)).getCoordinate()[0]; double y1 = ((DirectPosition) reducedVertices.get(1)).getCoordinate()[1]; double x2 = ((DirectPosition) reducedVertices.get(2)).getCoordinate()[0]; double y2 = ((DirectPosition) reducedVertices.get(2)).getCoordinate()[1]; // Calculation of Circumcicle center double t = (0.5 * (((x1 * x1) + (y1 * y1)) - (x1 * x2) - (y1 * y2))) / ((y1 * x2) - (x1 * y2)); // t = Math.abs(t); DirectPosition2D center = new DirectPosition2D( crs, (x2 / 2) - (t * y2) + p0.getCoordinate()[0], (y2 / 2) + (t * x2) + p0.getCoordinate()[1]); return new Circle(center.getDirectPosition(), center.distance(new DirectPosition2D(p0))); }
double[] minCP = envelope.getLowerCorner().getCoordinate(); double[] maxCP = new double[] {
public Point createPoint(Position position) throws MismatchedReferenceSystemException, MismatchedDimensionException { if (position == null) { throw new NullPointerException(); } setCoordinateReferenceSystem(position.getDirectPosition().getCoordinateReferenceSystem()); DirectPosition copy = (DirectPosition) getPositionFactory() .createDirectPosition(position.getDirectPosition().getCoordinate()); return getPrimitiveFactory().createPoint(copy); }
public Element encode(Object object, Document document, Element value) throws Exception { DirectPosition dp = (DirectPosition) object; if (dp == null) { value.appendChild( document.createElementNS( GML.NAMESPACE, org.geotools.gml3.GML.Null.getLocalPart())); } double[] coordinates = dp.getCoordinate(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < coordinates.length; i++) { sb.append(String.valueOf(coordinates[i])); if (i != (coordinates.length - 1)) { sb.append(" "); } } value.appendChild(document.createTextNode(sb.toString())); return null; }
/** Fills A matrix for m = (A<sup>T</sup>PA)<sup>-1</sup> A<sup>T</sup>Px' equation */ protected void fillAMatrix() { final DirectPosition[] sourcePoints = getSourcePoints(); final DirectPosition[] targetPoints = getTargetPoints(); A = new GeneralMatrix(2 * sourcePoints.length, 8); int numRow = 2 * sourcePoints.length; // fill first half of matrix for (int j = 0; j < ((2 * sourcePoints.length) / 2); j++) { double xs = sourcePoints[j].getCoordinate()[0]; double ys = sourcePoints[j].getCoordinate()[1]; double xd = targetPoints[j].getCoordinate()[0]; A.setRow(j, new double[] {xs, ys, 1, 0, 0, 0, -xd * xs, -xd * ys}); } // fill second half for (int j = numRow / 2; j < numRow; j++) { double xs = sourcePoints[j - (numRow / 2)].getCoordinate()[0]; double ys = sourcePoints[j - (numRow / 2)].getCoordinate()[1]; double yd = targetPoints[j - (numRow / 2)].getCoordinate()[1]; A.setRow(j, new double[] {0, 0, 0, xs, ys, 1, -yd * xs, -yd * ys}); } }
/** * Fills the x matrix by coordinates of source points. * * @return x matrix. */ protected GeneralMatrix getx() { final DirectPosition[] sourcePoints = getSourcePoints(); GeneralMatrix x = new GeneralMatrix(3 * sourcePoints.length, 1); for (int j = 0; j < (x.getNumRow()); j = j + 3) { x.setElement(j, 0, sourcePoints[j / 3].getCoordinate()[0]); x.setElement(j + 1, 0, sourcePoints[j / 3].getCoordinate()[1]); x.setElement(j + 2, 0, sourcePoints[j / 3].getCoordinate()[2]); } return x; }
/** * Fills the x matrix by coordinates of destination points. * * @return the X matrix */ protected GeneralMatrix getX() { final DirectPosition[] sourcePoints = getSourcePoints(); final DirectPosition[] targetPoints = getTargetPoints(); GeneralMatrix X = new GeneralMatrix(3 * sourcePoints.length, 1); for (int j = 0; j < (X.getNumRow()); j = j + 3) { X.setElement(j, 0, targetPoints[j / 3].getCoordinate()[0]); X.setElement(j + 1, 0, targetPoints[j / 3].getCoordinate()[1]); X.setElement(j + 2, 0, targetPoints[j / 3].getCoordinate()[2]); } return X; }
/** Fills x' matrix for m = (A<sup>T</sup>PA)<sup>-1</sup> A<sup>T</sup>Px' equation */ protected void fillXMatrix() { X = new GeneralMatrix(2 * getTargetPoints().length, 1); int numRow = X.getNumRow(); // Creates X matrix for (int j = 0; j < (numRow / 2); j++) { X.setElement(j, 0, getTargetPoints()[j].getCoordinate()[0]); } for (int j = numRow / 2; j < numRow; j++) { X.setElement(j, 0, getTargetPoints()[j - (numRow / 2)].getCoordinate()[1]); } }
/** * Test expected values against transformed values. * * @param mt mathTransform that will be tested * @param pts MappedPositions of source and target values. */ private void transformTest(MathTransform mt, List<MappedPosition> pts) throws FactoryException, TransformException { double[] points = new double[pts.size() * 2]; double[] ptCalculated = new double[pts.size() * 2]; for (int i = 0; i < pts.size(); i++) { points[(2 * i)] = pts.get(i).getSource().getCoordinate()[0]; points[(2 * i) + 1] = pts.get(i).getSource().getCoordinate()[1]; } mt.transform(points, 0, ptCalculated, 0, pts.size()); for (int i = 0; i < pts.size(); i++) { assertEquals(pts.get(i).getTarget().getCoordinate()[0], ptCalculated[2 * i], 0.001); assertEquals( pts.get(i).getTarget().getCoordinate()[1], ptCalculated[(2 * i) + 1], 0.001); } }
private Ring processBoundsToRing(Envelope bounds, LineSegment segment, final int D) { DirectPosition one = getPositionFactory().createDirectPosition(segment.getStartPoint().getCoordinate()); one.setOrdinate(D, bounds.getMinimum(D)); DirectPosition two = getPositionFactory().createDirectPosition(segment.getEndPoint().getCoordinate()); two.setOrdinate(D, bounds.getMinimum(D)); DirectPosition three = getPositionFactory().createDirectPosition(two.getCoordinate()); three.setOrdinate(D, bounds.getMaximum(D)); DirectPosition four = getPositionFactory().createDirectPosition(one.getCoordinate()); four.setOrdinate(D, bounds.getMaximum(D)); LineSegment edge1 = getGeometryFactory().createLineSegment(one, two); LineSegment edge2 = getGeometryFactory().createLineSegment(two, three); LineSegment edge3 = getGeometryFactory().createLineSegment(three, four); LineSegment edge4 = getGeometryFactory().createLineSegment(four, one); List<OrientableCurve> edges = new ArrayList<OrientableCurve>(); edges.add(createCurve(Arrays.asList(edge1))); edges.add(createCurve(Arrays.asList(edge2))); edges.add(createCurve(Arrays.asList(edge3))); edges.add(createCurve(Arrays.asList(edge4))); return createRing(edges); }
/** * Print the specified point to the specified table. This helper method is for use by {@link * #printPts}. * * @param point The point to print, or {@code null} if none. * @throws IOException if an error occured while writting to the output stream. */ private void print(final DirectPosition point, final TableWriter table) throws IOException { if (point != null) { table.nextColumn(); table.write(" ("); final double[] coords = point.getCoordinate(); for (int i = 0; i < coords.length; i++) { if (i != 0) { table.write(", "); } table.nextColumn(); table.write(numberFormat.format(coords[i])); } table.write(')'); } }
/** Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}. */ public DirectPosition transform(final DirectPosition ptSrc, DirectPosition ptDst) { if (ptDst == null) { ptDst = new GeneralDirectPosition(2); } else { final int dimension = ptDst.getDimension(); if (dimension != 2) { throw new MismatchedDimensionException( Errors.format(ErrorKeys.MISMATCHED_DIMENSION_$3, "ptDst", dimension, 2)); } } final double[] array = ptSrc.getCoordinate(); transform(array, 0, array, 0, 1); ptDst.setOrdinate(0, array[0]); ptDst.setOrdinate(1, array[1]); return ptDst; }
@Test public void testMBTilesMetaData() throws Exception { try (MBTilesFile file = new MBTilesFile(dbfile); ) { MBTilesMetadata metadata2 = file.loadMetaData(); assertEquals("osm2vectortiles", metadata2.getName()); assertEquals("Extract from http://osm2vectortiles.org", metadata2.getDescription()); assertEquals("2.0", metadata2.getVersion()); metadata2.getBounds().getLowerCorner().getCoordinate(); double delta = 0.0001; assertEquals(-180.0, metadata2.getBounds().getLowerCorner().getOrdinate(0), delta); assertEquals(180.0, metadata2.getBounds().getUpperCorner().getOrdinate(0), delta); assertEquals(-85.0511, metadata2.getBounds().getLowerCorner().getOrdinate(1), delta); assertEquals(85.0511, metadata2.getBounds().getUpperCorner().getOrdinate(1), delta); assertEquals( CRS.decode("EPSG:4326", true), metadata2.getBounds().getCoordinateReferenceSystem()); assertEquals(t_format.PBF, metadata2.getFormat()); assertEquals(t_type.BASE_LAYER, metadata2.getType()); assertEquals(0, metadata2.getMinZoom()); assertEquals(5, metadata2.getMaxZoom()); } }