void IlwisObjectModel::resetAttributeModel(const QString& attributeName){ auto setAttributeModel = [&](int i, const ColumnDefinition& coldef, const QString& attributeName){ if ( coldef.name() == attributeName){ AttributeModel *attribute = new AttributeModel(coldef, this, _ilwisobject); _attributes[i] = attribute; } }; IlwisTypes objecttype = _ilwisobject->ilwisType(); if ( objecttype == itRASTER){ IRasterCoverage raster = _ilwisobject.as<RasterCoverage>(); if ( raster->hasAttributes()){ for(int i = 0; i < raster->attributeTable()->columnCount(); ++i){ setAttributeModel(i,raster->attributeTable()->columndefinition(i), attributeName); } } } else if ( hasType(objecttype,itFEATURE)){ IFeatureCoverage features = _ilwisobject.as<FeatureCoverage>(); for(int i = 0; i < features->attributeDefinitions().definitionCount(); ++i){ setAttributeModel(i,features->attributeTable()->columndefinition(i), attributeName); } } else if ( hasType(objecttype,itTABLE)){ ITable tbl = _ilwisobject.as<Table>(); for(int i = 0; i < tbl->columnCount(); ++i){ setAttributeModel(i,tbl->columndefinition(i),attributeName); } } }
bool GdalFeatureConnector::setDataSourceAndLayers(const IFeatureCoverage& features, std::vector<SourceHandles>& datasources,std::vector<bool>& validAttributes) { ITable tbl = features->attributeTable(); validAttributes.resize(tbl->columnCount(), false); std::vector<OGRFieldDefnH> fielddefs(tbl->columnCount()); int index = 0; for(int i=0; i < tbl->columnCount(); ++i){ OGRFieldType ogrtype = ilwisType2GdalFieldType(tbl->columndefinition(i).datadef().domain<>()->valueType()); OGRFieldDefnH fieldef = gdal()->createAttributeDefintion(tbl->columndefinition(i).name().toLocal8Bit(),ogrtype); if ( fieldef == 0){ WARN2(ERR_INVALID_INIT_FOR_2, TR("data-type"), tbl->columndefinition(i).name()); }else validAttributes[i] = true; fielddefs[index++] = fieldef; } bool ok = false; OGRSpatialReferenceH srs = createSRS(features->coordinateSystem()); IlwisTypes types = features->featureTypes(); bool multipleoutputs = (types == (itPOINT | itLINE)) || (types == (itPOINT | itPOLYGON)) || (types == (itLINE | itPOLYGON)) || (types == (itFEATURE)); if ( multipleoutputs){ if ((features->featureTypes() & itPOINT) != 0) { ok = createDataSourceAndLayers(itPOINT, "point", features, srs,fielddefs,datasources,validAttributes); } if ((features->featureTypes() & itLINE) != 0) { ok = createDataSourceAndLayers(itLINE, "line", features, srs,fielddefs,datasources,validAttributes); } if ((features->featureTypes() & itPOLYGON) != 0) { ok = createDataSourceAndLayers(itPOLYGON, "polygon", features, srs,fielddefs,datasources,validAttributes); } }else { ok = createDataSourceAndLayers(types, "", features, srs,fielddefs,datasources,validAttributes); } for(OGRFieldDefnH fieldef : fielddefs) { gdal()->destroyAttributeDefintion(fieldef); } return ok; }
void tableCase(const IIlwisObject &obj, const QString& condition, int parmIndex, QVariantList& result) { ITable tbl ; if (hasType(obj->ilwisType(), itCOVERAGE)){ ICoverage coverage = obj.as<Coverage>(); tbl = coverage->attributeTable(); }else if (hasType(obj->ilwisType(), itTABLE) ){ tbl = obj.as<Table>(); } QVariantMap mp; mp["parameterIndex"] = parmIndex; QStringList names; int index; IlwisTypes domainType = itTEXTDOMAIN | itITEMDOMAIN | itNUMERICDOMAIN; if ( (index = condition.indexOf(" with ")) != -1){ QString domainPart = condition.mid(index + 6); QStringList parts = domainPart.split("="); QVariantMap mp; if ( parts.size() == 2){ QStringList types = parts[1].split(","); IlwisTypes domainType = 0; for(auto tp: types){ domainType |= IlwisObject::name2Type(tp); } } } for(int c=0; c < tbl->columnCount(); ++c){ if ( domainType != itUNKNOWN){ DataDefinition def = tbl->columndefinition(c).datadef(); if ( hasType(def.domain()->ilwisType(), domainType)) names.append(tbl->columndefinition(c).name()); }else { names.append(tbl->columndefinition(c).name()); } } mp["result"] = names; mp["uielement"] = "list"; result.append(mp); }
bool GdalFeatureConnector::createAttributes(const ITable& tbl, OGRLayerH layer, const std::vector<OGRFieldDefnH>& fielddefs,std::vector<bool>& validAttributes) { if ( layer == 0) return false; int index=0; for(int i=0; i < tbl->columnCount(); ++i){ if ( validAttributes[i]) { if(gdal()->addAttribute(layer,fielddefs[index],TRUE) != OGRERR_NONE){ validAttributes[i] = false; WARN2(ERR_NO_INITIALIZED_2,tbl->columndefinition(i).name(),tbl->name()); } ++index; } } return true; }
void FeatureCoverage::attributesFromTable(const ITable& otherTable) { _attributeDefinition.clearAttributeDefinitions(); for(int col =0; col < otherTable->columnCount(); ++col){ _attributeDefinition.addColumn(otherTable->columndefinition(col)); } if (otherTable->recordCount() != _features.size()) return; for(int rec =0; rec < otherTable->recordCount(); ++rec){ auto& feature= _features[rec]; feature->record(otherTable->record(rec)); } }
ITable CoverageConnector::prepareAttributeTable(const QString& file, const QString& basemaptype) const{ ITable extTable; if ( file != sUNDEF) { if(!extTable.prepare(file)){ kernel()->issues()->log(file,TR(ERR_NO_INITIALIZED_1).arg(file),IssueObject::itWarning); return ITable(); } } IDomain covdom; if (!covdom.prepare("count")){ return ITable(); } ITable attTable; if ( basemaptype != "Map" ) { Resource resource(QUrl(QString("ilwis://internal/%1").arg(_odf->fileinfo().baseName())), itFLATTABLE); if(!attTable.prepare(resource)) { ERROR1(ERR_NO_INITIALIZED_1,resource.name()); return ITable(); } if ( extTable.isValid()) { for(int i=0; i < extTable->columns(); ++i) { attTable->addColumn(extTable->columndefinition(i)); } } } else { attTable = extTable; } if ( attTable->columnIndex(FEATUREIDCOLUMN) == iUNDEF) { // external tables might already have these attTable->addColumn(COVERAGEKEYCOLUMN,covdom); attTable->addColumn(FEATUREIDCOLUMN,covdom); } bool isNumeric = _odf->value("BaseMap","Range") != sUNDEF; if ( isNumeric) { IDomain featuredom; if (!featuredom.prepare("value")){ return ITable(); } attTable->addColumn(FEATUREVALUECOLUMN,featuredom); } return attTable; }
QQmlListProperty<AttributeModel> IlwisObjectModel::attributes() { try { if ( _attributes.size() == 0){ if ( _ilwisobject.isValid()) { IlwisTypes objecttype = _ilwisobject->ilwisType(); if ( objecttype == itRASTER){ IRasterCoverage raster = _ilwisobject.as<RasterCoverage>(); if ( raster->hasAttributes()){ for(int i = 0; i < raster->attributeTable()->columnCount(); ++i){ AttributeModel *attribute = new AttributeModel(raster->attributeTable()->columndefinition(i), this, _ilwisobject); _attributes.push_back(attribute); } }else { AttributeModel *attribute = new AttributeModel(ColumnDefinition(PIXELVALUE, raster->datadef(),i64UNDEF), this, _ilwisobject); _attributes.push_back(attribute); } } else if ( hasType(objecttype,itFEATURE)){ IFeatureCoverage features = _ilwisobject.as<FeatureCoverage>(); for(int i = 0; i < features->attributeDefinitions().definitionCount(); ++i){ AttributeModel *attribute = new AttributeModel(features->attributeDefinitions().columndefinition(i), this, _ilwisobject); _attributes.push_back(attribute); } } else if ( hasType(objecttype,itTABLE)){ ITable tbl = _ilwisobject.as<Table>(); for(int i = 0; i < tbl->columnCount(); ++i){ AttributeModel *attribute = new AttributeModel(tbl->columndefinition(i), this, _ilwisobject); _attributes.push_back(attribute); } } } } if ( _attributes.size() > 0){ return QQmlListProperty<AttributeModel>(this, _attributes) ; } } catch(const ErrorObject& ){ // no exceptions may escape here } return QQmlListProperty<AttributeModel>(); }
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; }