/** Creates a new wrapper for the given axis. */ private ComparableAxisWrapper(final CoordinateSystemAxis axis) { this.axis = axis; meridian = DirectionAlongMeridian.parse(axis.getDirection()); }
/** * Returns {@code true} if the specified axis is oriented toward the specified direction and * uses decimal degrees units. */ private static boolean isStandard( final CoordinateSystemAxis axis, final AxisDirection direction) { return direction.equals(axis.getDirection()) && NonSI.DEGREE_ANGLE.equals(axis.getUnit()); }
/** * Returns the rank for the specified axis. Any axis that were not specified at construction * time will ordered after all known axis. */ private final int rank(final CoordinateSystemAxis axis) { int c = axis.getDirection().absolute().ordinal(); c = (c >= 0 && c < directionRanks.length) ? directionRanks[c] : directionRanks.length; return c; }
/** * Returns the axis direction for the specified coordinate system. * * @param cs The coordinate system. * @return The axis directions for the specified coordinate system. */ private static AxisDirection[] getAxisDirections(final CoordinateSystem cs) { final AxisDirection[] axis = new AxisDirection[cs.getDimension()]; for (int i = 0; i < axis.length; i++) { axis[i] = cs.getAxis(i).getDirection(); } return axis; }
private int indexOf(CoordinateReferenceSystem crs, Set<AxisDirection> direction) { CoordinateSystem cs = crs.getCoordinateSystem(); for (int index = 0; index < cs.getDimension(); index++) { CoordinateSystemAxis axis = cs.getAxis(index); if (direction.contains(axis.getDirection())) return index; } return -1; } }
/** * Returns a predefined axis similar to the specified one except for units. Returns {@code null} * if no predefined axis match. */ static DefaultCoordinateSystemAxis getPredefined(final CoordinateSystemAxis axis) { return getPredefined(axis.getName().getCode(), axis.getDirection()); }
/** Ensures that all axis are perpendicular. */ private void ensurePerpendicularAxis() throws IllegalArgumentException { final int dimension = getDimension(); for (int i = 0; i < dimension; i++) { final AxisDirection axis0 = getAxis(i).getDirection(); for (int j = i; ++j < dimension; ) { final AxisDirection axis1 = getAxis(j).getDirection(); final double angle = DefaultCoordinateSystemAxis.getAngle(axis0, axis1); if (Math.abs(Math.abs(angle) - 90) > DirectionAlongMeridian.EPS) { throw new IllegalArgumentException( Errors.format( ErrorKeys.NON_PERPENDICULAR_AXIS_$2, axis0.name(), axis1.name())); } } } }
/** * Applies heuristic rules in order to determine if the two first axis should be interchanged. */ private static boolean swapXY(final CoordinateSystem cs) { if (cs != null && cs.getDimension() >= 2) { return AxisDirection.NORTH.equals(cs.getAxis(0).getDirection().absolute()) && AxisDirection.EAST.equals(cs.getAxis(1).getDirection().absolute()); } return false; }
/** Compares directions only, without consideration for the axis name. */ final boolean directionColinearWith(final CoordinateSystem userCS) { if (userCS.getDimension() != axis.length) { return false; } final AxisDirection[] checks = new AxisDirection[axis.length]; for (int i = 0; i < checks.length; i++) { checks[i] = userCS.getAxis(i).getDirection().absolute(); } next: for (int i = 0; i < axis.length; i++) { final AxisDirection direction = axis[i].getDirection().absolute(); for (int j = 0; j < checks.length; j++) { final AxisDirection candidate = checks[j]; if (candidate != null && candidate.equals(direction)) { checks[j] = null; // Flags as already compared. continue next; } } return false; } return true; }
/** * Returns {@code true} if the specified coordinate system use standard axis and units. * * @param crs The coordinate system to test. * @param standard The coordinate system that defines the standard. Usually {@link * DefaultEllipsoidalCS#GEODETIC_2D} or {@link DefaultCartesianCS#PROJECTED}. */ private static boolean hasStandardAxis( final CoordinateSystem cs, final CoordinateSystem standard) { final int dimension = standard.getDimension(); if (cs.getDimension() != dimension) { return false; } for (int i = 0; i < dimension; i++) { final CoordinateSystemAxis a1 = cs.getAxis(i); final CoordinateSystemAxis a2 = standard.getAxis(i); if (!a1.getDirection().equals(a2.getDirection()) || !a1.getUnit().equals(a2.getUnit())) { return false; } } return true; }
/** * Compares with the specified object. See class javadoc for a description of the sorting order. */ public int compareTo(final Object other) { final ComparableAxisWrapper that = (ComparableAxisWrapper) other; final AxisDirection d1 = this.axis.getDirection(); final AxisDirection d2 = that.axis.getDirection(); final int compass = DefaultCoordinateSystemAxis.getCompassAngle(d2, d1); if (compass != Integer.MIN_VALUE) { return compass; } if (isCompassDirection(d1)) { assert !isCompassDirection(d2) : d2; return -1; } if (isCompassDirection(d2)) { assert !isCompassDirection(d1) : d1; return +1; } if (meridian != null) { if (that.meridian != null) { return meridian.compareTo(that.meridian); } return -1; } else if (that.meridian != null) { return +1; } return 0; }
private Primitive processSegmentToPrimitive( Envelope bounds, LineSegment segment, int dimension) { CoordinateSystemAxis axis = crs.getCoordinateSystem().getAxis(dimension); if (axis.getDirection() == AxisDirection.OTHER) { return processSegmentToPrimitive(bounds, segment, dimension + 1); } Ring ring = processBoundsToRing(bounds, segment, dimension); return processRingToPrimitive(bounds, ring, dimension + 1); }
/** * Constructs a new coordinate system axis with the same values than the specified one. This * copy constructor provides a way to wrap an arbitrary implementation into a Geotools one or a * user-defined one (as a subclass), usually in order to leverage some implementation-specific * API. This constructor performs a shallow copy, i.e. the properties are not cloned. * * @param axis The coordinate system axis to copy. * @since 2.2 */ public DefaultCoordinateSystemAxis(final CoordinateSystemAxis axis) { super(axis); abbreviation = axis.getAbbreviation(); direction = axis.getDirection(); unit = axis.getUnit(); minimum = axis.getMinimumValue(); maximum = axis.getMaximumValue(); rangeMeaning = axis.getRangeMeaning(); }
boolean isLatLonOrder(CoordinateSystem cs) { int dimension = cs.getDimension(); int longitudeDim = -1; int latitudeDim = -1; for (int i = 0; i < dimension; i++) { AxisDirection dir = cs.getAxis(i).getDirection().absolute(); if (dir.equals(AxisDirection.EAST)) { longitudeDim = i; } if (dir.equals(AxisDirection.NORTH)) { latitudeDim = i; } } if ((longitudeDim >= 0) && (latitudeDim >= 0)) { if (longitudeDim > latitudeDim) { return true; } } return false; } }
/** Tests {@link CRS#getHorizontalCRS} from a Geographic 3D CR. */ public void testHorizontalFromGeodetic() throws FactoryException { // retrives "WGS 84 (geographic 3D)" CoordinateReferenceSystem compound = CRS.decode("EPSG:4327"); CoordinateReferenceSystem horizontal = CRS.getHorizontalCRS(compound); // the horizonal version is basically 4326, but it won't compare positively // with 4326, not even using CRS.equalsIgnoreMetadata(), so we check the axis directly CoordinateSystem cs = horizontal.getCoordinateSystem(); assertEquals(2, cs.getDimension()); assertEquals(AxisDirection.NORTH, cs.getAxis(0).getDirection()); assertEquals(AxisDirection.EAST, cs.getAxis(1).getDirection()); }
private Primitive processRingToPrimitive(Envelope bounds, Ring ring, int dimension) { int D = crs.getCoordinateSystem().getDimension(); if (dimension == D) { // create Surface from ring and return SurfaceBoundary boundary = createSurfaceBoundary(ring, Collections.EMPTY_LIST); return createSurface(boundary); } CoordinateSystemAxis axis = crs.getCoordinateSystem().getAxis(dimension); if (axis.getDirection() == AxisDirection.OTHER) { return processRingToPrimitive(bounds, ring, dimension + 1); } return processRingToVolumne(bounds, ring, dimension + 1); }
final AxisDirection[] axis = new AxisDirection[] { cs.getAxis(xAxis).getDirection(), cs.getAxis(yAxis).getDirection() }; final AxisDirection[] normalized = axis.clone();
/** * Returns the angular unit of the specified coordinate system. The preference will be given to * the longitude axis, if found. */ static Unit<Angle> getAngularUnit(final CoordinateSystem coordinateSystem) { Unit<Angle> unit = NonSI.DEGREE_ANGLE; for (int i = coordinateSystem.getDimension(); --i >= 0; ) { final CoordinateSystemAxis axis = coordinateSystem.getAxis(i); final Unit<?> candidate = axis.getUnit(); if (NonSI.DEGREE_ANGLE.isCompatible(candidate)) { unit = candidate.asType(Angle.class); if (AxisDirection.EAST.equals(axis.getDirection().absolute())) { break; // Found the longitude axis. } } } return unit; }
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); }
/** Tests {@link AbstractCS#axisUsingUnit}. */ @Test public void testAxisUsingUnit() { assertNull( "Should detect that no axis change is needed", DefaultCartesianCS.PROJECTED.axisUsingUnit(SI.METRE)); final Unit<Length> KILOMETER = MetricPrefix.KILO(SI.METRE); final CoordinateSystemAxis[] axis = DefaultCartesianCS.PROJECTED.axisUsingUnit(KILOMETER); assertNotNull(axis); assertEquals("Expected two-dimensional", 2, axis.length); assertEquals(KILOMETER, axis[0].getUnit()); assertEquals(KILOMETER, axis[1].getUnit()); assertEquals(AxisDirection.EAST, axis[0].getDirection()); assertEquals(AxisDirection.NORTH, axis[1].getDirection()); assertEquals("Easting", axis[0].getName().getCode()); assertEquals("Northing", axis[1].getName().getCode()); }