コード例 #1
0
ファイル: selectionbase.cpp プロジェクト: 52North/IlwisCore
bool SelectionBase::ExpressionPart::match(const SPFeatureI &feature,SelectionBase *operation) const
{
    if ( _type == ExpressionPart::ptFEATURETYPE){
        return hasType(feature->geometryType(), _geometryType);
    }
    if ( _type == ExpressionPart::ptENVELOPE && _envelope.isValid())   {
        return _envelope.contains(feature->geometry().get());
    }
    if ( _type == ExpressionPart::ptPOLYGON && _polygon.get() != 0)   {
        return _polygon->contains(feature->geometry().get());
    }

    if ( _type == ExpressionPart::ptATTRIBUTESELECTION )   {
        QVariant val = feature(_leftSide);
        ColumnDefinition coldef = feature->attributedefinition(_leftSide);
        if ( coldef.datadef().domain()->ilwisType() == itITEMDOMAIN){
            val = coldef.datadef().domain()->impliedValue(val);
        }
        if ( QString(val.typeName()) == "QString" && QString(_rightSide.typeName()) == "QString"){
            return operation->compare1(_operator,val.toString(), _rightSide.toString());
        } else {
            bool ok1,ok2;
            double v1 = val.toDouble(&ok1);
            double v2 = _rightSide.toDouble(&ok2);
            bool ok3 = operation->compare2(_operator, v1, v2, true);
            return ok1&& ok2 && ok3;
        }
    }
    return false;
}
コード例 #2
0
QString IlwisObjectModel::rangeDefinition(bool defaultRange, bool calc, const QString& columnName) {
    try {
        IlwisTypes objectype = _ilwisobject->ilwisType();
        QString rangeString;
        if ( hasType( objectype, itCOVERAGE|itDOMAIN)){
            if ( objectype == itRASTER){
                IRasterCoverage raster = _ilwisobject.as<RasterCoverage>();
                if ( defaultRange){
                  rangeString = raster->datadef().domain()->range()->toString();
                }else{
                    if ( calc){
                        raster->loadData();
                        raster->statistics(NumericStatistics::pBASIC);
                    }
                  rangeString = raster->datadef().range()->toString();
                }
            } else if ( hasType( objectype , itFEATURE)){
                IFeatureCoverage features = _ilwisobject.as<FeatureCoverage>();
                ColumnDefinition coldef = features->attributeDefinitions().columndefinition(COVERAGEKEYCOLUMN);
                if ( coldef.isValid()){
                    if ( defaultRange)
                      rangeString =  coldef.datadef().domain()->range()->toString();
                    else{
                        if ( calc){
                            features->loadData();
                            std::vector<QVariant> data = features->attributeTable()->column(columnName);
                            if ( data.size() != 0){
                                std::vector<double> values(data.size());
                                int  i=0;
                                for(auto v : data)
                                    values[i++] = v.toDouble();
                                NumericStatistics stats; // realy like to do this with a template specialization of the proper calculate function, but the syntax was unclear to me
                                stats.calculate(values.begin(), values.end());
                                NumericRange *rng = new NumericRange(stats.prop(NumericStatistics::pMIN),stats.prop(NumericStatistics::pMAX));
                                features->attributeDefinitionsRef().columndefinitionRef(columnName).datadef().range(rng);
                            }
                        }
                        rangeString = coldef.datadef().range()->toString();
                    }
                }

            } else if ( hasType( objectype , itDOMAIN)){
                rangeString = _ilwisobject.as<Domain>()->range()->toString();
            }
        }
        return rangeString;
    }catch(const ErrorObject& ){
        // no exceptions may escape here
    }
    return "";

}
コード例 #3
0
QString PostgresqlTableConnector::createInsertValueString(QVariant value, const ColumnDefinition &coldef) const {
    IDomain domain = coldef.datadef().domain<>();
    if (hasType(domain->valueType(),itINTEGER)) {

        return QString::number(value.toInt());

    } else if (hasType(domain->valueType(),itDOUBLE | itFLOAT)) {

        return QString::number(value.toDouble());

    } else if (hasType(domain->valueType(),itTHEMATICITEM | itNAMEDITEM | itINDEXEDITEM | itNUMERICITEM | itTIMEITEM)) {

        return domain->impliedValue(value).toString();

    } else if (hasType(domain->valueType(), itDATETIME)) {
        if ( QString(value.typeName()).compare("Ilwis::Time") != 0){
            ERROR2(ERR_COULD_NOT_CONVERT_2,value.toString(), "time");
            Time time(0,0,0,0,0);
            return time.toString(itDATE);
        } else{
            Time time = value.value<Ilwis::Time>();
            return time.toString(itDATETIME);
        }
    } else if (hasType(domain->valueType(),itSTRING)){

        return QString("'%1'").arg(value.toString());

    } else {
        ERROR0("Could not determine data type.");
        return QString("");
    }
}
コード例 #4
0
QString IlwisObjectModel::valuetype() const
{
    try{
        if ( !_ilwisobject.isValid())
            return "";

        IlwisTypes objectype = _ilwisobject->ilwisType();
        IlwisTypes valueType = itUNKNOWN;
        if ( hasType( objectype, itCOVERAGE|itDOMAIN)){
            if ( objectype == itRASTER){
                IRasterCoverage raster = _ilwisobject.as<RasterCoverage>();
                valueType = raster->datadef().domain()->valueType();
            } else if ( hasType( objectype , itFEATURE)){
                IFeatureCoverage features = _ilwisobject.as<FeatureCoverage>();
                ColumnDefinition coldef = features->attributeDefinitions().columndefinition(COVERAGEKEYCOLUMN);
                if ( coldef.isValid()){
                    valueType = coldef.datadef().domain()->valueType();
                }

            } else if ( hasType( objectype , itDOMAIN)){
                IDomain dom = _ilwisobject.as<Domain>();
                valueType = dom->valueType();

            }
        }
        QString typeName =  TypeHelper::type2HumanReadable(valueType);

        return typeName == sUNDEF ? "" : typeName;
    }catch(const ErrorObject& ){
        // no exceptions may escape here
    }
    return "";
}
コード例 #5
0
ファイル: tableselector.cpp プロジェクト: 52North/IlwisCore
void TableSelector::stringCase(const LogicalExpressionPart& part, const ColumnDefinition& coldef, const QVariant& var, std::vector<bool>::iterator& iter) {
    QString text = part.value();
    QString fieldtxt = var.toString();
    if ( coldef.datadef().domain<>()->valueType() == itTHEMATICITEM){
        quint32 raw = var.toUInt();
        INamedIdDomain domainid = coldef.datadef().domain<>().as<NamedIdDomain>();
        SPDomainItem item = domainid->item(raw);
        fieldtxt = item->name();
    }
    LogicalOperator lconnector =  part.logicalConnector();
    switch(part.condition()){
    case loEQ:{
        switch(lconnector){
        case loNONE:
            *iter = fieldtxt == text;break;
        case loOR:
            *iter = *iter || fieldtxt == text;break;
        case loAND:
            *iter = *iter && fieldtxt == text;break;
        default:
            *iter = false;break;
        }
        break;
    }
    case loNEQ:{
        switch(lconnector){
        case loNONE:
            *iter = fieldtxt != text;break;
        case loOR:
            *iter = *iter || fieldtxt != text;break;
        case loAND:
            *iter = *iter && fieldtxt != text;break;
        default:
            *iter = false;break;
        }
        break;
    }
    default:
        *iter = false;
    }
}
コード例 #6
0
Ilwis::OperationImplementation::State SetAttributeTable::prepare(ExecutionContext *ctx, const SymbolTable &st)
{
    OperationImplementation::prepare(ctx,st);

    OperationHelper::check([&] ()->bool { return _inputTable.prepare(_expression.input<QString>(0), itTABLE); },
    {ERR_COULD_NOT_LOAD_2,_expression.input<QString>(0), "" } );

    OperationHelper::check([&] ()->bool { return _inputRaster.prepare(_expression.input<QString>(1), itRASTER); },
    {ERR_COULD_NOT_LOAD_2,_expression.input<QString>(1), "" } );

    _primaryKey = _expression.input<QString>(2);

    int index = _inputTable->columnIndex(_primaryKey);
    if ( index == iUNDEF){
        kernel()->issues()->log(TR("Table doesnt contain column ") + _primaryKey);
        return sPREPAREFAILED;
    }
    std::vector<QVariant> values = _inputTable->column(_primaryKey);
    std::set<QVariant> uniques;
    int undefs = 0;
    for(QVariant v : values){
        if ( isNumericalUndef(v.toDouble()))
            ++undefs;
        else
            uniques.insert(v);
    }
    if ( (uniques.size() + undefs ) != values.size()){
        kernel()->issues()->log(TR("Key column must not contain duplicate values"));
        return sPREPAREFAILED;
    }

    ColumnDefinition coldef = _inputTable->columndefinition(index);
    if ( !coldef.datadef().domain()->isCompatibleWith(_inputRaster->datadef().domain().ptr())){
        kernel()->issues()->log(TR("Key column doesnt match raster domain ") + _primaryKey);
        return sPREPAREFAILED;
    }

    OperationHelperRaster helper;
    helper.initialize(_inputRaster, _outputRaster, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF|itDOMAIN);

    for(quint32 i = 0; i < _outputRaster->size().zsize(); ++i){
        QString index = _outputRaster->stackDefinition().index(i);
        DataDefinition datadef = _outputRaster->datadef(i);
        _outputRaster->setBandDefinition(index,DataDefinition(datadef.domain(), datadef.range()->clone()));
    }
    return sPREPARED;
}
コード例 #7
0
void AttributeDefinition::columndefinition(const ColumnDefinition &coldef)
{
    if ( coldef.id() >=  _columnDefinitionsByIndex.size())     {
        addColumn({coldef.name(), coldef.datadef().domain<>()});
    } else {
        auto iter1 = _columnDefinitionsByName.find(coldef.name());
        if ( iter1 != _columnDefinitionsByName.end()) {
            ColumnDefinition cdef = coldef;
            cdef.columnindex((*iter1).second);
            _columnDefinitionsByIndex[cdef.columnindex()] = cdef;
            (*iter1).second = cdef.columnindex();

        }else {
            addColumn(coldef);
        }
    }
}
コード例 #8
0
bool FeatureConnector::storeMetaData(FeatureCoverage *fcov, IlwisTypes type) {
    if ( type == 0)
        return false;
    DataDefinition datadef;

    ITable attTable = fcov->attributeTable();
    ColumnDefinition coldef = attTable->columndefinition(COVERAGEKEYCOLUMN);
    if ( coldef.isValid()) {
        datadef = coldef.datadef();
    } else {
        IIndexedIdDomain indexdom;
        indexdom.prepare();
        indexdom->setRange(IndexedIdentifierRange(type2Prefix(type),fcov->featureCount(type)));
        datadef.domain(indexdom);
    }

    bool ok = CoverageConnector::storeMetaData(fcov, type, datadef);
    if ( !ok)
        return false;

    QString dataFile = fcov->name();
    int index = dataFile.lastIndexOf(".");
    if ( index != -1) {
        dataFile = dataFile.left(index);
    }

    _odf->setKeyValue("Domain","Type","DomainUniqueID");
    _odf->setKeyValue("DomainSort","Sorting","AlphaNumeric");
    _odf->setKeyValue("DomainSort","Prefix","feature");
    _odf->setKeyValue("DomainSort","Class","Domain UniqueID");
    _odf->setKeyValue("DomainIdentifier","Nr",QString::number(fcov->featureCount(type)));


    if ( fcov->featureTypes() & itPOLYGON){
        ok = storeMetaPolygon(fcov, dataFile);
    }
    if ( fcov->featureTypes() & itLINE){
        ok = storeMetaLine(fcov, dataFile);
    }

    _odf->store();
    return ok;
}
コード例 #9
0
ファイル: flattable.cpp プロジェクト: ridoo/IlwisCore
QVariant FlatTable::cell(const quint32 index, quint32 rec, bool asRaw) const
{
    if (!const_cast<FlatTable *>(this)->initLoad()) {
        return QVariant();
    }

    if ( !isColumnIndexValid(index)) {
        return QVariant();
    }
    if ( rec < recordCount()) {
        QVariant var = _datagrid[rec].cell(index);
        if ( !asRaw) {
            ColumnDefinition coldef = columndefinition(index);
            return coldef.datadef().domain<>()->impliedValue(var);
        }
        return var;
    }
    kernel()->issues()->log(TR(ERR_INVALID_RECORD_SIZE_IN).arg(name()),IssueObject::itWarning);
    return QVariant();
}
コード例 #10
0
ファイル: basetable.cpp プロジェクト: maduhu/IlwisCore
void BaseTable::initValuesColumn(const QString& colname){
    ColumnDefinition def = columndefinition(colname);
    if ( !def.isValid()){
        ERROR2(WARN_INVALID_OBJECT,TR("column definition"), name());
        return;
    }

    IlwisTypes valueType = def.datadef().domain<>()->valueType();
    std::vector<QVariant> col(recordCount());
    for(auto& var : col) {
        if ( hasType(valueType, itINTEGER | itDOMAINITEM))
            var = QVariant((int)iUNDEF);
        else if ( hasType(valueType, itDOUBLE | itFLOAT))
           var = QVariant(rUNDEF);
        else if ( hasType(valueType, itSTRING))
            var = QVariant(sUNDEF);
        else if ( hasType(valueType, itCOORDINATE))
            var.setValue(crdUNDEF);
    }
    column(def.name(),col);
}
コード例 #11
0
bool NumericRepresentationSetter::canUse(const IIlwisObject &obj, const ColumnDefinition &coldef) const
{
    if ( coldef.isValid())
        return hasType(coldef.datadef().domain()->ilwisType(), itNUMERICDOMAIN);
    return false;
}
コード例 #12
0
ファイル: selectionbase.cpp プロジェクト: 52North/IlwisCore
SelectionBase::ExpressionPart::ExpressionPart(const ICoverage& coverage, const QString& p){
    QString part = p.trimmed();
    _isValid = false;
    int index;
    if ( (index = part.indexOf("envelope("))!= -1) {
        _envelope = QString(part).replace("envelope", "box");
        _isValid = _envelope.isValid();
        _type = ptENVELOPE;
        if ( coverage->ilwisType() == itRASTER && _envelope.isValid()){
            IRasterCoverage raster = coverage.as<RasterCoverage>();
            _box = raster->georeference()->coord2Pixel(_envelope);
            //setEnvelopePolygon(raster);
        }
    } else if ((index = part.indexOf("boundingbox("))==0){
        _box = QString(part).replace("boundingbox", "box");
        _isValid = _box.isValid();
        _type = ptBOX;

    }else if ( (index = part.indexOf("polygon(")) != -1){
        _polygon.reset(GeometryHelper::fromWKT(part,0));
        _isValid = _polygon.get() != 0;
        _type = ptPOLYGON;

    }else if ( part.indexOf("attributes(")!= -1) {
        index = part.indexOf("(");
        int len = part.lastIndexOf(")") - index - 1;
        QString lst = part.mid(index + 1, len);
        QStringList attribs = lst.split(",");
        for(auto attrib : attribs){
            if ( coverage->attributeTable()->columnIndex(attrib) != iUNDEF)    {
                _attributes.push_back(attrib);
                _isValid = true;
            }
        }
        _type = ptATTRIBUTE;
    } else if (part.indexOf("rasterbands(")!=-1){
        index = part.indexOf("(");
        int len = part.lastIndexOf(")") - index - 1;
        QString lst = part.mid(index + 1, len);
        QStringList indexes = lst.split(",");
        IRasterCoverage raster = coverage.as<RasterCoverage>();
        for(auto ind : indexes){
            if (raster->stackDefinition().index(ind) != iUNDEF){
                _bands.push_back(ind);
                _isValid = true;
            }
        }
        _type = ptBANDS;

    }else if ((index = part.indexOf("featuretype("))==0){
        QString ft = part.mid(index + 1);
        if ( ft == "point")
            _geometryType = itPOINT;
        if ( ft == "line")
            _geometryType = itLINE;
        if ( ft == "polygon"){
            _geometryType = itPOLYGON;
        }
        _isValid = true;

    }else {
        std::map<QString,LogicalOperator> operators = {{"==", loEQ},{"<=",loLESSEQ},{">=", loGREATEREQ},{"<",loLESS},{">", loGREATER},{"!=",loNEQ}};
        int index1 = part.indexOf("\"");
        if ( index1 == -1)
            index1 = 10000;
        int index2 = 0;
        for(auto op : operators){
            if ((index2 = part.indexOf(op.first)) != -1){
                if ( index2 < index1)    {
                    _operator = op.second;
                    QString rights = part.mid(index2 + op.first.size()).trimmed();
                    _rightSide = rights.remove("\'");
                    QString leftSide = part.left(index2).trimmed();
                    if ( leftSide.toLower() == "pixelvalue"){
                        _leftSide = iUNDEF;
                        _isValid = true;
                    }else {
                        if ( (_leftSide = coverage->attributeTable()->columnIndex(leftSide)) == iUNDEF){
                            _isValid = false;
                        }else {
                            ColumnDefinition coldef = coverage->attributeTable()->columndefinition(_leftSide);
                            QVariant val = coldef.datadef().domain()->impliedValue(_rightSide);
                            _rightSide = val;
                        }
                    }

                    _type = ptATTRIBUTESELECTION;
                    break;
                }
            }
        }
    }
}