private Unit<?> getFirstAxisUnit(CoordinateSystem coordinateSystem) { if (coordinateSystem == null || coordinateSystem.getDimension() > 0) { return null; } return coordinateSystem.getAxis(0).getUnit(); }
/** * Returns the axis for the underlying {@linkplain CoordinateSystem coordinate system} at the * specified dimension. This is equivalent to <code> * {@linkplain #coordinateSystem}.{@linkplain CoordinateSystem#getAxis getAxis}(dimension) * </code>. * * @param dimension The zero based index of axis. * @return The axis at the specified dimension. * @throws IndexOutOfBoundsException if {@code dimension} is out of bounds. */ public CoordinateSystemAxis getAxis(int dimension) throws IndexOutOfBoundsException { return coordinateSystem.getAxis(dimension); }
final CoordinateSystem cs = crs.getCoordinateSystem(); for (int i = 0; i < cs.getDimension(); i++) { writer.write("<axisName>" + cs.getAxis(i).getName().getCode() + "</axisName>\n");
/** * Constructs a new coordinate system 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 cs The coordinate system to copy. * @since 2.2 */ public AbstractCS(final CoordinateSystem cs) { super(cs); if (cs instanceof AbstractCS) { axis = ((AbstractCS) cs).axis; } else { axis = new CoordinateSystemAxis[cs.getDimension()]; for (int i = 0; i < axis.length; i++) { axis[i] = cs.getAxis(i); } } }
private static double distanceConversionFactor( CoordinateReferenceSystem srcCRS, CoordinateReferenceSystem dstCRS) { Unit<?> srcUnit = srcCRS.getCoordinateSystem().getAxis(0).getUnit(); Unit<?> dstUnit = dstCRS.getCoordinateSystem().getAxis(0).getUnit(); if (srcUnit == dstUnit) { return 1; } else if (srcUnit == NonSI.DEGREE_ANGLE && dstUnit == SI.METRE) { return METRES_PER_DEGREE; } else if (srcUnit == SI.METRE && dstUnit == NonSI.DEGREE_ANGLE) { return 1.0 / METRES_PER_DEGREE; } throw new IllegalStateException( "Unable to convert distances from " + srcUnit + " to " + dstUnit); }
/** * 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; }
/** Initialize the fields required for {@link #toDate} and {@link #toValue} operations. */ @SuppressWarnings("unchecked") private void initializeConverter() { origin = ((TemporalDatum) datum).getOrigin().getTime(); Unit<Time> time = (Unit<Time>) coordinateSystem.getAxis(0).getUnit(); toMillis = time.getConverterTo(MILLISECOND); }
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 the axis of all coordinate systems. */ private static CoordinateSystemAxis[] getAxis(final CoordinateSystem[] cs) { int count = 0; for (int i = 0; i < cs.length; i++) { count += cs[i].getDimension(); } final CoordinateSystemAxis[] axis = new CoordinateSystemAxis[count]; count = 0; for (int i = 0; i < cs.length; i++) { final CoordinateSystem c = cs[i]; final int dim = c.getDimension(); for (int j = 0; j < dim; j++) { axis[count++] = c.getAxis(j); } } assert count == axis.length; return axis; }
/** * 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; }
/** * Returns every axis from the specified coordinate system as instance of {@link * DefaultCoordinateSystemAxis}. This allow usage of some methods specific to that * implementation. */ private static DefaultCoordinateSystemAxis[] getDefaultAxis(final CoordinateSystem cs) { final DefaultCoordinateSystemAxis[] axis = new DefaultCoordinateSystemAxis[cs.getDimension()]; for (int i = 0; i < axis.length; i++) { final CoordinateSystemAxis a = cs.getAxis(i); DefaultCoordinateSystemAxis c = DefaultCoordinateSystemAxis.getPredefined(a); if (c == null) { if (a instanceof DefaultCoordinateSystemAxis) { c = (DefaultCoordinateSystemAxis) a; } else { c = new DefaultCoordinateSystemAxis(a); } } axis[i] = c; } return axis; }
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); }
/** * Tests again EPSG:4326, but forced to (longitude, latitude) axis order. * * @todo Partially uncomment since we are allowed to compile for J2SE 1.5, but doesn't work as * it did prior some changes in the referencing module. Need to investigate why. */ public void testSystemPropertyToForceXY() throws NoSuchAuthorityCodeException, FactoryException { assertNull(System.getProperty(GeoTools.FORCE_LONGITUDE_FIRST_AXIS_ORDER)); System.setProperty(GeoTools.FORCE_LONGITUDE_FIRST_AXIS_ORDER, "true"); try { CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); final CoordinateSystem cs = crs.getCoordinateSystem(); assertEquals(2, cs.getDimension()); cs.getAxis(0); cs.getAxis(1); } finally { System.clearProperty(GeoTools.FORCE_LONGITUDE_FIRST_AXIS_ORDER); } }
/** * Default implementation of {@link #formatWKT}. For {@link DefaultEngineeringCRS} and {@link * DefaultVerticalCRS} use only. */ void formatDefaultWKT(final Formatter formatter) { final Unit<?> unit = getUnit(); formatter.append(unit); final int dimension = coordinateSystem.getDimension(); for (int i = 0; i < dimension; i++) { formatter.append(coordinateSystem.getAxis(i)); } if (unit == null) { formatter.setInvalidWKT(CoordinateReferenceSystem.class); } } }
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 the (latitude, longitude) axis order for EPSG:4326. */ public void testCorrectAxisOrder() throws NoSuchAuthorityCodeException, FactoryException { final CoordinateReferenceSystem crs = CRS.decode("EPSG:4326"); final CoordinateSystem cs = crs.getCoordinateSystem(); assertEquals(2, cs.getDimension()); CoordinateSystemAxis axis0 = cs.getAxis(0); assertEquals("Lat", axis0.getAbbreviation()); CoordinateSystemAxis axis1 = cs.getAxis(1); assertEquals("Long", axis1.getAbbreviation()); }
/** 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); }
/** * 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); }