bool GdalFeatureTableConnector::loadData(IlwisObject * data, const IOOptions &){
    if(!GdalConnector::loadMetaData(data, IOOptions())) // ??
        return false;

    Table *attTable = static_cast<Table *>(data);

    OGRLayerH hLayer = getLayerHandle();
    bool ok = true;
    if ( hLayer) {
        std::vector<QVariant> record(attTable->columnCount());

        GdalTableLoader loader;
        loader.setColumnCallbacks(attTable, hLayer);
        OGRFeatureH hFeature = 0;
        gdal()->resetReading(hLayer);
        //each FEATURE
        try {
            quint32 index = 0;
            while( (hFeature = gdal()->getNextFeature(hLayer)) != NULL){
                loader.loadRecord(attTable, hFeature, record);
                attTable->record(index++, record);
                gdal()->destroyFeature( hFeature );
            }
            _binaryIsLoaded = true;
        } catch (FeatureCreationError& ) {
            gdal()->destroyFeature( hFeature );
            ok = false;
        }
    }
    gdal()->closeFile(_fileUrl.toLocalFile(), data->id());
    return ok;
}
bool GdalFeatureConnector::loadData(IlwisObject* data, const IOOptions &){

    if(!GdalConnector::loadMetaData(data, IOOptions()))
        return false;

    bool ok = true;
    FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(data);
    if ( fcoverage->isValid() ) {
        ITable attTable = fcoverage->attributeTable();
        if (!attTable.isValid()){
            ERROR2(ERR_NO_INITIALIZED_2,"attribute table",_filename.toString());
            return false;
        }
        fcoverage->setFeatureCount(itFEATURE, iUNDEF, FeatureInfo::ALLFEATURES); // metadata already set it to correct number, creating new features will up the count agains; so reset to 0.

        OGRLayerH hLayer = getLayerHandle();
        if ( hLayer) {
            GdalTableLoader loader;
            attTable->dataLoaded(true); // new table, dont want any loading behaviour
            loader.setColumnCallbacks(attTable.ptr(), hLayer);
            std::vector<QVariant> record(attTable->columnCount());
            OGRFeatureH hFeature = 0;
            gdal()->resetReading(hLayer);
            //each FEATURE
            try {
                while( (hFeature = gdal()->getNextFeature(hLayer)) != NULL){
                    loader.loadRecord(attTable.ptr(), hFeature, record);
                    geos::geom::Geometry * geometry = fillFeature(fcoverage, gdal()->getGeometryRef(hFeature));
                    if (geometry){
                        auto feature = fcoverage->newFeature(geometry, false);
                        feature->record(record);
                    }else{
                        ERROR1("GDAL error during load of binary data: no geometry detected for feature in %1", _filename.toString());
                    }
                    gdal()->destroyFeature( hFeature );
                }
            } catch (FeatureCreationError& ) {
                gdal()->destroyFeature( hFeature );
                ok = false;
            }
        }
        //layer envelopes/extents
        Envelope bbox;
        OGREnvelope envelope;//might sometimes be supported as 3D now only posssible from OGRGeometry
        OGRErr err = gdal()->getLayerExtent(hLayer, &envelope , TRUE);//TRUE to FORCE
        if (err != OGRERR_NONE && fcoverage->featureCount() != 0){
            ERROR0(QString("Couldn't load extent of a layer from %1 after binary was loaded: %2").arg(_filename.toString()).arg(gdal()->translateOGRERR(err)));
        }else{
            bbox = Envelope(Coordinate(envelope.MinX,envelope.MinY),Coordinate(envelope.MaxX,envelope.MaxY));
        }
        fcoverage->envelope(bbox);
    }
    gdal()->closeFile(sourceRef().toLocalFile(), data->id());
    _binaryIsLoaded = ok;
    return ok;
}
bool GdalFeatureTableConnector::loadMetaData(IlwisObject* data, const IOOptions& options){
    if(!GdalConnector::loadMetaData(data, options))
        return false;

    OGRLayerH hLayer = getLayerHandle();
    if ( hLayer){
        GdalTableLoader loader;
        loader.loadMetaData((Table *)data, hLayer);
    }
    return true;
}