예제 #1
0
bool SelectionBase::ExpressionPart::match(const SPFeatureI &feature,SelectionBase *operation) const
{
    if ( _type == ExpressionPart::ptFEATURETYPE){
        return hasType(feature->geometryType(), _geometryType);
    }
    if ( _type == ExpressionPart::ptENVELOPE && _envelope.isValid())   {
        return _envelope.contains(feature->geometry().get());
    }
    if ( _type == ExpressionPart::ptPOLYGON && _polygon.get() != 0)   {
        return _polygon->contains(feature->geometry().get());
    }

    if ( _type == ExpressionPart::ptATTRIBUTESELECTION )   {
        QVariant val = feature(_leftSide);
        ColumnDefinition coldef = feature->attributedefinition(_leftSide);
        if ( coldef.datadef().domain()->ilwisType() == itITEMDOMAIN){
            val = coldef.datadef().domain()->impliedValue(val);
        }
        if ( QString(val.typeName()) == "QString" && QString(_rightSide.typeName()) == "QString"){
            return operation->compare1(_operator,val.toString(), _rightSide.toString());
        } else {
            bool ok1,ok2;
            double v1 = val.toDouble(&ok1);
            double v2 = _rightSide.toDouble(&ok2);
            bool ok3 = operation->compare2(_operator, v1, v2, true);
            return ok1&& ok2 && ok3;
        }
    }
    return false;
}
bool GdalFeatureConnector::store(IlwisObject *obj, const IOOptions&   )
{

    if (!loadDriver())
        return false;

    IFeatureCoverage coverage;
    coverage.set(static_cast<FeatureCoverage *>(obj));

    std::vector<SourceHandles> datasources(3);
    std::vector<bool> validAttributes;
    if(!setDataSourceAndLayers(coverage, datasources, validAttributes))
        return false;

    std::vector<ColumnDefinition> defs;
    for(int i=0; i < coverage->attributeTable()->columnCount(); ++i){
        defs.push_back(coverage->attributeTable()->columndefinition(i));
    }

    FeatureIterator fiter(coverage);
    FeatureIterator endIter = end(coverage);
    for(; fiter != endIter; ++fiter) {
        SPFeatureI feature = *fiter;
        IlwisTypes geomType = feature->geometryType();
        if ( geomType != 0){
            OGRLayerH lyr = datasources[ilwisType2Index(geomType)]._layers[0];
            OGRFeatureH hfeature = gdal()->createFeature(gdal()->getLayerDef(lyr));
            if (hfeature) {
                setAttributes(hfeature, feature, validAttributes, defs);
                const geos::geom::Geometry* geometry = feature->geometry().get();
                if (gdal()->setGeometryDirectly(hfeature,createFeature(geometry)) != OGRERR_NONE)
                    ERROR2(ERR_COULD_NOT_ALLOCATE_2, TR("geometry"), _filename.toString());
                if (gdal()->addFeature2Layer(lyr, hfeature) != OGRERR_NONE) {
                    ERROR2(ERR_COULD_NOT_ALLOCATE_2, TR("feature"), _filename.toString());
                }
                gdal()->destroyFeature(hfeature);
            };
        }
    }
    for(auto& datasource : datasources){
        if ( datasource._source != 0)
            gdal()->destroyDataSource(datasource._source);
    }

    return true;

}
예제 #3
0
SPFeatureI FeatureCoverage::newFeatureFrom(const SPFeatureI& existingFeature, const ICoordinateSystem& csySource) {
    Locker<> lock(_mutex);

    auto transform = [&](const UPGeometry& geom)->geos::geom::Geometry * {
        if ( geom.get() == 0)
            return 0;

        geos::geom::Geometry *newgeom = geom->clone();
        if ( csySource.isValid() && !csySource->isEqual(coordinateSystem().ptr())){
            CsyTransform trans(csySource, coordinateSystem());
            newgeom->apply_rw(&trans);
            newgeom->geometryChangedAction();
        }
        GeometryHelper::setCoordinateSystem(newgeom, coordinateSystem().ptr());

        return newgeom;
    };
    if (!connector()->dataIsLoaded()) {
        connector()->loadData(this);
    }
    auto *newfeature = createNewFeature(existingFeature->geometryType());
    const UPGeometry& geom = existingFeature->geometry();
    newfeature->geometry(transform(geom)) ;

    auto variantIndexes = _attributeDefinition.indexes();
    for(auto index : variantIndexes){
        const auto& variant = existingFeature[index];
        auto *variantFeature = createNewFeature(variant->geometryType());
        const auto& geom = variant->geometry();
        variantFeature->geometry(transform(geom)) ;
        newfeature->setSubFeature(index, variantFeature);


    }
    _features.push_back(newfeature);
    return _features.back();
}