Ejemplo n.º 1
0
QString IlwisObjectModel::projectionInfo() const
{
    try {
        if ( isProjectedCoordinateSystem()){
            IConventionalCoordinateSystem csy = hasType(_ilwisobject->ilwisType(), itCOVERAGE) ? _ilwisobject.as<Coverage>()->coordinateSystem().as<ConventionalCoordinateSystem>()
                                                                                               : _ilwisobject.as<ConventionalCoordinateSystem>();
            QString projection = Projection::projectionCode2Name(csy->projection()->code());
            QVariant var = csy->projection()->parameter(Projection::pvZONE);
            if ( var.isValid() && !var.toInt() == 1){
                projection += " zone=" + var.toString();
            }
            QString ellipsoid = Ellipsoid::ellipsoidCode2Name(csy->ellipsoid()->name());
            if ( ellipsoid == sUNDEF){
                QString wkt = csy->ellipsoid()->wktShort();
                if ( wkt != sUNDEF && wkt != "")
                    ellipsoid = wkt;
                else {
                    QString authority = csy->ellipsoid()->authority();
                    if ( wkt != sUNDEF && wkt != "")
                        ellipsoid = authority;
                    else
                        ellipsoid = QString("custom(%1,%2)").arg(csy->ellipsoid()->majorAxis(),0,'f',3).arg(csy->ellipsoid()->flattening(),0,'f',6);
                }
            }
            return projection + "; ellipsoid=" + ellipsoid;
        }
        return "";
    } catch(const ErrorObject& ){
        // no exceptions may escape here
    }
    return "";
}
bool CoordinateSystemConnector::storeMetaData(IlwisObject *data) {
    bool ok = true;
    if ((ok = Ilwis3Connector::storeMetaData(data, itCOORDSYSTEM)) == false){
        return false;
    }
    ICoordinateSystem csy(static_cast<CoordinateSystem *>(data));
    if (!csy.isValid() || !csy->isValid()){
        return ERROR1(ERR_NO_INITIALIZED_1, "CoordinateSystem");
    }
    Envelope bounds = csy->envelope();
    if(!bounds.isValid()){
        ERROR2(ERR_NO_INITIALIZED_2, "Bounds", csy->name());
        return sUNDEF;
    }

    _odf->setKeyValue("CoordSystem","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'));

    if ( csy->isLatLon()) {
        _odf->setKeyValue("CoordSystem", "Datum", "WGS 1984");
        _odf->setKeyValue("CoordSystem","Type","LatLon");
        if ( csy.as<ConventionalCoordinateSystem>()->ellipsoid().isValid()){
            IEllipsoid ell = csy.as<ConventionalCoordinateSystem>()->ellipsoid();
            _odf->setKeyValue("CoordSystem","Ellipsoid","User Defined");
            _odf->setKeyValue("Ellipsoid","1/f", 1.0 / ell->flattening());
            _odf->setKeyValue("Ellipsoid","a", ell->majorAxis());
        }
    }else{
        IConventionalCoordinateSystem projectedCsy = csy.as<ConventionalCoordinateSystem>();
        if( !projectedCsy->ellipsoid().isValid() || !projectedCsy->projection().isValid()){
                ERROR2(ERR_NO_INITIALIZED_2, "Ellipsoid/Projection", csy->name());
                return sUNDEF;
        }
        QString projectionName = Ilwis3Connector::code2name(projectedCsy->projection()->name(), "projection");
        _odf->setKeyValue("CoordSystem","Type","Projection");
        _odf->setKeyValue("CoordSystem","Projection",projectionName);
        QString ellipsoidName = projectedCsy->ellipsoid()->name();
        //ellipsoidName = Ilwis3Connector::name2Code(ellipsoidName, "ellipsoid");
        if ( ellipsoidName == sUNDEF){
            ellipsoidName = "User Defined";
            _odf->setKeyValue("Ellipsoid","a",projectedCsy->ellipsoid()->majorAxis() );
            _odf->setKeyValue("Ellipsoid","1/f",projectedCsy->ellipsoid()->flattening() );

        }else
            ellipsoidName = Ilwis3Connector::code2name(ellipsoidName, "ellipsoid");
        _odf->setKeyValue("CoordSystem","Ellipsoid",ellipsoidName);
        IProjection projection = projectedCsy->projection();
        if ( projection->isSet(Projection::pvAZIMCLINE))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvAZIMCLINE),projection->parameter(Projection::pvAZIMCLINE).toDouble());
        if ( projection->isSet(Projection::pvAZIMYAXIS))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvAZIMYAXIS),projection->parameter(Projection::pvAZIMYAXIS).toDouble());
        if ( projection->isSet(Projection::pvHEIGHT))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvHEIGHT),projection->parameter(Projection::pvHEIGHT).toDouble());
        if ( projection->isSet(Projection::pvK0))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvK0),projection->parameter(Projection::pvK0).toDouble());
        if ( projection->isSet(Projection::pvLAT0))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvLAT0),projection->parameter(Projection::pvLAT0).toDouble());
        if ( projection->isSet(Projection::pvLAT1))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvLAT1),projection->parameter(Projection::pvLAT1).toDouble());
        if ( projection->isSet(Projection::pvLAT2))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvLAT2),projection->parameter(Projection::pvLAT2).toDouble());
        if ( projection->isSet(Projection::pvLATTS))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvLATTS),projection->parameter(Projection::pvLATTS).toDouble());
        if ( projection->isSet(Projection::pvLON0))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvLON0),projection->parameter(Projection::pvLON0).toDouble());
        if ( projection->isSet(Projection::pvNORIENTED))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvNORIENTED),projection->parameter(Projection::pvNORIENTED).toString());
        if ( projection->isSet(Projection::pvNORTH))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvNORTH),projection->parameter(Projection::pvNORTH).toString());
        if ( projection->isSet(Projection::pvX0))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvX0),projection->parameter(Projection::pvX0).toDouble());
        if ( projection->isSet(Projection::pvY0))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvY0),projection->parameter(Projection::pvY0).toDouble());
        if ( projection->isSet(Projection::pvZONE))
            _odf->setKeyValue("Projection",prjParam2IlwisName(Projection::pvZONE),projection->parameter(Projection::pvZONE).toInt());

    }
    _odf->store("csy", source().toLocalFile());
    return true;


}