bool FeatureConnector::loadBinaryData(Ilwis::IlwisObject *obj) {
    if ( obj == nullptr)
        return false;

    FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(obj);

    QString file = _odf->value("BaseMap", "AttributeTable");
    ITable extTable;
    if ( file != sUNDEF) {
        if(!extTable.prepare(file)){
            kernel()->issues()->log(file,TR(ERR_NO_INITIALIZED_1).arg(file),IssueObject::itWarning);
            return false;
        }
    }
    bool ok = false;
     if (fcoverage->featureTypes() == itPOINT)
        ok = loadBinaryPoints(fcoverage);
    else if (fcoverage->featureTypes() == itLINE)
        ok = loadBinarySegments(fcoverage);
    else if (fcoverage->featureTypes() == itPOLYGON)
        ok = loadBinaryPolygons(fcoverage);
    if ( ok && extTable.isValid()) {
        ITable attTbl = fcoverage->attributeTable();
        quint32 keyIndex = attTbl->columnIndex(COVERAGEKEYCOLUMN);
        for(quint32 rowExt=0; rowExt < extTable->records(); ++rowExt) {
            vector<QVariant> rec = extTable->record(rowExt);
            for(quint32 rowAtt = 0; rowAtt < attTbl->records(); ++rowAtt ) {
                if ( attTbl->cell(keyIndex, rowAtt) == rowExt + 1) {
                    attTbl->record(rowAtt,rec);
                }
            }
        }
    }
    return ok;
}
ITable RasterCoverage::histogramAsTable()
{
    std::vector<NumericStatistics::HistogramBin> hist;
    if ( histogramCalculated())
        hist = statistics().histogram();
    else {
        hist = statistics(ContainerStatistics<PIXVALUETYPE>::pHISTOGRAM).histogram();
    }
    
    int count = 0;
    ITable histogram;

    histogram.prepare();
    histogram->addColumn("min", IDomain("value"), true);
    histogram->addColumn("max", IDomain("value"), true);
    histogram->addColumn("counts", IDomain("count"));

    count = 0;
    PIXVALUETYPE vstart = datadef().range<NumericRange>()->min();
	if (hist.size() > 0) {
		for (int i = 0; i < hist.size() - 1; ++i) {
			auto& h = hist[i];
			histogram->record(count, { vstart, h._limit, h._count });
			vstart = h._limit;
			++count;
		}
	}

    return histogram;
}
bool FeatureConnector::loadData(Ilwis::IlwisObject *obj, const IOOptions &) {
    if ( obj == nullptr)
        return false;

    FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(obj);

    QString file = _odf->value("BaseMap", "AttributeTable");
    ITable extTable;
    if ( file != sUNDEF) {
        if(!extTable.prepare(file)){
            kernel()->issues()->log(file,TR(ERR_NO_INITIALIZED_1).arg(file),IssueObject::itWarning);
            return false;
        }
    }
    bool ok = false;

    try {
        _binaryIsLoaded = true; // to prevent any subsequent calls to this routine while loading (which mat trigger it).
         if (fcoverage->featureTypes() == itPOINT)
             ok = loadBinaryPoints(fcoverage);
         else if (fcoverage->featureTypes() == itLINE)
             ok = loadBinarySegments(fcoverage);
         else if (fcoverage->featureTypes() == itPOLYGON)
             ok = loadBinaryPolygons(fcoverage);

         _binaryIsLoaded = ok;

         if ( ok && extTable.isValid()) {
             ITable attTbl = fcoverage->attributeTable();
             quint32 nrAttrCols = std::min(attTbl->columnCount(),extTable->columnCount());
            // quint32 keyIndex = extTable->columnIndex(COVERAGEKEYCOLUMN);
             for(quint32 rowExt=0; rowExt < extTable->recordCount(); ++rowExt) {
                 if ( rowExt < fcoverage->featureCount()){
                     vector<QVariant> rec = extTable->record(rowExt);
                     rec.resize(nrAttrCols); // extTable received an extra "Domain" column, which is not there (and will not be there) in attTbl
                     attTbl->record(rowExt,rec);
                 }
             }
         }
    } catch (FeatureCreationError& ) {
    }
    if ( ok)
        _binaryIsLoaded = true;
    return ok;
}
Ejemplo n.º 4
0
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));
    }
}