private static void setLatLongMetadata( final Product product, final MetadataElement absRoot, final String tagLat, final String tagLon, final float x, final float y) { final PixelPos pixelPos = new PixelPos(x, y); final GeoPos geoPos = new GeoPos(); if (product.getGeoCoding() == null) return; product.getGeoCoding().getGeoPos(pixelPos, geoPos); final MetadataAttribute lat = absRoot.getAttribute(tagLat); if (lat != null) lat.getData().setElemDouble(geoPos.getLat()); final MetadataAttribute lon = absRoot.getAttribute(tagLon); if (lon != null) lon.getData().setElemDouble(geoPos.getLon()); }
private void syncLatLonWithXYParams() { final PixelPos pixelPos1 = new PixelPos( ((Number) paramX1.getValue()).intValue(), ((Number) paramY1.getValue()).intValue()); final PixelPos pixelPos2 = new PixelPos( ((Number) paramX2.getValue()).intValue(), ((Number) paramY2.getValue()).intValue()); final GeoCoding geoCoding = product.getGeoCoding(); final GeoPos geoPos1 = geoCoding.getGeoPos(pixelPos1, null); final GeoPos geoPos2 = geoCoding.getGeoPos(pixelPos2, null); paramNorthLat1.setValue(geoPos1.getLat(), null); paramWestLon1.setValue(geoPos1.getLon(), null); paramSouthLat2.setValue(geoPos2.getLat(), null); paramEastLon2.setValue(geoPos2.getLon(), null); }
/** * Writes the systems byte order to the out stream. In java only high byte first. * * @param out the stream to write to * @param rasterDataNode */ private static void writeMapProjectionInfo(PrintWriter out, RasterDataNode rasterDataNode) { Product product = rasterDataNode.getProduct(); if (product == null) { return; } String mapProjectionName = "Arbitrary"; String mapUnits = "Meters"; double referencePixelX = 0, referencePixelY = 0; double easting = 0, northing = 0; double pixelSizeX = 0, pixelSizeY = 0; String datumName = ""; int utmZone = -1; String utmHemisphere = ""; MapProjection mapProjection = null; if (product.getGeoCoding() instanceof CrsGeoCoding) { final CrsGeoCoding crsGeoCoding = (CrsGeoCoding) product.getGeoCoding(); final CoordinateReferenceSystem crs = crsGeoCoding.getMapCRS(); final ImageGeometry imgGeom = ImageGeometry.createTargetGeometry( product, crs, null, null, null, null, null, null, null, null, null); final String crsName = crs.getName().toString().toUpperCase(); if (crsName.equals("WGS84(DD)")) { mapProjectionName = "Geographic Lat/Lon"; mapUnits = "Degrees"; } else if (crsName.contains("UTM")) { mapProjectionName = "UTM"; String zoneStr = crsName.substring(crsName.indexOf("ZONE") + 5, crsName.length()).trim(); int i = 0; String zoneNumStr = ""; while (Character.isDigit(zoneStr.charAt(i))) { zoneNumStr += zoneStr.charAt(i++); } utmZone = Integer.parseInt(zoneNumStr); GeoPos centrePos = crsGeoCoding.getGeoPos( new PixelPos(product.getSceneRasterWidth() / 2, product.getSceneRasterHeight() / 2), null); utmHemisphere = centrePos.getLat() > 0 ? "North" : "South"; } referencePixelX = imgGeom.getReferencePixelX(); referencePixelY = imgGeom.getReferencePixelY(); easting = imgGeom.getEasting(); northing = imgGeom.getNorthing(); pixelSizeX = imgGeom.getPixelSizeX(); pixelSizeY = imgGeom.getPixelSizeY(); datumName = crsGeoCoding.getDatum().getName(); } else if (product.getGeoCoding() instanceof MapGeoCoding) { final MapGeoCoding mapGeoCoding = (MapGeoCoding) product.getGeoCoding(); final MapInfo info = mapGeoCoding.getMapInfo(); if (info == null) { return; } mapProjection = info.getMapProjection(); if (mapProjection instanceof UTMProjection) { mapProjectionName = "UTM"; final UTMProjection utmProjection = (UTMProjection) mapProjection; utmZone = utmProjection.getZone(); utmHemisphere = utmProjection.isNorth() ? "North" : "South"; } else if (mapProjection.isPreDefined()) { mapProjectionName = mapProjection.getName(); } if ("meter".equals(mapProjection.getMapUnit())) { mapUnits = "Meters"; } else if ("degree".equals(mapProjection.getMapUnit())) { mapUnits = "Degrees"; } else { mapUnits = mapProjection.getMapUnit(); } datumName = mapGeoCoding.getDatum().getName(); } else { return; } out.print(_enviMapInfo); out.print(" = {"); out.print(mapProjectionName); out.print(","); out.print(referencePixelX + 1.0f); out.print(","); out.print(referencePixelY + 1.0f); out.print(","); out.print(easting); out.print(","); out.print(northing); out.print(","); out.print(pixelSizeX); out.print(","); out.print(pixelSizeY); out.print(","); if (utmZone != -1) { out.print(utmZone); out.print(","); out.print(utmHemisphere); out.print(","); } out.print(datumName); out.print(","); out.print("units=" + mapUnits); out.print("}"); out.println(); if (mapProjection != null && !mapProjection.isPreDefined()) { final MapTransform mapTransform = mapProjection.getMapTransform(); final double[] parameterValues = mapTransform.getParameterValues(); final String transformName = mapTransform.getDescriptor().getName(); out.print(_enviProjectionInfo); out.print(" = {"); if (transformName.equals(TransverseMercatorDescriptor.NAME)) { out.print(3); out.print(","); out.print(parameterValues[0]); // semi_major (meters) out.print(","); out.print(parameterValues[1]); // semi_minor (meters) out.print(","); out.print(parameterValues[2]); // latitude_of_origin (degree) out.print(","); out.print(parameterValues[3]); // central_meridian (degree) out.print(","); out.print(parameterValues[5]); // false_easting (meters) out.print(","); out.print(parameterValues[6]); // false_northing (meters) out.print(","); out.print(parameterValues[4]); // scaling_factor (no unit) out.print(","); } else if (transformName.equals(LambertConformalConicDescriptor.NAME)) { out.print(4); out.print(","); out.print(parameterValues[0]); // semi_major (meters) out.print(","); out.print(parameterValues[1]); // semi_minor (meters) out.print(","); out.print(parameterValues[2]); // latitude_of_origin (degree) out.print(","); out.print(parameterValues[3]); // central_meridian (degree) out.print(","); out.print(0.0); // false_easting (meters) out.print(","); out.print(0.0); // false_northing (meters) out.print(","); out.print(parameterValues[4]); // latitude_of_intersection_1 (meters) out.print(","); out.print(parameterValues[5]); // latitude_of_intersection_2 (meters) out.print(","); } out.print(mapProjectionName); out.print(","); out.print("units=" + mapUnits); out.print("}"); out.println(); } }