CrossSectionPin::CrossSectionPin(const QString& lbl, const Coordinate& crd, const IGeoReference& grf, QObject *parent) : QObject(parent),
_label(lbl),
_coord(crd.isValid() ? crd : Coordinate(0, 0))
{
    if (grf.isValid()) {
        if (crd.isValid())
            _pix = grf->coord2Pixel(crd);
        else
            _pix = Pixel(0, 0);
    }
 
}
IRasterCoverage OperationHelperRaster::resample(const IRasterCoverage& sourceRaster, const IGeoReference& targetGrf) {
    if (!sourceRaster.isValid() || !targetGrf.isValid())
        return IRasterCoverage();

        Resource res;
        res.prepare();
        QString expr = QString("%3=resample(%1,%2,nearestneighbour)").arg(sourceRaster->resource().url().toString()).arg(targetGrf->resource().url().toString()).arg(res.name());
        ExecutionContext ctxLocal;
        SymbolTable symtabLocal;
        if (!commandhandler()->execute(expr, &ctxLocal, symtabLocal))
            return false;
        QVariant var = symtabLocal.getValue(res.name());
        return var.value<IRasterCoverage>();
}
Exemple #3
0
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;
}
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;
}