Ejemplo n.º 1
0
void DataAccess::features() {
    Ilwis::IFeatureCoverage features;

    features.prepare(makeInputPath("rainfall.mpp"));

    Ilwis::FeatureIterator iter(features);
    Ilwis::SPFeatureI f = *(iter + 4);
    DOCOMPARE(f("january").toInt(), 93,"accessing value of 4th feature, january attribute column");

    features.prepare(makeInputPath("Contour.mps"));
    Ilwis::FeatureIterator iter2(features);
    Ilwis::SPFeatureI f2 = *(iter2 + 10);
    DOCOMPARE(f2(FEATUREVALUECOLUMN).toInt(), 2600, "accessing map value of the 10th segment");

    features.prepare(makeInputPath("soils_sadc.mpa"));
    Ilwis::FeatureIterator iter3(features);
    Ilwis::SPFeatureI f3 = *(iter3 + 4);
    auto result = f3->cell(QString("FAOSOIL"),false);
    DOTEST(result.toString() == "Rd18-3ab", "accessing attribute value of the 4th polygon");

}
Ejemplo n.º 2
0
QString AttributeModel::actualRangeDefintion(bool calc) const
{
    QString rangeString;
    if ( _coldefinition.isValid()) {
        if ( calc || _coldefinition.datadef().range().isNull()) {
            if ( hasType( _owner->ilwisType() , itFEATURE)) {
                Ilwis::IFeatureCoverage features = _owner.as<Ilwis::FeatureCoverage>();
                if ( !features.isValid())
                    return "";
                features->loadData();
                std::vector<QVariant> data = features->attributeTable()->column(_coldefinition.name());
                if ( data.size() != 0) {
                    std::vector<double> values(data.size());
                    int  i=0;
                    for(auto v : data)
                        values[i++] = v.toDouble();
                    Ilwis::NumericStatistics stats; // realy like to do this with a template specialization of the proper calculate function, but the syntax was unclear to me
                    stats.calculate(values.begin(), values.end());
                    Ilwis::NumericRange *rng = new Ilwis::NumericRange(stats.prop(Ilwis::NumericStatistics::pMIN),stats.prop(Ilwis::NumericStatistics::pMAX));
                    features->attributeDefinitionsRef().columndefinitionRef(_coldefinition.name()).datadef().range(rng);
                    const_cast<AttributeModel *>(this)->_coldefinition = features->attributeDefinitions().columndefinition(_coldefinition.name());
                }
            }
        }
        rangeString = _coldefinition.datadef().range()->toString();

    }
    return rangeString;
}
Ejemplo n.º 3
0
void GdalDataAccess::accessingFeatureData() {
    try {
        Ilwis::IFeatureCoverage fc;
        qDebug() << "Features : accessing data ";

        DOTEST(fc.prepare(makeInputPath("regions.shp")), "Loading regions.shp");
        QString env = fc->envelope().toString();
        DOTEST(env == "33.0065 3.40088 47.9605 14.9637","FeatureCoverage: testing envelope (bbox)");

        DOTEST(fc.prepare(makeInputPath("rainfall.shp")),"loading point map");
        Ilwis::FeatureIterator iter1(fc);

        Ilwis::SPFeatureI f1 = *(iter1 + 1);
        QVariant output = f1->cell("RAINFALL");
        DOTEST(output.toString() =="taquina","accesing attribute string data of pointmap");

        Ilwis::SPFeatureI f2 = *(iter1 + 4);
        output = f2("JANUARY");
        DOCOMPARE(output.toInt(), 85 ,"accesing attribute numeric data of pointmap");

        DOTEST(fc.prepare(makeInputPath("drainage.shp")),"loading segment map");
        Ilwis::FeatureIterator iter2(fc);

        Ilwis::SPFeatureI f3 = *(iter2 + 104);
        output = f3->cell("DRAINAGE");
        DOTEST(output.toString() == "lake","accesing attribute string data of line coverage");

        Ilwis::SPFeatureI f4 = *(iter2 + 21);
        output = f4("C1");
        DOCOMPARE(output.toInt(), 1 ,"accesing attribute numeric data ofline coverage");

        DOTEST(fc.prepare(makeInputPath("geology.shp")),"loading polygon map");
        Ilwis::FeatureIterator iter3(fc);

        Ilwis::SPFeatureI f5 = *(iter3 + 40);
        output = f5->cell("GEOLOGY");
        DOTEST(output.toString() == "Shales","accesing attribute string data of polygon coverage");


    }catch (const Ilwis::ErrorObject& err) {
        QString error = "Test threw exception : " + err.message();
        QFAIL(error.toLatin1());
    }
}
Ejemplo n.º 4
0
void FeatureCoverageTest::testVariants() {
    Ilwis::IFeatureCoverage featureCoverage;
       featureCoverage.prepare();

       Ilwis::ICoordinateSystem csy("code=proj4:+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");

       Ilwis::Envelope env(Ilwis::LatLon(50,-30), Ilwis::LatLon(-50, 60));
       featureCoverage->coordinateSystem(csy);
       featureCoverage->envelope(env);

       Ilwis::ITimeDomain dom;
       dom.prepare();
       dom->range(new Ilwis::TimeInterval("20090101", "20110101"));
       std::vector<QString> times = {"20090101","20090131","20090602","20090703", "20100109","20110101"};

       featureCoverage->attributeDefinitionsRef().addColumn("population", "value");
       featureCoverage->attributeDefinitionsRef().setSubDefinition(dom,times);

       Ilwis::SPFeatureI feature1 = featureCoverage->newFeature(0);

       geos::geom::Geometry *geom = Ilwis::GeometryHelper::fromWKT("Linestring(40 20, 10 12, -20 -10)", featureCoverage->coordinateSystem().ptr());
       feature1->geometry(geom);
       feature1("population", 200);

       geom = Ilwis::GeometryHelper::fromWKT("Linestring(40 30, 10 12, -20 -10)", featureCoverage->coordinateSystem().ptr());
       Ilwis::SPFeatureI feature2 = featureCoverage->newFeature(geom);
       feature2("population", 300);

       geom = Ilwis::GeometryHelper::fromWKT("Linestring(40 30, 12 12, -20 -10)", featureCoverage->coordinateSystem().ptr());
       Ilwis::SPFeatureI feature3 = featureCoverage->newFeature(geom);
       feature3("population", 100);
    feature1->createSubFeature("20090101", geom);
    feature1->createSubFeature("20090703", geom);

       geom = Ilwis::GeometryHelper::fromWKT("Linestring(30 10, 10 15, -23 -12)",featureCoverage->coordinateSystem().ptr());

       feature1->createSubFeature("20090101", geom);

       geom = Ilwis::GeometryHelper::fromWKT("Linestring(20 10, 10 15, -23 -12)",featureCoverage->coordinateSystem().ptr());

       feature2->createSubFeature("20090101", geom);

       auto *attrdef = new Ilwis::FeatureAttributeDefinition();
       attrdef->addColumn("temperature", "value");
       featureCoverage->attributeDefinitionsRef().featureAttributeDefinition(attrdef);

       feature1["20090101"]("temperature", 26.5);
       feature2["20090101"]("temperature", 19.5);


    FeatureIterator featureIter(featureCoverage);
    featureIter.flow(FeatureIterator::fDEPTHFIRST);

    while(featureIter != featureIter.end()) {
        SPFeatureI f = (*featureIter);
        f->geometry(); // test if geometry is null
        DOTEST(true, "geometry of (sub)feature not null.");
        featureIter++; // move to next
    }






}