Java Code Examples for org.geotools.referencing.CRS#equalsIgnoreMetadata()

The following examples show how to use org.geotools.referencing.CRS#equalsIgnoreMetadata() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportKmzFileAction.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    ProductSceneView view = SnapApp.getDefault().getSelectedProductSceneView();
    final GeoCoding geoCoding = view.getProduct().getSceneGeoCoding();
    boolean isGeographic = false;
    if (geoCoding instanceof MapGeoCoding) {
        MapGeoCoding mapGeoCoding = (MapGeoCoding) geoCoding;
        MapTransformDescriptor transformDescriptor = mapGeoCoding.getMapInfo()
                .getMapProjection().getMapTransform().getDescriptor();
        String typeID = transformDescriptor.getTypeID();
        if (typeID.equals(IdentityTransformDescriptor.TYPE_ID)) {
            isGeographic = true;
        }
    } else if (geoCoding instanceof CrsGeoCoding) {
        isGeographic = CRS.equalsIgnoreMetadata(geoCoding.getMapCRS(), DefaultGeographicCRS.WGS84);
    }

    if (isGeographic) {
        exportImage(view);
    } else {
        String message = "Product must be in ''Geographic Lat/Lon'' projection.";
        Dialogs.showInformation(message, null);
    }
}
 
Example 2
Source File: WmsAssistantPage2.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({"unchecked"})
private String getMatchingCRSCode(Layer layer) {
    Set<String> srsSet = layer.getSrs();
    String modelSRS = CRS.toSRS(modelCRS);
    if (modelSRS != null) {
        for (String srs : srsSet) {
            try {
                final CoordinateReferenceSystem crs = CRS.decode(srs,true);
                if (CRS.equalsIgnoreMetadata(crs, modelCRS)) {
                    return srs;
                }
            } catch (FactoryException ignore) {
            }
        }
    }
    return null;
}
 
Example 3
Source File: NwwUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private static SimpleFeatureCollection reprojectToWGS84( SimpleFeatureCollection fc ) {
    // BOUNDS
    ReferencedEnvelope bounds = fc.getBounds();
    CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem();
    if (!CRS.equalsIgnoreMetadata(crs, GPS_CRS)) {
        try {
            fc = new ReprojectingFeatureCollection(fc, GPS_CRS);
        } catch (Exception e) {
            throw new IllegalArgumentException("The data need to be of WGS84 lat/lon projection.", e);
        }
    }
    return fc;
}
 
Example 4
Source File: ExportTimeBasedKmz.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    view = SnapApp.getDefault().getSelectedProductSceneView();
    final GeoCoding geoCoding = view.getProduct().getGeoCoding();
    boolean isGeographic = false;
    if (geoCoding instanceof MapGeoCoding) {
        MapGeoCoding mapGeoCoding = (MapGeoCoding) geoCoding;
        MapTransformDescriptor transformDescriptor = mapGeoCoding.getMapInfo()
                .getMapProjection().getMapTransform().getDescriptor();
        String typeID = transformDescriptor.getTypeID();
        if (typeID.equals(IdentityTransformDescriptor.TYPE_ID)) {
            isGeographic = true;
        }
    } else if (geoCoding instanceof CrsGeoCoding) {
        isGeographic = CRS.equalsIgnoreMetadata(geoCoding.getMapCRS(), DefaultGeographicCRS.WGS84);
    }

    if (isGeographic) {
        final File output = fetchOutputFile(view);
        if (output == null) {
            return;
        }
        final String title = "KMZ Export";
        final ProgressMonitorSwingWorker worker = new KmzSwingWorker(title, output);
        worker.executeWithBlocking();
    } else {
        String message = "Product must be in ''Geographic Lat/Lon'' projection.";
        SnapDialogs.showInformation(message, null);
    }
}
 
