/** * 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 } }
|| CRS.getAxisOrder(crs).equals(AxisOrder.NORTH_EAST); swapAxes &= !retainAxesOrder;
if (CRS.getAxisOrder(DefaultGeographicCRS.WGS84).equals(CRS.AxisOrder.NORTH_EAST)) { x = 1; y = 0;
if (CRS.getAxisOrder(DefaultGeographicCRS.WGS84).equals(CRS.AxisOrder.NORTH_EAST)) { x = 1; y = 0;
CoordinateReferenceSystem crs = reader.getCoordinateReferenceSystem(); String srsName = getSRSName(crs); final boolean axisSwap = CRS.getAxisOrder(crs).equals(AxisOrder.EAST_NORTH); double minx = ge.getLowerCorner().getOrdinate(axisSwap ? 1 : 0); double miny = ge.getLowerCorner().getOrdinate(axisSwap ? 0 : 1);
!CRS.getAxisOrder(CRS.decode(srsName)).equals(AxisOrder.EAST_NORTH);
final boolean axisSwap = !CRS.getAxisOrder(crs).equals(AxisOrder.EAST_NORTH);
if (CRS.getAxisOrder(outputCRS).equals(CRS.getAxisOrder(finalCRS))) { return coverage;
/** * 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 } }
private void encodeDatasetBounds(CoverageInfo ci, GridCoverage2DReader reader) throws IOException { // get the crs and look for an EPSG code final CoordinateReferenceSystem crs = ci.getCRS(); GeneralEnvelope envelope = reader.getOriginalEnvelope(); List<String> axesNames = envelopeAxisMapper.getAxesNames(envelope, true); // lookup EPSG code Integer EPSGCode = null; try { EPSGCode = CRS.lookupEpsgCode(crs, false); } catch (FactoryException e) { throw new IllegalStateException( "Unable to lookup epsg code for this CRS:" + crs, e); } if (EPSGCode == null) { throw new IllegalStateException("Unable to lookup epsg code for this CRS:" + crs); } final String srsName = GetCoverage.SRS_STARTER + EPSGCode; // handle axes swap for geographic crs final boolean axisSwap = CRS.getAxisOrder(crs).equals(AxisOrder.EAST_NORTH); final StringBuilder builder = new StringBuilder(); for (String axisName : axesNames) { builder.append(axisName).append(" "); } String axesLabel = builder.substring(0, builder.length() - 1); dcTranslator.handleBoundedBy(envelope, axisSwap, srsName, axesLabel, null); }
/** * 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); }
/** * 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) { boolean invertXY; if (axisOrder.equals(WFSDataStore.AXIS_ORDER_EAST_NORTH)) { invertXY = false; } else if (axisOrder.equals(WFSDataStore.AXIS_ORDER_NORTH_EAST)) { invertXY = true; } else { invertXY = CRS.getAxisOrder(crs).equals(CRS.AxisOrder.NORTH_EAST); } return invertXY; }
/** * @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)); } }
public static CoordinateReferenceSystem findKnownCrs(CoordinateReferenceSystem crs) throws FactoryException, CRSException { String srs = CRS.toSRS(crs); if (srs != null && !srs.startsWith("EPSG:")) { boolean fullScan = true; String knownIdentifier; knownIdentifier = CRS.lookupIdentifier(crs, fullScan); if (knownIdentifier != null) { boolean longitudeFirst = CRS.getAxisOrder(crs).equals(CRS.AxisOrder.EAST_NORTH); crs = CRS.decode(knownIdentifier, longitudeFirst); } else { throw new CRSException( "Could not find identifier associated with the defined CRS: \n" + crs); } } return crs; } }
/** * This utility method tells me whether or not we should do a final reverse on the axis of the * data. * * @param outputCRS the final {@link CoordinateReferenceSystem} for the data as per the request * @return <code>true</code> in case we need to swap axes, <code>false</code> otherwise. */ private boolean requestingLatLonAxesOrder(CoordinateReferenceSystem outputCRS) { try { final Integer epsgCode = CRS.lookupEpsgCode(outputCRS, false); if (epsgCode != null && epsgCode > 0) { CoordinateReferenceSystem originalCRS = CRS.decode(SRS_STARTER + epsgCode); return !CRS.getAxisOrder(originalCRS).equals(CRS.getAxisOrder(outputCRS)); } } catch (FactoryException e) { LOGGER.log(Level.INFO, e.getMessage(), e); return false; } return false; }
public static CoordinateReferenceSystem findKnownCrs(CoordinateReferenceSystem crs) throws FactoryException, CRSException { String srs = CRS.toSRS(crs); if (srs != null && !srs.startsWith("EPSG:")) { boolean fullScan = true; String knownIdentifier; knownIdentifier = CRS.lookupIdentifier(crs, fullScan); if (knownIdentifier != null) { boolean longitudeFirst = CRS.getAxisOrder(crs).equals(CRS.AxisOrder.EAST_NORTH); crs = CRS.decode(knownIdentifier, longitudeFirst); } else { throw new CRSException( "Could not find identifier associated with the defined CRS: \n" + crs); } } return crs; } }
/** 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); }
/** * @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)); } }