Beispiel #1
0
DataDefinition IfOperation::findParameterDataDef(const OperationExpression &expr, int index)  {
    const Parameter& parm = expr.parm(index);
    DataDefinition def;
    QString parmvalue = parm.value();
    IlwisTypes ptype = parm.valuetype();
    if (hasType(ptype,itRASTER)) {
        IRasterCoverage cov;
        if (cov.prepare(parmvalue)) {
            def = cov->datadef();
            _coverages[index - 1] = cov.as<Coverage>();
        }
    } else {
        bool ok;
        _number[index - 1] = parmvalue.toDouble(&ok);
        if ( ok){
            IDomain dom("code=domain:value");
            def.domain(dom);
        } else {
            std::vector<QString> bools = {"true","false","yes","no","?"};
            auto iter = std::find(bools.begin(), bools.end(), parmvalue.toLower());
            if ( iter != bools.end()) {
                int v = 0;
                if ( parmvalue == "?" )
                    v= 2;
                else if ( parmvalue == "yes" || parmvalue == "true")
                    v = 1;
                _number[index - 1] = v;
                IDomain dm;
                dm.prepare("boolean");
                def.domain(dm);
            }
        }
    }
    return def;
}
DataDefinition IfOperation::findParameterDataDef(const OperationExpression &expr, int index)  {
    const Parameter& parm = expr.parm(index);
    DataDefinition def;
    QString parmvalue = parm.value().toLower();

    quint64 gcid = mastercatalog()->name2id(parmvalue, itRASTER);
    if ( gcid != i64UNDEF) {
        IRasterCoverage cov;
        if(cov.prepare(gcid)) {
            def = cov->datadef();
            _coverages[index - 1] = cov.get<Coverage>();
        }
    } else {
        bool ok;
        _number[index - 1] =parmvalue.toDouble(&ok);
        if ( ok){
            def.domain().prepare("value");
        } else {
            std::vector<QString> bools = {"true","false","yes","no","?"};
            auto iter = std::find(bools.begin(), bools.end(), parmvalue.toLower());
            if ( iter != bools.end()) {
                int v = 0;
                if ( parmvalue == "?" )
                    v= 2;
                else if ( parmvalue == "yes" || parmvalue == "true")
                    v = 1;
                _number[index - 1] = v;
                IDomain dm;
                dm.prepare("boolean");
                def.domain(dm);
            }
        }
    }
    return def;
}
bool VersionedSerializer::storeDataDefintion(const DataDefinition &def, QDataStream &stream, const IOOptions &options) const
{
    VersionedDataStreamFactory *factory = kernel()->factory<VersionedDataStreamFactory>("ilwis::VersionedDataStreamFactory");
    if (!factory)
        return false;
    std::unique_ptr<DataInterface> domainStreamer(factory->create(Version::interfaceVersion, itDOMAIN,_stream));
    if ( !domainStreamer)
        return false;
    _stream << def.domain()->valueType();
    domainStreamer->store(def.domain().ptr(), options);
    if ( !def.range().isNull()) // no range for textdomains
        def.range()->store(_stream);

    return true;
}
Ilwis::OperationImplementation::State SetAttributeTable::prepare(ExecutionContext *ctx, const SymbolTable &st)
{
    OperationImplementation::prepare(ctx,st);

    OperationHelper::check([&] ()->bool { return _inputTable.prepare(_expression.input<QString>(0), itTABLE); },
    {ERR_COULD_NOT_LOAD_2,_expression.input<QString>(0), "" } );

    OperationHelper::check([&] ()->bool { return _inputRaster.prepare(_expression.input<QString>(1), itRASTER); },
    {ERR_COULD_NOT_LOAD_2,_expression.input<QString>(1), "" } );

    _primaryKey = _expression.input<QString>(2);

    int index = _inputTable->columnIndex(_primaryKey);
    if ( index == iUNDEF){
        kernel()->issues()->log(TR("Table doesnt contain column ") + _primaryKey);
        return sPREPAREFAILED;
    }
    std::vector<QVariant> values = _inputTable->column(_primaryKey);
    std::set<QVariant> uniques;
    int undefs = 0;
    for(QVariant v : values){
        if ( isNumericalUndef(v.toDouble()))
            ++undefs;
        else
            uniques.insert(v);
    }
    if ( (uniques.size() + undefs ) != values.size()){
        kernel()->issues()->log(TR("Key column must not contain duplicate values"));
        return sPREPAREFAILED;
    }

    ColumnDefinition coldef = _inputTable->columndefinition(index);
    if ( !coldef.datadef().domain()->isCompatibleWith(_inputRaster->datadef().domain().ptr())){
        kernel()->issues()->log(TR("Key column doesnt match raster domain ") + _primaryKey);
        return sPREPAREFAILED;
    }

    OperationHelperRaster helper;
    helper.initialize(_inputRaster, _outputRaster, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF|itDOMAIN);

    for(quint32 i = 0; i < _outputRaster->size().zsize(); ++i){
        QString index = _outputRaster->stackDefinition().index(i);
        DataDefinition datadef = _outputRaster->datadef(i);
        _outputRaster->setBandDefinition(index,DataDefinition(datadef.domain(), datadef.range()->clone()));
    }
    return sPREPARED;
}
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;
}
DataDefinition RasterCoverageConnector::createDataDef(double vmin, double vmax, double resolution, bool accurate, GdalOffsetScale gdalOffsetScale){

    if (gdalOffsetScale.offset != rUNDEF && gdalOffsetScale.scale != rUNDEF) {
        vmin = vmin * gdalOffsetScale.scale  + gdalOffsetScale.offset ;
        vmax = vmax * gdalOffsetScale.scale  + gdalOffsetScale.offset ;
    }

    QString domName = NumericDomain::standardNumericDomainName(vmin, vmax,  resolution);
    IDomain dom;
    dom.prepare(domName);
    if(!dom.isValid()) {
        ERROR1(ERR_FIND_SYSTEM_OBJECT_1, domName);
        return DataDefinition();
    }
    DataDefinition def;
    def.domain(dom);
    if (accurate)
        def.range(new NumericRange(vmin, vmax, dom->range<NumericRange>()->resolution()));
    else
        def.range(new NumericRange()); // invalid NumericRange, force computing raster statistics
    return def;
}
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);
}
Beispiel #8
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   DataDefinition dataDef;
   string name = "/cpp_datadefinition_create";
   unsigned char byteData[50];
   unsigned int dataLength = 50;

   try {
      if ( argc > 1 ) {
         process.Init( argv[1], argv[0] );
      }
      else {
         process.Init( "10701", argv[0] );
      }
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed in init phase, error = " << exc.Message() << endl;
      cerr << "Is the server running?" << endl;
      return 1;
   }

   // Session is not initialized
   
   try {
      dataDef.Create( session, 
                      name,
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_HANDLE ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      session.Init();
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   // Wrong arguments to tested function
   
   try {
      dataDef.Create( session, 
                      "",
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_INVALID_LENGTH ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      dataDef.Create( session, 
                      "Default",
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_ITEM_ALREADY_PRESENT ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      dataDef.Create( session, 
                      name,
                      (psoDefinitionType)0,
                      byteData,
                      dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_WRONG_OBJECT_TYPE ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }
   
   try {
      dataDef.Create( session, 
                      name,
                      PSO_DEF_USER_DEFINED,
                      NULL,
                      dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_POINTER ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      dataDef.Create( session, 
                      name,
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      0 );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_INVALID_LENGTH ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }
   
   // This call should work
   
   try {
      dataDef.Create( session, 
                      name,
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      dataLength );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   return 0;
}
bool DataDefinition::isCompatibleWith(const DataDefinition& datdef){
    return this->ptr().isCompatibleWith(datdef.ptr());
}
DataDefinition::DataDefinition(const DataDefinition &datdef){
    if(datdef.__bool__())
        this->_ilwisDatadef.reset(new Ilwis::DataDefinition(datdef.ptr()));
}
bool CoverageConnector::storeMetaData(IlwisObject *obj, IlwisTypes type, const DataDefinition& datadef)
{
    bool ok = Ilwis3Connector::storeMetaData(obj, type);
    if ( !ok)
        return false;

    Coverage *coverage = static_cast<Coverage *>(obj);

    const ICoordinateSystem csy = coverage->coordinateSystem();
    if (!csy.isValid())
        return ERROR2(ERR_NO_INITIALIZED_2, "CoordinateSystem", coverage->name());

    QString localName = Resource::toLocalFile(csy->source().url(),true);
    if ( localName == sUNDEF) {
        localName = CoordinateSystemConnector::createCsyFromCode(csy->code());
    }
    if ( localName == sUNDEF) {
        return ERROR2(ERR_NO_INITIALIZED_2, "CoordinateSystem", coverage->name());
    }
    _odf->setKeyValue("BaseMap","CoordSystem", localName);
    Box2D<double> bounds = coverage->envelope();
    if(!bounds.isValid())
        return ERROR2(ERR_NO_INITIALIZED_2, "Bounds", coverage->name());

    _odf->setKeyValue("BaseMap","CoordBounds",QString("%1 %2 %3 %4").
                      arg(bounds.min_corner().x(),10,'f').
                      arg(bounds.min_corner().y(),10,'f').
                      arg(bounds.max_corner().x(),10,'f').
                      arg(bounds.max_corner().y(),10,'f'));

    const IDomain dom = datadef.domain();
    if (!dom.isValid())
        return ERROR2(ERR_NO_INITIALIZED_2, "Domain", coverage->name());

    calcStatics(obj,NumericStatistics::pBASIC);
    if ( dom->ilwisType() == itNUMERICDOMAIN) {

        quint16 digits = coverage->statistics().significantDigits();
        qint32 delta = coverage->statistics()[NumericStatistics::pDELTA];
        if ( delta >= 0 && delta < 256 && digits == 0){
            if ( delta >= 0 && delta < 256 && digits == 0){
                if ( datadef.domain()->code() == "boolean"){
                    QString domInfo = QString("bool.dom;Byte;bool;0;;");
                    _odf->setKeyValue("BaseMap","DomainInfo",domInfo);
                    _odf->setKeyValue("BaseMap","Range","0:1:offset=-1");
                    _odf->setKeyValue("BaseMap","Domain","bool.dom");
                }
                else{
                    QString domInfo = QString("Image.dom;Byte;image;0;;");
                    _odf->setKeyValue("BaseMap","DomainInfo",domInfo);
                    _odf->setKeyValue("BaseMap","Range","0:255:offset=0");
                    _odf->setKeyValue("BaseMap","MinMax","0:255");
                    _odf->setKeyValue("BaseMap","Domain","Image.dom");
                }
            }
        }
        else {
            const NumericStatistics& stats = coverage->statistics();
            int digits = stats.significantDigits();
            RawConverter conv(stats[NumericStatistics::pMIN], stats[NumericStatistics::pMAX],pow(10, - digits));
            QString rangeString = QString("%1:%2:%3:offset=%4").arg(stats[NumericStatistics::pMIN]).arg(stats[NumericStatistics::pMAX]).arg(conv.scale()).arg(conv.offset());
            _odf->setKeyValue("BaseMap","Range",rangeString);
            _odf->setKeyValue("BaseMap","Domain","value.dom");

            _odf->setKeyValue("BaseMap","MinMax",QString("%1:%2").arg(stats[NumericStatistics::pMIN]).arg(stats[NumericStatistics::pMAX]));
            QString domInfo = QString("value.dom;Long;value;0;-9999999.9:9999999.9:0.1:offset=0");
            _odf->setKeyValue("BaseMap","DomainInfo",domInfo);
        }
    } if ( dom->ilwisType() == itITEMDOMAIN) {
        QString source = Resource::toLocalFile(dom->source().url(), true);
        if ( dom->valueType() == itTHEMATICITEM && coverage->ilwisType() == itRASTER) {
            IThematicDomain themdom = dom.get<ThematicDomain>();
            if ( themdom.isValid()) {
                QString domInfo = QString("%1;Byte;class;%2;;").arg(source).arg(themdom->count());
                _odf->setKeyValue("BaseMap","DomainInfo",domInfo);
                _odf->setKeyValue("BaseMap","Domain",source);
            }
        } else if(dom->valueType() == itINDEXEDITEM) {
            QString domName = _odf->fileinfo().fileName();
            QString domInfo = QString("%1;Long;UniqueID;0;;").arg(domName);
            _odf->setKeyValue("BaseMap","DomainInfo",domInfo);
            _odf->setKeyValue("BaseMap","Domain",domName);
        } else if ( dom->valueType() == itNAMEDITEM) {
            INamedIdDomain iddom = dom.get<NamedIdDomain>();
            QString domName = _odf->fileinfo().fileName();
            int index;
            if ( (index=domName.lastIndexOf("."))!= -1)             {
                domName = domName.left(index);
            }
            QString domInfo = QString("%1;;Int;id;%2;;").arg(domName).arg(iddom->count());
            _odf->setKeyValue("BaseMap","DomainInfo",domInfo);
            _odf->setKeyValue("BaseMap","Domain",domName);
            iddom->connectTo(QUrl(),"domain","ilwis3", IlwisObject::cmOUTPUT);
            iddom->store(Ilwis::IlwisObject::smMETADATA | Ilwis::IlwisObject::smBINARYDATA);
        }
    }

    ITable attTable = coverage->attributeTable();
    if ( attTable.isValid()) {
        QScopedPointer<TableConnector> conn(createTableConnector(attTable, coverage, type));
        conn->storeMetaData(attTable.ptr());
    }
    return true;
}
ColumnDefinition::ColumnDefinition(const std::string& name, const Domain &dom, quint64 colindex){
    DataDefinition datdef = DataDefinition(dom);
    _ilwisColDef.reset(new Ilwis::ColumnDefinition(QString::fromStdString(name), datdef.ptr(), colindex));
}
bool FeatureConnector::storeMetaData(FeatureCoverage *fcov, IlwisTypes type) {
    if ( type == itUNKNOWN)
        return true;//if type is itUNKNOWN we dont store
    DataDefinition datadef;

    ITable attTable = fcov->attributeTable();
    QString primkey = attTable->primaryKey();
    if (primkey == sUNDEF)
        primkey = COVERAGEKEYCOLUMN;
    int index = attTable->columnIndex(primkey);
    if ( index != iUNDEF ) {
        const ColumnDefinition& coldef = attTable->columndefinitionRef(index);
        if ( coldef.datadef().domain<>()->ilwisType() == itITEMDOMAIN)
            datadef = DataDefinition(coldef.datadef().domain(),coldef.datadef().range()->clone());
    }
    if ( !datadef.isValid()) {
        INamedIdDomain indexdom;
        indexdom.prepare();
        indexdom->name(fcov->name());
        NamedIdentifierRange range;
        for(quint32 i=0; i < fcov->featureCount(type); ++i){
            QStringList parts = Ilwis3Connector::ilwis3ClassName(type).split(" ");
            QString itemname = QString("%1_%2").arg(parts[0]).arg(i);
            range << itemname;
        }
        indexdom->setRange(range);
        datadef.domain(indexdom);
        QFileInfo inf ( _resource.url(true).toLocalFile());
        QString filename = context()->workingCatalog()->filesystemLocation().toLocalFile() + "/" + inf.baseName() + ".dom";
        indexdom->connectTo(filename,"domain","ilwis3", Ilwis::IlwisObject::cmOUTPUT);
        indexdom->store();
    }
    bool isMulti = (fcov->featureTypes() & (fcov->featureTypes() - 1)) != 0;
    QString baseName = Ilwis3Connector::outputNameFor(fcov, isMulti, type);
    index = baseName.lastIndexOf(".");
    if ( index != -1) {
        baseName = baseName.left(index);
    }

    bool ok = CoverageConnector::storeMetaData(fcov, type, datadef, baseName);
    if ( !ok)
        return false;

    if ( datadef.domain()->valueType() == itINDEXEDITEM) {
        _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",IniFile::FormatElement(fcov->featureCount(type)));
    }

    Envelope bounds = fcov->envelope();
    if ( bounds.isNull() || !bounds.isValid())
        bounds = fcov->coordinateSystem()->envelope();

    _odf->setKeyValue("BaseMap","CoordBounds",QString("%1 %2 %3 %4").
                      arg(bounds.min_corner().x,0,'f',10).
                      arg(bounds.max_corner().y,0,'f',10).
                      arg(bounds.max_corner().x,0,'f',10).
                      arg(bounds.min_corner().y,0,'f',10));

    QString ext = "mpa";
    if ( hasType(type, itPOLYGON)){
        ok = storeMetaPolygon(fcov, baseName);
    }
    if ( hasType(type, itLINE)){
        ok = storeMetaLine(fcov, baseName);
        ext = "mps";
    }
    if ( hasType(type, itPOINT)){
        ok = storeMetaPoint(fcov, baseName);
        ext = "mpp";
    }
    if ( attTable.isValid() && attTable->columnCount() > 0) {
        QFileInfo basename (baseName);
        QScopedPointer<TableConnector> conn(createTableStoreConnector(attTable, fcov, type, basename.baseName()));
        std::vector<quint32> recs(_itemCount);
        conn->selectedRecords(recs);
        conn->storeMetaData(attTable.ptr());
    }

    _odf->store(ext, QFileInfo(baseName));
    return ok;
}
Beispiel #14
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   DataDefinition dataDef;
   string name = "/cpp_datadefinition_close";
   unsigned char byteData[50];
   unsigned int dataLength = 50;

   try {
      if ( argc > 1 ) {
         process.Init( argv[1], argv[0] );
      }
      else {
         process.Init( "10701", argv[0] );
      }
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed in init phase, error = " << exc.Message() << endl;
      cerr << "Is the server running?" << endl;
      return 1;
   }

   // DataDefinition is not initialized

   try {
      dataDef.Close();
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_HANDLE ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      session.Init();
      dataDef.Create( session, 
                      name,
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      dataLength );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   try {
      dataDef.Close();
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   return 0;
}
Beispiel #15
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   HashMap * hashmap;
   string fname = "/cpp_hashmap_definition";
   string hname = fname + "/test";

   psoObjectDefinition mapDef = { PSO_HASH_MAP, 0, 0, 0 };
   psoFieldDefinition fields[5] = {
      { "field1", PSO_TINYINT,       {0} },
      { "field2", PSO_INTEGER,       {0} },
      { "field3", PSO_CHAR,         {30} },
      { "field4", PSO_SMALLINT,      {0} },
      { "field5", PSO_LONGVARBINARY, {0} }
   };
   psoKeyFieldDefinition keys[2] = {
      { "LastName",  PSO_KEY_CHAR,    30 },
      { "FirstName", PSO_KEY_VARCHAR, 30 }
   };
   
   DataDefinition * retDataDef = NULL;
   KeyDefinition  * retKeyDef  = NULL;
   unsigned char * retFields = NULL;
   unsigned char * retKeys   = NULL;

   try {
      if ( argc > 1 ) {
         process.Init( argv[1], argv[0] );
      }
      else {
         process.Init( "10701", argv[0] );
      }
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed in init phase, error = " << exc.Message() << endl;
      cerr << "Is the server running?" << endl;
      return 1;
   }
   
   try {
      session.Init();
      session.CreateFolder( fname );

      DataDefinition dataDefObj( session, 
                                 "cpp_hashmap_definition",
                                 PSO_DEF_PHOTON_ODBC_SIMPLE,
                                 (unsigned char *)fields,
                                 5*sizeof(psoFieldDefinition) );
      KeyDefinition keyDefObj( session, 
                               "cpp_hashmap_definition",
                               PSO_DEF_PHOTON_ODBC_SIMPLE,
                               (unsigned char *)keys,
                               2*sizeof(psoKeyFieldDefinition) );
      session.CreateMap( hname, mapDef, dataDefObj, keyDefObj );
      hashmap = new HashMap( session, hname );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   try {
      retDataDef = hashmap->GetDataDefinition();
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   try {
      if ( retDataDef->GetType() != PSO_DEF_PHOTON_ODBC_SIMPLE ) {
         cerr << "Test failed - line " << __LINE__ << endl;
         return 1;
      }
      if ( retDataDef->GetLength() != 5*sizeof(psoFieldDefinition) ) {
         cerr << "Test failed - line " << __LINE__ << endl;
         return 1;
      }
      retFields = new unsigned char [5*sizeof(psoFieldDefinition)];
      retDataDef->GetDefinition( retFields, 5*sizeof(psoFieldDefinition) );
      if ( memcmp( retFields, fields, 5*sizeof(psoFieldDefinition) ) != 0 ) {
         cerr << "Test failed - line " << __LINE__ << endl;
         return 1;
      }
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   try {
      retKeyDef = hashmap->GetKeyDefinition();
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   try {
      if ( retKeyDef->GetType() != PSO_DEF_PHOTON_ODBC_SIMPLE ) {
         cerr << "Test failed - line " << __LINE__ << endl;
         return 1;
      }
      if ( retKeyDef->GetLength() != 2*sizeof(psoKeyFieldDefinition) ) {
         cerr << "Test failed - line " << __LINE__ << endl;
         return 1;
      }
      retKeys = new unsigned char [2*sizeof(psoKeyFieldDefinition)];
      retKeyDef->GetDefinition( retKeys, 2*sizeof(psoKeyFieldDefinition) );
      if ( memcmp( retKeys, keys, 2*sizeof(psoKeyFieldDefinition) ) != 0 ) {
         cerr << "Test failed - line " << __LINE__ << endl;
         return 1;
      }
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   return 0;
}
bool RasterCoverageConnector::store(IlwisObject *obj, const IOOptions & )
{
    if(!loadDriver())
        return false;

    RasterCoverage *raster = static_cast<RasterCoverage *>(obj);

    DataDefinition currentDef = raster->datadefRef();
    if (! hasType(raster->datadef().domain()->ilwisType(),itNUMERICDOMAIN | itCOLORDOMAIN)){
        IDomain dom;
        QString code = raster->datadef().domain()->ilwisType() == itITEMDOMAIN ? "code=count" : "code=value";
        if(!dom.prepare(code)) { //TODO:  for the moment only value maps in gdal
            return ERROR1(ERR_NO_INITIALIZED_1,obj->name());
        }
        currentDef.domain(dom);
    }
    Size<> sz = raster->size();
    GDALDataType gdalType = ilwisType2GdalType(currentDef.range()->valueType());
    QString filename = constructOutputName(_driver);
    bool isColorMap = currentDef.domain()->ilwisType() == itCOLORDOMAIN;
    bool ispaletteMap = currentDef.domain()->valueType() == itPALETTECOLOR;

    GDALDatasetH dataset = 0;
    if ( ispaletteMap && format() == "GTiff"){
        char *options[] = {"PHOTOMETRIC=PALETTE", NULL};
        dataset = gdal()->create( _driver, filename.toLocal8Bit(), sz.xsize(), sz.ysize(),  sz.zsize(), gdalType, options );
    }else
        dataset = gdal()->create( _driver, filename.toLocal8Bit(), sz.xsize(), sz.ysize(),  isColorMap ?  sz.zsize() * 3 : sz.zsize(), gdalType, 0 );
    if ( dataset == 0) {
        return ERROR2(ERR_COULDNT_CREATE_OBJECT_FOR_2, "data set",_fileUrl.toLocalFile());
    }
    bool ok = setGeotransform(raster, dataset);
    if (ok)
        ok = setSRS(raster, dataset);

    if (!ok)
        return false;

    if ( isColorMap ){
        ok = storeColorRaster(raster, dataset)    ;
    } else {
        switch(gdalType) {
        case GDT_Byte:
            ok = save<quint8>(raster, dataset,gdalType);break;
        case GDT_UInt16:
            ok = save<quint16>(raster, dataset,gdalType);break;
        case GDT_Int16:
            ok = save<qint16>(raster, dataset,gdalType);break;
        case GDT_Int32:
            ok = save<qint32>(raster, dataset,gdalType);break;
        case GDT_UInt32:
            ok = save<quint32>(raster, dataset,gdalType);break;
        case GDT_Float32:
            ok = save<float>(raster, dataset,gdalType);break;
        case GDT_Float64:
            ok = save<double>(raster, dataset,gdalType);break;
        default:
            ok= ERROR1(ERR_NO_INITIALIZED_1, "gdal Data type");
        }
    }

    gdal()->close(dataset);

    return ok;
}
ColumnDefinition::ColumnDefinition(const std::string& name, const DataDefinition& datdef, quint64 colindex){
    if(datdef.__bool__())
        _ilwisColDef.reset(new Ilwis::ColumnDefinition(QString::fromStdString(name), datdef.ptr(), colindex));
}
Beispiel #18
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   FastMap * map;
   string fname = "/cpp_fastmap_fielddefODBC";
   string hname = fname + "/test";
   
   size_t len;
   psoObjectDefinition mapDef = { PSO_FAST_MAP, 0, 0, 0 };

   DataDefBuilderODBC fieldDef( 5 );
   KeyDefBuilderODBC keyDef( 3 );

   DataDefinition * returnedDataDef;
   KeyDefinition * returnedKeyDef;
   unsigned char * buffer;
   
   try {
      fieldDef.AddField( "field1", 6, PSO_TINYINT,       0, 0, 0 );
      fieldDef.AddField( "field2", 6, PSO_INTEGER,       0, 0, 0 );
      fieldDef.AddField( "field3", 6, PSO_CHAR,         30, 0, 0 );
      fieldDef.AddField( "field4", 6, PSO_SMALLINT,      0, 0, 0 );
      fieldDef.AddField( "field5", 6, PSO_LONGVARBINARY, 0, 0, 0 );
      keyDef.AddKeyField( "keyfield1", 9, PSO_KEY_INTEGER,       0 );
      keyDef.AddKeyField( "keyfield2", 9, PSO_KEY_CHAR,         30 );
      keyDef.AddKeyField( "keyfield3", 9, PSO_KEY_LONGVARBINARY, 0 );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   try {
      if ( argc > 1 ) {
         process.Init( argv[1], argv[0] );
      }
      else {
         process.Init( "10701", argv[0] );
      }
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed in init phase, error = " << exc.Message() << endl;
      cerr << "Is the server running?" << endl;
      return 1;
   }

   try {
      session.Init();
      session.CreateFolder( fname );

      DataDefinition dataDefObj( session, 
                                 "cpp_fastmap_datadef_odbc",
                                 PSO_DEF_PHOTON_ODBC_SIMPLE,
                                 fieldDef.GetDefinition(),
                                 fieldDef.GetDefLength() );
      KeyDefinition keyDefObj( session, 
                               "cpp_fastmap_datadef_odbc",
                               PSO_DEF_PHOTON_ODBC_SIMPLE,
                               keyDef.GetDefinition(),
                               keyDef.GetDefLength() );

      session.CreateMap( hname, mapDef, dataDefObj, keyDefObj );

      map = new FastMap( session, hname );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   try {
      returnedDataDef = map->GetDataDefinition();
      returnedKeyDef  = map->GetKeyDefinition();
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   try {
      len = 5 * sizeof(psoFieldDefinition);
      buffer = new unsigned char [len];
      if ( len != returnedDataDef->GetLength() ) {
         cerr << "Test failed - line " << __LINE__ << endl;
         return 1;
      }
      returnedDataDef->GetDefinition( buffer, len );      
      if ( memcmp( fieldDef.GetDefinition(), buffer, len ) != 0 ) {
         cerr << "Test failed - line " << __LINE__ << endl;
         return 1;
      }
      delete [] buffer;
      
      len = 3 * sizeof(psoKeyFieldDefinition);
      buffer = new unsigned char [len];
      if ( len != returnedKeyDef->GetLength() ) {
         cerr << "Test failed - line " << __LINE__ << endl;
         return 1;
      }
      returnedKeyDef->GetDefinition( buffer, len );      
      if ( memcmp( keyDef.GetDefinition(), buffer, len ) != 0 ) {
         cerr << "Test failed - line " << __LINE__ << endl;
         return 1;
      }

   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }
   
   return 0;
}
Beispiel #19
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   DataDefinition dataDef;
   string name = "/cpp_datadefinition_get_definition";
   unsigned char byteData[50], returnedData[50];
   unsigned int dataLength = 50;

   for ( int i = 0; i < 50; ++i ) {
      byteData[i] = i*2 + 1;
   }
   
   try {
      if ( argc > 1 ) {
         process.Init( argv[1], argv[0] );
      }
      else {
         process.Init( "10701", argv[0] );
      }
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed in init phase, error = " << exc.Message() << endl;
      cerr << "Is the server running?" << endl;
      return 1;
   }

   // DataDefinition is not initialized

   try {
      dataDef.GetDefinition( returnedData, dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_HANDLE ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      session.Init();
      dataDef.Create( session, 
                      name,
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      dataLength );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   // Wrong arguments to tested function
   
   try {
      dataDef.GetDefinition( NULL, dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_POINTER ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      dataDef.GetDefinition( returnedData, 0 );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_INVALID_LENGTH ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   // This call should work
   
   try {
      dataDef.GetDefinition( returnedData, dataLength );
   }
   catch( pso::Exception exc ) {
      cerr << exc.ErrorCode() << endl;
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   if ( memcmp( byteData, returnedData, dataLength ) != 0 ) {
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   
   dataDef.Close();
   
   return 0;
}
Beispiel #20
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   DataDefinition dataDef;
   string name = "/cpp_datadefinition_get_definition";
   unsigned char byteData[50];
   unsigned int dataLength = 50;
   string fieldDescription;
   
   memcpy( &byteData[0],  "Field 1  ", 9 );
   memcpy( &byteData[10], "Field 2  ", 9 );
   memcpy( &byteData[20], "Field 3  ", 9 );
   memcpy( &byteData[30], "Field 4  ", 9 );
   memcpy( &byteData[40], "Field 5  ", 9 );
   byteData[9]  = 0;
   byteData[19] = 0;
   byteData[29] = 0;
   byteData[39] = 0;
   byteData[49] = 0;
   
   try {
      if ( argc > 1 ) {
         process.Init( argv[1], argv[0] );
      }
      else {
         process.Init( "10701", argv[0] );
      }
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed in init phase, error = " << exc.Message() << endl;
      cerr << "Is the server running?" << endl;
      return 1;
   }

   // DataDefinition is not initialized

   try {
      fieldDescription = dataDef.GetNext();
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_HANDLE ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      session.Init();
      dataDef.Create( session, 
                      name,
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      dataLength );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   // This call should work
   
   try {
      do {
         fieldDescription = dataDef.GetNext();
         cout << fieldDescription << endl;
      } while ( fieldDescription.length() > 0 );
   }
   catch( pso::Exception exc ) {
      cerr << exc.ErrorCode() << endl;
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   dataDef.Close();
   
   return 0;
}