private static CrsGeoCoding createMapGeoCoding(Rectangle outputRegion, double pixelSize) { CrsGeoCoding geoCoding; try { geoCoding = new CrsGeoCoding(DefaultGeographicCRS.WGS84, outputRegion.width, outputRegion.height, -180.0 + pixelSize * outputRegion.x, 90.0 - pixelSize * outputRegion.y, pixelSize, pixelSize, 0.0, 0.0); } catch (FactoryException e) { throw new IllegalStateException(e); } catch (TransformException e) { throw new IllegalStateException(e); } return geoCoding; } }
private void initGeoCoding() throws IOException { float pixelX = 0.0f; float pixelY = 0.0f; float easting = -180f; float northing = +90f; float pixelSizeX = 360.0f / _sceneRasterWidth; float pixelSizeY = 180.0f / _sceneRasterHeight; try { _product.setGeoCoding(new CrsGeoCoding(DefaultGeographicCRS.WGS84, _sceneRasterWidth, _sceneRasterHeight, easting, northing, pixelSizeX, pixelSizeY, pixelX, pixelY)); } catch (FactoryException e) { throw new IOException(e); } catch (TransformException e) { throw new IOException(e); } }
private void initGeoCoding(Product product) throws IOException { float pixelX = 0.0f; float pixelY = 0.0f; float easting = -180f; float northing = +90f; float pixelSizeX = 360.0f / sceneWidth; float pixelSizeY = 180.0f / sceneHeight; try { product.setGeoCoding(new CrsGeoCoding(DefaultGeographicCRS.WGS84, sceneWidth, sceneHeight, easting, northing, pixelSizeX, pixelSizeY, pixelX, pixelY)); } catch (FactoryException e) { throw new IOException(e); } catch (TransformException e) { throw new IOException(e); } }
private void initGeoCoding(Product product) throws IOException { float pixelX = 0.0f; float pixelY = 0.0f; float easting = -180f; float northing = +90f; float pixelSizeX = 360.0f / sceneWidth; float pixelSizeY = 180.0f / sceneHeight; try { product.setGeoCoding(new CrsGeoCoding(DefaultGeographicCRS.WGS84, sceneWidth, sceneHeight, easting, northing, pixelSizeX, pixelSizeY, pixelX, pixelY)); } catch (FactoryException e) { throw new IOException(e); } catch (TransformException e) { throw new IOException(e); } }
private CrsGeoCoding createCrsGeoCoding(Rectangle imageBounds) throws Exception { AffineTransform i2m = new AffineTransform(); final int northing = 60; final int easting = 5; i2m.translate(easting, northing); final int scaleX = 1; final int scaleY = 1; i2m.scale(scaleX, -scaleY); return new CrsGeoCoding(DefaultGeographicCRS.WGS84, imageBounds, i2m); }
private CrsGeoCoding createCrsGeoCodingCross180(Rectangle imageBounds) throws Exception { AffineTransform i2m = new AffineTransform(); final int northing = 60; final int easting = 175; i2m.translate(easting, northing); final int scaleX = 1; final int scaleY = 1; i2m.scale(scaleX, -scaleY); return new CrsGeoCoding(DefaultGeographicCRS.WGS84, imageBounds, i2m); }
private CrsGeoCoding createCrsGeoCodingCoveringWholeWorld(Rectangle imageBounds) throws Exception { AffineTransform i2m = new AffineTransform(); final int northing = 60; final int easting = -180; i2m.translate(easting, northing); final double scaleX = 360 / imageBounds.getWidth(); final double scaleY = 1.0; i2m.scale(scaleX, -scaleY); return new CrsGeoCoding(DefaultGeographicCRS.WGS84, imageBounds, i2m); } }
private GeoCoding createGeoCodingFromWKT(Product p, String wktString, String i2mString) { try { CoordinateReferenceSystem crs = CRS.parseWKT(wktString); String[] parameters = StringUtils.csvToArray(i2mString); double[] matrix = new double[parameters.length]; for (int i = 0; i < matrix.length; i++) { matrix[i] = Double.valueOf(parameters[i]); } AffineTransform i2m = new AffineTransform(matrix); Rectangle imageBounds = new Rectangle(p.getSceneRasterWidth(), p.getSceneRasterHeight()); return new CrsGeoCoding(crs, imageBounds, i2m); } catch (FactoryException ignore) { } catch (TransformException ignore) { } return null; }
@BeforeClass public static void beforeClass() throws TransformException, FactoryException { AffineTransform i2mTransform = new AffineTransform(); final int northing = 60; final int easting = -5; i2mTransform.translate(easting, northing); final double scaleX = 0.3; final double scaleY = 0.3; i2mTransform.scale(scaleX, -scaleY); GEO_CODING = new CrsGeoCoding(DefaultGeographicCRS.WGS84, DATA_BOUNDS, i2mTransform); }
private static void setGeoCoding(Product product, String epsgCode) throws FactoryException, TransformException { final CoordinateReferenceSystem crs = CRS.decode(epsgCode, true); final Rectangle imageBounds = new Rectangle(product.getSceneRasterWidth(), product.getSceneRasterHeight()); final AffineTransform imageToMap = new AffineTransform(); imageToMap.translate(0.7, 0.8); imageToMap.scale(0.9, -0.8); imageToMap.translate(-0.5, -0.6); product.setGeoCoding(new CrsGeoCoding(crs, imageBounds, imageToMap)); }
private void setMapGeoCoding(Product product) { try { GeoCoding geoCoding = new CrsGeoCoding(DefaultGeographicCRS.WGS84, new Rectangle(0, 0, SIZE, SIZE), new AffineTransform(I2M)); product.setGeoCoding(geoCoding); } catch (FactoryException e) { fail(e.getMessage()); } catch (TransformException e) { fail(e.getMessage()); } }
private static Product createProduct(final String name, final int easting, final int northing, final float bandFillValue) throws FactoryException, TransformException { final Product product = new Product(name, "T", WIDTH, HEIGHT); product.addBand(createBand(bandFillValue)); final AffineTransform transform = new AffineTransform(); transform.translate(easting, northing); transform.scale(1, -1); transform.translate(-0.5, -0.5); product.setGeoCoding( new CrsGeoCoding(CRS.decode("EPSG:4326", true), new Rectangle(0, 0, WIDTH, HEIGHT), transform)); return product; }
private Product createSourceProduct() throws FactoryException, TransformException { Product sourceProduct = new Product("MERIS", "MARCO", 10, 10); sourceProduct.addBand("x", "5.1"); sourceProduct.setGeoCoding(new CrsGeoCoding(DefaultGeographicCRS.WGS84, 10, 10, 0, 0, 1, 1)); return sourceProduct; }
@Test public void testGeoCodingIsCopied() throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(); BandMathsOp.BandDescriptor[] bandDescriptors = new BandMathsOp.BandDescriptor[1]; bandDescriptors[0] = createBandDescription("aBandName", "1.0", ProductData.TYPESTRING_UINT8, "simpleUnits"); parameters.put("targetBands", bandDescriptors); Product sourceProduct = createTestProduct(4, 4); CoordinateReferenceSystem decode = CRS.decode("EPSG:32632"); Rectangle imageBounds = new Rectangle(4, 4); AffineTransform imageToMap = new AffineTransform(); final GeoCoding geoCoding = new CrsGeoCoding(decode, imageBounds, imageToMap); sourceProduct.setGeoCoding(geoCoding); Product targetProduct = GPF.createProduct("BandMaths", parameters, sourceProduct); assertNotNull(targetProduct); assertNotNull(targetProduct.getGeoCoding()); }
@Before public void setup() throws TransformException, FactoryException { final AffineTransform i2m = new AffineTransform(); i2m.scale(2.0, 2.0); final GeoCoding geoCoding = new CrsGeoCoding(DefaultGeographicCRS.WGS84, new Rectangle(0, 0, 10, 10), i2m); final Product product = new Product("P", "T", 10, 10); product.setGeoCoding(geoCoding); placemark = Placemark.createPointPlacemark(PinDescriptor.getInstance(), "P1", "L", "", new PixelPos(1.0f, 1.0f), null, product.getGeoCoding()); product.getPinGroup().add(placemark); }
@Test public void testReadTrack() throws Exception { CrsGeoCoding geoCoding = new CrsGeoCoding(DefaultGeographicCRS.WGS84, new Rectangle(360, 180), new AffineTransform()); InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("TrackData.csv")); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = ImportTrackAction.readTrack(reader, geoCoding); assertNotNull(featureCollection); assertEquals(23, featureCollection.size()); // test ordering SimpleFeature[] simpleFeatures = featureCollection.toArray(new SimpleFeature[0]); assertEquals(23, simpleFeatures.length); assertEquals("ID00000000", simpleFeatures[0].getID()); assertEquals("ID00000011", simpleFeatures[11].getID()); assertEquals("ID00000022", simpleFeatures[22].getID()); } }
public static void main(String[] args) throws TransformException, FactoryException { Product product1 = new Product("A", "B", 360, 180); product1.setGeoCoding(new CrsGeoCoding(DefaultGeographicCRS.WGS84, 360, 180, -180.0, 90.0, 1.0, 1.0, 0.0, 0.0)); PinDescriptor descriptor = PinDescriptor.getInstance(); Placemark pin1 = Placemark.createPointPlacemark(descriptor, "pin_1", "Pin 1", "Schnatter!", new PixelPos(0, 0), new GeoPos(), product1.getGeoCoding()); product1.getPinGroup().add(pin1); showEditPlacemarkDialog(null, product1, pin1, descriptor); } }
public void testCreateGeoCodingForCrsGeoCoding() throws Exception { final Rectangle imageBounds = new Rectangle(product.getSceneRasterWidth(), product.getSceneRasterHeight()); final AffineTransform expectedI2m = new AffineTransform(0.12, 1.23, 2.34, 3.45, 4.56, 5.67); final CoordinateReferenceSystem expectedCrs = CRS.decode("EPSG:4326"); final byte[] bytes = createCrsGeoCodingString( new CrsGeoCoding(expectedCrs, imageBounds, expectedI2m)).getBytes(); final Document dom = DimapProductHelpers.createDom(new ByteArrayInputStream(bytes)); final GeoCoding geoCoding = DimapProductHelpers.createGeoCoding(dom, product)[0]; assertNotNull(geoCoding); assertEquals(CrsGeoCoding.class, geoCoding.getClass()); final CrsGeoCoding crsGeoCoding = (CrsGeoCoding) geoCoding; final CoordinateReferenceSystem mapCRS = crsGeoCoding.getMapCRS(); // ignoring metadata because scope and domainOfValidity are not restored // but not important for our GeoCoding assertTrue(CRS.equalsIgnoreMetadata(expectedCrs, mapCRS)); assertEquals(expectedI2m, crsGeoCoding.getImageToMapTransform()); }
public Product getBoundaryProduct() throws FactoryException, TransformException { final CoordinateReferenceSystem mapCRS = getTargetCRS(); if (mapCRS != null) { final ReferencedEnvelope envelope = getTargetEnvelope(); final Envelope mapEnvelope = envelope.transform(mapCRS, true); final double pixelSizeX = (Double) getPropertyValue(PROPERTY_PIXEL_SIZE_X); final double pixelSizeY = (Double) getPropertyValue(PROPERTY_PIXEL_SIZE_Y); final int w = MathUtils.floorInt(mapEnvelope.getSpan(0) / pixelSizeX); final int h = MathUtils.floorInt(mapEnvelope.getSpan(1) / pixelSizeY); final Product product = new Product("mosaic", "MosaicBounds", w, h); final GeoCoding geoCoding = new CrsGeoCoding(mapCRS, w, h, mapEnvelope.getMinimum(0), mapEnvelope.getMaximum(1), pixelSizeX, pixelSizeY); product.setGeoCoding(geoCoding); return product; } return null; }
@Test public void testIteration() throws Exception { int width = 18; int height = 36; PlanarImage[] sourceImages = createSourceImages(width, height); CrsGeoCoding gc = new CrsGeoCoding(DefaultGeographicCRS.WGS84, width, height, -180, 90, 10.0, 10.0); Product product = new Product("name", "desc", width, height); product.setGeoCoding(gc); BinningContext binningContext = createBinningContext(); ObservationIterator iterator = ObservationIterator.create(sourceImages, null, product, new float[]{0.5f}, sourceImages[0].getBounds(), binningContext); assertTrue(iterator.hasNext()); Observation observation = iterator.next(); assertNotNull(observation); assertEquals(1, observation.size()); }