private float interpolate(float wi, float wj, int i0, int j0) { final float[] tiePoints = getTiePoints(); final int w = getRasterWidth(); final int i1 = i0 + 1; final int j1 = j0 + 1; return MathUtils.interpolate2D(wi, wj, tiePoints[i0 + j0 * w], tiePoints[i1 + j0 * w], tiePoints[i0 + j1 * w], tiePoints[i1 + j1 * w]); }
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 int findStart(int x) { int increaseDecreaseCount = 0; final float[] latPoints = _latGrid.getTiePoints(); int latWidth = _latGrid.getRasterWidth(); for(int i=1; i<_latGrid.getRasterHeight(); i++) { float p0 = latPoints[(i - 1) * latWidth + x]; float p1 = latPoints[i * latWidth + x]; if (Float.isNaN(p0) || p0 > 90.0 || p0 < -90.0 || Float.isNaN(p1) || p1 > 90.0 || p1 < -90.0) { continue; } int change = 0; if((p0 - p1) < -0.001) { // increase change = +1; } else if((p1 - p0) < -0.001) { // decrease change = -1; } if (increaseDecreaseCount > 1 && change == -1) { return (int)(i*_latGrid.getSubSamplingY()); } else if (increaseDecreaseCount < -1 && change == +1) { return (int)(i*_latGrid.getSubSamplingY()); } else { increaseDecreaseCount += change; } } return -1; }
@Test public void testGetPixelPos() throws IOException { Product product = createProduct(); TiePointGeoCoding tiePointGeoCoding = (TiePointGeoCoding) product.getGeoCoding(); GeoCoding pixelGeoCoding = GeoCodingFactory.createPixelGeoCoding(product.getBand("latBand"), product.getBand("lonBand"), null, 2, ProgressMonitor.NULL); product.setGeoCoding(pixelGeoCoding); TiePointGrid latGrid = tiePointGeoCoding.getLatGrid(); TiePointGrid lonGrid = tiePointGeoCoding.getLonGrid(); GeoPos gp = new GeoPos(latGrid.getTiePoints()[0], lonGrid.getTiePoints()[0]); PixelPos pixelPos = pixelGeoCoding.getPixelPos(gp, null); assertEquals(new PixelPos(0.5f, 0.5f), pixelPos); System.out.println("----"); gp = new GeoPos((latGrid.getTiePoints()[0] + latGrid.getTiePoints()[1]) / 2, (lonGrid.getTiePoints()[0] + lonGrid.getTiePoints()[1]) / 2); pixelPos = pixelGeoCoding.getPixelPos(gp, null); assertEquals(new PixelPos(2.5f, 0.5f), pixelPos); }
public static TiePointGrid createZenithFromElevationAngleTiePointGrid(TiePointGrid elevationAngleGrid) { final float[] elevationAngles = elevationAngleGrid.getTiePoints(); final float[] zenithAngles = new float[elevationAngles.length]; for (int i = 0; i < zenithAngles.length; i++) { zenithAngles[i] = 90.0f - elevationAngles[i]; } return new TiePointGrid(elevationAngleGrid.getName(), elevationAngleGrid.getRasterWidth(), elevationAngleGrid.getRasterHeight(), elevationAngleGrid.getOffsetX(), elevationAngleGrid.getOffsetY(), elevationAngleGrid.getSubSamplingX(), elevationAngleGrid.getSubSamplingY(), zenithAngles); }
public TiePointGrid cloneTiePointGrid() { final float[] srcTiePoints = this.getTiePoints(); final float[] destTiePoints = new float[srcTiePoints.length]; System.arraycopy(srcTiePoints, 0, destTiePoints, 0, srcTiePoints.length); TiePointGrid clone = new TiePointGrid(this.getName(), this.getRasterWidth(), this.getRasterHeight(), this.getOffsetX(), this.getOffsetY(), this.getSubSamplingX(), this.getSubSamplingY(), destTiePoints, this.getDiscontinuity()); clone.setUnit(getUnit()); clone.setDescription(getDescription()); return clone; }
private void initDiscont() { TiePointGrid base = this; final float[] tiePoints = base.getTiePoints(); final float[] sinTiePoints = new float[tiePoints.length]; final float[] cosTiePoints = new float[tiePoints.length]; for (int i = 0; i < tiePoints.length; i++) { float tiePoint = tiePoints[i]; sinTiePoints[i] = (float) Math.sin(MathUtils.DTOR * tiePoint); cosTiePoints[i] = (float) Math.cos(MathUtils.DTOR * tiePoint); } sinGrid = new TiePointGrid(base.getName(), base.getRasterWidth(), base.getRasterHeight(), base.getOffsetX(), base.getOffsetY(), base.getSubSamplingX(), base.getSubSamplingY(), sinTiePoints); cosGrid = new TiePointGrid(base.getName(), base.getRasterWidth(), base.getRasterHeight(), base.getOffsetX(), base.getOffsetY(), base.getSubSamplingX(), base.getSubSamplingY(), cosTiePoints); }
boolean eastNormalized = false; final float[] longitudes = lonGrid.getTiePoints(); final int numValues = longitudes.length; final float[] normalizedLongitudes = new float[numValues];
final float[] oldTiePoints = sourceTiePointGrid.getTiePoints(); final float[] tiePoints = new float[newTPGWidth * newTPGHeight]; for (int y = 0; y < newTPGHeight; y++) {
public void testAttributeQueries() { TiePointGrid grid = new TiePointGrid("x", 3, 5, 0, 0, 4, 2, _tiePoints); assertEquals("x", grid.getName()); assertEquals(3, grid.getRasterWidth()); assertEquals(5, grid.getRasterHeight()); assertEquals(9, grid.getSceneRasterHeight()); assertEquals(9, grid.getSceneRasterWidth()); assertEquals(9, grid.getSceneRasterHeight()); assertEquals(0, grid.getOffsetX(), 1e-6F); assertEquals(0, grid.getOffsetY(), 1e-6F); assertEquals(4, grid.getSubSamplingX(), 1e-6F); assertEquals(2, grid.getSubSamplingY(), 1e-6F); assertNotNull(grid.getTiePoints()); assertSame(grid.getTiePoints(), _tiePoints); assertEquals(15, grid.getTiePoints().length); for (int i = 0; i < 15; i++) { assertEquals(_tiePoints[i], grid.getTiePoints()[i], 1e-10F); } }
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()); }
final float[] sourcePoints = sourceTiePointGrid.getTiePoints(); final float[] targetPoints = new float[sourcePoints.length]; final int width = sourceTiePointGrid.getRasterWidth();