Ejemplo n.º 1
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.º 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
    }






}