Merge pull request #57 from doinachiroiu:master

PiperOrigin-RevId: 333529053
Change-Id: I6e2b7b31ecaa4f7ef11fc7b1260d441d897dd41a
This commit is contained in:
Copybara-Service 2020-09-24 09:22:44 -07:00
commit 73be2c4212

View File

@ -94,11 +94,20 @@ absl::Status GdalMain(std::string filename) {
// Checking that GetGeoTransform is valid.
std::vector<double> adf_geo_transform(6);
sapi::v::Array<double> adfGeoTransformArray(&adf_geo_transform[0],
adf_geo_transform.size());
sapi::v::Array<double> adf_geo_transform_array(&adf_geo_transform[0],
adf_geo_transform.size());
api.GDALGetGeoTransform(&ptr_dataset, adfGeoTransformArray.PtrBoth())
.IgnoreError();
// For this function that returns CPLErr, the error-handling must be done
// analyzing the returning object.
// Same for GDALReturnsIO from below.
CPLErr err;
SAPI_ASSIGN_OR_RETURN(err, api.GDALGetGeoTransform(
&ptr_dataset, adf_geo_transform_array.PtrBoth()));
// If GDALGetGeoTransform generates an error.
if (err != CE_None) {
return absl::InternalError("GDAL rasterization failed.");
}
LOG(INFO) << "Origin = (" << adf_geo_transform[0] << ", "
<< adf_geo_transform[3] << ")" << std::endl;
@ -136,10 +145,17 @@ absl::Status GdalMain(std::string filename) {
std::vector<int8_t> raster_data(nX_size.value() * nY_size.value(), -1);
sapi::v::Array<int8_t> raster_data_array(&raster_data[0], raster_data.size());
api.GDALRasterIO(&ptr_band, GF_Read, 0, 0, nX_size.value(), nY_size.value(),
raster_data_array.PtrBoth(), nX_size.value(),
nY_size.value(), GDT_Byte, 0, 0)
.IgnoreError();
// We will use CPLErr type of returning value, as before with
// GDALGetGeoTransorm.
SAPI_ASSIGN_OR_RETURN(
err, api.GDALRasterIO(&ptr_band, GF_Read, 0, 0, nX_size.value(),
nY_size.value(), raster_data_array.PtrBoth(),
nX_size.value(), nY_size.value(), GDT_Byte, 0, 0));
// If GDALRasterIO generates an error.
if (err != CE_None) {
return absl::InternalError("GDAL rasterization failed.");
}
std::cout << "Raster data info: " << raster_data_array.ToString()
<< std::endl;