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;
}
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;

}