@Override public CoordinateReferenceSystem crs() throws IOException { String proj = dataset.GetProjection(); if (proj != null) { SpatialReference ref = new SpatialReference(proj); return Proj.crs(ref.ExportToProj4()); } return null; }
/** * Fetches metadata from the given GDAL dataset. */ GridGeometry(final Dataset ds) throws IOException { if (ds == null) { throw new IOException("DataSet is closed."); } xSize = ds.getRasterXSize(); ySize = ds.getRasterYSize(); numBands = ds.getRasterCount(); final double[] gt = ds.GetGeoTransform(); gridToCRS = new AffineTransform(gt[1], gt[4], gt[2], gt[5], gt[0], gt[3]); crs = CRS.create(ds.GetProjection()); }
public Dataset extractRegionAsDataset( Envelope region, int pixelsX, int pixelsY, boolean withAlpha ) throws IOException { byte[][] buffer = extractRegionAsByteArray( region, pixelsX, pixelsY, withAlpha ); Driver vrtDriver = gdal.GetDriverByName( "MEM" ); Dataset ds = vrtDriver.Create( "/tmp/whatever", pixelsX, pixelsY, buffer.length ); ds.SetProjection( dataset.GetProjection() ); int i = 1; for ( byte[] bytes : buffer ) { Band band = ds.GetRasterBand( i ); if ( band.WriteRaster( 0, 0, pixelsX, pixelsY, pixelsX, pixelsY, GDT_Byte, bytes ) != CE_None ) { throw new RuntimeException( "Error writing raster band." ); } i++; } return ds; }
/** * Set georeferencing information from an input <code>Dataset</code> * * @param dataset * a <code>Dataset</code> from where to retrieve all * georeferencing information available */ private void setGeoreferencingInfo(final Dataset dataset) { // Setting CRS's related information final double[] geoT = new double[6]; dataset.GetGeoTransform(geoT); setGeoTransformation(geoT); setProjection(dataset.GetProjection()); setGcpProjection(dataset.GetGCPProjection()); setGcpNumber(dataset.GetGCPCount()); }
/** * Set georeferencing information from an input <code>Dataset</code> * * @param dataset * a <code>Dataset</code> from where to retrieve all * georeferencing information available */ private void setGeoreferencingInfo(final Dataset dataset) { // Setting CRS's related information final double[] geoT = new double[6]; dataset.GetGeoTransform(geoT); setGeoTransformation(geoT); setProjection(dataset.GetProjection()); setGcpProjection(dataset.GetGCPProjection()); setGcpNumber(dataset.GetGCPCount()); }
String sourceWkt = dataset.GetProjection(); String destinationWkt = gdalImageReadParam.getDestinationWkt(); SpatialReference sourceReference = new SpatialReference(sourceWkt); dataset = gdal.AutoCreateWarpedVRT( dataset, dataset.GetProjection(), destinationWkt, gdalImageReadParam.getResampleAlgorithm().getGDALResampleAlgorithm(),
final String projection = dataset.GetProjection(); final double[] geoTransform = dataset.GetGeoTransform(); if (projection != null) {