private boolean detect180MeridianCrossing() throws TransformException, FactoryException { final Rectangle bounds = this.imageBounds; ReferencedEnvelope referencedEnvelope = new ReferencedEnvelope(bounds.getMinX() + 0.5, bounds.getMaxX() - 0.5, bounds.getMinY() + 0.5, bounds.getMaxY() - 0.5, getImageCRS()); referencedEnvelope = referencedEnvelope.transform(getGeoCRS(), true); final DirectPosition uc = referencedEnvelope.getUpperCorner(); final DirectPosition lc = referencedEnvelope.getLowerCorner(); return uc.getOrdinate(0) > 180 || lc.getOrdinate(0) < -180; }
@Test public void testCustomSpheroidDatum() throws TransformException, FactoryException { String wkt = "PROJCS[\"MODIS_Sinusoidal\", \n" + " GEOGCS[\"Unknown datum based upon the custom spheroid\", \n" + " DATUM[\"Not specified (based on custom spheroid)\", \n" + " SPHEROID[\"Custom spheroid\", 6371007.181, 0.0]], \n" + " PRIMEM[\"Greenwich\", 0.0], \n" + " UNIT[\"degree\", 0.017453292519943295], \n" + " AXIS[\"Longitude\", EAST], \n" + " AXIS[\"Latitude\", NORTH]], \n" + " PROJECTION[\"Sinusoidal\"], \n" + " PARAMETER[\"central_meridian\", 0.0], \n" + " PARAMETER[\"scale_factor\", 1.0], \n" + " PARAMETER[\"false_easting\", 0.0], \n" + " PARAMETER[\"false_northing\", 0.0], \n" + " UNIT[\"m\", 1.0], \n" + " AXIS[\"x\", EAST], \n" + " AXIS[\"y\", NORTH]]"; CoordinateReferenceSystem crs = CRS.parseWKT(wkt); CrsGeoCoding geoCoding = new CrsGeoCoding(crs, new Rectangle(10, 10, 10, 10), new AffineTransform()); DefaultGeographicCRS defaultCrs = (DefaultGeographicCRS) geoCoding.getGeoCRS(); Ellipsoid wgs84Spheroid = DefaultGeographicCRS.WGS84.getDatum().getEllipsoid(); Ellipsoid customSpheroid = defaultCrs.getDatum().getEllipsoid(); assertNotSame(DefaultGeographicCRS.WGS84, defaultCrs); assertTrue(wgs84Spheroid.getSemiMinorAxis() != customSpheroid.getSemiMinorAxis()); assertTrue(wgs84Spheroid.getSemiMajorAxis() != customSpheroid.getSemiMajorAxis()); assertSame(DefaultEllipsoidalCS.GEODETIC_2D, defaultCrs.getCoordinateSystem()); }
@Test public void testTransferGeoCodingWithoutSubset() { final boolean returnValue = srcScene.transferGeoCodingTo(destScene, null); assertTrue(returnValue); final GeoCoding destGeoCoding = destScene.getGeoCoding(); assertNotNull(destGeoCoding); assertNotSame(srcGeoCoding, destGeoCoding); assertEquals(srcGeoCoding.getDatum(), destGeoCoding.getDatum()); assertEquals(srcGeoCoding.getMapCRS(), destGeoCoding.getMapCRS()); assertEquals(srcGeoCoding.getGeoCRS(), destGeoCoding.getGeoCRS()); assertEquals(srcGeoCoding.getGeoPos(new PixelPos(3.5f, 0.5f), null), destGeoCoding.getGeoPos(new PixelPos(3.5f, 0.5f), null)); }
MathTransform map2Geo = CRS.findMathTransform(mapCRS, getGeoCRS(), true); Hints hints = new Hints(Hints.LENIENT_DATUM_SHIFT, Boolean.TRUE);
@Test public void testTransferGeoCodingWithSubset_Subsampling() { final ProductSubsetDef subsetDef = new ProductSubsetDef("subset"); subsetDef.setSubSampling(2, 4); final boolean transfered = srcScene.transferGeoCodingTo(destScene, subsetDef); assertTrue(transfered); final GeoCoding destGeoCoding = destScene.getGeoCoding(); assertNotNull(destGeoCoding); assertNotSame(srcGeoCoding, destGeoCoding); assertEquals(srcGeoCoding.getDatum(), destGeoCoding.getDatum()); assertEquals(srcGeoCoding.getMapCRS(), destGeoCoding.getMapCRS()); assertEquals(srcGeoCoding.getGeoCRS(), destGeoCoding.getGeoCRS()); comparePixelPos(destGeoCoding, new PixelPos(0, 0), new PixelPos(0, 0)); comparePixelPos(destGeoCoding, new PixelPos(8, 0), new PixelPos(4, 0)); comparePixelPos(destGeoCoding, new PixelPos(8, 16), new PixelPos(4, 4)); comparePixelPos(destGeoCoding, new PixelPos(0, 16), new PixelPos(0, 4)); }
@Test public void testTransferGeoCodingWithSubset_SubsamplingAndRegion() { final ProductSubsetDef subsetDef = new ProductSubsetDef("subset"); subsetDef.setRegion(2, 2, 8, 8); subsetDef.setSubSampling(2, 2); final boolean transfered = srcScene.transferGeoCodingTo(destScene, subsetDef); assertTrue(transfered); final GeoCoding destGeoCoding = destScene.getGeoCoding(); assertNotNull(destGeoCoding); assertNotSame(srcGeoCoding, destGeoCoding); assertEquals(srcGeoCoding.getDatum(), destGeoCoding.getDatum()); assertEquals(srcGeoCoding.getMapCRS(), destGeoCoding.getMapCRS()); assertEquals(srcGeoCoding.getGeoCRS(), destGeoCoding.getGeoCRS()); comparePixelPos(destGeoCoding, new PixelPos(2, 2), new PixelPos(0, 0)); comparePixelPos(destGeoCoding, new PixelPos(10, 2), new PixelPos(4, 0)); comparePixelPos(destGeoCoding, new PixelPos(10, 10), new PixelPos(4, 4)); comparePixelPos(destGeoCoding, new PixelPos(2, 10), new PixelPos(0, 4)); }