/** * Gets the coordinate reference system used for the model space. The model space is coordinate system * that is used to render images for display. * * @param geoCoding A geo-coding, may be {@code null}. * @return The coordinate reference system used for the model space. If {@code geoCoding} is {@code null}, * it will be a default image coordinate reference system (an instance of {@code org.opengis.referencing.crs.ImageCRS}). */ public static CoordinateReferenceSystem getModelCrs(GeoCoding geoCoding) { if (geoCoding != null) { final MathTransform image2Map = geoCoding.getImageToMapTransform(); if (image2Map instanceof AffineTransform) { return geoCoding.getMapCRS(); } return geoCoding.getImageCRS(); } else { return DEFAULT_IMAGE_CRS; } }
sb.append(geoCoding.getImageCRS().toString()); sb.append("\n"); sb.append("Well-known text format (WKT) of the geographical CRS:\n\n");
private static Rectangle2D createMapBoundary(final Product product, CoordinateReferenceSystem targetCrs) { try { final CoordinateReferenceSystem sourceCrs = product.getGeoCoding().getImageCRS(); final int sourceW = product.getSceneRasterWidth(); final int sourceH = product.getSceneRasterHeight(); final Rectangle2D rect = XRectangle2D.createFromExtremums(0.5, 0.5, sourceW - 0.5, sourceH - 0.5); int pointsPerSide = Math.max(sourceH, sourceW) / 10; pointsPerSide = Math.max(9, pointsPerSide); final ReferencedEnvelope sourceEnvelope = new ReferencedEnvelope(rect, sourceCrs); final ReferencedEnvelope targetEnvelope = sourceEnvelope.transform(targetCrs, true, pointsPerSide); double minX = targetEnvelope.getMinX(); double width = targetEnvelope.getWidth(); if (product.getGeoCoding().isCrossingMeridianAt180()) { minX = -180.0; width = 360; } return new Rectangle2D.Double(minX, targetEnvelope.getMinY(), width, targetEnvelope.getHeight()); } catch (Exception e) { throw new IllegalStateException(e); } }
private static SimpleFeatureType createTrackFeatureType(GeoCoding geoCoding) { SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); ftb.setName("org.esa.beam.TrackPoint"); /*0*/ ftb.add("pixelPos", Point.class, geoCoding.getImageCRS()); /*1*/ ftb.add("geoPos", Point.class, DefaultGeographicCRS.WGS84); /*2*/ ftb.add("data", Double.class); ftb.setDefaultGeometry(geoCoding instanceof CrsGeoCoding ? "geoPos" : "pixelPos"); // GeoTools Bug: this doesn't work // ftb.userData("trackPoints", "true"); final SimpleFeatureType ft = ftb.buildFeatureType(); ft.getUserData().put("trackPoints", "true"); return ft; }
private static Map<Class<?>, List<SimpleFeature>> createGeometryToFeaturesListMap(VectorDataNode vectorNode) { FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = vectorNode.getFeatureCollection(); CoordinateReferenceSystem crs = vectorNode.getFeatureType().getCoordinateReferenceSystem(); if (crs == null) { // for pins and GCPs crs is null --> assume image crs crs = vectorNode.getProduct().getGeoCoding().getImageCRS(); } final CoordinateReferenceSystem modelCrs; if (vectorNode.getProduct().getGeoCoding() instanceof CrsGeoCoding) { modelCrs = ImageManager.getModelCrs(vectorNode.getProduct().getGeoCoding()); } else { modelCrs = DefaultGeographicCRS.WGS84; } if (!CRS.equalsIgnoreMetadata(crs, modelCrs)) { // we have to reproject the features featureCollection = new ReprojectingFeatureCollection(featureCollection, crs, modelCrs); } Map<Class<?>, List<SimpleFeature>> featureListMap = new HashMap<>(); final FeatureIterator<SimpleFeature> featureIterator = featureCollection.features(); while (featureIterator.hasNext()) { SimpleFeature feature = featureIterator.next(); Object defaultGeometry = feature.getDefaultGeometry(); Class<?> geometryType = defaultGeometry.getClass(); List<SimpleFeature> featureList = featureListMap.get(geometryType); if (featureList == null) { featureList = new ArrayList<>(); featureListMap.put(geometryType, featureList); } featureList.add(feature); } return featureListMap; }
private SimpleFeatureType createFeatureType() throws IOException { readHeader(); SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder(); //ftb.setName("org.esa.beam.TrackPoint"); ftb.setName("gov.nasa.gsfc.seabass.vectorData"); /*0*/ ftb.add("pixelPos", Point.class, geoCoding.getImageCRS()); /*1*/ ftb.add("geoPos", Point.class, DefaultGeographicCRS.WGS84); for (ColumnInfo info : columnInfos) { if (!info.getName().equals("lat") && !info.getName().equals("lon")) { ftb.add(info.getName(), info.getDataClass()); } } ftb.setDefaultGeometry(geoCoding instanceof CrsGeoCoding ? "geoPos" : "pixelPos"); // GeoTools Bug: this doesn't work // ftb.userData("trackPoints", "true"); final SimpleFeatureType ft = ftb.buildFeatureType(); ft.getUserData().put("trackPoints", "true"); return ft; }
addRow("WKT of the image CRS", geoCoding.getImageCRS().toString()); addRow("WKT of the geographical CRS", geoCoding.getGeoCRS().toString());