IProjection CoordinateSystemConnector::getProjection(ConventionalCoordinateSystem *csycc) {
    QString projection = _odf->value("CoordSystem","Projection");
    if (projection == "?") {
        QString type = _odf->value("CoordSystem","Type");
        if ( type == "LatLon") {
            projection = type;
            GeodeticDatum *gdata = new GeodeticDatum();
            gdata->fromCode("DWGS84");
            csycc->setDatum(gdata);
        } else
            return IProjection();
    }

    QString code = name2Code(projection, "projection");
    Resource resource(QUrl(QString("ilwis://tables/projection?code=%1").arg(code)), itPROJECTION);

    if ( code == sUNDEF) {
        kernel()->issues()->log(TR("Couldnt find projection %1").arg(projection));
        return IProjection();
    }

    IProjection proj;
    if(!proj.prepare(resource))
        return IProjection();

    bool ok;
    double falseEasting = _odf->value("Projection","False Easting").toDouble(&ok);
    if ( ok)
        proj->setParameter(Projection::pvX0, falseEasting);
    double falseNorthing = _odf->value("Projection","False Northing").toDouble(&ok);
    if ( ok)
        proj->setParameter(Projection::pvY0, falseNorthing);
    double centralMeridian = _odf->value("Projection","Central Meridian").toDouble(&ok);
    if ( ok)
        proj->setParameter(Projection::pvLON0, centralMeridian);
    double centralParllel = _odf->value("Projection","Central Parallel").toDouble(&ok);
    if ( ok)
        proj->setParameter(Projection::pvLAT0, centralParllel);
    double standardParllel = _odf->value("Projection","Standard Parallel 1").toDouble(&ok);
    if ( ok)
        proj->setParameter(Projection::pvLAT1, standardParllel);
    standardParllel = _odf->value("Projection","Standard Parallel 2").toDouble(&ok);
    if ( ok)
        proj->setParameter(Projection::pvLAT2, standardParllel);
    double lattitudeOfTrueScale = _odf->value("Projection","Latitude of True Scale").toDouble(&ok);
    if ( ok)
        proj->setParameter(Projection::pvLATTS, lattitudeOfTrueScale);
    double scaleFactor = _odf->value("Projection","Scale Factor").toDouble(&ok);
    if ( ok)
        proj->setParameter(Projection::pvK0, scaleFactor);
    int gzone = _odf->value("Projection","Zone").toInt(&ok);
    if ( ok)
        proj->setParameter(Projection::pvZONE, gzone);
    QString hemisphere = _odf->value("Projection","Northern Hemisphere");
    if ( hemisphere != sUNDEF && code == "utm")
        proj->setParameter(Projection::pvNORTH, hemisphere);

    return proj;
}
Beispiel #2
0
GeodeticDatum *GeodeticDatum::clone() const
{
    GeodeticDatum *datum = new GeodeticDatum();
    datum->name(name())    ;
    datum->code(code());
    datum->setDescription(description());
    datum->_area = _area;
    datum->_authority = _authority;
    datum->_datumParams = _datumParams;
    datum->_mode = _mode;
    datum->_isValid = _isValid;
    datum->_wkt = _wkt;

    return datum;
}
string 
ToJSON( const GeodeticDatum & datum )
{
    JSONObject jsonObj;
    jsonObj[ "ellipsoid" ] = ToJSON( datum.Ellipsoid() );
    return ToJSON( jsonObj );
}
GeodeticDatum *CoordinateSystemConnector::getDatum(QString& ellipsoid) {
    QString datum =_odf->value("CoordSystem","Datum");
    if ( datum == sUNDEF)
        return 0; // not an error; simply no datum with this csy

    QString area = _odf->value("CoordSystem","Datum Area");
    if ( area != sUNDEF && area != "" )
        datum = datum + "." + area;
    QString code = name2Code(datum,"datum");

    if ( code == "?"){
        kernel()->issues()->log(TR("No datum code for this alias %1").arg(datum));
        return 0;
    }

    QSqlQuery stmt(kernel()->database());
    QString query = QString("Select * from datum where code='%1'").arg(code);

    if (stmt.exec(query)) {
        if ( stmt.next()) {
            GeodeticDatum *gdata = new GeodeticDatum();
            QString area = stmt.value(stmt.record().indexOf("area")).toString();
            QString code = stmt.value(stmt.record().indexOf("code")).toString();
            double dx = stmt.value(stmt.record().indexOf("dx")).toDouble();
            double dy = stmt.value(stmt.record().indexOf("dy")).toDouble();
            double dz = stmt.value(stmt.record().indexOf("dz")).toDouble();
            gdata->setArea(area);
            gdata->code(code);
            gdata->set3TransformationParameters(dx, dy, dz);
            ellipsoid = stmt.value(stmt.record().indexOf("ellipsoid")).toString();

            return gdata;

        } else {
            kernel()->issues()->log(TR("No datum for this code %1").arg(code));
        }
    } else {
        kernel()->issues()->logSql(stmt.lastError());
    }
    return 0;
}
GeodeticDatum *InternalIlwisObjectFactory::createDatum(const Resource& resource, const IOOptions &options) const {
    QString query;
    if ( resource.code() != sUNDEF) {
        QString code = resource.code();
        if ( code != "") {
            query = QString("Select * from datum where code = '%1'").arg(code);
        }
    }
    if ( resource["area"] != sUNDEF) {
        QString name = resource.name();
        QString area = resource["area"].toString();
        query = QString("Select * from datum where name='%1' and area='%1'").arg(name, area);
    }

    if ( query == "")
        return 0;

    InternalDatabaseConnection db;
    if (db.exec(query) && db.next()) {
        GeodeticDatum *datum = new GeodeticDatum();
        QSqlRecord rec = db.record();
        datum->name(rec.field("name").value().toString());
        datum->setDescription(rec.field("description").value().toString());
        datum->setAuthority(rec.field("authority").value().toString());
        datum->setArea(rec.field("area").value().toString());
        datum->code(rec.field("code").value().toString());
        QString ellips = rec.field("code").value().toString();
        IEllipsoid ell;
        QString ellres = QString("code=ellipsoid:%1").arg(ellips);
        ell.prepare(ellres);
        datum->set3TransformationParameters(rec.field("dx").value().toDouble(),
                                            rec.field("dy").value().toDouble(),
                                            rec.field("dz").value().toDouble(),
                                            ell);

        return datum;
    }

    return 0;
}