Esempio n. 1
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());
    }
}
Esempio n. 2
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
    }






}