IlwisObject *InternalIlwisObjectFactory::createCsyFromCode(const Resource& resource, const IOOptions &options) const { QString code = resource.code(); bool isUnknown = code == "unknown" || code == "csy:unknown"; QString projParms = code; if ( code.left(6) == "proj4:"){ projParms = code.mid(6); }else if(!isUnknown && code.left(5) == "epsg:"){ QString query = QString("select * from projectedcsy where code='%1'").arg(code); InternalDatabaseConnection db; if ( db.exec(query)) { if (db.next()) { QSqlRecord rec = db.record(); projParms = rec.value("proj_params").toString(); } else { kernel()->issues()->log(TR(ERR_COULDNT_CREATE_OBJECT_FOR_2).arg("coordinatesystem", resource.name())); return 0; } } } CoordinateSystem *csy = 0; if ( isUnknown){ csy = createFromResource<BoundsOnlyCoordinateSystem>(resource, options); csy->name("unknown"); csy->code("unknown"); csy->setDescription(TR("Unknown coordinate system")); }else { csy = createFromResource<ConventionalCoordinateSystem>(resource, options); csy->setDescription(resource.name()); csy->prepare("proj4=" + projParms); } return csy; }
void GeodeticDatum::getFromInternal(const QString &ellips) { InternalDatabaseConnection db; QString query = "Select * from datum"; if ( db.exec(query) ){ while( db.next()){ QSqlRecord rec = db.record(); double dx = rec.field("dx").value().toDouble(); double dy = rec.field("dy").value().toDouble(); double dz = rec.field("dz").value().toDouble(); QString ellipsoid = rec.field("ellipsoid").value().toString(); // the combination of ellips-name, dx, dy and dz uniquely identifies the datum by name and area if ( ellipsoid.toLower() == ellips.toLower() && std::abs(_datumParams[dmDX] - dx) < 0.01 && std::abs(_datumParams[dmDY] - dy) < 0.01 && std::abs(_datumParams[dmDZ] - dz) < 0.01) { _datumParams[dmDX] = dx; _datumParams[dmDY] = dy; _datumParams[dmDZ] = dz; code(rec.field("code").value().toString()); name(rec.field("name").value().toString()); setArea(rec.field("area").value().toString()); setWktName(rec.field("wkt").value().toString()); setAuthority(rec.field("authority").value().toString()); return; } } } }
void GeodeticDatum::fromCode(const QString &gcode) { InternalDatabaseConnection stmt; QString query = QString("Select * from datum where code='%1' or code='%2'").arg(gcode).arg('D' + gcode); // temporary workaround (only working for wgs84) because file datums.csv does not have datumnames that match the ones in epsg.pcs if (stmt.exec(query)) { if ( stmt.next()) { QString area = stmt.value(stmt.record().indexOf("area")).toString(); QString geocode = stmt.value(stmt.record().indexOf("code")).toString(); QString ellipsoid = stmt.value(stmt.record().indexOf("ellipsoid")).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(); setArea(area); code(geocode); setWktName(stmt.value(stmt.record().indexOf("wkt")).toString()); IEllipsoid ellips; ellips.prepare("code=ellipsoid:" + ellipsoid); set3TransformationParameters(dx, dy, dz, ellips); } else { kernel()->issues()->log(TR("No datum for this code %1").arg(gcode)); } } else { kernel()->issues()->logSql(stmt.lastError()); } }
IlwisObject *InternalIlwisObjectFactory::createProjection(const Resource& resource, const IOOptions &options) const { QString query; QString code = resource.code(); Projection *proj = 0; if ( code == sUNDEF){ // meant for new projections which will be initialized later (e.g by the streaming connector) proj = createFromResource<Projection>(resource, options); } else if ( code != "") { InternalDatabaseConnection db; query = QString("Select * from projection where code = '%1'").arg(code); if ( db.exec(query)) { if (db.next()) { QSqlRecord rec = db.record(); const ProjectionFactory *factory = kernel()->factory<ProjectionFactory>("ProjectionFactory",resource); if ( factory) { ProjectionImplementation *projimpl = 0; if ( options.contains("proj4")) projimpl = static_cast<ProjectionImplementation *>(factory->create(resource.code(), options["proj4"].toString())); else projimpl = static_cast<ProjectionImplementation *>(factory->create(resource)); if (!projimpl) { kernel()->issues()->log(TR(ERR_COULDNT_CREATE_OBJECT_FOR_2).arg("projection", resource.name())); return 0; } proj = createFromResource<Projection>(resource, options); proj->setImplementation(projimpl); proj->fromInternal(rec); proj->setAuthority(rec.field("authority").value().toString()); proj->setWkt(rec.field("wkt").value().toString()); } else { kernel()->issues()->log(TR(ERR_COULDNT_CREATE_OBJECT_FOR_2).arg("ProjectionFactory",resource.name())); } } else { kernel()->issues()->log(TR(ERR_FIND_SYSTEM_OBJECT_1).arg(code)); } } else{ kernel()->issues()->logSql(db.lastError()); } } else { kernel()->issues()->log(TR(ERR_MISSING_CODE_FOR_SYSTEM_OBJECT)); } return proj; }
IlwisObject *InternalIlwisObjectFactory::createRepresentation(const Resource& resource, const IOOptions &options) const{ QString code = resource.code(); Representation *rpr = createFromResource<Representation>(resource, options); if ( code != sUNDEF) { InternalDatabaseConnection db; QString query = QString("Select linkedtable from codes where code = '%1'").arg(code); if (db.exec(query)) { if ( db.next()){ QString table = db.value(0).toString(); if ( table == "representation"){ query = QString("Select * from representation where code='%1'").arg(code); if (db.exec(query)) { if ( db.next()){ QSqlRecord rec = db.record(); rpr->fromInternal(rec); QString relateddomain = rec.field("relateddomain").value().toString(); QString rprType = rec.field("representationtype").value().toString(); QString definition = rec.field("definition").value().toString(); QString mode = rec.field("mode").value().toString(); if ( rprType == "continuouscolor"){ rpr->colors(new ContinuousColorLookup(definition, mode)); }else if ( rprType == "palettecolor"){ rpr->colors(new PaletteColorLookUp(definition)); } if ( relateddomain == "value"){ rpr->domain(IDomain("value")); } rpr->readOnly(true); }else return 0; }else return 0; }else return 0; }else return 0; }else return 0; } return rpr; }
template<class DomainItemType, class RangeType> Domain* createItemDomain2(const QSqlRecord& rec, const Resource& resource){ ItemDomain<DomainItemType> *itemdom = new ItemDomain<DomainItemType>(resource); const ConnectorFactory *factory = kernel()->factory<ConnectorFactory>("ilwis::ConnectorFactory"); ConnectorInterface *connector = factory->createFromResource<>(resource, "internal"); itemdom->setConnector(connector,IlwisObject::cmINPUT, IOOptions()); itemdom->createTime(Time::now()); itemdom->modifiedTime(Time::now()); itemdom->fromInternal(rec); itemdom->name(resource.name()); RangeType range ; InternalDatabaseConnection itemstable; QString query = "Select * from domainitems where code='" + resource.code() + "'"; if (itemstable.exec(query) ) { while ( itemstable.next()){ QSqlRecord rec = itemstable.record(); range << rec.value("itemname").toString() + "|" + rec.value("itemcode").toString() + "|" + rec.value("itemdescription").toString(); } itemdom->range(range.clone()); } return itemdom; }
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; }