void RasterCoverage::georeference(const IGeoReference &grf, bool resetData) { if ( isReadOnly()) return; changed(true); _georef = grf; if ( resetData) _grid.reset(0); else if ( !_grid || grf->size().twod() != _grid->size().twod() ) { _grid.reset(0); } if ( _georef.isValid() ) { _georef->compute(); coordinateSystem(grf->coordinateSystem()); // mandatory } if (_georef.isValid()){ if ( _size.isValid() && !_size.isNull() && !resetData) _size = Size<>(_georef->size().xsize(), _georef->size().ysize(), _size.zsize()); else _size = _georef->size(); } else _size = Size<>(); if (!_grid && _size.isValid()){ gridRef()->prepare(this,_size); } }
bool GeoReference::isCompatible(const IGeoReference &georefOther) const { if (!georefOther.isValid()) return false; if (georefOther->id() == id()) return true; if ( coordinateSystem() != georefOther->coordinateSystem()) return false; if ( isValid()) return _georefImpl->isCompatible(georefOther); return false; }
void RasterCoverage::georeference(const IGeoReference &grf, bool resetData) { if ( isReadOnly()) return; changed(true); _georef = grf; if ( resetData) _grid.reset(0); else if ( !_grid || grf->size().twod() != _grid->size().twod() ) { _grid.reset(0); } if ( _georef.isValid() ) { _georef->compute(); coordinateSystem(grf->coordinateSystem()); // mandatory resourceRef().addProperty("coordinatesystem",coordinateSystem()->id()); resourceRef().addProperty("georeference",_georef->id()); if ( coordinateSystem()->envelope(true).isValid()) resourceRef().addProperty("latlonenvelop", coordinateSystem()->envelope(true).toString()); if ( _size.isValid() && !_size.isNull() && !resetData) _size = Size<>(_georef->size().xsize(), _georef->size().ysize(), _size.zsize()); else _size = _georef->size(); Envelope env = grf->envelope(); if ( env.isValid() && !env.isNull()) envelope(grf->envelope()); } else _size = Size<>(); if (!_grid && _size.isValid()){ gridRef()->prepare(this,_size); } resourceRef().dimensions(_size.toString()); }
IlwisObject *InternalIlwisObjectFactory::createRasterCoverage(const Resource& resource, const IOOptions &options) const { if ( !resource.isValid()) { ERROR1(ERR_NO_INITIALIZED_1,"resource"); return 0; } RasterCoverage *gcoverage = createFromResource<RasterCoverage>(resource, options); if (!createCoverage(resource, gcoverage, options)) return 0; Size<> sz; QString typenm = resource["size"].typeName(); if ( typenm == "Ilwis::Size<quint32>"){ sz = resource["size"].value<Size<>>(); } else if (typenm == "QSize") { sz = resource["size"].toSize(); } else if (typenm == "QString") { QStringList parts = resource["size"].toString().split(" "); if ( parts.size() >= 2) sz = Size<>(parts[0].toInt(), parts[1].toInt(), 1); if ( parts.size() == 3) sz.zsize(parts[2].toInt()); } gcoverage->gridRef()->prepare(gcoverage, sz); IGeoReference grf; QString tpnam = resource["georeference"].typeName(); if (tpnam == "Ilwis::IGeoReference") grf = resource["georeference"].value<Ilwis::IGeoReference>(); else if( tpnam == "QString" && resource["georeference"].toString() != sUNDEF) { Resource newresource = resource.property2Resource("georeference", itGEOREF); if ( newresource.isValid()) { if (!grf.prepare(newresource)) return 0; } } else if ( tpnam == "qulonglong"){ if(!grf.prepare(resource["georeference"].value<quint64>())) return 0; } else{ Envelope bounds = gcoverage->envelope(); if ( bounds.isValid() && !bounds.isNull()){ grf = new GeoReference(); grf->create("corners"); grf->name("subset_" + gcoverage->name()); grf->coordinateSystem(gcoverage->coordinateSystem()); QSharedPointer< CornersGeoReference> spGrf = grf->as< CornersGeoReference>(); spGrf->internalEnvelope(bounds); grf->size(sz); if (!grf->compute()){ ERROR1(ERR_COULDNT_CREATE_OBJECT_FOR_1, "Georeference"); return 0; } } } if ( grf.isValid()) gcoverage->georeference(grf); if ( sz.isValid()) gcoverage->size(sz); return gcoverage; }
bool RasterCoverageConnector::loadMetaData(IlwisObject *data, const IOOptions &options){ if(!CoverageConnector::loadMetaData(data, options)) return false; auto *raster = static_cast<RasterCoverage *>(data); if (_handle->type() == GdalHandle::etGDALDatasetH){ Coordinate cMin, cMax; quint32 layer = sourceRef().hasProperty("bandindex")? sourceRef()["bandindex"].toUInt(): iUNDEF; Size<> rastersize(gdal()->xsize(_handle->handle()), gdal()->ysize(_handle->handle()), layer != iUNDEF ? 1 : gdal()->layerCount(_handle->handle())); _offsetScales.resize(rastersize.zsize()); std::vector<double> bands(layer != iUNDEF ? 1 : rastersize.zsize()); for(int i =0; i < rastersize.zsize(); ++i){ bands[i] = i; } raster->stackDefinitionRef().setSubDefinition(IDomain("count"),bands); auto layerHandle = gdal()->getRasterBand(_handle->handle(), layer != iUNDEF ? layer + 1 : 1); GDALColorInterp colorType = gdal()->colorInterpretation(layerHandle); bool ok = false; if ( layer != iUNDEF){ raster->size(rastersize); if (sourceRef().hasProperty("scale") && sourceRef().hasProperty("offset")) { _offsetScales[layer].offset = sourceRef()["offset"].toDouble(); _offsetScales[layer].scale = sourceRef()["scale"].toDouble(); } ok = handleNumericLayerCase(layer, raster); }else if( colorType <=1 || layer != iUNDEF){ // no colors + grayscale which equals image domain raster->size(rastersize); ok = handleNumericCase(raster->size(), raster); } else if ( colorType >= 3 && colorType <= 12){ raster->size(Size<>(rastersize.xsize(), rastersize.ysize(), layer != iUNDEF ? 1 : rastersize.zsize() / 3)); ok = handleColorCase(raster->size(), raster,colorType); }else if (colorType == 2){ // color palette ok = handlePaletteCase(rastersize, raster); } if (!ok) return false; IGeoReference georeference; double geosys[6]; CPLErr err = gdal()->getGeotransform(_handle->handle(), geosys) ; if ( err == CE_None) { double a1 = geosys[0]; double b1 = geosys[3]; double a2 = geosys[1]; double b2 = geosys[5]; Coordinate crdLeftup( a1 , b1); Coordinate crdRightDown(a1 + rastersize.xsize() * a2, b1 + rastersize.ysize() * b2 ) ; cMin = Coordinate( min(crdLeftup.x, crdRightDown.x), min(crdLeftup.y, crdRightDown.y)); cMax = Coordinate( max(crdLeftup.x, crdRightDown.x), max(crdLeftup.y, crdRightDown.y)); if(!georeference.prepare(_resource.url().toString())) return ERROR2(ERR_COULDNT_CREATE_OBJECT_FOR_2,"Georeference",raster->name() ); } else { int iNrTiePoints = gdal()->getGCPCount(_handle->handle()); if (iNrTiePoints > 0) { const GDAL_GCP* amtp = gdal()->getGCPs(_handle->handle()); Envelope envTieLimits; for (int i = 0; i < iNrTiePoints; i++) { Coordinate crdtiep(amtp[i].dfGCPX,amtp[i].dfGCPY,0); envTieLimits += crdtiep; } cMin = envTieLimits.min_corner(); cMax = envTieLimits.max_corner(); if(!georeference.prepare(_resource.url().toString())) return ERROR2(ERR_COULDNT_CREATE_OBJECT_FOR_2,"Georeference",raster->name() ); } else { cMin = Coordinate( 0, 0 ); cMax = Coordinate( rastersize.xsize() - 1, rastersize.ysize() - 1); if(!georeference.prepare("code=georef:undetermined")) return ERROR2(ERR_COULDNT_CREATE_OBJECT_FOR_2,"Georeference",raster->name() ); georeference->coordinateSystem(raster->coordinateSystem()); // the grf.prepare() for internal ilwis georeferences (among others "undetermined") does not autmatically set its csy georeference->envelope(Envelope(cMin, cMax)); } } georeference->size(rastersize); georeference->compute(); raster->envelope(Envelope(cMin, cMax)); raster->coordinateSystem()->envelope(raster->envelope()); raster->georeference(georeference); //if (!raster->gridRef()->prepare(raster,rastersize)) // return false; return true; }else{ return ERROR2(ERR_INVALID_PROPERTY_FOR_2,"non-RasterCoverage",_fileUrl.toLocalFile()); } }