Example 5
Source File: OverlayWorldMapLayerAction.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private boolean isGeographicLatLon(GeoCoding geoCoding) {
    if (geoCoding instanceof MapGeoCoding) {
        MapGeoCoding mapGeoCoding = (MapGeoCoding) geoCoding;
        MapTransformDescriptor transformDescriptor = mapGeoCoding.getMapInfo()
                .getMapProjection().getMapTransform().getDescriptor();
        String typeID = transformDescriptor.getTypeID();
        if (typeID.equals(IdentityTransformDescriptor.TYPE_ID)) {
            return true;
        }
    } else if (geoCoding instanceof CrsGeoCoding) {
        return CRS.equalsIgnoreMetadata(geoCoding.getMapCRS(), DefaultGeographicCRS.WGS84);
    }
    return false;
}
 
Example 6
Source File: ProductLayerAssistantPage.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void collectCompatibleRasterDataNodes(CoordinateReferenceSystem thisCrs,
                                              RasterDataNode[] bands, Collection<RasterDataNode> rasterDataNodes) {
    for (RasterDataNode node : bands) {
        CoordinateReferenceSystem otherCrs = Product.findModelCRS(node.getGeoCoding());
        // For GeoTools, two CRS where unequal if the authorities of their CS only differ in version
        // This happened with the S-2 L1C CRS, namely an EPSG:32615. Here one authority's version was null,
        // the other "7.9". Extremely annoying to debug and find out :-(   (nf, Feb 2013)
        if (CRS.equalsIgnoreMetadata(thisCrs, otherCrs)
                || haveCommonReferenceIdentifiers(thisCrs, otherCrs)) {
            rasterDataNodes.add(node);
        }
    }
}
 
Example 7
Source File: GeoWaveRasterReader.java    From geowave with Apache License 2.0 4 votes vote down vote up
/**
 * transforms (if necessary) the requested envelope into the CRS used by this reader.
 *
 * @throws DataSourceException
 */
public static void transformRequestEnvelope(
    final GeoWaveRasterReaderState state,
    final CoordinateReferenceSystem crs) throws DataSourceException {

  if (CRS.equalsIgnoreMetadata(
      state.getRequestedEnvelope().getCoordinateReferenceSystem(),
      crs)) {
    state.setRequestEnvelopeXformed(state.getRequestedEnvelope());

    return; // and finish
  }

  try {
    /** Buffered factory for coordinate operations. */

    // transforming the envelope back to the dataset crs in
    final MathTransform transform =
        OPERATION_FACTORY.createOperation(
            state.getRequestedEnvelope().getCoordinateReferenceSystem(),
            crs).getMathTransform();

    if (transform.isIdentity()) { // Identity Transform ?
      state.setRequestEnvelopeXformed(state.getRequestedEnvelope());
      return; // and finish
    }

    state.setRequestEnvelopeXformed(CRS.transform(transform, state.getRequestedEnvelope()));
    state.getRequestEnvelopeXformed().setCoordinateReferenceSystem(crs);

    // if (config.getIgnoreAxisOrder() == false) { // check for axis
    // order
    // required
    final int indexX = indexOfX(crs);
    final int indexY = indexOfY(crs);
    final int indexRequestedX =
        indexOfX(state.getRequestedEnvelope().getCoordinateReferenceSystem());
    final int indexRequestedY =
        indexOfY(state.getRequestedEnvelope().getCoordinateReferenceSystem());

    // x Axis problem ???
    if ((indexX == indexRequestedY) && (indexY == indexRequestedX)) {
      state.setAxisSwap(true);
      final Rectangle2D tmp =
          new Rectangle2D.Double(
              state.getRequestEnvelopeXformed().getMinimum(1),
              state.getRequestEnvelopeXformed().getMinimum(0),
              state.getRequestEnvelopeXformed().getSpan(1),
              state.getRequestEnvelopeXformed().getSpan(0));
      state.setRequestEnvelopeXformed(new GeneralEnvelope(tmp));
      state.getRequestEnvelopeXformed().setCoordinateReferenceSystem(crs);
    } else if ((indexX == indexRequestedX) && (indexY == indexRequestedY)) {
      // everything is fine
    } else {
      throw new DataSourceException("Unable to resolve the X Axis problem");
    }
    // }
  } catch (final Exception e) {
    throw new DataSourceException("Unable to create a coverage for this source", e);
  }
}