/** * Installs an Envisat-specific tie-point geo-coding in the given product. */ public static void initTiePointGeoCoding(final Product product) { TiePointGrid latGrid = product.getTiePointGrid(EnvisatConstants.LAT_DS_NAME); TiePointGrid lonGrid = product.getTiePointGrid(EnvisatConstants.LON_DS_NAME); if (latGrid != null && lonGrid != null) { product.setGeoCoding(new TiePointGeoCoding(latGrid, lonGrid, Datum.WGS_84)); } }
final String latGridName = getLatGrid().getName(); final String lonGridName = getLonGrid().getName(); final Product destProduct = destScene.getProduct(); TiePointGrid latGrid = destProduct.getTiePointGrid(latGridName); if (latGrid == null) { latGrid = TiePointGrid.createSubset(getLatGrid(), subsetDef); destProduct.addTiePointGrid(latGrid); lonGrid = TiePointGrid.createSubset(getLonGrid(), subsetDef); destProduct.addTiePointGrid(lonGrid); destScene.setGeoCoding(new TiePointGeoCoding(latGrid, lonGrid, getDatum())); return true; } else {
private GeoCoding createStripeGeocode(float[] lats, float[] lons, int y, int stripeW, int stripeH, float offsetX, float offsetY, float subSamplingX, float subSamplingY) throws IOException { final Range range = Range.computeRangeFloat(lats, IndexValidator.TRUE, null, ProgressMonitor.NULL); if (range.getMin() < -90) { return null; } else { final ModisTiePointGrid latGrid = new ModisTiePointGrid("lat" + y, stripeW, stripeH, offsetX, offsetY, subSamplingX, subSamplingY, lats); final ModisTiePointGrid lonGrid = new ModisTiePointGrid("lon" + y, stripeW, stripeH, offsetX, offsetY, subSamplingX, subSamplingY, lons, TiePointGrid.DISCONT_AT_180); final TiePointGeoCoding geoCoding = new TiePointGeoCoding(latGrid, lonGrid, getDatum()); _cross180 = _cross180 || geoCoding.isCrossingMeridianAt180(); return geoCoding; } }
private void writeGeoCoding(final TiePointGeoCoding geoCoding) throws IOException { final int groupID = createH5G(_fileID, "geo_coding"); try { createScalarAttribute(groupID, "java_class_name", TiePointGeoCoding.class.getName()); createScalarAttribute(groupID, "lat_grid", geoCoding.getLatGrid().getName()); createScalarAttribute(groupID, "lon_grid", geoCoding.getLonGrid().getName()); } finally { closeH5G(groupID); } }
destScene.setGeoCoding(new TiePointGeoCoding(latGrid, lonGrid, getDatum())); return true; tmpStripeFloats = stripeGc.getLatGrid().getPixels(region.x, newScanlineOffset, region.width, copyH, tmpStripeFloats); System.arraycopy(tmpStripeFloats, 0, newLatFloats, 0, copyH*region.width); tmpStripeFloats = stripeGc.getLonGrid().getPixels(region.x, newScanlineOffset, region.width, copyH, tmpStripeFloats); System.arraycopy(tmpStripeFloats, 0, newLonFloats, 0, copyH*region.width); tmpStripeFloats = stripeGc.getLatGrid().getPixels(region.x, 0, region.width, _scanlineHeight, tmpStripeFloats); System.arraycopy(tmpStripeFloats, 0, newLatFloats, (firstY-region.y)*region.width, _scanlineHeight*region.width); tmpStripeFloats = stripeGc.getLonGrid().getPixels(region.x, 0, region.width, _scanlineHeight, tmpStripeFloats); System.arraycopy(tmpStripeFloats, 0, newLonFloats, (firstY-region.y)*region.width, _scanlineHeight*region.width); if(lastH > 0) { TiePointGeoCoding stripeGc = (TiePointGeoCoding) _gcList.get(gcIndex); tmpStripeFloats = stripeGc.getLatGrid().getPixels(region.x, 0, region.width, lastH, tmpStripeFloats); System.arraycopy(tmpStripeFloats, 0, newLatFloats, (firstY-region.y)*region.width, lastH*region.width); tmpStripeFloats = stripeGc.getLonGrid().getPixels(region.x, 0, region.width, lastH, tmpStripeFloats); System.arraycopy(tmpStripeFloats, 0, newLonFloats, (firstY-region.y)*region.width, lastH*region.width);
"Name of latitude tie-point grid:", tgc.getLatGrid().getName())); sb.append(String.format("%1$-35s \t%2$s\n", "Name of longitude tie-point grid:", tgc.getLonGrid().getName())); String.valueOf(tgc.isCrossingMeridianAt180()))); "by linear interpolation between tie points.\n"); final int numApproximations = tgc.getNumApproximations(); if (numApproximations > 0) { sb.append("\n"); final TiePointGeoCoding.Approximation approximation = tgc.getApproximation(i); final FXYSum fX = approximation.getFX(); final FXYSum fY = approximation.getFY();
private void doTestGetGeoPos() throws IOException { Product product = createProduct(); TiePointGeoCoding tiePointGeoCoding = (TiePointGeoCoding) product.getGeoCoding(); GeoCoding pixelGeoCoding = GeoCodingFactory.createPixelGeoCoding(product.getBand("latBand"), product.getBand("lonBand"), null, 5, ProgressMonitor.NULL); product.setGeoCoding(pixelGeoCoding); String gp; gp = new GeoPos(tiePointGeoCoding.getLatGrid().getTiePoints()[0], tiePointGeoCoding.getLonGrid().getTiePoints()[0]).toString(); assertEquals(gp, tiePointGeoCoding.getGeoPos(new PixelPos(0.5f, 0.5f), null).toString()); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(0.5f, 0.5f), null).toString()); gp = new GeoPos(tiePointGeoCoding.getLatGrid().getTiePoints()[GW - 1], tiePointGeoCoding.getLonGrid().getTiePoints()[GW - 1]).toString(); assertEquals(gp, tiePointGeoCoding.getGeoPos(new PixelPos(PW - 0.5f, 0.5f), null).toString()); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(PW - 0.5f, 0.5f), null).toString()); gp = new GeoPos(tiePointGeoCoding.getLatGrid().getTiePoints()[GW * (GH - 1)], tiePointGeoCoding.getLonGrid().getTiePoints()[GW * (GH - 1)]).toString(); assertEquals(gp, tiePointGeoCoding.getGeoPos(new PixelPos(0.5f, PH - 0.5f), null).toString()); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(0.5f, PH - 0.5f), null).toString()); gp = new GeoPos(tiePointGeoCoding.getLatGrid().getTiePoints()[GW * GH - 1], tiePointGeoCoding.getLonGrid().getTiePoints()[GW * GH - 1]).toString(); assertEquals(gp, tiePointGeoCoding.getGeoPos(new PixelPos(PW - 0.5f, PH - 0.5f), null).toString()); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(PW - 0.5f, PH - 0.5f), null).toString()); }
private void writeGeoCoding(final TiePointGeoCoding tiePointGeoCoding, final int indent, final int index) { final String[] crsTags = createTags(indent, DimapProductConstants.TAG_COORDINATE_REFERENCE_SYSTEM); println(crsTags[0]); writeDatum(tiePointGeoCoding.getDatum(), indent + 1); println(crsTags[1]); final String latGridName = tiePointGeoCoding.getLatGrid().getName(); final String lonGridName = tiePointGeoCoding.getLonGrid().getName(); if (latGridName == null || lonGridName == null) { return; } final String[] geopositionTags = createTags(indent, DimapProductConstants.TAG_GEOPOSITION); println(geopositionTags[0]); writeBandIndexIf(index >= 0, index, indent + 1); final String[] pointsTags = createTags(indent + 1, DimapProductConstants.TAG_GEOPOSITION_POINTS); println(pointsTags[0]); printLine(indent + 2, DimapProductConstants.TAG_TIE_POINT_GRID_NAME_LAT, latGridName); printLine(indent + 2, DimapProductConstants.TAG_TIE_POINT_GRID_NAME_LON, lonGridName); println(pointsTags[1]); println(geopositionTags[1]); }
private void initLatLonMinMax(TiePointGrid normalizedLonGrid) { final float[] latPoints = getLatGrid().getTiePoints(); final float[] lonPoints = normalizedLonGrid.getTiePoints(); normalizedLonMin = +Float.MAX_VALUE; normalizedLonMax = -Float.MAX_VALUE; latMin = +Float.MAX_VALUE; latMax = -Float.MAX_VALUE; for (float lonPoint : lonPoints) { normalizedLonMin = Math.min(normalizedLonMin, lonPoint); normalizedLonMax = Math.max(normalizedLonMax, lonPoint); } for (float latPoint : latPoints) { latMin = Math.min(latMin, latPoint); latMax = Math.max(latMax, latPoint); } overlapStart = normalizedLonMin; if (overlapStart < -180) { overlapStart += 360; } overlapEnd = normalizedLonMax; if (overlapEnd > 180) { overlapEnd -= 360; } Debug.trace("TiePointGeoCoding.normalizedLonMin = " + normalizedLonMin); Debug.trace("TiePointGeoCoding.normalizedLonMax = " + normalizedLonMax); Debug.trace("TiePointGeoCoding.latMin = " + latMin); Debug.trace("TiePointGeoCoding.latMax = " + latMax); Debug.trace("TiePointGeoCoding.overlapRange = " + overlapStart + " - " + overlapEnd); }
private static int getGeoBoundaryStep(final GeoCoding geoCoding) { int step = 16; if (geoCoding instanceof TiePointGeoCoding) { final TiePointGeoCoding tiePointGeoCoding = (TiePointGeoCoding) geoCoding; step = Math.round(Math.min(tiePointGeoCoding.getLonGrid().getSubSamplingX(), tiePointGeoCoding.getLonGrid().getSubSamplingY())); } return step; }
private void testPositions(TestSet ts) { assertEquals(true, ts.gc.canGetGeoPos()); assertEquals(true, ts.gc.canGetPixelPos()); testGeoPos(ts, TestSet.UL); testGeoPos(ts, TestSet.UC); testGeoPos(ts, TestSet.UR); testGeoPos(ts, TestSet.CL); testGeoPos(ts, TestSet.CC); testGeoPos(ts, TestSet.CR); testGeoPos(ts, TestSet.LL); testGeoPos(ts, TestSet.LC); testGeoPos(ts, TestSet.LR); testPixelPos(ts, TestSet.UL); testPixelPos(ts, TestSet.UC); testPixelPos(ts, TestSet.UR); testPixelPos(ts, TestSet.CL); testPixelPos(ts, TestSet.CC); testPixelPos(ts, TestSet.CR); testPixelPos(ts, TestSet.LL); testPixelPos(ts, TestSet.LC); testPixelPos(ts, TestSet.LR); assertEquals(ts.crossingMeridianAt180, ts.gc.isCrossingMeridianAt180()); }
private static PolyLine createCenterPolyLine(TiePointGeoCoding geoCoding, final int sceneWidth, final int sceneHeight) { final double numberOfSegments = 100.0; final double stepX = sceneWidth / numberOfSegments; final PixelPos pixelPos = new PixelPos(); final GeoPos geoPos = new GeoPos(); final PolyLine polyLine = new PolyLine(); pixelPos.y = sceneHeight / 2f; for (pixelPos.x = 0; pixelPos.x < sceneWidth + 0.5; pixelPos.x += stepX) { geoCoding.getGeoPos(pixelPos, geoPos); if (pixelPos.x == 0) { polyLine.moveTo(geoPos.lon, geoPos.lat); } else { polyLine.lineTo(geoPos.lon, geoPos.lat); } } return polyLine; }
private void checkGeoCoding(final GeoCoding geoCoding) { if (geoCoding instanceof TiePointGeoCoding) { final TiePointGeoCoding gc = (TiePointGeoCoding) geoCoding; Guardian.assertSame("gc.getLatGrid()", gc.getLatGrid(), getTiePointGrid(gc.getLatGrid().getName())); Guardian.assertSame("gc.getLonGrid()", gc.getLonGrid(), getTiePointGrid(gc.getLonGrid().getName())); } else if (geoCoding instanceof MapGeoCoding) { final MapGeoCoding gc = (MapGeoCoding) geoCoding; final MapInfo mapInfo = gc.getMapInfo(); Guardian.assertNotNull("mapInfo", mapInfo); Guardian.assertEquals("mapInfo.getSceneWidth()", mapInfo.getSceneWidth(), getSceneRasterWidth()); Guardian.assertEquals("mapInfo.getSceneHeight()", mapInfo.getSceneHeight(), getSceneRasterHeight()); } }
private void writeTiePointGeoCoding(TiePointGeoCoding tgc, String nodeType) { addRow("The " + nodeType + " uses a tie-point based geo-coding."); addEmptyRow(); addRow("Name of latitude tie-point grid", tgc.getLatGrid().getName()); addRow("Name of longitude tie-point grid", tgc.getLonGrid().getName()); addRow("Crossing 180 degree meridian", String.valueOf(tgc.isCrossingMeridianAt180())); addEmptyRow(); addRow("Geographic coordinates (lat,lon) are computed from pixel coordinates (x,y)\n" + "by linear interpolation between tie points."); final int numApproximations = tgc.getNumApproximations(); if (numApproximations > 0) { addRow("Pixel coordinates (x,y) are computed from geographic coordinates (lat,lon)\n" + final TiePointGeoCoding.Approximation approximation = tgc.getApproximation(i); final FXYSum fX = approximation.getFX(); final FXYSum fY = approximation.getFY();
private double[][] createWarpPoints(TiePointGrid lonGrid, Rectangle subsetRect) { final TiePointGrid latGrid = getLatGrid(); final int w = latGrid.getRasterWidth(); final int sw = subsetRect.width;
private void testGeoPos(TestSet ts, int i) { PixelPos pp = ts.pp[i]; GeoPos gp = ts.gc.getGeoPos(pp, null); assertNotNull(gp); assertEquals(ts.getPositionName(i) + " GeoPos.lat for " + pp, ts.gp[i].lat, gp.lat, GP_ERROR); assertEquals(ts.getPositionName(i) + " GeoPos.lon for " + pp, ts.gp[i].lon, gp.lon, GP_ERROR); }
final SortedMap<Integer, GeoKeyEntry> geoKeyEntries = info.getGeoKeyEntries(); final Datum datum = getDatum(geoKeyEntries); product.setGeoCoding(new TiePointGeoCoding(latGrid, lonGrid, datum));
final ModisTiePointGrid lonTPG = new ModisTiePointGrid("lon" + y, stripeW, stripeH, osX, osY, ssX, ssY, lons, true); final TiePointGeoCoding geoCoding = new TiePointGeoCoding(latTPG, lonTPG, datum); cross180 = cross180 || geoCoding.isCrossingMeridianAt180(); gcList.add(geoCoding); centerLineList.add(createCenterPolyLine(geoCoding, gcStripeSceneWidth, gcStripeSceneHeight));
@Override public void preEncode(ProfileWriteContext ctx, Product p) throws IOException { super.preEncode(ctx, p); final GeoCoding geoCoding = p.getGeoCoding(); if (geoCoding instanceof TiePointGeoCoding) { final TiePointGeoCoding tpGC = (TiePointGeoCoding) geoCoding; final String[] names = new String[2]; names[LON_INDEX] = tpGC.getLonGrid().getName(); names[LAT_INDEX] = tpGC.getLatGrid().getName(); final String value = StringUtils.arrayToString(names, " "); ctx.getNetcdfFileWriteable().addGlobalAttribute(TIEPOINT_COORDINATES, value); } else { if (geoCoding instanceof CrsGeoCoding) { addWktAsVariable(ctx.getNetcdfFileWriteable(), geoCoding); } } }
String gp = tiePointGeoCoding.getGeoPos(new PixelPos(0.5f, 0.5f), null).toString(); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(0.25f, 0.25f), null).toString()); gp = tiePointGeoCoding.getGeoPos(new PixelPos(0.5f, 0.5f), null).toString(); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(0.5f, 0.5f), null).toString()); gp = tiePointGeoCoding.getGeoPos(new PixelPos(0.25f, 0.25f), null).toString(); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(0.25f, 0.25f), null).toString()); gp = tiePointGeoCoding.getGeoPos(new PixelPos(0.75f, 0.75f), null).toString(); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(0.75f, 0.75f), null).toString()); gp = tiePointGeoCoding.getGeoPos(new PixelPos(0.25f, 0.75f), null).toString(); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(0.25f, 0.75f), null).toString()); gp = tiePointGeoCoding.getGeoPos(new PixelPos(0.75f, 0.25f), null).toString(); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(0.75f, 0.25f), null).toString()); gp = tiePointGeoCoding.getGeoPos(new PixelPos(1.5f, 1.5f), null).toString(); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(1.5f, 1.5f), null).toString()); gp = tiePointGeoCoding.getGeoPos(new PixelPos(1.25f, 1.25f), null).toString(); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(1.25f, 1.25f), null).toString()); gp = tiePointGeoCoding.getGeoPos(new PixelPos(1.75f, 1.75f), null).toString(); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(1.75f, 1.75f), null).toString()); gp = tiePointGeoCoding.getGeoPos(new PixelPos(1.25f, 1.75f), null).toString(); assertEquals(gp, pixelGeoCoding.getGeoPos(new PixelPos(1.25f, 1.75f), null).toString());