bool FeatureConnector::loadMetaData(Ilwis::IlwisObject *obj) { bool ok = CoverageConnector::loadMetaData(obj); if ( !ok) return false; FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(obj); IlwisTypes coverageType = itPOINT; int features = _odf->value("PointMap","Points").toInt(&ok); if (!ok) { coverageType = itLINE; features = _odf->value("SegmentMapStore","Segments").toInt(&ok); if (!ok) { coverageType = itPOLYGON; features = _odf->value("PolygonMapStore","Polygons").toInt(&ok); } } if (ok){ fcoverage->featureTypes(coverageType); fcoverage->setFeatureCount(coverageType, features); } else return ERROR2(ERR_INVALID_PROPERTY_FOR_2,"Records",obj->name()); ITable tbl = fcoverage->attributeTable(); tbl->setRows(fcoverage->featureCount()); return true; }
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); } } }
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::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; }
bool PostgresqlFeatureCoverageLoader::loadData(FeatureCoverage *fcoverage) const { //qDebug() << "PostgresqlFeatureCoverageLoader::loadData()"; ITable table; PostgresqlDatabaseUtil pgUtil(_resource,_options); Resource tableResource = pgUtil.resourceForType(itFLATTABLE); table.prepare(tableResource, _options); PostgresqlTableLoader tableLoader(table->source(), _options); if (!tableLoader.loadData(table.ptr())) { ERROR1("Could not load table data for table '%1'", table->name()); return false; } // metadata already set it to correct number, creating new features will up the count agains; so reset to 0. fcoverage->setFeatureCount(itFEATURE, iUNDEF, FeatureInfo::ALLFEATURES); QList<MetaGeometryColumn> metaGeometries; pgUtil.getMetaForGeometryColumns(metaGeometries); QSqlQuery query = pgUtil.doQuery(selectGeometries(metaGeometries), "featurecoverageloader"); quint32 geometriesPerFeature = metaGeometries.size(); IDomain semantics; pgUtil.prepareSubFeatureSemantics(semantics, metaGeometries); while (query.next()) { if (geometriesPerFeature == 0) { fcoverage->newFeature(0); } else { // index 0 is root, indeces > 0 are subfeatures of root bool atRoot = true; SPFeatureI rootFeature; // iterate semantics to keep predefined order ItemRangeIterator iter(semantics->range<>().data()); while (iter.isValid()) { QString geomName = (*iter)->name(); ICoordinateSystem crs; std::for_each(metaGeometries.begin(), metaGeometries.end(), [&crs,geomName](MetaGeometryColumn c) { if (c.geomColumn == geomName) { crs = c.crs; } }); if (atRoot) { atRoot = false; geos::geom::Geometry *rootGeometry = createGeometry(query, geomName, crs); rootFeature = fcoverage->newFeature(rootGeometry, false); } else { geos::geom::Geometry *subGeometry = createGeometry(query, geomName, crs); rootFeature->createSubFeature(geomName,subGeometry); } ++iter; } } } fcoverage->attributesFromTable(table); return true; }
bool Assignment::assignTable(ExecutionContext *ctx) { ITable outputFC = _outputObj.as<Table>(); ITable inputFC = _inputObj.as<Table>(); outputFC = inputFC->copyTable(ANONYMOUS_PREFIX); return true; }
bool GdalFeatureConnector::loadMetaData(Ilwis::IlwisObject *data,const IOOptions& options){ if(!CoverageConnector::loadMetaData(data, options)) return false; FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(data); fcoverage->setFeatureCount(itFEATURE, iUNDEF, FeatureInfo::ALLFEATURES); OGRLayerH hLayer = getLayerHandle(); if ( hLayer) { //feature types IlwisTypes type = translateOGRType(gdal()->getLayerGeometry(hLayer)); if (type == itUNKNOWN){ WARN(QString("Unknown feature type of layer %1 from: %2").arg(0).arg(_filename.toString())); }else{ fcoverage->featureTypes(type); } //feature counts int temp = gdal()->getFeatureCount(hLayer, FALSE);//TRUE to FORCE databases to scan whole layer, FALSe can end up in -1 for unknown result if (temp == -1){ WARN(QString("Couldn't determine feature count of layer %1 from meta data of %2").arg(0).arg(_filename.toString())); }else{ int featureCount = fcoverage->featureCount(type); featureCount += temp; fcoverage->setFeatureCount(type, featureCount,0); // subgeometries are not known at this level } //attribute table ITable attTable; Resource resource(_filename, itFLATTABLE); if(!attTable.prepare(resource,{"asflattable", true})) {//will load whole meta data of the table ERROR1(ERR_NO_INITIALIZED_1,resource.name()); return false; } fcoverage->setAttributes(attTable); //layer envelopes/extents Envelope bbox; OGREnvelope envelope;//might sometimes be supported as 3D now only posssible from OGRGeometry OGRErr err = gdal()->getLayerExtent(hLayer, &envelope , FALSE);//TRUE to FORCE if (err != OGRERR_NONE){ if (err == OGRERR_FAILURE){//on an empty layer or if simply too expensive(FORECE=FALSE) OGR_L_GetExtent may return OGRERR_FAILURE WARN(QString("Couldn't determine the extent of layer %1 from meta data of %2").arg(0).arg(_filename.toString())); }else{ ERROR0(QString("Couldn't load extent of layer %1 from %2: %3").arg(0).arg(_filename.toString()).arg(gdal()->translateOGRERR(err))); } }else{ bbox = Envelope(Coordinate(envelope.MinX,envelope.MinY),Coordinate(envelope.MaxX,envelope.MaxY)); } fcoverage->envelope(bbox); // fcoverage->coordinateSystem()->envelope(bbox); } gdal()->closeFile(sourceRef().toLocalFile(), data->id()); return true; }
/** * Maps the specified key to the specified value in this table. * The key can not be NULL. * The value can be retrieved by calling the get method with a key that is equal to the original key. * @param keyName the key * @param value the value */ void SmartDashboard::PutData(std::string key, Sendable *data) { if (data == NULL) { //TODO wpi_setWPIErrorWithContext(NullParameter, "value"); return; } ITable* dataTable = m_table->GetSubTable(key); dataTable->PutString("~TYPE~", data->GetSmartDashboardType()); data->InitTable(dataTable); m_tablesToData[dataTable] = data; }
bool CoverageConnector::storeBinaryData(IlwisObject *obj, IlwisTypes tp) { Coverage *coverage = static_cast<Coverage *>(obj); ITable attTable = coverage->attributeTable(); if ( attTable.isValid()) { QScopedPointer<TableConnector> conn(createTableConnector(attTable, coverage, tp)); return conn->storeBinaryData(attTable.ptr()); } return false; }
bool FeatureConnector::loadBinaryPolygons30(FeatureCoverage *fcoverage, ITable& tbl) { BinaryIlwis3Table polTable; if ( !polTable.load(_odf)) { return ERROR1(ERR_COULD_NOT_OPEN_READING_1,_odf->fileinfo().fileName()) ; } BinaryIlwis3Table topTable; if ( !topTable.load(_odf,"top")) { return ERROR1(ERR_COULD_NOT_OPEN_READING_1,_odf->fileinfo().fileName()) ; } qint32 colValue = polTable.index("PolygonValue"); qint32 colTopStart = polTable.index("TopStart"); qint32 colArea = polTable.index("Area"); int nrPolygons = polTable.rows(); bool isNumeric = _odf->value("BaseMap","Range") != sUNDEF; double v; for(int i = 0; i < nrPolygons; ++i) { polTable.get(i,colArea, v); if ( v < 0) continue; polTable.get(i,colTopStart,v); qint32 index = v; std::vector<std::vector<Coordinate2d>> rings; if (getRings(index, topTable, polTable, rings)) { if ( rings.size() == 0) continue; Polygon polygon; polygon.outer().resize(rings[0].size()); std::copy(rings[0].begin(), rings[0].end(), polygon.outer().begin()); for(int j = 1; j < rings.size(); ++j) { polygon.inners()[j-1].resize(rings[j].size()); std::copy(rings[j].begin(), rings[j].end(), polygon.inners()[j-1].begin()); } polTable.get(i, colValue, v); if ( isNumeric) { tbl->cell(COVERAGEKEYCOLUMN, i, QVariant(i)); tbl->cell(FEATUREVALUECOLUMN, i, QVariant(v)); fcoverage->newFeature({polygon}); } else { quint32 itemId = v; tbl->cell(COVERAGEKEYCOLUMN, i, QVariant(itemId)); SPFeatureI feature = fcoverage->newFeature({polygon}); tbl->cell(FEATUREIDCOLUMN, i, QVariant(feature->featureid())); } } } return true; }
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)); } }
bool CoverageConnector::loadMetaData(Ilwis::IlwisObject *data) { Ilwis3Connector::loadMetaData(data); Coverage *coverage = static_cast<Coverage *>(data); QString csyName = _odf->value("BaseMap","CoordSystem"); if ( csyName.toLower() == "latlonwgs84.csy") csyName = "code=epsg:4326"; ICoordinateSystem csy; if ( !csy.prepare(csyName)) { kernel()->issues()->log(csyName,TR("Coordinate system couldnt be initialized, defaulting to 'unknown'"),IssueObject::itWarning); QString resource = QString("ilwis://file/unknown.csy"); if (!csy.prepare(resource)) { kernel()->issues()->log(TR("Fallback to 'unknown failed', corrupt system files defintion")); return false; } } coverage->setCoordinateSystem(csy); QString attfile = _odf->value("BaseMap", "AttributeTable"); QString basemaptype = _odf->value("BaseMap", "Type"); // feature coverages always have an attribute table; rasters might have if ( basemaptype != "Map" || attfile != sUNDEF) { ITable attTable = prepareAttributeTable(attfile, basemaptype); if (!attTable.isValid()) return false; coverage->attributeTable(attTable); } QString cbounds = _odf->value("BaseMap","CoordBounds"); QStringList parts = cbounds.split(" "); if ( parts.size() == 4) { double minx = parts[0].toDouble(); double miny = parts[1].toDouble(); double maxx = parts[2].toDouble(); double maxy = parts[3].toDouble(); Box2D<double> env(Coordinate(minx, miny), Coordinate(maxx, maxy)); coverage->envelope(env); } else { kernel()->issues()->log(TR(ERR_INVALID_PROPERTY_FOR_2).arg("Coordinate boundaries", data->name()), IssueObject::itWarning); } return true; }
bool FeatureConnector::loadBinaryPolygons37(FeatureCoverage *fcoverage, ITable& tbl) { QString datafile = _odf->value("PolygonMapStore","DataPol"); datafile = context()->workingCatalog()->filesystemLocation().toLocalFile() + "/" + datafile; QFile file(datafile); if (!file.exists()){ kernel()->issues()->log(TR(ERR_MISSING_DATA_FILE_1).arg(file.fileName())); return false; } if(!file.open(QIODevice::ReadOnly )){ kernel()->issues()->log(TR(ERR_COULD_NOT_OPEN_READING_1).arg(file.fileName())); return false; } QDataStream stream(&file); int nrPolygons = fcoverage->featureCount(itPOLYGON); SPAttributeRecord record( new AttributeRecord(tbl,FEATUREIDCOLUMN)); bool isNumeric = _odf->value("BaseMap","Range") != sUNDEF; for(int j=0; j < nrPolygons; ++j) { Polygon pol; readRing(stream, pol.outer()); double value; quint32 numberOfHoles; stream.readRawData((char *)&value, 8); stream.readRawData((char *)&numberOfHoles, 4); pol.inners().resize(numberOfHoles); for(quint32 i=0; i< numberOfHoles;++i) readRing(stream, pol.inners()[i]); if ( isNumeric) { tbl->cell(COVERAGEKEYCOLUMN, j, QVariant(j)); tbl->cell(FEATUREVALUECOLUMN, j, QVariant(value)); SPFeatureI feature = fcoverage->newFeature({pol}); tbl->cell(FEATUREIDCOLUMN, j, QVariant(feature->featureid())); } else { quint32 itemId = value; tbl->cell(COVERAGEKEYCOLUMN, j, QVariant(itemId)); SPFeatureI feature = fcoverage->newFeature({pol}); tbl->cell(FEATUREIDCOLUMN, j, QVariant(feature->featureid())); } } file.close(); return true; }
UserModelEditor::UserModelEditor() : ModelEntityEditor< ::Model::User >() { // Remove unsed widget getForm()->removeWidget("id"); getForm()->removeWidget("created_at"); getForm()->removeWidget("last_access"); getForm()->removeWidget("puppetftp_role"); getForm()->removeWidget("passwd"); // Set label getForm()->getWidget("firstname")->setLabel("First Name"); getForm()->getWidget("lastname")->setLabel("Last Name"); getForm()->getWidget("email")->setLabel("Email"); // Add custom attribute getForm()->getWidget("email")->setAttribute("autocomplete", "off"); // Get role ITable* table = DatabaseManager::instance()->getTable("puppetftp_role"); if (table == NULL) { // rediriger ou gérer le cas d'erreur } QList<QObject*> roles = table->getAll(); // Create custom widget InputChoice* selectRole = new InputChoice("puppetftp_role", InputChoice::SELECT); selectRole->setLabel("Role"); for (QList<QObject*>::const_iterator it = roles.begin(); it != roles.end(); it++) { Model::Role* role = dynamic_cast<Model::Role*>(*it); selectRole->addOption(QString::number(role->getId()), role->getName()); } getForm()->addWidget("editor", selectRole); Input* password = new Input("passwd", Input::PASSWORD); password->setLabel("Password"); password->setAttribute("autocomplete", "off"); getForm()->addWidget("editor", password); roles.clear(); delete table; }
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; }
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>(); }
void ServerListProcessor::process(HTTPRequest& request) { Session* s = SessionManager::instance()->getSession(request.getSessionId()); addNotify(s->getNotification("edit")); ITable* object = DatabaseManager::instance()->getTable("server"); if (object == 0) { s->setNotification("listing", "Entity 'server' doesn't exists.", UI::Notify::ERROR); request.redirect("index"); return; } _table = UI::ModelWidgetFactory::instance()->getListWidget("serverConfigurationList"); if (_table == NULL) { s->setNotification("listing", "Model Entity List 'serverConfiguration' doesn't exists.", UI::Notify::ERROR); request.redirect("index"); } else { _table->fill(object->getAll()); } delete object; }
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; }
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); }
OperationImplementation::State BinaryMathFeature::prepare(ExecutionContext *ctx, const SymbolTable &) { QString featureCovName = _expression.parm(0).value(); if (!_inputFeatureSet1.prepare(featureCovName)) { ERROR2(ERR_COULD_NOT_LOAD_2,featureCovName,"" ); return sPREPAREFAILED; } featureCovName = _expression.parm(1).value(); if (!_inputFeatureSet2.prepare(featureCovName)) { ERROR2(ERR_COULD_NOT_LOAD_2,featureCovName,"" ); return sPREPAREFAILED; } bool ok = false; if ( ctx->_masterCsy != sUNDEF) { ok = _csyTarget.prepare(ctx->_masterCsy); if (!ok){ WARN1(WARN_COULDNT_CREATE_OBJECT_FOR_1,ctx->_masterCsy); } } if (!ok) { _csyTarget = _inputFeatureSet1->coordinateSystem(); } Resource resource(_inputFeatureSet1->ilwisType() | _inputFeatureSet2->ilwisType()); _outputFeatures.prepare(resource); Envelope envelope = addEnvelopes(); _outputFeatures->coordinateSystem(_csyTarget); _outputFeatures->envelope(envelope); ITable attTable = _merger.mergeMetadataTables(_inputFeatureSet1->attributeTable(), _inputFeatureSet2->attributeTable()); attTable->recordCount(_inputFeatureSet1->featureCount() + _inputFeatureSet2->featureCount()); _outputFeatures->setAttributes(attTable); QString outname = _expression.parm(0,false).value(); if ( outname != sUNDEF) _outputFeatures->name(outname); return sPREPARED; }
void OperationWorker::process(){ try { Operation op(_expression); SymbolTable tbl; ExecutionContext ctx; if(op->execute(&ctx, tbl)){ if ( ctx._results.size() > 0){ for(auto resultName : ctx._results){ Symbol symbol = tbl.getSymbol(resultName); if ( hasType(symbol._type, itNUMBER)){ _result += symbol._var.toDouble(); }else if ( hasType(symbol._type, itSTRING)){ _result += symbol._var.toString(); }else if ( hasType(symbol._type, (itCOVERAGE | itTABLE))){ if ( symbol._type == itRASTER){ IRasterCoverage raster = symbol._var.value<IRasterCoverage>(); if ( raster.isValid()) _result = raster->resource().url().toString(); }else if(symbol._type == itTABLE){ ITable table = symbol._var.value<ITable>(); if(table.isValid()) _result = table->resource().url().toString(); } } } } kernel()->issues()->log(QString(TR("Operation has executed succesfully")), IssueObject::itMessage); }else { qDebug() << "operation failed"; } emit finished(); }catch(const ErrorObject& err){ } emit finished(); }
bool FeatureConnector::storeBinaryDataTable(IlwisObject *obj, IlwisTypes tp, const QString& baseName) { FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(obj); ITable attTable = fcoverage->attributeTable(); if ( attTable.isValid() && attTable->columnCount() > 0) { QFileInfo basename (baseName); QScopedPointer<TableConnector> conn(createTableStoreConnector(attTable, fcoverage, tp, basename.baseName())); IFeatureCoverage cov(fcoverage); FeatureIterator iter(cov); quint32 i = 0; std::vector<quint32> recordnr(fcoverage->featureCount(tp)); for(quint32 rec=0; rec < fcoverage->featureCount(); ++rec){ if ( hasType((*iter)->geometryType(), tp)) recordnr[i++] = rec; ++iter; }; conn->selectedRecords(recordnr); return conn->storeBinaryData(attTable.ptr()); } return true; // no store needed }
/** * Initialize all the LiveWindow elements the first time we enter LiveWindow mode. * By holding off creating the NetworkTable entries, it allows them to be redefined * before the first time in LiveWindow mode. This allows default sensor and actuator * values to be created that are replaced with the custom names from users calling * addActuator and addSensor. */ void LiveWindow::InitializeLiveWindowComponents() { for (std::map<LiveWindowSendable *, LiveWindowComponent>::iterator it = m_components.begin(); it != m_components.end(); ++it) { LiveWindowSendable *component = it->first; LiveWindowComponent c = it->second; std::string subsystem = c.subsystem; std::string name = c.name; m_liveWindowTable->GetSubTable(subsystem)->PutString("~TYPE~", "LW Subsystem"); ITable *table = m_liveWindowTable->GetSubTable(subsystem)->GetSubTable( name); table->PutString("~TYPE~", component->GetSmartDashboardType()); table->PutString("Name", name); table->PutString("Subsystem", subsystem); component->InitTable(table); if (c.isSensor) { m_sensors.push_back(component); } } }
bool PostgresqlFeatureCoverageLoader::loadMetadata(FeatureCoverage *fcoverage) const { //qDebug() << "PostgresqlFeatureCoverageLoader::loadMetadata()"; ITable featureTable; if(!featureTable.prepare(_resource.url().toString(), itFLATTABLE, _options)) { ERROR1(ERR_NO_INITIALIZED_1, _resource.name() + "[itFLATTABLE]"); return false; } setFeatureCount(fcoverage); setSpatialMetadata(fcoverage); fcoverage->attributesFromTable(featureTable); IDomain semantics; QList<MetaGeometryColumn> metaGeometries; PostgresqlDatabaseUtil pgUtil(_resource,_options); pgUtil.getMetaForGeometryColumns(metaGeometries); pgUtil.prepareSubFeatureSemantics(semantics, metaGeometries); setSubfeatureSemantics(fcoverage, semantics); return true; }
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 FeatureConnector::loadBinaryPoints(FeatureCoverage *fcoverage) { BinaryIlwis3Table mppTable; if ( !mppTable.load(_odf)) { return ERROR1(ERR_COULD_NOT_OPEN_READING_1,_odf->fileinfo().fileName()) ; } // two cases; the old case; 2 columns for x and y. and the new case one column for coord int coordColumnX = mppTable.index("x"); int coordColumnY = mppTable.index("y"); int coordColumn = mppTable.index("Coordinate"); int colItemId = mppTable.index("Name"); ITable tbl = fcoverage->attributeTable(); bool newCase = coordColumnX == iUNDEF; for(quint32 i= 0; i < mppTable.rows(); ++i) { Coordinate c; double itemIdT; if ( newCase) { mppTable.get(i, coordColumn, c); } else { double x,y; mppTable.get(i, coordColumnX, x); mppTable.get(i, coordColumnY, y); c = Coordinate(x,y); } mppTable.get(i, colItemId,itemIdT); quint32 itemId = itemIdT; tbl->cell(COVERAGEKEYCOLUMN, i, QVariant(itemId)); SPFeatureI feature = fcoverage->newFeature({c}); tbl->cell(FEATUREIDCOLUMN, i, QVariant(feature->featureid())); } return true; }
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; }
bool FeatureConnector::loadBinarySegments(FeatureCoverage *fcoverage) { BinaryIlwis3Table mpsTable; if ( !mpsTable.load(_odf)) { return ERROR1(ERR_COULD_NOT_OPEN_READING_1,_odf->fileinfo().fileName()) ; } int colCoords = mpsTable.index("Coords"); int colItemId = mpsTable.index("SegmentValue"); bool isNumeric = _odf->value("BaseMap","Range") != sUNDEF; ITable tbl = fcoverage->attributeTable(); // if ( isNumeric) // in other case nr of record already has been set as it is based on a real table // tbl->setRows(mpsTable.rows()); double value; for(quint32 i= 0; i < mpsTable.rows(); ++i) { std::vector<Coordinate > coords; mpsTable.get(i,colCoords,coords); Line2D<Coordinate2d > line; line.resize(coords.size()); std::copy(coords.begin(), coords.end(), line.begin()); mpsTable.get(i, colItemId,value); if ( isNumeric) { tbl->cell(COVERAGEKEYCOLUMN, i, QVariant(i)); tbl->cell(FEATUREVALUECOLUMN, i, QVariant(value)); SPFeatureI feature = fcoverage->newFeature({line}); tbl->cell(FEATUREIDCOLUMN, i, QVariant(feature->featureid())); } else { quint32 itemId = value; tbl->cell(COVERAGEKEYCOLUMN, i, QVariant(itemId)); SPFeatureI feature = fcoverage->newFeature({line}); tbl->cell(FEATUREIDCOLUMN, i, QVariant(feature->featureid())); } } return true; }
int main(void) { Object **obj = MyUnitTests(); LittlePony *lp = (LittlePony *)obj[0]; Teddy *t = (Teddy *)obj[1]; ITable *theTruc = createTable(); const std::string **myTab; theTruc->Put(new Teddy("Beer")); theTruc->Put(new Teddy("Pokemon")); theTruc->Put(new LittlePony("Jeremy")); theTruc->Take(1); myTab = theTruc->Look(); int i = 0; while (myTab[i]) { std::cout << *myTab[i] << std::endl; i++; } lp->isTaken(); t->isTaken(); obj = new Object*[4]; obj[0] = new Teddy("bisounours"); obj[1] = new Box; obj[2] = new GiftPaper; obj[3] = NULL; std::cout << obj[1]->getTitle() << std::endl; std::cout << obj[2]->getTitle() << std::endl; MyUnitTests(obj); return (0); }