QVariant AttributeDefinition::checkInput(const QVariant& inputVar, quint32 columnIndex) const{ QVariant actualval= inputVar; const ColumnDefinition& coldef = columndefinitionRef(columnIndex); QString typenm = inputVar.typeName(); if ( !coldef.datadef().domain<>().isValid()){ ERROR2(ERR_NO_INITIALIZED_2,"Domain",coldef.name()); return QVariant(); } IlwisTypes domtype = coldef.datadef().domain<>()->ilwisType(); IlwisTypes valueType = coldef.datadef().domain<>()->valueType(); IDomain dm = coldef.datadef().domain<>(); if ( domtype == itITEMDOMAIN){ if ( inputVar == sUNDEF){ return QVariant((int)iUNDEF); } else if ( typenm == "QString"){ actualval = dm->impliedValue(inputVar); SPItemRange rng2 = coldef.datadef().range<ItemRange>(); if ( !hasType(valueType,itINDEXEDITEM)){ SPItemRange rng1 = dm->range<ItemRange>(); SPDomainItem item = rng1->item(inputVar.toString()); if ( item.isNull()){ return QVariant((int)iUNDEF); } if ( !rng2->contains(item->name())){ rng2->add(item->clone()); } actualval = item->raw(); } } }else if ( domtype == itNUMERICDOMAIN){ if (typenm == "QString") actualval = dm->impliedValue(inputVar); if ( hasType(valueType,itDATETIME) && actualval.value<Ilwis::Time>() == tUNDEF) return actualval; else if (isNumericalUndef(actualval.toDouble())) return rUNDEF; if (! dm->contains(actualval)) actualval = rUNDEF; else { SPNumericRange rng = coldef.datadef().range<NumericRange>(); if ( !rng.isNull()){ if ( hasType(valueType,itDATETIME)) rng->add(actualval.value<Ilwis::Time>()); else rng->add(actualval.toDouble()); } } } else if ( domtype == itTEXTDOMAIN){ return dm->impliedValue(inputVar); } return actualval; }
void PostgresqlFeatureCoverageLoader::setSubfeatureSemantics(FeatureCoverage *fcoverage, IDomain &semantics) const { std::vector<QString> items; ItemRangeIterator iter(semantics->range<>().data()); while (iter.isValid()) { SPDomainItem geomName = (*iter); items.push_back(geomName->name()); ++iter; } fcoverage->attributeDefinitionsRef().setSubDefinition(semantics, items); }
bool MapCalc::execute(ExecutionContext *ctx, SymbolTable& symTable) { if (_prepState == sNOTPREPARED) if((_prepState = prepare(ctx, symTable)) != sPREPARED) return false; PixelIterator iterOut(_outputRaster); PixelIterator iterEnd = end(iterOut); while(iterOut != iterEnd) { double v = calc(); *iterOut = v; ++iterOut; for(auto& item : _inputRasters){ ++(item.second); } updateTranquilizer(iterOut.linearPosition(), 1000); } if ( _outputRaster->datadef().domain()->ilwisType() == itNUMERICDOMAIN){ double rmin = rUNDEF, rmax= rUNDEF; bool isInt = true; for(double v : _outputRaster ){ rmin = Ilwis::min(rmin, v); rmax = Ilwis::max(rmax, v); if ( v != rUNDEF){ isInt &= std::abs((qint64)v - v) <EPS8; } } NumericRange *range = new NumericRange(rmin,rmax, isInt ? 1 : 0); _outputRaster->datadefRef().range(range); }else { IFlatTable tbl; tbl.prepare(); tbl->addColumn(_outputRaster->primaryKey(),_outputRaster->datadef().domain()); int rec = 0; ItemRangeIterator iter(_outputRaster->datadef().range<>().data()); while (iter.isValid()) { SPDomainItem item = (*iter); tbl->setCell(0,rec++,item->raw()); ++iter; } _outputRaster->setAttributes(tbl); } QVariant value; value.setValue<IRasterCoverage>(_outputRaster); logOperation(_outputRaster, _expression); ctx->setOutput(symTable,value,_outputRaster->name(), itRASTER,_outputRaster->resource() ); return true; }
void BaseTable::adjustRange(int index) { ColumnDefinition& coldef = columndefinitionRef(index); if (!coldef.isValid()) return; if( hasType(coldef.datadef().domain<>()->ilwisType(), itNUMERICDOMAIN)) { SPNumericRange rng = coldef.datadef().range<NumericRange>(); std::vector<QVariant> values = column(coldef.id()); if ( values.size() > 0 && !rng.isNull()) { double vmin=1e208, vmax=-1e208; bool hasfraction = true; for(const QVariant& var : values ){ double v = var.toDouble(); if ( !isNumericalUndef2(v, this)) vmin = std::min(vmin, v) ; v = var.toDouble(); if (!isNumericalUndef2(v, this)) { vmax = std::max(vmax, v) ; } hasfraction |= (v - (qint64)v != 0); } if ( vmin != 1e208 && vmax != -1e208) { //something has changed rng->min(vmin); rng->max(vmax); if (!hasfraction) rng->resolution(1); } } } else if ( hasType(coldef.datadef().domain<>()->ilwisType(), itITEMDOMAIN)) { SPItemRange rng = coldef.datadef().range<ItemRange>(); SPItemRange rngDomain = coldef.datadef().domain<>()->range<ItemRange>(); std::vector<QVariant> values = column(coldef.id()); if ( values.size() > 0 && !rng.isNull()) { rng->clear(); for(auto qval : values) { quint32 id = qval.toUInt(); SPDomainItem item = rngDomain->item(id); if ( !item.isNull()) { rng->add(item->clone()); } } } } coldef.changed(false); }
void ItemDomainMergerNamedItems::renumber(const std::unique_ptr<NamedIdentifierRange>& newRange, const QSharedPointer<NamedIdentifierRange>& range1, QSharedPointer<NamedIdentifierRange>& range2 ) { quint32 maxraw = 0; for(int i=0; i < range1->count(); ++i) { maxraw = std::max(range1->itemByOrder(i)->raw(), maxraw); } for(int i=0; i < newRange->count(); ++i) { SPDomainItem item = newRange->item(i); bool inrange1 = range1->contains(item->name()); bool inrange2 = range2->contains(item->name()); if ( !inrange1 && inrange2){ _renumber[item->raw()] = ++maxraw; item->raw(maxraw); } } }
void NumericItemRange::add(SPDomainItem item) { if ( item.isNull() || !item->isValid() || item->valueType() != itNUMERICITEM) return; SPNumericItem nitem = item.staticCast<NumericItem>(); for(auto iter = _items.rbegin(); iter != _items.rend(); ++iter) { if ( nitem->range() > (*iter)->range()) { if ( nitem->raw() == iUNDEF) nitem->_raw = _items.size(); _items.insert(iter.base(),1, nitem ); return; } } if ( _items.size() == 0) { // no overlapping items allowed; so the only case that is legal here is the first nitem->_raw = 0; _items.push_back(nitem); } }
void IndexedIdentifierRange::add(SPDomainItem item) { if (!item->isValid()) return; SPIndexedIdentifier ii = item.staticCast<IndexedIdentifier>(); _start = ii; _count = ii->_count; return; }
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; } }
QString IntervalRange::valueAsString(quint32 index, const Range *rng) { SPDomainItem item = valueAt(index, rng); return item->name(); }