void OgrWriter::_addFeatureToLayer(OGRLayer* layer, shared_ptr<Feature> f, const Geometry* g, OGRFeature* poFeature) { std::string wkt = g->toString(); char* t = (char*)wkt.data(); OGRGeometry* geom; int errCode = OGRGeometryFactory::createFromWkt(&t, layer->GetSpatialRef(), &geom) ; if (errCode != OGRERR_NONE) { throw HootException( QString("Error parsing WKT (%1). OGR Error Code: (%2)").arg(QString::fromStdString(wkt)).arg(QString::number(errCode))); } errCode = poFeature->SetGeometryDirectly(geom); if (errCode != OGRERR_NONE) { throw HootException( QString("Error setting geometry - OGR Error Code: (%1) Geometry: (%2)").arg(QString::number(errCode)).arg(QString::fromStdString(g->toString()))); } errCode = layer->CreateFeature(poFeature); if (errCode != OGRERR_NONE) { throw HootException( QString("Error creating feature - OGR Error Code: (%1) \nFeature causing error: (%2)").arg(QString::number(errCode)).arg(f->toString())); } }
bool isMatchCandidate(ConstElementPtr e) { Context::Scope context_scope(_script->getContext()); HandleScope handleScope; Persistent<Object> plugin = getPlugin(); Handle<String> isMatchCandidateStr = String::New("isMatchCandidate"); if (plugin->Has(isMatchCandidateStr) == false) { throw HootException("Error finding 'isMatchCandidate' function."); } Handle<v8::Value> value = plugin->Get(isMatchCandidateStr); if (value->IsFunction() == false) { throw HootException("isMatchCandidate is not a function."); } Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value); Handle<Value> jsArgs[2]; int argc = 0; jsArgs[argc++] = OsmMapJs::create(_map); jsArgs[argc++] = ElementJs::New(e); Handle<Value> f = func->Call(plugin, argc, jsArgs); return f->BooleanValue(); }
/* * This is meant to run one time when the match creator is initialized. */ void customScriptInit() { Context::Scope context_scope(_script->getContext()); HandleScope handleScope; Persistent<Object> plugin = getPlugin(); Handle<String> initStr = String::New("init"); if (plugin->Has(initStr) == false) { throw HootException("Error finding 'init' function."); } Handle<v8::Value> value = plugin->Get(initStr); if (value->IsFunction() == false) { throw HootException("init is not a function."); } Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(value); Handle<Value> jsArgs[1]; int argc = 0; HandleScope scope; assert(_map.get()); OsmMapPtr copiedMap(new OsmMap(_map)); jsArgs[argc++] = OsmMapJs::create(copiedMap); func->Call(plugin, argc, jsArgs); //this is meant to have been set externally in a js rules file _searchRadius = getNumber(plugin, "searchRadius", -1.0, 15.0); }
void ServicesDb::closeChangeSet(long mapId, long changeSetId, Envelope env, int numChanges) { if (!changesetExists(mapId, changeSetId)) { throw HootException("No changeset exists with ID: " + changeSetId); } _checkLastMapId(mapId); if (_closeChangeSet == 0) { _closeChangeSet.reset(new QSqlQuery(_db)); _closeChangeSet->prepare( QString("UPDATE %1 SET min_lat=:min_lat, max_lat=:max_lat, min_lon=:min_lon, " "max_lon=:max_lon, closed_at=NOW(), num_changes=:num_changes WHERE id=:id") .arg(_getChangesetsTableName(mapId))); } _closeChangeSet->bindValue(":min_lat", env.getMinY()); _closeChangeSet->bindValue(":max_lat", env.getMaxY()); _closeChangeSet->bindValue(":min_lon", env.getMinX()); _closeChangeSet->bindValue(":max_lon", env.getMaxX()); _closeChangeSet->bindValue(":num_changes", numChanges); _closeChangeSet->bindValue(":id", (qlonglong)changeSetId); if (_closeChangeSet->exec() == false) { LOG_ERROR("query bound values: "); LOG_ERROR(_closeChangeSet->boundValues()); LOG_ERROR("\n"); throw HootException("Error executing close changeset: " + _closeChangeSet->lastError().text() + " (SQL: " + _closeChangeSet->executedQuery() + ")" + " with envelope: " + QString::fromStdString(env.toString())); } }
WordCountReader::WordCountReader(QString path) { if (QSqlDatabase::contains(path) == false) { _db = QSqlDatabase::addDatabase("QSQLITE", path); _db.setDatabaseName(path); if (_db.open() == false) { throw HootException("Error opening DB. " + path); } } else { _db = QSqlDatabase::database(path); } if (_db.isOpen() == false) { throw HootException("Error DB is not open. " + path); } _select = QSqlQuery(_db); if (_select.prepare("SELECT count FROM words WHERE word=:word") == false) { throw HootException(QString("Error preparing query: %1").arg(_select.lastError().text())); } }
QSqlQuery ServicesDb::_exec(QString sql, QVariant v1, QVariant v2, QVariant v3) const { QSqlQuery q(_db); LOG_VARD(sql); if (q.prepare(sql) == false) { throw HootException(QString("Error preparing query: %1 (%2)").arg(q.lastError().text()). arg(sql)); } if (v1.isValid()) { q.bindValue(0, v1); } if (v2.isValid()) { q.bindValue(1, v2); } if (v3.isValid()) { q.bindValue(2, v3); } if (q.exec() == false) { throw HootException(QString("Error executing query: %1 (%2)").arg(q.lastError().text()). arg(sql)); } return q; }
QString ServicesDb::getDbVersion() { if (_selectDbVersion == 0) { _selectDbVersion.reset(new QSqlQuery(_db)); _selectDbVersion->prepare("SELECT id || ':' || author AS version_id FROM databasechangelog " "ORDER BY dateexecuted DESC LIMIT 1"); } if (_selectDbVersion->exec() == false) { throw HootException(_selectDbVersion->lastError().text()); } QString result; if (_selectDbVersion->next()) { result = _selectDbVersion->value(0).toString(); } else { throw HootException("Unable to retrieve the DB version."); } return result; }
Envelope BaseCommand::parseEnvelope(QString envStr) const { QStringList envArr = envStr.split(","); if (envArr.size() != 4) { throw HootException("Invalid bounds format, requires 4 values: " + envStr); } bool ok, allOk = true; double left = envArr[0].toDouble(&ok); allOk &= ok; double bottom = envArr[1].toDouble(&ok); allOk &= ok; double right = envArr[2].toDouble(&ok); allOk &= ok; double top = envArr[3].toDouble(&ok); allOk &= ok; if (allOk == false) { throw HootException("Invalid bounds format: " + envStr); } return Envelope(left, right, bottom, top); }
void ConflateMapper::_addNode(const shared_ptr<Node>& n) { long key = -1; // if the node falls in one of the envelopes for (size_t i = 0; i < _envelopes.size(); i++) { // set a positive key if (_envelopes[i].contains(n->getX(), n->getY())) { if (key != -1) { throw HootException("This should never happen. Envelopes must not overlap."); } key = i; } } // if the node is not in one of the envelopes. if (key == -1) { // calculate a negative key based on node ID key = -1 - (abs(n->getId()) % _reduceTaskCount); } if (key < -_reduceTaskCount || key >= (int)_envelopes.size()) { LOG_INFO("envelope size: " << _envelopes.size()); throw HootException(QString("Key is out of range. nid: %1 key: %2").arg(n->getId()).arg(key)); } if (Debug::isTroubledNode(n->getId())) { LOG_WARN("Writing a troubled node: " << n->toString()); LOG_WARN(" key: " << key) }
shared_ptr<OGRDataSource> OgrUtilities::createDataSource(QString url) { const char* driverName = NULL; int i = 0; while (extensions[i][0] != NULL) { if (url.endsWith(extensions[i][0])) { driverName = extensions[i][1]; } i++; } i = 0; while (beginName[i][0] != NULL) { if (url.startsWith(beginName[i][0])) { driverName = beginName[i][1]; } i++; } if (driverName == NULL) { throw HootException("No driver found for: " + url); } OGRSFDriver* driver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(driverName); if (driver == 0) { throw HootException("Error getting driver by name: " + QString(driverName)); } // if the user specifies a shapefile then crop off the .shp and create a directory. if (url.toLower().endsWith(".shp")) { url = url.mid(0, url.length() - 4); } shared_ptr<OGRDataSource> result(driver->CreateDataSource(url.toAscii())); if (result == NULL) { throw HootException("Unable to create data source: " + url + " (" + QString(CPLGetLastErrorMsg()) + ")"); } result->SetDriver(driver); if (QString(driverName) == "FileGDB") { long v = GDAL_VERSION_MAJOR * 1000000 + GDAL_VERSION_MINOR * 1000 + GDAL_VERSION_REV; long lowest = 1 * 1000000 + 10 * 1000 + 1; if (v < lowest) { LOG_WARN("Writing to FileGDB with GDAL v" << GDAL_RELEASE_NAME << ". FileGDB with a GDAL " "v1.9.0 is known to create files that can't be read by ArcMap 10.2. " "GDAL v1.10.1 is known to work."); } } return result; }
long SequenceIdReserver::_reserveIds() { if (_query == 0) { _query.reset(new QSqlQuery(_db)); _query->setForwardOnly(true); //// // This query contains a race condition. It is possible that one process could call SETVAL // between the call to CURRVAL and SETVAL. This can result in a smaller value than expected // and duplicate IDs. See #3607 for details. // LOG_WARN("This query contains a race condition and may not do what you want."); _query->prepare( QString("SELECT NEXTVAL('%1'), " "SETVAL('%1', CURRVAL('%1') + :count)").arg(_sequenceName)); } _query->bindValue(0, (qlonglong)_bulkSize - 1); if (_query->exec() == false) { throw HootException("Error reserving IDs. count: " + QString::number(_bulkSize) + " Error: " + _query->lastError().text()); } long result = -1; if (_query->next()) { bool ok; result = _query->value(1).toLongLong(&ok); if (!ok) { throw HootException("Did not retrieve starting reserved ID."); } } else { LOG_VARW(_nextId); LOG_VARW(result); LOG_VARW(_bulkSize); throw HootException("Error retrieving sequence value. count: " + QString::number(_bulkSize) + " Error: " + _query->lastError().text()); } if (result < _nextId) { LOG_VARW(_nextId); LOG_VARW(result); LOG_VARW(_bulkSize); QString err = QString("Error allocating new sequence value. Expected to retrieve a value " ">= %1, but got %2.").arg(_nextId).arg(result); LOG_WARN(err); throw HootException(err); } _query->finish(); return result; }
void ServicesDbReader::open(QString urlStr) { if (!isSupported(urlStr)) { throw HootException("An unsupported URL was passed in."); } QUrl url(urlStr); QString osmElemId = url.queryItemValue("osm-element-id"); QString osmElemType = url.queryItemValue("osm-element-type"); QStringList pList = url.path().split("/"); bool ok; bool ok2; QString mapName; _database.open(url); _mapId = pList[pList.size() - 1].toLong(&ok); if(osmElemId.length() > 0 && osmElemType.length() > 0) { _osmElemId = osmElemId.toLong(&ok2); _osmElemType = ElementType::fromString(osmElemType); } if (!ok) { if (_email == "") { throw HootException("If a map name is specified then the user email must also be specified " "via: " + emailKey()); } mapName = pList[pList.size() - 1]; long userId = _database.getUserId(_email); set<long> mapIds = _database.selectMapIds(mapName, userId); if (mapIds.size() != 1) { QString str = QString("Expected 1 map with the name '%1' but found %2 maps.").arg(mapName) .arg(mapIds.size()); throw HootException(str); } _mapId = *mapIds.begin(); } if (!_database.mapExists(_mapId)) { _database.close(); throw HootException("No map exists with ID: " + QString::number(_mapId)); } //using a transaction seems to make sense here, b/c we don't want to read a map being modified //in the middle of its modification caused by a changeset upload, which could cause the map to //be invalid as a whole _database.transaction(); _open = true; }
void OgrWriter::open(QString url) { if (_scriptPath.isEmpty()) { throw HootException("A script path must be set before the output data source is opened."); } if (_translator == 0) { // Great bit of code taken from TranslatedTagDifferencer.cpp shared_ptr<ScriptTranslator> st(ScriptTranslatorFactory::getInstance().createTranslator( _scriptPath)); st->setErrorTreatment(_strictChecking); _translator = dynamic_pointer_cast<ScriptToOgrTranslator>(st); } if (!_translator) { throw HootException("Error allocating translator, the translation script must support " "converting to OGR."); } _schema = _translator->getOgrOutputSchema(); try { _ds = OgrUtilities::getInstance().openDataSource(url); } catch(HootException& openException) { try { _ds = OgrUtilities::getInstance().createDataSource(url); } catch(HootException& createException) { throw HootException(QString("Error opening or creating data source. Opening error: \"%1\" " "Creating error: \"%2\"").arg(openException.what()).arg(createException.what())); } } if (_createAllLayers) { for (size_t i = 0; i < _schema->getLayerCount(); ++i) { _createLayer(_schema->getLayer(i)); } } }
void ServicesDb::insertRelationMembers(long mapId, long relationId, ElementType type, long elementId, QString role, int sequenceId) { _checkLastMapId(mapId); if (_insertRelationMembers == 0) { _insertRelationMembers.reset(new QSqlQuery(_db)); _insertRelationMembers->prepare( "INSERT INTO " + _getRelationMembersTableName(mapId) + " (relation_id, member_type, member_id, member_role, sequence_id) " "VALUES (:relation_id, :member_type, :member_id, :member_role, :sequence_id)"); } _insertRelationMembers->bindValue(":relation_id", (qlonglong)relationId); _insertRelationMembers->bindValue(":member_type", type.toString().toLower()); _insertRelationMembers->bindValue(":member_id", (qlonglong)elementId); _insertRelationMembers->bindValue(":member_role", role); _insertRelationMembers->bindValue(":sequence_id", sequenceId); if (!_insertRelationMembers->exec()) { throw HootException("Error inserting relation memeber: " + _insertRelationMembers->lastError().text()); } }
bool TileBoundsCalculator::_isDone(vector<PixelBox> &boxes) { bool smallEnough = true; bool minSize = false; for (size_t i = 0; i < boxes.size(); i++) { PixelBox& b = boxes[i]; if (b.getWidth() == 1 || b.getHeight() == 1) { minSize = true; } if (_sumPixels(b) > _maxNodesPerBox) { smallEnough = false; } } if (minSize == true && smallEnough == false) { throw HootException("Could not find a solution. Try reducing the pixel size or increasing the " "max nodes per pixel value."); } else { return smallEnough; } }
OsmMapPtr AlphaShapeGenerator::generateMap(OsmMapPtr inputMap) { boost::shared_ptr<Geometry> cutterShape = generateGeometry(inputMap); if (cutterShape->getArea() == 0.0) { //would rather this be thrown than a warning logged, as the warning may go unoticed by web //clients who are expecting the alpha shape to be generated throw HootException("Alpha Shape area is zero. Try increasing the buffer size and/or alpha."); } OsmMapPtr result; result.reset(new OsmMap(inputMap->getProjection())); // add the resulting alpha shape for debugging. GeometryConverter(result).convertGeometryToElement(cutterShape.get(), Status::Invalid, -1); const RelationMap& rm = result->getRelations(); for (RelationMap::const_iterator it = rm.begin(); it != rm.end(); ++it) { Relation* r = result->getRelation(it->first).get(); r->setTag("area", "yes"); } return result; }
double LogisticRegression::evaluate(map<QString, double> sample) { // Taken from Weka's documentation: // // The probability for class j with the exception of the last class is // Pj(Xi) = exp(XiBj)/((sum[j=1..(k-1)]exp(Xi*Bj))+1) // since we only have two classes: // this code shamelessly modified from Weka double prob = 0.0; double v = 0.0; // Log-posterior before normalizing for (Coeff::iterator it = _coeff.begin(); it != _coeff.end(); ++it) { double par = it->second; map<QString, double>::const_iterator sit = sample.find(it->first); if (sit == sample.end()) { throw HootException("Error finding sample key: " + it->first); } double data = sample.find(it->first)->second; v += par * data; } v += _intercept; // Do so to avoid scaling problems prob = 1 / (1 + exp(-v)); return prob; }
bool OsmApiDbChangesetWriter::conflictExistsInTarget(const QString boundsStr, const QString timeStr) { LOG_INFO("Checking for OSM API DB conflicts for changesets within " << boundsStr << " and " << "created after " << timeStr << "..."); const Envelope bounds = GeometryUtils::envelopeFromConfigString(boundsStr); LOG_VARD(bounds.toString()); const QDateTime time = QDateTime::fromString(timeStr, OsmApiDb::TIME_FORMAT); LOG_VARD(time); if (!time.isValid()) { throw HootException( "Invalid timestamp: " + time.toString() + ". Should be of the form " + OsmApiDb::TIME_FORMAT); } shared_ptr<QSqlQuery> changesetItr = _db.getChangesetsCreatedAfterTime(timeStr); while (changesetItr->next()) { shared_ptr<Envelope> changesetBounds( new Envelope(changesetItr->value(0).toDouble(), changesetItr->value(1).toDouble(), changesetItr->value(2).toDouble(), changesetItr->value(3).toDouble())); LOG_VARD(changesetBounds->toString()); if (changesetBounds->intersects(bounds)) { return true; } } return false; }
WayLocation::WayLocation(ConstOsmMapPtr map, ConstWayPtr way, int segmentIndex, double segmentFraction) : _map(map) { _way = way; _segmentIndex = segmentIndex; _segmentFraction = segmentFraction; if (_segmentFraction == 1.0) { _segmentIndex++; _segmentFraction = 0.0; } if (_segmentFraction < 0.0 || _segmentFraction >= 1.0) { throw HootException("Segment Fraction is out of range."); } if (_segmentIndex < 0) { _segmentIndex = 0; _segmentFraction = 0.0; } if (_segmentIndex >= (int)_way->getNodeCount() - 1) { _segmentIndex = _way->getNodeCount() - 1; _segmentFraction = 0.0; } }
long Hoot::_toBytes(const QString& str) const { QString s = str; long multiplier = 1; if (s.endsWith("KB")) { multiplier = 1000; s = s.remove(s.size() - 2, 2); } else if (s.endsWith("MB")) { multiplier = 1000 * 1000; s = s.remove(s.size() - 2, 2); } else if (s.endsWith("GB")) { multiplier = 1000 * 1000 * 1000; s = s.remove(s.size() - 2, 2); } bool ok; long result = s.toLong(&ok) * multiplier; if (!ok) { throw HootException("Unable to parse max memory usage: " + s); } return result; }
LanguageDetectionConfidenceLevel::Level LanguageDetectionConfidenceLevel::fromString( QString levelString) { levelString = levelString.toLower(); if (levelString == "none") { return None; } else if (levelString == "low") { return Low; } else if (levelString == "medium") { return Medium; } else if (levelString == "high") { return High; } else { throw HootException("Invalid language detection confidence string: " + levelString); } }
void WaySublineCollection::addSubline(const WaySubline& subline) { if (_sublines.size() == 0) { _sublines.push_back(subline); } else { for (size_t i = 0; i < _sublines.size(); i++) { if (subline.overlaps(_sublines[i])) { throw HootException("A subline string may not contain overlapping sublines."); //use this for debugging only /*if (logWarnCount < Log::getWarnMessageLimit()) { LOG_WARN("A subline string may not contain overlapping sublines."); } else if (logWarnCount == Log::getWarnMessageLimit()) { LOG_WARN(className() << ": " << Log::LOG_WARN_LIMIT_REACHED_MESSAGE); } logWarnCount++;*/ } } _sublines.push_back(subline); } }
void MergerFactory::createMergers(const OsmMapPtr& map, const MatchSet& matches, vector<Merger*>& result) const { for (size_t i = 0; i < _creators.size(); i++) { OsmMapConsumer* omc = dynamic_cast<OsmMapConsumer*>(_creators[i]); if (omc) { omc->setOsmMap(map.get()); } if (_creators[i]->createMergers(matches, result)) { return; } // we don't want the creators to hold onto a map pointer that will go out of scope if (omc) { omc->setOsmMap((OsmMap*)0); } } LOG_WARN("Error finding Mergers for these matches: " << matches); LOG_WARN("Creators: " << _creators); throw HootException("Error creating a merger for the provided set of matches."); }
unsigned long ElementCacheLRU::typeCount(const ElementType::Type typeToCount) const { unsigned long retVal = 0; switch ( typeToCount ) { case ElementType::Node: retVal = _nodes.size(); break; case ElementType::Way: retVal = _ways.size(); break; case ElementType::Relation: retVal = _relations.size(); break; default: throw HootException("Invalid type passed"); break; } return retVal; }
void OsmApiDbReader::open(QString urlStr) { if (!isSupported(urlStr)) { throw HootException("An unsupported URL was passed in."); } _elementResultIterator.reset(); _selectElementType = ElementType::Node; QUrl url(urlStr); QString osmElemId = url.queryItemValue("osm-element-id"); QString osmElemType = url.queryItemValue("osm-element-type"); LOG_DEBUG("url path = "+url.path()); bool ok; _database.open(url); if(osmElemId.length() > 0 && osmElemType.length() > 0) { _osmElemId = osmElemId.toLong(&ok); _osmElemType = ElementType::fromString(osmElemType); } //using a transaction seems to make sense here, b/c we don't want to read a map being modified //in the middle of its modification caused by a changeset upload, which could cause the map to //be invalid as a whole _database.transaction(); _open = true; }
long ServicesDb::insertUser(QString email, QString displayName) { if (_insertUser == 0) { _insertUser.reset(new QSqlQuery(_db)); _insertUser->prepare("INSERT INTO users (email, display_name) " "VALUES (:email, :display_name) " "RETURNING id"); } _insertUser->bindValue(":email", email); _insertUser->bindValue(":display_name", displayName); long id = -1; // if we failed to execute the query the first time if (_insertUser->exec() == false) { // it may be that another process beat us to it and the user was already inserted. This can // happen if a bunch of converts are run in parallel. See #3588 id = getUserId(email, false); // nope, there is something else wrong. Report an error. if (id == -1) { QString err = QString("Error executing query: %1 (%2)").arg(_insertUser->executedQuery()). arg(_insertUser->lastError().text()); LOG_WARN(err) throw HootException(err); } else { LOG_DEBUG("Did not insert user, queryied a previously created user.") } }
void runUncompressTest() { const std::string cmd( "gzip -c test-files/ToyTestA.osm > test-output/ToyTestA_compressed.osm.gz"); LOG_DEBUG("Running compress command: " << cmd); int retVal; if ((retVal = std::system(cmd.c_str())) != 0) { QString error = QString("Error %1 returned from compress command: %2").arg(retVal). arg(QString::fromStdString(cmd)); throw HootException(error); } OsmXmlReader uut; OsmMapPtr map(new OsmMap()); uut.setUseDataSourceIds(true); // Excercise the code uut.read("test-output/ToyTestA_compressed.osm.gz", map); // Check a few things CPPUNIT_ASSERT_EQUAL(36,(int)map->getNodes().size()); CPPUNIT_ASSERT_EQUAL(4, (int)map->getWays().size()); QFile f("test-output/ToyTestA_compressed.osm.gz"); CPPUNIT_ASSERT(f.exists()); CPPUNIT_ASSERT(f.remove()); }
boost::shared_ptr<HootNetworkCookieJar> NetworkIoUtils::getUserSessionCookie( const QString userName, const QString accessToken, const QString accessTokenSecret, const QString url) { LOG_VART(userName); LOG_VART(accessToken); LOG_VART(url); HootApiDb db; LOG_VART(HootApiDb::getBaseUrl()); //hoot db requires a layer to open, but we don't need one here...so put anything in QUrl dbUrl(HootApiDb::getBaseUrl().toString() + "/blah"); db.open(dbUrl); const QString sessionId = db.getSessionIdByAccessTokens(userName, accessToken, accessTokenSecret); LOG_VART(sessionId); db.close(); if (sessionId.isEmpty()) { throw HootException("User: "******" has not been authenticated."); } boost::shared_ptr<HootNetworkCookieJar> cookieJar(new HootNetworkCookieJar()); QList<QNetworkCookie> cookies; QNetworkCookie sessionCookie(QString("SESSION").toUtf8(), sessionId.toUtf8()); cookies.append(sessionCookie); cookieJar->setCookiesFromUrl(cookies, url); LOG_VART(cookieJar->size()); LOG_VART(cookieJar->toString()); return cookieJar; }
shared_ptr<QSqlQuery> OsmApiDb::selectElements(const ElementType& elementType) { LOG_DEBUG("IN selectElement"); _selectElementsForMap.reset(new QSqlQuery(_db)); _selectElementsForMap->setForwardOnly(true); // setup base sql query string QString sql = "SELECT " + _elementTypeToElementTableName(elementType); // sort them in descending order, set limit and offset sql += " ORDER BY id DESC"; // let's see what that sql query string looks like LOG_DEBUG(QString("The sql query= "+sql)); _selectElementsForMap->prepare(sql); // execute the query on the DB and get the results back if (_selectElementsForMap->exec() == false) { QString err = _selectElementsForMap->lastError().text(); LOG_WARN(sql); throw HootException("Error selecting elements of type: " + elementType.toString() + " Error: " + err); } LOG_DEBUG("LEAVING OsmApiDb::selectElements..."); return _selectElementsForMap; }
shared_ptr<OsmMapWriter> OsmMapWriterFactory::createWriter(QString url) { QString writerOverride = ConfigOptions().getOsmMapWriterFactoryWriter(); shared_ptr<OsmMapWriter> writer; if (writerOverride != "") { writer.reset(Factory::getInstance().constructObject<OsmMapWriter>(writerOverride)); } vector<std::string> names = Factory::getInstance().getObjectNamesByBase(OsmMapWriter::className()); for (size_t i = 0; i < names.size() && !writer; ++i) { writer.reset(Factory::getInstance().constructObject<OsmMapWriter>(names[i])); if (writer->isSupported(url)) { LOG_DEBUG("Using writer: " << names[i]); } else { writer.reset(); } } if (!writer) { throw HootException("A valid writer could not be found for the URL: " + url); } return writer; }