/** * Returns the starting position in user coordinates, which doesn't need to be geographic. The * coordinate reference system is the one specified to the {@linkplain * #GeodeticCalculator(CoordinateReferenceSystem) constructor}. * * @return The starting position in user CRS. * @throws TransformException if the position can't be transformed to user coordinates. * @since 2.3 */ public DirectPosition getStartingPosition() throws TransformException { DirectPosition position = userToGeodetic; if (position == null) { position = new DirectPosition2D(); } position.setOrdinate(0, long1); position.setOrdinate(1, lat1); if (userToGeodetic != null) { position = userToGeodetic.inverseTransform(); } return position; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { CoordinateReferenceSystem crs = GML3ParsingUtils.crs(node); // double[] position = (double[]) value; Double[] position = (Double[]) value; DirectPosition dp = null; if (position.length < 2) { dp = (crs != null) ? new DirectPosition1D(crs) : new DirectPosition1D(); dp.setOrdinate(0, position[0].doubleValue()); } else if (position.length < 3) { dp = (crs != null) ? new DirectPosition2D(crs) : new DirectPosition2D(); dp.setOrdinate(0, position[0].doubleValue()); dp.setOrdinate(1, position[1].doubleValue()); } else { dp = (crs != null) ? new DirectPosition3D(crs) : new DirectPosition3D(); dp.setOrdinate(0, position[0].doubleValue()); dp.setOrdinate(1, position[1].doubleValue()); dp.setOrdinate(2, position[2].doubleValue()); } return dp; }
/** * Parse a single coordinate from a <code>StreamTokenizer</code> * * @param tokenizer * @return a single DirectPosition * @throws IOException * @throws ParseException */ private DirectPosition getPreciseCoordinate(StreamTokenizer tokenizer) throws IOException, ParseException { DirectPosition pos = geometryFactory.createDirectPosition(); pos.setOrdinate(0, getNextNumber(tokenizer)); pos.setOrdinate(1, getNextNumber(tokenizer)); if (isNumberNext(tokenizer)) { pos.setOrdinate(1, getNextNumber(tokenizer)); } return pos; }
/** * Returns the destination position in user coordinates, which doesn't need to be geographic. * The coordinate reference system is the one specified to the {@linkplain * #GeodeticCalculator(CoordinateReferenceSystem) constructor}. * * @return The destination position in user CRS. * @throws TransformException if the position can't be transformed to user coordinates. * @since 2.2 */ public DirectPosition getDestinationPosition() throws TransformException { if (!destinationValid) { computeDestinationPoint(); } DirectPosition position = userToGeodetic; if (position == null) { position = new DirectPosition2D(); } position.setOrdinate(0, long2); position.setOrdinate(1, lat2); if (userToGeodetic != null) { position = userToGeodetic.inverseTransform(); } return position; }
for (int i = 0; i < coordCount; i++) { dps[i] = new DirectPosition1D(crs); dps[i].setOrdinate(0, values[i].doubleValue()); dps[coordIndex].setOrdinate(0, values[ordinateIdx].doubleValue()); dps[coordIndex].setOrdinate(1, values[ordinateIdx + 1].doubleValue()); ordinateIdx += crsDimension; dps[coordIndex].setOrdinate(0, values[ordinateIdx].doubleValue()); dps[coordIndex].setOrdinate(1, values[ordinateIdx + 1].doubleValue()); dps[coordIndex].setOrdinate(2, values[ordinateIdx + 2].doubleValue()); ordinateIdx += crsDimension;
/** * Transform the provided 2D direct position into 3D (0 Ellipsoidal height assumed when * converting from {@link DefaultGeographicCRS#WGS84} to {@link DefaultGeographicCRS#WGS84_3D}). * * @param srcPosition Source 2D position * @param transformToWGS84 From source CRS to To WGS84 * @param transformFromWGS84_3D From WGS84_3D to target CRS * @return Position in target CRS as calculated by transform2 * @throws TransformException */ private static DirectPosition transformTo3D( GeneralDirectPosition srcPosition, MathTransform transformToWGS84, MathTransform transformFromWGS84_3D) throws TransformException { DirectPosition world2D = transformToWGS84.transform(srcPosition, null); DirectPosition world3D = new GeneralDirectPosition(DefaultGeographicCRS.WGS84_3D); world3D.setOrdinate(0, world2D.getOrdinate(0)); world3D.setOrdinate(1, world2D.getOrdinate(1)); world3D.setOrdinate(2, 0.0); // 0 elliposial height is assumed DirectPosition targetPosition = transformFromWGS84_3D.transform(world3D, null); return targetPosition; }
geom.setOrdinate(1, parameters.get(3).evaluate(object, Double.class)); geom.setOrdinate(0, parameters.get(2).evaluate(object, Double.class)); } else { geom.setOrdinate(1, parameters.get(1).evaluate(object, Double.class)); geom.setOrdinate(0, param1.evaluate(object, Double.class));
/** 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; }
/** * Transform the provided 3D direct position into 2D (Ellipsoidal height is ignored when * converting from {@link DefaultGeographicCRS#WGS84_3D} to {@link DefaultGeographicCRS#WGS84}). * * @param srcPosition Source 3D position * @param transformToWGS84_3D From source CRS to To WGS84_3D * @param transformFromWGS84 From WGS84 to target CRS * @return Position in target CRS as calculated by transform2 * @throws TransformException */ private static DirectPosition transformTo2D( GeneralDirectPosition srcPosition, MathTransform transformToWGS84_3D, MathTransform transformFromWGS84) throws TransformException { if (Double.isNaN(srcPosition.getOrdinate(2))) { srcPosition.setOrdinate( 2, 0.0); // lazy add 3rd ordinate if not provided to prevent failure } DirectPosition world3D = transformToWGS84_3D.transform(srcPosition, null); DirectPosition world2D = new GeneralDirectPosition(DefaultGeographicCRS.WGS84); world2D.setOrdinate(0, world3D.getOrdinate(0)); world2D.setOrdinate(1, world3D.getOrdinate(1)); DirectPosition targetPosition = transformFromWGS84.transform(world2D, null); return targetPosition; }
final double c = origin.getOrdinate(i); final double d = source.getOrdinate(i) * 0.5; P1.setOrdinate(i, c - d); P2.setOrdinate(i, c + d); P2.setOrdinate(i, P2.getOrdinate(i) - P1.getOrdinate(i));
/** * Copies the values from {@code ptSrc} to {@code ptDst}. Overrides the super-class method for * performance reason. * * @since 2.2 */ @Override public DirectPosition transform(final DirectPosition ptSrc, final DirectPosition ptDst) { if (ptSrc.getDimension() == dimension) { if (ptDst == null) { return new GeneralDirectPosition(ptSrc); } if (ptDst.getDimension() == dimension) { for (int i = 0; i < dimension; i++) { ptDst.setOrdinate(i, ptSrc.getOrdinate(i)); } return ptDst; } } try { // The super class will take care of throwing the MismatchedDimensionException. return super.transform(ptSrc, ptDst); } catch (TransformException e) { throw new AssertionError(e); // Should never happen. } }
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); }
private LineSegment processBoundsToSegment(Envelope bounds) { final int D = 0; CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem(); CoordinateSystemAxis axis = crs.getCoordinateSystem().getAxis(D); DirectPosition positionA = getPositionFactory().createDirectPosition(null); DirectPosition positionB = getPositionFactory().createDirectPosition(null); if (axis.getDirection() != AxisDirection.OTHER) { positionA.setOrdinate(D, bounds.getMinimum(D)); positionB.setOrdinate(D, bounds.getMaximum(D)); } return getGeometryFactory().createLineSegment(positionA, positionB); }
DirectPosition sourcePt = new GeneralDirectPosition(DefaultGeographicCRS.WGS84); sourcePt.setOrdinate(0, Double.parseDouble(8.751426)); // longitude sourcePt.setOrdinate(1, Double.parseDouble(45.12478)); // latitude DirectPosition targetPt = tr.transform(p.getValue(), null);
sourcePt = new GeneralDirectPosition(dimension); for (int j = 0; j < dimension; j++) { sourcePt.setOrdinate(j, envelope.getMedian(j)); sourcePt.setOrdinate(i, v1); transformed.add(targetPt = mt.transform(sourcePt, targetPt)); sourcePt.setOrdinate(i, v2); transformed.add(targetPt = mt.transform(sourcePt, targetPt)); sourcePt.setOrdinate(i, envelope.getMedian(i)); DirectPosition lowerCorner = transformed.getLowerCorner(); if (getAxisOrder(targetCRS) == AxisOrder.NORTH_EAST) { lowerCorner.setOrdinate(1, -180); transformed.add(lowerCorner); lowerCorner.setOrdinate(1, 180); transformed.add(lowerCorner); } else { lowerCorner.setOrdinate(0, -180); transformed.add(lowerCorner); lowerCorner.setOrdinate(0, 180); transformed.add(lowerCorner); && generalEnvelope.getMaximum(0) > originX) { DirectPosition lc = generalEnvelope.getLowerCorner(); lc.setOrdinate(0, originX); mt.transform(lc, lc); transformed.add(lc);
/** * Sets the value for the specified cell. * * @param value The new value for the cell. * @param rowIndex Row number of the cell modified. * @param columnIndex Column number of the cell modified. */ public void setValueAt(final Object value, final int rowIndex, final int columnIndex) { final double ordinate = ((Number) value).doubleValue(); ((DirectPosition) positions.get(rowIndex)).setOrdinate(columnIndex, ordinate); fireTableCellUpdated(rowIndex, columnIndex); }
ptDst.setOrdinate(i, array[i]);
public DirectPosition getPosition( int index, DirectPosition position ) throws IndexOutOfBoundsException { int D = getDimension(); if( position == null ){ double[] copy = new double[ D ]; System.arraycopy( array, start+index*D, copy, 0, D ); return new DoubleDirectPosition( crs, copy ); } for( int i =0; i< D; i++){ position.setOrdinate( i, array[ start+index*D+i]); } return position; } public void setPosition( int index, DirectPosition position ) throws IndexOutOfBoundsException, UnsupportedOperationException {
public void setPosition(int index, DirectPosition position) throws IndexOutOfBoundsException, UnsupportedOperationException { // Test ok // Set copy of the coordinates of the given DirectPosition Position pos = get(index); DirectPosition inPlace = pos.getPosition(); double[] coord = position.getCoordinates(); for( int i=0; i<coord.length; i++){ inPlace.setOrdinate( i, coord[i] ); } }
@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()); }