ProjectionImplementationInternal::ProjectionImplementationInternal(const Resource& resource) :
    ProjectionImplementation(resource.code()),
    _easting(0),
    _northing(0),
    _maxis(6371007.180918499800),
    _centralMeridian(0)
{
}
ProjectionImplementationProj4::ProjectionImplementationProj4(const Resource &resource) : ProjectionImplementation(resource.code())
{
    QString cd = resource.code();
    _outputIsLatLon = cd == "latlong" || cd == "longlat";
    _targetDef = QString("+proj=%1").arg(cd);
    _pjLatlon =  pj_init_plus("+proj=latlong +ellps=WGS84");
    _pjBase = pj_init_plus(_targetDef.toLatin1());
}
Example #3
0
IlwisObject::IlwisObject(const Resource& resource) :
    Identity(resource.name(), resource.id(), resource.code(), resource.description()) ,
    _valid(false),
    _readOnly(false),
    _changed(false)
{
    if (!resource.isValid())
        Identity::prepare();
}
// TODO: this method should be merged with the prepare above
bool ConventionalCoordinateSystem::prepare(const QString &parms)
{
    Proj4Parameters proj4(parms);

    QString ell = proj4["ellps"];
    if ( ell != sUNDEF) {
        _ellipsoid.prepare("code=ellipsoid:" + ell);
    } else {
        _ellipsoid.prepare();
        QString laxis = proj4["a"];
        if ( laxis != sUNDEF) {
            QString saxis = proj4["b"];
            bool ok;
            double a = laxis.toDouble(&ok);
            if (!ok) return ERROR2(ERR_INVALID_PROPERTY_FOR_2, "ellipsoid", name());
            double b = saxis.toDouble(&ok);
            if (!ok) return ERROR2(ERR_INVALID_PROPERTY_FOR_2, "ellipsoid", name());

            double f = (a - b) / a;
            _ellipsoid->setEllipsoid(a, f);
        } else
            _ellipsoid->setEllipsoid(6378137.0, 298.257223563);
    }
    if ( proj4.hasDatum()) {
        _datum.reset(new GeodeticDatum());
        if ( proj4["dx"] != sUNDEF) {
            if (proj4["rx"] != sUNDEF) { // 7 parameter version
                _datum->set7TransformationParameters(proj4["dx"].toDouble(),
                                                     proj4["dy"].toDouble(),
                                                     proj4["dz"].toDouble(),
                                                     proj4["rx"].toDouble(),
                                                     proj4["ry"].toDouble(),
                                                     proj4["rz"].toDouble(),
                                                     proj4["dscale"].toDouble());
            } else { // 3 parameter version
                _datum->set3TransformationParameters(proj4["dx"].toDouble(),
                                                     proj4["dy"].toDouble(),
                                                     proj4["dz"].toDouble(),
                                                     _ellipsoid->name());
            }
        } else if ( proj4["datum"] != sUNDEF) {
            _datum->fromCode(proj4["datum"]);
        }
    }
    QString code = extractProjection(proj4);

    if ( code == sUNDEF) {
        kernel()->issues()->log(TR(ERR_INVALID_PROPERTY_FOR_2).arg("projection name", name()));
        return false;
    }
    code = "code=proj4: " + code;
    Resource prj = mastercatalog()->name2Resource(code, itPROJECTION);
    if (!prj.isValid()) {
        prj = Resource("ilwis://projection/" + code, itPROJECTION);
        prj.code(proj4["proj"]); // set the code to the projection "CODE", as in projections.csv
        mastercatalog()->addItems({prj});
    }
    IOOptions opt;
    opt << IOOptions::Option("proj4",parms.mid(6));
    bool ok =_projection.prepare(prj.id(),opt);
    _projection->setCoordinateSystem(this);
    if ( _projection.isValid())  {
        ok = _projection->prepare(parms);
    }
    QString unit = proj4["units"];
    if ( ok && (_projection->code().contains("longlat") || _projection->code().contains("latlon") || unit=="?"))
        _unit = "degrees";
    else{
        if ( unit == "m")
            _unit = "meter";
        else
            _unit = "feet";
    }


    return ok;
}