if (CRS.getAxisOrder(destCrs) == CRS.AxisOrder.NORTH_EAST) latLon = true; else if (CRS.getAxisOrder(destCrs) == CRS.AxisOrder.EAST_NORTH) latLon = false; else
/** * Determines the axis ordering of a specified crs object. * * @param crs The coordinate reference system. * @return One of {@link AxisOrder#EAST_NORTH}, {@link AxisOrder@NORTH_EAST}, or {@link * AxisOrder#INAPPLICABLE} * @see AxisOrder * @since 2.7 */ public static AxisOrder getAxisOrder(CoordinateReferenceSystem crs) { return getAxisOrder(crs, false); }
private static org.opengis.geometry.Envelope getCRSEnvelope(CoordinateReferenceSystem targetCRS) throws FactoryException, NoSuchAuthorityCodeException { if (targetCRS.getDomainOfValidity() == null) { Integer code = CRS.lookupEpsgCode(targetCRS, true); if (code != null) { CRS.decode("EPSG:" + code, CRS.getAxisOrder(targetCRS) != AxisOrder.NORTH_EAST); } } org.opengis.geometry.Envelope envelope = CRS.getEnvelope(targetCRS); return envelope; }
CoordinateReferenceSystem crs = CRS.decode(srsName, true); if (CRS.getAxisOrder(crs) == AxisOrder.NORTH_EAST) { Integer epsgCode = CRS.lookupEpsgCode(crs, false); if (epsgCode == null) {
/** * Checks if axis flipping is needed comparing axis order requested for the DataStore with query * crs. * * @param axisOrder * @param coordinateSystem * @return */ public static boolean invertAxisNeeded(String axisOrder, CoordinateReferenceSystem crs) { CRS.AxisOrder requestedAxis = CRS.getAxisOrder(crs); if (requestedAxis == CRS.AxisOrder.INAPPLICABLE) { boolean forcedLonLat = Boolean.getBoolean("org.geotools.referencing.forceXY") || Boolean.TRUE.equals( Hints.getSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER)); if (forcedLonLat) { requestedAxis = CRS.AxisOrder.EAST_NORTH; } else { requestedAxis = CRS.AxisOrder.NORTH_EAST; } } if (WFSDataStoreFactory.AXIS_ORDER_NORTH_EAST.equals(axisOrder)) { return requestedAxis.equals(CRS.AxisOrder.EAST_NORTH); } else if (WFSDataStoreFactory.AXIS_ORDER_EAST_NORTH.equals(axisOrder)) { return requestedAxis.equals(CRS.AxisOrder.NORTH_EAST); } else { return false; // compliant, don't do anything } }
protected void setCentralMeridian(double centralMeridian) { // compute the earth radius try { CoordinateReferenceSystem targetCRS = renderingEnvelope.getCoordinateReferenceSystem(); MathTransform mt = CRS.findMathTransform(WGS84, targetCRS, true); double[] src = new double[] {centralMeridian, 0, 180 + centralMeridian, 0}; double[] dst = new double[4]; mt.transform(src, 0, dst, 0, 2); if (CRS.getAxisOrder(targetCRS) == CRS.AxisOrder.NORTH_EAST) { radius = Math.abs(dst[3] - dst[1]); } else { radius = Math.abs(dst[2] - dst[0]); } if (radius <= 0) { throw new RuntimeException("Computed Earth radius is 0, what is going on?"); } } catch (Exception e) { throw new RuntimeException( "Unexpected error computing the Earth radius " + "in the current projection", e); } computeDatelineX(); }
return null; if (isForcedLonLat() && CRS.getAxisOrder(crs, false) == AxisOrder.NORTH_EAST) { try {
public void testSRSAxisOrder2() throws Exception { try { Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); CoordinateReferenceSystem crsEN = CRS.decode("EPSG:4326"); assertEquals(AxisOrder.EAST_NORTH, CRS.getAxisOrder(crsEN)); CoordinateReferenceSystem crsNE = CRS.decode("urn:ogc:def:crs:EPSG::4326"); assertEquals(AxisOrder.NORTH_EAST, CRS.getAxisOrder(crsNE)); } finally { Hints.removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER); } }
if (CRS.getAxisOrder(this.crs) == CRS.AxisOrder.NORTH_EAST) {
/** Encodes the given geometry with no srsName attribute and forcing 2D */ public void encode(Geometry geometry) { String srsName = null; // see if we have a EPSG CRS attached to the geometry if (geometry.getUserData() instanceof CoordinateReferenceSystem) { try { CoordinateReferenceSystem crs = (CoordinateReferenceSystem) geometry.getUserData(); Integer code = CRS.lookupEpsgCode(crs, false); if (code != null) { if (AxisOrder.NORTH_EAST.equals(CRS.getAxisOrder(crs))) { srsName = "urn:ogc:def:crs:EPSG::" + code; } else { srsName = "EPSG:" + code; } } } catch (Exception e) { LOGGER.fine("Failed to encode the CoordinateReferenceSystem into a srsName"); } } encode(geometry, srsName); }
private static boolean isPole(DirectPosition point, CoordinateReferenceSystem crs) { DirectPosition result = new DirectPosition2D(); GeographicCRS geographic; try { ProjectedCRS projectedCRS = getProjectedCRS(crs); if (projectedCRS != null) { geographic = projectedCRS.getBaseCRS(); MathTransform mt = CRS.findMathTransform(projectedCRS, geographic); mt.transform(point, result); } else if (crs instanceof GeographicCRS) { result = point; geographic = (GeographicCRS) crs; } else { return false; } } catch (MismatchedDimensionException | TransformException | FactoryException e) { return false; } final double EPS = 1e-6; if (getAxisOrder(geographic) == AxisOrder.NORTH_EAST) { return Math.abs(result.getOrdinate(0) - 90) < EPS || Math.abs(result.getOrdinate(0) + 90) < EPS; } else { return Math.abs(result.getOrdinate(1) - 90) < EPS || Math.abs(result.getOrdinate(1) + 90) < EPS; } }
|| CRS.getAxisOrder(crs).equals(AxisOrder.NORTH_EAST); swapAxes &= !retainAxesOrder;
/** * @param lon * @param lat */ public void setTopLeft(double lon, double lat) { boolean isLongitudeFirstAxisOrderForced = Boolean.getBoolean(GeoTools.FORCE_LONGITUDE_FIRST_AXIS_ORDER) || GeoTools.getDefaultHints().get(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER) == Boolean.TRUE; CoordinateReferenceSystem crs = getCrs(); if (isLongitudeFirstAxisOrderForced || (crs != null && CRS.getAxisOrder(crs).equals(CRS.AxisOrder.EAST_NORTH))) { topLeft = gf.createPoint(new Coordinate(lon, lat)); return; } else { // guess lat/lon? topLeft = gf.createPoint(new Coordinate(lat, lon)); } }
@BeforeClass public static void setupCRS() throws FactoryException { CRS.reset("all"); Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); // the following is only to make the test work in Eclipse, where the test // classpath is tainted by the test classpath of dependent modules (whilst in Maven it's // not) Set<CRSAuthorityFactory> factories = ReferencingFactoryFinder.getCRSAuthorityFactories(null); for (CRSAuthorityFactory factory : factories) { if (factory.getClass().getSimpleName().equals("EPSGCRSAuthorityFactory")) { ReferencingFactoryFinder.removeAuthorityFactory(factory); } } assertEquals( AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.decode("urn:ogc:def:crs:EPSG::4326"))); }
ReferencedEnvelope readerEnvelope = ReferencedEnvelope.reference(reader.getOriginalEnvelope()); boolean northEast = CRS.getAxisOrder(readerCRS) == AxisOrder.NORTH_EAST; int lonAxis = northEast ? 1 : 0; if (readerEnvelope.getMaximum(lonAxis) > 180) {
CRS.reset("all"); Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); assertEquals(AxisOrder.EAST_NORTH, CRS.getAxisOrder(CRS.decode("EPSG:4326", false))); assertEquals(AxisOrder.EAST_NORTH, CRS.getAxisOrder(CRS.decode("EPSG:4326", true))); assertEquals( AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.decode("urn:x-ogc:def:crs:EPSG::4326", false))); assertEquals( AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.decode("urn:x-ogc:def:crs:EPSG::4326", true))); } finally { Hints.removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER); assertEquals(AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.decode("EPSG:4326", false))); assertEquals(AxisOrder.EAST_NORTH, CRS.getAxisOrder(CRS.decode("EPSG:4326", true))); assertEquals( AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.decode("urn:x-ogc:def:crs:EPSG::4326", false))); assertEquals( AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.decode("urn:x-ogc:def:crs:EPSG::4326", true))); } finally { CRS.reset("all"); System.setProperty("org.geotools.referencing.forceXY", "true"); assertEquals(AxisOrder.EAST_NORTH, CRS.getAxisOrder(CRS.decode("EPSG:4326", false))); assertEquals(AxisOrder.EAST_NORTH, CRS.getAxisOrder(CRS.decode("EPSG:4326", true))); assertEquals( AxisOrder.NORTH_EAST,
+ "AXIS[\"Geodetic longitude\", EAST]," + "AXIS[\"Geodetic latitude\", NORTH]]"; assertEquals(AxisOrder.LON_LAT, CRS.getAxisOrder(CRS.parseWKT(wkt))); assertEquals(AxisOrder.EAST_NORTH, CRS.getAxisOrder(CRS.parseWKT(wkt))); + "AXIS[\"Geodetic latitude\", NORTH]," + "AXIS[\"Geodetic longitude\", EAST]]"; assertEquals(AxisOrder.LAT_LON, CRS.getAxisOrder(CRS.parseWKT(wkt))); assertEquals(AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.parseWKT(wkt))); CRS.getAxisOrder(CRS.getHorizontalCRS(DefaultEngineeringCRS.GENERIC_2D))); + " AXIS[\"Northing\", NORTH], " + " AUTHORITY[\"EPSG\",\"23031\"]]"; assertEquals(AxisOrder.EAST_NORTH, CRS.getAxisOrder(CRS.parseWKT(wkt))); assertEquals(AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.parseWKT(wkt), true));
AxisOrder axisOrder = CRS.getAxisOrder(crs, true);
if (CRS.getAxisOrder(sourceCrs) == AxisOrder.NORTH_EAST) { validArea = new ReferencedEnvelope(
@Test public void testGDA94Points() throws Exception { Style style = RendererBaseTest.loadStyle(this, "markCircle.sld"); BufferedImage reference = toImage(point_test_2d, style); BufferedImage actual = null; if (CRS.getAxisOrder(point_test_strict.getSchema().getCoordinateReferenceSystem()) == AxisOrder.NORTH_EAST) { actual = toImage(point_test_strict, style); } if (CRS.getAxisOrder(point_test.getSchema().getCoordinateReferenceSystem()) == AxisOrder.EAST_NORTH) { actual = toImage(point_test, style); } ImageAssert.assertEquals(reference, actual, 10); }