Ejemplo n.º 1
0
void printPOIDetailInfo(std::ostream& output, const OsmAnd::Inspector::Configuration& cfg, const std::shared_ptr<OsmAnd::ObfReader>& reader, const std::shared_ptr<const OsmAnd::ObfPoiSectionInfo>& section)
#endif
{
    output << xT("\tBounds ") << formatBounds(section->area31.left, section->area31.right, section->area31.top, section->area31.bottom) << std::endl;
    QList< std::shared_ptr<const OsmAnd::Model::AmenityCategory> > categories;
    OsmAnd::ObfPoiSectionReader::loadCategories(reader, section, categories);
    output << xT("\tCategories:") << std::endl;
    for(auto itCategory = categories.cbegin(); itCategory != categories.cend(); ++itCategory)
    {
        auto category = *itCategory;
        output << xT("\t\t") << QStringToStlString(category->name) << std::endl;
        for(auto itSubcategory = category->subcategories.cbegin(); itSubcategory != category->subcategories.cend(); ++itSubcategory)
            output << xT("\t\t\t") << QStringToStlString(*itSubcategory) << std::endl;
    }

    QList< std::shared_ptr<const OsmAnd::Model::Amenity> > amenities;
    OsmAnd::AreaI bbox31;
    bbox31.top = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.top);
    bbox31.bottom = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.bottom);
    bbox31.left = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.left);
    bbox31.right = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.right);
    OsmAnd::ObfPoiSectionReader::loadAmenities(reader, section, cfg.zoom, 3, &bbox31, nullptr, &amenities);
    output << xT("\tAmenities, ") << amenities.count() << xT(" item(s)");
    if(!cfg.verboseAmenities)
    {
        output << std::endl;
        return;
    }
    output << ":" << std::endl;;
    for(auto itAmenity = amenities.cbegin(); itAmenity != amenities.cend(); ++itAmenity)
    {
        auto amenity = *itAmenity;

        output << xT("\t\t") <<
            QStringToStlString(amenity->latinName) << xT(" [") << amenity->id << xT("], ") <<
            QStringToStlString(categories[amenity->categoryId]->name) << xT(":") << QStringToStlString(categories[amenity->categoryId]->subcategories[amenity->subcategoryId]) <<
            xT(", lat ") << OsmAnd::Utilities::get31LatitudeY(amenity->point31.y) << xT(" lon ") << OsmAnd::Utilities::get31LongitudeX(amenity->point31.x) << std::endl;
    }
}
Ejemplo n.º 2
0
void printMapDetailInfo(std::ostream& output, const OsmAndTools::Inspector::Configuration& cfg, const std::shared_ptr<OsmAnd::ObfReader>& reader, const std::shared_ptr<const OsmAnd::ObfMapSectionInfo>& section)
#endif
{
    OsmAnd::AreaI bbox31;
    bbox31.top() = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.top());
    bbox31.bottom() = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.bottom());
    bbox31.left() = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.left());
    bbox31.right() = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.right());
    if (cfg.verboseMapObjects)
    {
        QList< std::shared_ptr<const OsmAnd::Model::BinaryMapObject> > mapObjects;
        OsmAnd::ObfMapSectionReader::loadMapObjects(reader, section, cfg.zoom, &bbox31, &mapObjects);
        output << xT("\tTotal map objects: ") << mapObjects.count() << std::endl;
        for (auto itMapObject = mapObjects.cbegin(); itMapObject != mapObjects.cend(); ++itMapObject)
        {
            auto mapObject = *itMapObject;
            output << xT("\t\t") << mapObject->id << std::endl;
            if (mapObject->captions.count() > 0)
            {
                output << xT("\t\t\tNames:") << std::endl;
                for (auto itCaption = mapObject->captions.cbegin(); itCaption != mapObject->captions.cend(); ++itCaption)
                {
                    const auto& rule = mapObject->section->encodingDecodingRules->decodingRules[itCaption.key()];
                    output << xT("\t\t\t\t") << QStringToStlString(rule.tag) << xT(" = ") << QStringToStlString(itCaption.value()) << std::endl;
                }
            }
        }
    }
    else
    {
        uint32_t mapObjectsCount = 0;
        OsmAnd::ObfMapSectionReader::loadMapObjects(reader, section, cfg.zoom, &bbox31, nullptr, nullptr, nullptr,
            [&mapObjectsCount]
            (const std::shared_ptr<const OsmAnd::Model::BinaryMapObject>& mapObject) -> bool
            {
                mapObjectsCount++;
                return false;
            });
        output << xT("\tTotal map objects: ") << mapObjectsCount << std::endl;
    }
}
Ejemplo n.º 3
0
void printMapDetailInfo(std::ostream& output, const OsmAnd::Inspector::Configuration& cfg, const std::shared_ptr<OsmAnd::ObfReader>& reader, const std::shared_ptr<const OsmAnd::ObfMapSectionInfo>& section)
#endif
{
    OsmAnd::AreaI bbox31;
    bbox31.top = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.top);
    bbox31.bottom = OsmAnd::Utilities::get31TileNumberY(cfg.bbox.bottom);
    bbox31.left = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.left);
    bbox31.right = OsmAnd::Utilities::get31TileNumberX(cfg.bbox.right);
    if(cfg.verboseMapObjects)
    {
        QList< std::shared_ptr<const OsmAnd::Model::MapObject> > mapObjects;
        OsmAnd::ObfMapSectionReader::loadMapObjects(reader, section, cfg.zoom, &bbox31, &mapObjects);
        output << xT("\tTotal map objects: ") << mapObjects.count() << std::endl;
        for(auto itMapObject = mapObjects.cbegin(); itMapObject != mapObjects.cend(); ++itMapObject)
        {
            auto mapObject = *itMapObject;
            output << xT("\t\t") << mapObject->id << std::endl;
            if(mapObject->names.count() > 0)
            {
                output << xT("\t\t\tNames:");
                for(auto itName = mapObject->names.cbegin(); itName != mapObject->names.cend(); ++itName)
                    output << QStringToStlString(itName.value()) << xT(", ");
                output << std::endl;
            }
            else
                output << xT("\t\t\tNames: [none]") << std::endl;
        }
    }
    else
    {
        uint32_t mapObjectsCount = 0;
        OsmAnd::ObfMapSectionReader::loadMapObjects(reader, section, cfg.zoom, &bbox31, nullptr, nullptr, nullptr, [&mapObjectsCount](const std::shared_ptr<const OsmAnd::Model::MapObject>& mapObject) -> bool
        {
            mapObjectsCount++;
            return false;
        });
        output << xT("\tTotal map objects: ") << mapObjectsCount << std::endl;
    }
}
Ejemplo n.º 4
0
void printAddressDetailedInfo(std::ostream& output, const OsmAnd::Inspector::Configuration& cfg, const std::shared_ptr<OsmAnd::ObfReader>& reader, const std::shared_ptr<const OsmAnd::ObfAddressSectionInfo>& section)
#endif
{
    OsmAnd::ObfAddressBlockType types[] = {
        OsmAnd::ObfAddressBlockType::CitiesOrTowns,
        OsmAnd::ObfAddressBlockType::Villages,
        OsmAnd::ObfAddressBlockType::Postcodes,
    };
    char* strTypes[] = {
        "Cities/Towns section",
        "Villages section",
        "Postcodes section",
    };
    for(int typeIdx = 0; typeIdx < sizeof(types)/sizeof(types[0]); typeIdx++)
    {
        auto type = types[typeIdx];

        QList< std::shared_ptr<const OsmAnd::Model::StreetGroup> > streetGroups;
        QSet<OsmAnd::ObfAddressBlockType> typeSet;
        typeSet << types[typeIdx];
        OsmAnd::ObfAddressSectionReader::loadStreetGroups(reader, section, &streetGroups, nullptr, nullptr, &typeSet);

        output << xT("\t") << strTypes[typeIdx] << xT(", ") << streetGroups.size() << xT(" group(s)");
        if(!cfg.verboseStreetGroups)
        {
            output << std::endl;
            continue;
        }
        output << ":" << std::endl;
        for(auto itStreetGroup = streetGroups.cbegin(); itStreetGroup != streetGroups.cend(); itStreetGroup++)
        {
            auto g = *itStreetGroup;

            QList< std::shared_ptr<const OsmAnd::Model::Street> > streets;
            OsmAnd::ObfAddressSectionReader::loadStreetsFromGroup(reader, g, &streets);
            output << xT("\t\t'") << QStringToStlString(g->_latinName) << xT("' [") << g->_id << xT("], ") << streets.size() << xT(" street(s)");
            if(!cfg.verboseStreets)
            {
                output << std::endl;
                continue;
            }
            output << xT(":") << std::endl;
            for(auto itStreet = streets.cbegin(); itStreet != streets.cend(); ++itStreet)
            {
                auto s = *itStreet;
                //TODO: proper filter
                //const bool isInside =
                //    cfg.latTop >= s->latitude &&
                //    cfg.latBottom <= s->latitude &&
                //    cfg.lonLeft <= s->longitude &&
                //    cfg.lonRight >= s->longitude;
                //if(!isInside)
                //    continue;
                //
                QList< std::shared_ptr<const OsmAnd::Model::Building> > buildings;
                OsmAnd::ObfAddressSectionReader::loadBuildingsFromStreet(reader, s, &buildings);
                QList< std::shared_ptr<const OsmAnd::Model::StreetIntersection> > intersections;
                OsmAnd::ObfAddressSectionReader::loadIntersectionsFromStreet(reader, s, &intersections);
                output << xT("\t\t\t'") << QStringToStlString(s->latinName) << xT("' [") << s->id << xT("], ") << buildings.size() << xT(" building(s), ") << intersections.size() << xT(" intersection(s)") << std::endl;
                if(cfg.verboseBuildings && buildings.size() > 0)
                {
                    output << xT("\t\t\t\tBuildings:") << std::endl;
                    for(auto itBuilding = buildings.cbegin(); itBuilding != buildings.cend(); ++itBuilding)
                    {
                        auto building = *itBuilding;

                        if(building->_interpolationInterval != 0)
                            output << xT("\t\t\t\t\t") << QStringToStlString(building->_latinName) << xT("-") << QStringToStlString(building->_latinName2) << xT(" (+") << building->_interpolationInterval << xT(") [") << building->_id << xT("]") << std::endl;
                        else if(building->_interpolation != OsmAnd::Model::Building::Interpolation::Invalid)
                            output << xT("\t\t\t\t\t") << QStringToStlString(building->_latinName) << xT("-") << QStringToStlString(building->_latinName2) << xT(" (") << building->_interpolation << xT(") [") << building->_id << xT("]") << std::endl;
                    }
                }
                if(cfg.verboseIntersections && intersections.size() > 0)
                {
                    output << xT("\t\t\t\tIntersects with:") << std::endl;
                    for(auto itIntersection = intersections.cbegin(); itIntersection != intersections.cend(); ++itIntersection)
                    {
                        auto intersection = *itIntersection;

                        output << xT("\t\t\t\t\t") << QStringToStlString(intersection->latinName) << std::endl;
                    }
                }
            }
        }
    }
}
Ejemplo n.º 5
0
void dump(std::ostream &output, const QString& filePath, const OsmAnd::Inspector::Configuration& cfg)
#endif
{
    std::shared_ptr<QFile> file(new QFile(filePath));
    if(!file->exists())
    {
        output << xT("OBF '") << QStringToStlString(filePath) << xT("' does not exist.") << std::endl;
        return;
    }

    if(!file->open(QIODevice::ReadOnly))
    {
        output << xT("Failed to open OBF '") << QStringToStlString(file->fileName()) << xT("'") << std::endl;
        return;
    }

    std::shared_ptr<OsmAnd::ObfReader> obfReader(new OsmAnd::ObfReader(file));
    const auto& obfInfo = obfReader->obtainInfo();

    output << xT("OBF '") << QStringToStlString(file->fileName()) << xT("' version = ") << obfInfo->version << std::endl;
    int idx = 1;
    for(auto itSection = obfInfo->mapSections.cbegin(); itSection != obfInfo->mapSections.cend(); ++itSection, idx++)
    {
        const auto& section = *itSection;

        output << idx << xT(". Map data '") << QStringToStlString(section->name) << xT("' - ") << section->length << xT(" bytes") << std::endl;
        int levelIdx = 1;
        for(auto itLevel = section->levels.cbegin(); itLevel != section->levels.cend(); ++itLevel, levelIdx++)
        {
            auto level = (*itLevel);
            output << xT("\t") << idx << xT(".") << levelIdx << xT(" Map level minZoom = ") << level->minZoom << xT(", maxZoom = ") << level->maxZoom << std::endl;
            output << xT("\t\tBounds ") << formatBounds(level->area31.left, level->area31.right, level->area31.top, level->area31.bottom) << std::endl;
        }

        if(cfg.verboseMap)
            printMapDetailInfo(output, cfg, obfReader, section);
    }
    for(auto itSection = obfInfo->transportSections.cbegin(); itSection != obfInfo->transportSections.cend(); ++itSection, idx++)
    {
        const auto& section = *itSection;

        output << idx << xT(". Transport data '") << QStringToStlString(section->name) << xT("' - ") << section->length << xT(" bytes") << std::endl;
        output << "\tBounds " << formatBounds(section->area24.left << (31 - 24), section->area24.right << (31 - 24), section->area24.top << (31 - 24), section->area24.bottom << (31 - 24)) << std::endl;
    }
    for(auto itSection = obfInfo->routingSections.cbegin(); itSection != obfInfo->routingSections.cend(); ++itSection, idx++)
    {
        const auto& section = *itSection;

        output << idx << xT(". Routing data '") << QStringToStlString(section->name) << xT("' - ") << section->length << xT(" bytes") << std::endl;
        double lonLeft = 180;
        double lonRight = -180;
        double latTop = -90;
        double latBottom = 90;
        for(auto itSubsection = section->subsections.cbegin(); itSubsection != section->subsections.cend(); ++itSubsection)
        {
            auto subsection = itSubsection->get();

            lonLeft = std::min(lonLeft, OsmAnd::Utilities::get31LongitudeX(subsection->area31.left));
            lonRight = std::max(lonRight, OsmAnd::Utilities::get31LongitudeX(subsection->area31.right));
            latTop = std::max(latTop, OsmAnd::Utilities::get31LatitudeY(subsection->area31.top));
            latBottom = std::min(latBottom, OsmAnd::Utilities::get31LatitudeY(subsection->area31.bottom));
        }
        output << xT("\tBounds ") << formatGeoBounds(lonLeft, lonRight, latTop, latBottom) << std::endl;
    }
    for(auto itSection = obfInfo->poiSections.cbegin(); itSection != obfInfo->poiSections.cend(); ++itSection, idx++)
    {
        const auto& section = *itSection;

        output << idx << xT(". POI data '") << QStringToStlString(section->name) << xT("' - ") << section->length << xT(" bytes") << std::endl;
        if(cfg.verbosePoi)
            printPOIDetailInfo(output, cfg, obfReader, section);
    }
    for(auto itSection = obfInfo->addressSections.cbegin(); itSection != obfInfo->addressSections.cend(); ++itSection, idx++)
    {
        const auto& section = *itSection;

        output << idx << xT(". Address data '") << QStringToStlString(section->name) << xT("' - ") << section->length << xT(" bytes") << std::endl;
        printAddressDetailedInfo(output, cfg, obfReader, section);
    }

    file->close();
}
Ejemplo n.º 6
0
void performJourney(std::ostream &output, const OsmAnd::Voyager::Configuration& cfg)
#endif
{
    if(cfg.generateXml)
    {
#if defined(_UNICODE) || defined(UNICODE)
        output << xT("<?xml version=\"1.0\" encoding=\"UTF-16\"?>") << std::endl;
#else
        output << xT("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") << std::endl;
#endif
    }

    QList< std::shared_ptr<OsmAnd::ObfReader> > obfData;
    for(auto itObf = cfg.obfs.begin(); itObf != cfg.obfs.end(); ++itObf)
    {
        const auto& obf = *itObf;
        std::shared_ptr<OsmAnd::ObfReader> obfReader(new OsmAnd::ObfReader(std::shared_ptr<QIODevice>(new QFile(obf.absoluteFilePath()))));
        obfData.push_back(obfReader);
    }

    OsmAnd::RoutePlannerContext plannerContext(obfData, cfg.routingConfig, cfg.vehicle, false);
    std::shared_ptr<OsmAnd::Model::Road> startRoad;
    if(!OsmAnd::RoutePlanner::findClosestRoadPoint(&plannerContext, cfg.startLatitude, cfg.startLongitude, &startRoad))
    {
        if(cfg.generateXml)
            output << xT("<!--");
        output << xT("Failed to find road near start point");
        if(cfg.generateXml)
            output << xT("-->");
        output << std::endl;
        return;
    }
    std::shared_ptr<OsmAnd::Model::Road> endRoad;
    if(!OsmAnd::RoutePlanner::findClosestRoadPoint(&plannerContext, cfg.endLatitude, cfg.endLongitude, &endRoad))
    {
        if(cfg.generateXml)
            output << xT("<!--");
        output << xT("Failed to find road near end point");
        if(cfg.generateXml)
            output << xT("-->");
        output << std::endl;
        return;
    }

    if(cfg.verbose)
    {
        if(cfg.generateXml)
            output << xT("<!--");
        output << xT("Start point (LAT ") << cfg.startLatitude << xT("; LON ") << cfg.startLongitude << xT("):");
        if(cfg.generateXml)
            output << xT("-->");
        output << std::endl;
        if(cfg.generateXml)
            output << xT("<!--");
        output << xT("\tRoad name(s): ");
        if(startRoad->names.size() == 0)
        {
            output << xT("\t[none] (") << startRoad->id << xT(")");
            if(cfg.generateXml)
                output << xT("-->");
            output << std::endl;
        }
        else
        {
            for(auto itName = startRoad->names.begin(); itName != startRoad->names.end(); ++itName)
                output << QStringToStlString(itName.value()) << xT("; ");
            output << xT(" (") << startRoad->id << xT(")");
            if(cfg.generateXml)
                output << xT("-->");
            output << std::endl;
        }
        output << std::endl;
    
        if(cfg.generateXml)
            output << xT("<!--");
        output << xT("End point (LAT ") << cfg.endLatitude << xT("; LON ") << cfg.endLongitude << xT("):");
        if(cfg.generateXml)
            output << xT("-->");
        output << std::endl;
        if(cfg.generateXml)
            output << xT("<!--");
        output << xT("\tRoad name(s): ");
        if(endRoad->names.size() == 0)
        {
            output << xT("\t[none] (") << endRoad->id << xT(")");
            if(cfg.generateXml)
                output << xT("-->");
            output << std::endl;
        }
        else
        {
            for(auto itName = endRoad->names.begin(); itName != endRoad->names.end(); ++itName)
                output << QStringToStlString(itName.value()) << xT("; ");
            output << xT(" (") << endRoad->id << xT(")");
            if(cfg.generateXml)
                output << xT("-->");
            output << std::endl;
        }
        output << std::endl;
    }

    QList< std::pair<double, double> > points;
    points.push_back(std::pair<double, double>(cfg.startLatitude, cfg.startLongitude));
    for(auto itIntermediatePoint = cfg.waypoints.begin(); itIntermediatePoint != cfg.waypoints.end(); ++itIntermediatePoint)
        points.push_back(*itIntermediatePoint);
    points.push_back(std::pair<double, double>(cfg.endLatitude, cfg.endLongitude));

    QList< std::shared_ptr<OsmAnd::RouteSegment> > route;
    auto routeCalculationStart = std::chrono::steady_clock::now();
    if(cfg.verbose)
    {
        if(cfg.generateXml)
            output << xT("<!--");
        output << xT("Started route calculation ") << QStringToStlString(QTime::currentTime().toString());
        if(cfg.generateXml)
            output << xT("-->");
        output << std::endl;
    }
    OsmAnd::RouteCalculationResult routeFound =
            OsmAnd::RoutePlanner::calculateRoute(&plannerContext, points, cfg.leftSide, nullptr);
    route = routeFound.list;
    auto routeCalculationFinish = std::chrono::steady_clock::now();
    if(cfg.verbose)
    {
        if(cfg.generateXml)
            output << xT("<!--");
        output << xT("Finished route calculation ") << QStringToStlString(QTime::currentTime().toString()) << xT(", took ") << std::chrono::duration<double, std::milli> (routeCalculationFinish - routeCalculationStart).count() << xT(" ms");
        if(cfg.generateXml)
            output << xT("-->");
        output << std::endl;
    }
    if(cfg.doRecalculate)
    {
        auto routeRecalculationStart = std::chrono::steady_clock::now();
        if(cfg.verbose)
        {
            if(cfg.generateXml)
                output << xT("<!--");
            output << xT("Started route recalculation ") << QStringToStlString(QTime::currentTime().toString());
            if(cfg.generateXml)
                output << xT("-->");
            output << std::endl;
        }
        routeFound = OsmAnd::RoutePlanner::calculateRoute(&plannerContext, points, cfg.leftSide, nullptr);
        route = routeFound.list;
        auto routeRecalculationFinish = std::chrono::steady_clock::now();
        if(cfg.verbose)
        {
            if(cfg.generateXml)
                output << xT("<!--");
            output << xT("Finished route recalculation ") << QStringToStlString(QTime::currentTime().toString()) << xT(", took ") << std::chrono::duration<double, std::milli> (routeRecalculationFinish - routeRecalculationStart).count() << xT(" ms");
            if(cfg.generateXml)
                output << xT("-->");
            output << std::endl;
        }
    }
    if(routeFound.warnMessage == "")
    {
        if(cfg.generateXml)
            output << xT("<!--");
        output << xT("FAILED TO FIND ROUTE!") << QStringToStlString(routeFound.warnMessage);
        if(cfg.generateXml)
            output << xT("-->");
        output << std::endl;
    }

    float totalTime = 0.0f;
    float totalDistance = 0.0f;
    for(auto itSegment = route.begin(); itSegment != route.end(); ++itSegment)
    {
        auto segment = *itSegment;

        totalTime += segment->time;
        totalDistance += segment->distance;
    }

    if(cfg.generateXml)
        output << xT("<test") << std::endl;
    else
        output << xT("ROUTE:") << std::endl;

    output << xT("\tregions=\"\"") << std::endl;
    output << xT("\tdescription=\"\"") << std::endl;
    output << xT("\tbest_percent=\"\"") << std::endl;
    output << xT("\tvehicle=\"") << QStringToStlString(cfg.vehicle) << xT("\"") << std::endl;
    output << xT("\tstart_lat=\"") << cfg.startLatitude << xT("\"") << std::endl;
    output << xT("\tstart_lon=\"") << cfg.startLongitude << xT("\"") << std::endl;
    output << xT("\ttarget_lat=\"") << cfg.endLatitude << xT("\"") << std::endl;
    output << xT("\ttarget_lon=\"") << cfg.endLongitude << xT("\"") << std::endl;
    output << xT("\tloadedTiles=\"") << 0 << xT("\"") << std::endl;
    output << xT("\tvisitedSegments=\"") << 0 << xT("\"") << std::endl;
    output << xT("\tcomplete_distance=\"") << totalDistance << xT("\"") << std::endl;
    output << xT("\tcomplete_time=\"") << totalTime << xT("\"") << std::endl;
    output << xT("\trouting_time=\"") << 0 << xT("\"") << std::endl;

    if(cfg.generateXml)
        output << xT(">") << std::endl;
    else
        output << std::endl;

    std::unique_ptr<QFile> gpxFile;
    std::unique_ptr<QTextStream> gpxStream;
    if(!cfg.gpxPath.isEmpty())
    {
        gpxFile.reset(new QFile(cfg.gpxPath));
        gpxFile->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
        gpxStream.reset(new QTextStream(gpxFile.get()));
    }
    if(gpxFile && gpxFile->isOpen())
    {
        *(gpxStream.get()) << "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
        *(gpxStream.get()) << "<gpx version=\"1.0\" creator=\"OsmAnd Voyager tool\" xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n";
        *(gpxStream.get()) << "\t<trk>\n";
        *(gpxStream.get()) << "\t\t<trkseg>\n";
    }
    for(auto itSegment = route.begin(); itSegment != route.end(); ++itSegment)
    {
        auto segment = *itSegment;

        if(cfg.generateXml)
            output << xT("\t<segment") << std::endl;
        else
            output << xT("\tSEGMENT:") << std::endl;

        output << xT("\t\tid=\"") << segment->road->id << xT("\"") << std::endl;
        output << xT("\t\tstart=\"") << segment->startPointIndex << xT("\"") << std::endl;
        output << xT("\t\tend=\"") << segment->endPointIndex << xT("\"") << std::endl;

        QString name;
        if(!segment->road->names.isEmpty())
            name += segment->road->names.begin().value();
        /*String ref = res.getObject().getRef();
        if (ref != null) {
            name += " (" + ref + ") ";
        }*/
        output << xT("\t\tname=\"") << QStringToStlString(name) << xT("\"") << std::endl;

        output << xT("\t\ttime=\"") << segment->time << xT("\"") << std::endl;
        output << xT("\t\tdistance=\"") << segment->distance << xT("\"") << std::endl;
        /*float ms = res.getObject().getMaximumSpeed();
        if(ms > 0) {
            additional.append("maxspeed = \"").append(ms * 3.6f).append("\" ").append(res.getObject().getHighway()).append(" ");
        }*/
        /*
        if (res.getTurnType() != null) {
            additional.append("turn = \"").append(res.getTurnType()).append("\" ");
            additional.append("turn_angle = \"").append(res.getTurnType().getTurnAngle()).append("\" ");
            if (res.getTurnType().getLanes() != null) {
                additional.append("lanes = \"").append(Arrays.toString(res.getTurnType().getLanes())).append("\" ");
            }
        }*/
        output << xT("\t\tstart_bearing=\"") << segment->getBearingBegin() << xT("\"") << std::endl;
        output << xT("\t\tend_bearing=\"") << segment->getBearingEnd() << xT("\"") << std::endl;
        //additional.append("description = \"").append(res.getDescription()).append("\" ");
        
        if(cfg.generateXml)
            output << xT("\t/>") << std::endl;
        else
            output << std::endl;

        if(gpxFile && gpxFile->isOpen())
        {
            output << xT("\t\tstart=\"") << segment->startPointIndex << xT("\"") << std::endl;
            output << xT("\t\tend=\"") << segment->endPointIndex << xT("\"") << std::endl;
            for(auto pointIdx = segment->startPointIndex; pointIdx < segment->endPointIndex; pointIdx++)
            {
                const auto& point = segment->road->points[pointIdx];

                *(gpxStream.get()) << "\t\t\t<trkpt lon=\"" << OsmAnd::Utilities::get31LongitudeX(point.x) << "\" lat=\"" << OsmAnd::Utilities::get31LatitudeY(point.y) << "\"/>\n";
            }
        }
    }

    if(gpxFile && gpxFile->isOpen())
    {
        *(gpxStream.get()) << "\t\t</trkseg>\n";
        *(gpxStream.get()) << "\t</trk>\n";
        *(gpxStream.get()) << "</gpx>\n";
        gpxStream->flush();
        gpxFile->close();
    }

    if(cfg.generateXml)
        output << xT("</test>") << std::endl;
}
Ejemplo n.º 7
0
bool OsmAndTools::Styler::evaluate(EvaluatedMapObjects& outEvaluatedMapObjects, std::ostream& output)
#endif
{
    bool success = true;
    for (;;)
    {
        // Find style
        if (configuration.verbose)
            output << xT("Resolving style '") << QStringToStlString(configuration.styleName) << xT("'...") << std::endl;
        const auto mapStyle = configuration.stylesCollection->getResolvedStyleByName(configuration.styleName);
        if (!mapStyle)
        {
            if (configuration.verbose)
            {
                output
                    << "Failed to resolve style '"
                    << QStringToStlString(configuration.styleName)
                    << "' from collection:"
                    << std::endl;
                for (const auto& style : configuration.stylesCollection->getCollection())
                {
                    if (style->isMetadataLoaded())
                    {
                        if (style->isStandalone())
                            output << "\t" << QStringToStlString(style->name) << std::endl;
                        else
                        {
                            output
                                << "\t"
                                << QStringToStlString(style->name)
                                << "::"
                                << QStringToStlString(style->parentName)
                                << std::endl;
                        }
                    }
                    else
                        output << "\t[missing metadata]" << std::endl;
                }
            }
            else
            {
                output
                    << "Failed to resolve style '"
                    << QStringToStlString(configuration.styleName)
                    << "' from collection:"
                    << std::endl;
            }

            success = false;
            break;
        }

        // Load all map objects
        const auto mapObjectsFilterById =
            [this]
            (const std::shared_ptr<const OsmAnd::ObfMapSectionInfo>& section,
            const uint64_t mapObjectId,
            const OsmAnd::AreaI& bbox,
            const OsmAnd::ZoomLevel firstZoomLevel,
            const OsmAnd::ZoomLevel lastZoomLevel,
            const OsmAnd::ZoomLevel requestedZoom) -> bool
            {
                return configuration.mapObjectsIds.contains(mapObjectId);
            };
        if (configuration.verbose)
        {
            if (configuration.mapObjectsIds.isEmpty())
                output << xT("Going to load all available map objects...") << std::endl;
            else
                output << xT("Going to load ") << configuration.mapObjectsIds.size() << xT(" map objects...") << std::endl;
        }
        const auto obfDataInterface = configuration.obfsCollection->obtainDataInterface();
        QList< std::shared_ptr<const OsmAnd::BinaryMapObject> > mapObjects_;
        success = obfDataInterface->loadBinaryMapObjects(
            &mapObjects_,
            nullptr,
            configuration.zoom,
            nullptr,
            configuration.mapObjectsIds.isEmpty() ? OsmAnd::ObfMapSectionReader::FilterByIdFunction() : mapObjectsFilterById,
            nullptr,
            nullptr,
            nullptr,
            nullptr);
        const auto mapObjects = OsmAnd::copyAs< QList< std::shared_ptr<const OsmAnd::MapObject> > >(mapObjects_);
        if (!success)
        {
            if (configuration.verbose)
                output << xT("Failed to load map objects!") << std::endl;
            break;
        }
        if (configuration.verbose)
            output << xT("Loaded ") << mapObjects.size() << xT(" map objects") << std::endl;

        // Prepare all resources for map style evaluation
        if (configuration.verbose)
        {
            output
                << xT("Initializing map presentation environment with display density ")
                << configuration.displayDensityFactor
                << xT(", map scale ")
                << configuration.mapScale
                << xT(", symbols scale ")
                << configuration.symbolsScale
                << xT(" and locale '")
                << QStringToStlString(configuration.locale)
                << xT("'...") << std::endl;
        }
        const std::shared_ptr<OsmAnd::MapPresentationEnvironment> mapPresentationEnvironment(new OsmAnd::MapPresentationEnvironment(
            mapStyle,
            configuration.displayDensityFactor,
            configuration.mapScale,
            configuration.symbolsScale,
            configuration.locale));

        if (configuration.verbose)
            output << xT("Applying extra style settings to map presentation environment...") << std::endl;
        mapPresentationEnvironment->setSettings(configuration.styleSettings);

        // Create primitiviser
        const std::shared_ptr<OsmAnd::MapPrimitiviser> primitiviser(new OsmAnd::MapPrimitiviser(mapPresentationEnvironment));
        if (configuration.verbose)
            output << xT("Going to primitivise map objects...") << std::endl;
        OsmAnd::MapPrimitiviser_Metrics::Metric_primitiviseAllMapObjects metrics;
        const auto primitivisedData = primitiviser->primitiviseAllMapObjects(
                configuration.zoom,
                mapObjects,
                nullptr,
                nullptr,
                configuration.metrics ? &metrics : nullptr);
        if (configuration.verbose)
        {
            output
                << xT("Primitivised ")
                << primitivisedData->primitivesGroups.size()
                << xT(" groups from ")
                << mapObjects.size()
                << xT(" map objects") << std::endl;
        }

        // Obtain evaluated values for each group and print it
        for (const auto& primitivisedGroup : OsmAnd::constOf(primitivisedData->primitivesGroups))
        {
            const auto& mapObject = primitivisedGroup->sourceObject;
            const auto binaryMapObject = std::dynamic_pointer_cast<const OsmAnd::BinaryMapObject>(mapObject);
            const auto& encDecRules = mapObject->encodingDecodingRules;

            // Skip objects that were not requested
            if (!configuration.mapObjectsIds.isEmpty() &&
                binaryMapObject &&
                !configuration.mapObjectsIds.contains(binaryMapObject->id))
            {
                continue;
            }

            outEvaluatedMapObjects[mapObject] = primitivisedGroup;

            output << QStringToStlString(QString(80, QLatin1Char('-'))) << std::endl;
            output << QStringToStlString(mapObject->toString()) << std::endl;

            for (const auto& typeRuleId : OsmAnd::constOf(mapObject->typesRuleIds))
            {
                const auto itTypeRule = encDecRules->decodingRules.constFind(typeRuleId);
                if (itTypeRule != encDecRules->decodingRules.cend())
                {
                    const auto& typeRule = *itTypeRule;

                    output
                        << xT("\tType: ")
                        << QStringToStlString(typeRule.tag)
                        << xT(" = ")
                        << QStringToStlString(typeRule.value)
                        << std::endl;
                }
                else
                {
                    output << xT("\tType: #") << typeRuleId << xT(" (UNRESOLVED)") << std::endl;
                }
            }

            for (const auto& typeRuleId : OsmAnd::constOf(mapObject->additionalTypesRuleIds))
            {
                const auto itTypeRule = encDecRules->decodingRules.constFind(typeRuleId);
                if (itTypeRule != encDecRules->decodingRules.cend())
                {
                    const auto& typeRule = *itTypeRule;

                    output
                        << xT("\tExtra type: ")
                        << QStringToStlString(typeRule.tag)
                        << xT(" = ")
                        << QStringToStlString(typeRule.value)
                        << std::endl;
                }
                else
                {
                    output << xT("\tExtra type: #") << typeRuleId << xT(" (UNRESOLVED)") << std::endl;
                }
            }

            for (const auto& captionTagId : OsmAnd::constOf(mapObject->captionsOrder))
            {
                const auto& captionValue = mapObject->captions[captionTagId];

                if (encDecRules->name_encodingRuleId == captionTagId)
                    output << xT("\tCaption: ") << QStringToStlString(captionValue) << std::endl;
                else if (encDecRules->ref_encodingRuleId == captionTagId)
                    output << xT("\tRef: ") << QStringToStlString(captionValue) << std::endl;
                else
                {
                    const auto itCaptionTagAsLocalizedName = encDecRules->localizedName_decodingRules.constFind(captionTagId);
                    const auto itCaptionTagRule = encDecRules->decodingRules.constFind(captionTagId);

                    QString captionTag(QLatin1String("UNRESOLVED"));
                    if (itCaptionTagAsLocalizedName != encDecRules->localizedName_decodingRules.cend())
                        captionTag = *itCaptionTagAsLocalizedName;
                    if (itCaptionTagRule != encDecRules->decodingRules.cend())
                        captionTag = itCaptionTagRule->tag;
                    output
                        << xT("\tCaption [")
                        << QStringToStlString(captionTag)
                        << xT("]: ")
                        << QStringToStlString(captionValue)
                        << std::endl;
                }
            }

            if (!primitivisedGroup->points.isEmpty())
            {
                output << primitivisedGroup->points.size() << xT(" point(s):") << std::endl;

                unsigned int pointPrimitiveIndex = 0u;
                for (const auto& pointPrimitive : OsmAnd::constOf(primitivisedGroup->points))
                {
                    output << xT("\tPoint #") << pointPrimitiveIndex << std::endl;
                    QString ruleTag;
                    QString ruleValue;
                    const auto typeRuleResolved = mapObject->obtainTagValueByTypeRuleIndex(
                        pointPrimitive->typeRuleIdIndex,
                        ruleTag,
                        ruleValue);
                    if (typeRuleResolved)
                    {
                        output
                            << xT("\t\tTag/value: ")
                            << QStringToStlString(ruleTag)
                            << xT(" = ")
                            << QStringToStlString(ruleValue)
                            << std::endl;
                    }
                    else
                    {
                        output
                            << xT("\t\tTag/value: ")
                            << pointPrimitive->typeRuleIdIndex
                            << xT(" (failed to resolve)")
                            << std::endl;
                    }
                    output << xT("\t\tZ order: ") << pointPrimitive->zOrder << std::endl;
                    output << xT("\t\tArea*2: ") << pointPrimitive->doubledArea << std::endl;
                    const auto& values = pointPrimitive->evaluationResult.getValues();
                    for (const auto& evaluatedValueEntry : OsmAnd::rangeOf(values))
                    {
                        const auto valueDefinitionId = evaluatedValueEntry.key();
                        const auto value = evaluatedValueEntry.value();

                        const auto valueDefinition = mapStyle->getValueDefinitionById(valueDefinitionId);

                        output << xT("\t\t") << QStringToStlString(valueDefinition->name) << xT(" = ");
                        if (valueDefinition->dataType == OsmAnd::MapStyleValueDataType::Color)
                            output << QStringToStlString(OsmAnd::ColorARGB(value.toUInt()).toString());
                        else
                            output << QStringToStlString(value.toString());
                        output << std::endl;
                    }

                    pointPrimitiveIndex++;
                }
            }

            if (!primitivisedGroup->polylines.isEmpty())
            {
                output << primitivisedGroup->polylines.size() << xT(" polyline(s):") << std::endl;

                unsigned int polylinePrimitiveIndex = 0u;
                for (const auto& polylinePrimitive : OsmAnd::constOf(primitivisedGroup->polylines))
                {
                    output << xT("\tPolyline #") << polylinePrimitiveIndex << std::endl;
                    QString ruleTag;
                    QString ruleValue;
                    const auto typeRuleResolved = mapObject->obtainTagValueByTypeRuleIndex(
                        polylinePrimitive->typeRuleIdIndex,
                        ruleTag,
                        ruleValue);
                    if (typeRuleResolved)
                    {
                        output
                            << xT("\t\tTag/value: ")
                            << QStringToStlString(ruleTag)
                            << xT(" = ")
                            << QStringToStlString(ruleValue) << std::endl;
                    }
                    else
                    {
                        output
                            << xT("\t\tTag/value: ")
                            << polylinePrimitive->typeRuleIdIndex
                            << xT(" (failed to resolve)")
                            << std::endl;
                    }
                    output << xT("\t\tZ order: ") << polylinePrimitive->zOrder << std::endl;
                    output << xT("\t\tArea*2: ") << polylinePrimitive->doubledArea << std::endl;
                    const auto& values = polylinePrimitive->evaluationResult.getValues();
                    for (const auto& evaluatedValueEntry : OsmAnd::rangeOf(values))
                    {
                        const auto valueDefinitionId = evaluatedValueEntry.key();
                        const auto value = evaluatedValueEntry.value();

                        const auto valueDefinition = mapStyle->getValueDefinitionById(valueDefinitionId);

                        output << xT("\t\t") << QStringToStlString(valueDefinition->name) << xT(" = ");
                        if (valueDefinition->dataType == OsmAnd::MapStyleValueDataType::Color)
                            output << QStringToStlString(OsmAnd::ColorARGB(value.toUInt()).toString());
                        else
                            output << QStringToStlString(value.toString());
                        output << std::endl;
                    }

                    polylinePrimitiveIndex++;
                }
            }

            if (!primitivisedGroup->polygons.isEmpty())
            {
                output << primitivisedGroup->polygons.size() << xT(" polygon(s):") << std::endl;

                unsigned int polygonPrimitiveIndex = 0u;
                for (const auto& polygonPrimitive : OsmAnd::constOf(primitivisedGroup->polygons))
                {
                    output << xT("\tPolygon #") << polygonPrimitiveIndex << std::endl;
                    QString ruleTag;
                    QString ruleValue;
                    const auto typeRuleResolved = mapObject->obtainTagValueByTypeRuleIndex(
                        polygonPrimitive->typeRuleIdIndex,
                        ruleTag,
                        ruleValue);
                    if (typeRuleResolved)
                    {
                        output
                            << xT("\t\tTag/value: ")
                            << QStringToStlString(ruleTag)
                            << xT(" = ")
                            << QStringToStlString(ruleValue)
                            << std::endl;
                    }
                    else
                    {
                        output
                            << xT("\t\tTag/value: ")
                            << polygonPrimitive->typeRuleIdIndex
                            << xT(" (failed to resolve)")
                            << std::endl;
                    }
                    output << xT("\t\tZ order: ") << polygonPrimitive->zOrder << std::endl;
                    output << xT("\t\tArea*2: ") << polygonPrimitive->doubledArea << std::endl;
                    const auto& values = polygonPrimitive->evaluationResult.getValues();
                    for (const auto& evaluatedValueEntry : OsmAnd::rangeOf(values))
                    {
                        const auto valueDefinitionId = evaluatedValueEntry.key();
                        const auto value = evaluatedValueEntry.value();

                        const auto valueDefinition = mapStyle->getValueDefinitionById(valueDefinitionId);

                        output << xT("\t\t") << QStringToStlString(valueDefinition->name) << xT(" = ");
                        if (valueDefinition->dataType == OsmAnd::MapStyleValueDataType::Color)
                            output << QStringToStlString(OsmAnd::ColorARGB(value.toUInt()).toString());
                        else
                            output << QStringToStlString(value.toString());
                        output << std::endl;
                    }

                    polygonPrimitiveIndex++;
                }
            }

            const auto itSymbolsGroup = primitivisedData->symbolsGroups.constFind(mapObject);
            if (itSymbolsGroup != primitivisedData->symbolsGroups.cend())
            {
                const auto& symbolsGroup = *itSymbolsGroup;

                output << symbolsGroup->symbols.size() << xT(" symbol(s):") << std::endl;

                unsigned int symbolIndex = 0u;
                for (const auto& symbol : OsmAnd::constOf(symbolsGroup->symbols))
                {
                    const auto textSymbol = std::dynamic_pointer_cast<const OsmAnd::MapPrimitiviser::TextSymbol>(symbol);
                    const auto iconSymbol = std::dynamic_pointer_cast<const OsmAnd::MapPrimitiviser::IconSymbol>(symbol);

                    output << xT("\tSymbol #") << symbolIndex;
                    if (textSymbol)
                        output << xT(" (text)");
                    else if (iconSymbol)
                        output << xT(" (icon)");
                    output << std::endl;

                    auto primitiveIndex = -1;
                    if (primitiveIndex == -1)
                    {
                        primitiveIndex = primitivisedGroup->points.indexOf(symbol->primitive);
                        if (primitiveIndex >= 0)
                            output << xT("\t\tPrimitive: Point #") << primitiveIndex << std::endl;
                    }
                    if (primitiveIndex == -1)
                    {
                        primitiveIndex = primitivisedGroup->polylines.indexOf(symbol->primitive);
                        if (primitiveIndex >= 0)
                            output << xT("\t\tPrimitive: Polyline #") << primitiveIndex << std::endl;
                    }
                    if (primitiveIndex == -1)
                    {
                        primitiveIndex = primitivisedGroup->polygons.indexOf(symbol->primitive);
                        if (primitiveIndex >= 0)
                            output << xT("\t\tPrimitive: Polygon #") << primitiveIndex << std::endl;
                    }

                    output << xT("\t\tPosition31: ") << symbol->location31.x << xT("x") << symbol->location31.y << std::endl;
                    output << xT("\t\tOrder: ") << symbol->order << std::endl;
                    output << xT("\t\tDraw along path: ") << (symbol->drawAlongPath ? xT("yes") : xT("no")) << std::endl;
                    output
                        << xT("\t\tIntersects with: ")
                        << QStringToStlString(QStringList(symbol->intersectsWith.toList()).join(QLatin1String(", ")))
                        << std::endl;
                    output << xT("\t\tMinDistance: ") << symbol->minDistance << std::endl;
                    if (textSymbol)
                    {
                        output << xT("\t\tText: ") << QStringToStlString(textSymbol->value) << std::endl;
                        output << xT("\t\tLanguage: ");
                        switch (textSymbol->languageId)
                        {
                            case OsmAnd::LanguageId::Invariant:
                                output << xT("invariant");
                                break;
                            case OsmAnd::LanguageId::Native:
                                output << xT("native");
                                break;
                            case OsmAnd::LanguageId::Localized:
                                output << xT("localized");
                                break;
                        }
                        output << std::endl;
                        output << xT("\t\tDraw text on path: ") << (textSymbol->drawOnPath ? xT("yes") : xT("no")) << std::endl;
                        output << xT("\t\tText vertical offset: ") << textSymbol->verticalOffset << std::endl;
                        output << xT("\t\tText color: ") << QStringToStlString(textSymbol->color.toString()) << std::endl;
                        output << xT("\t\tText size: ") << textSymbol->size << std::endl;
                        output << xT("\t\tText shadow radius: ") << textSymbol->shadowRadius << std::endl;
                        output
                            << xT("\t\tText shadow color: ")
                            << QStringToStlString(textSymbol->shadowColor.toString())
                            << std::endl;
                        output << xT("\t\tText wrap width: ") << textSymbol->wrapWidth << std::endl;
                        output << xT("\t\tText is bold: ") << (textSymbol->isBold ? xT("yes") : xT("no")) << std::endl;
                        output << xT("\t\tText is italic: ") << (textSymbol->isItalic ? xT("yes") : xT("no")) << std::endl;
                        output
                            << xT("\t\tShield resource name: ")
                            << QStringToStlString(textSymbol->shieldResourceName)
                            << std::endl;
                    }
                    else if (iconSymbol)
                    {
                        output << xT("\t\tIcon resource name: ") << QStringToStlString(iconSymbol->resourceName) << std::endl;
                        for (const auto& overlayResoucreName : iconSymbol->overlayResourceNames)
                            output << xT("\t\tOverlay resource name: ") << QStringToStlString(overlayResoucreName) << std::endl;
                        output
                            << xT("\t\tShield resource name: ")
                            << QStringToStlString(iconSymbol->shieldResourceName)
                            << std::endl;
                        output << xT("\t\tIntersection size: ") << iconSymbol->intersectionSize << std::endl;
                    }

                    symbolIndex++;
                }
            }
        }

        if (configuration.metrics)
        {
            output
                << xT("Metrics:\n")
                << QStringToStlString(metrics.toString(false, QLatin1String("\t")))
                << std::endl;
        }

        break;
    }

    return success;
}
Ejemplo n.º 8
0
void rasterize(std::ostream &output, const OsmAnd::EyePiece::Configuration& cfg)
#endif
{
    // Obtain and configure rasterization style context
    OsmAnd::MapStyles stylesCollection;
    for(auto itStyleFile = cfg.styleFiles.begin(); itStyleFile != cfg.styleFiles.end(); ++itStyleFile)
    {
        const auto& styleFile = *itStyleFile;

        if(!stylesCollection.registerStyle(styleFile.absoluteFilePath()))
            output << xT("Failed to parse metadata of '") << QStringToStlString(styleFile.fileName()) << xT("' or duplicate style") << std::endl;
    }
    std::shared_ptr<const OsmAnd::MapStyle> style;
    if(!stylesCollection.obtainStyle(cfg.styleName, style))
    {
        output << xT("Failed to resolve style '") << QStringToStlString(cfg.styleName) << xT("'") << std::endl;
        return;
    }
    if(cfg.dumpRules)
        style->dump();
    
    OsmAnd::ObfsCollection obfsCollection;
    obfsCollection.watchDirectory(cfg.obfsDir);

    // Collect all map objects (this should be replaced by something like RasterizerViewport/RasterizerContext)
    QList< std::shared_ptr<const OsmAnd::Model::MapObject> > mapObjects;
    OsmAnd::AreaI bbox31(
            OsmAnd::Utilities::get31TileNumberY(cfg.bbox.top),
            OsmAnd::Utilities::get31TileNumberX(cfg.bbox.left),
            OsmAnd::Utilities::get31TileNumberY(cfg.bbox.bottom),
            OsmAnd::Utilities::get31TileNumberX(cfg.bbox.right)
        );
    const auto& obfDI = obfsCollection.obtainDataInterface();
    OsmAnd::MapFoundationType mapFoundation;
    obfDI->obtainMapObjects(&mapObjects, &mapFoundation, bbox31, cfg.zoom, nullptr);
    bool basemapAvailable;
    obfDI->obtainBasemapPresenceFlag(basemapAvailable);
    
    // Calculate output size in pixels
    const auto tileWidth = OsmAnd::Utilities::getTileNumberX(cfg.zoom, cfg.bbox.right) - OsmAnd::Utilities::getTileNumberX(cfg.zoom, cfg.bbox.left);
    const auto tileHeight = OsmAnd::Utilities::getTileNumberY(cfg.zoom, cfg.bbox.bottom) - OsmAnd::Utilities::getTileNumberY(cfg.zoom, cfg.bbox.top);
    const auto pixelWidth = qCeil(tileWidth * cfg.tileSide);
    const auto pixelHeight = qCeil(tileHeight * cfg.tileSide);
    output << xT("Will rasterize ") << mapObjects.count() << xT(" objects onto ") << pixelWidth << xT("x") << pixelHeight << xT(" bitmap") << std::endl;

    // Allocate render target
    SkBitmap renderSurface;
    renderSurface.setConfig(cfg.is32bit ? SkBitmap::kARGB_8888_Config : SkBitmap::kRGB_565_Config, pixelWidth, pixelHeight);
    if(!renderSurface.allocPixels())
    {
        output << xT("Failed to allocated render target ") << pixelWidth << xT("x") << pixelHeight;
        return;
    }
    SkDevice renderTarget(renderSurface);

    // Create render canvas
    SkCanvas canvas(&renderTarget);

    // Perform actual rendering
    OsmAnd::RasterizerEnvironment rasterizerEnv(style, basemapAvailable);
    OsmAnd::RasterizerContext rasterizerContext;
    OsmAnd::Rasterizer::prepareContext(rasterizerEnv, rasterizerContext, bbox31, cfg.zoom, cfg.tileSide, cfg.densityFactor, mapFoundation, mapObjects, OsmAnd::PointF(), nullptr);
    if(cfg.drawMap)
        OsmAnd::Rasterizer::rasterizeMap(rasterizerEnv, rasterizerContext, true, canvas, nullptr);
    /*if(cfg.drawText)
        OsmAnd::Rasterizer::rasterizeText(rasterizerContext, !cfg.drawMap, canvas, nullptr);*/

    // Save rendered area
    if(!cfg.output.isEmpty())
    {
        std::unique_ptr<SkImageEncoder> encoder(CreatePNGImageEncoder());
        std::unique_ptr<SkImageEncoder> outputStream(CreatePNGImageEncoder());
        encoder->encodeFile(cfg.output.toLocal8Bit(), renderSurface, 100);
    }

    return;
}
Ejemplo n.º 9
0
bool OsmAndTools::Styler::evaluate(bool& outRejected, QHash<QString, QString>& outEvaluatedValues, std::ostream& output)
#endif
{
    bool success = true;
    for (;;)
    {
        // Find style
        if (configuration.verbose)
            output << xT("Resolving style '") << QStringToStlString(configuration.styleName) << xT("'...") << std::endl;
        const auto mapStyle = configuration.stylesCollection->getResolvedStyleByName(configuration.styleName);
        if (!mapStyle)
        {
            if (configuration.verbose)
            {
                output << "Failed to resolve style '" << QStringToStlString(configuration.styleName) << "' from collection:" << std::endl;
                for (const auto& style : configuration.stylesCollection->getCollection())
                {
                    if (style->isMetadataLoaded())
                    {
                        if (style->isStandalone())
                            output << "\t" << QStringToStlString(style->name) << std::endl;
                        else
                            output << "\t" << QStringToStlString(style->name) << "::" << QStringToStlString(style->parentName) << std::endl;
                    }
                    else
                        output << "\t[missing metadata]" << std::endl;
                }
            }
            else
            {
                output << "Failed to resolve style '" << QStringToStlString(configuration.styleName) << "' from collection:" << std::endl;
            }

            success = false;
            break;
        }

        // Load all map objects
        QList< std::shared_ptr<const OsmAnd::Model::BinaryMapObject> > mapObjects;
        const auto mapObjectsFilterById =
            [this]
            (const std::shared_ptr<const OsmAnd::ObfMapSectionInfo>& section,
            const uint64_t mapObjectId,
            const OsmAnd::AreaI& bbox,
            const OsmAnd::ZoomLevel firstZoomLevel,
            const OsmAnd::ZoomLevel lasttZoomLevel) -> bool
            {
                return configuration.mapObjectsIds.contains(mapObjectId);
            };
        if (configuration.verbose)
            output << xT("Going to load ") << configuration.mapObjectsIds.size() << xT(" map objects...") << std::endl;
        const auto obfDataInterface = configuration.obfsCollection->obtainDataInterface();
        success = obfDataInterface->loadMapObjects(
            &mapObjects,
            nullptr,
            configuration.zoom,
            nullptr,
            mapObjectsFilterById,
            nullptr,
            nullptr,
            nullptr,
            nullptr);
        if (!success)
            break;


        //// Prepare all resources for renderer
        //if (configuration.verbose)
        //{
        //    output
        //        << xT("Initializing map presentation environment with display density ")
        //        << configuration.displayDensityFactor
        //        << xT(" and locale '")
        //        << QStringToStlString(configuration.locale)
        //        << xT("'...") << std::endl;
        //}
        //const std::shared_ptr<OsmAnd::MapPresentationEnvironment> mapPresentationEnvironment(new OsmAnd::MapPresentationEnvironment(
        //    mapStyle,
        //    configuration.displayDensityFactor,
        //    configuration.locale));

        //if (configuration.verbose)
        //    output << xT("Applying extra style settings to map presentation environment...") << std::endl;
        //mapPresentationEnvironment->setSettings(configuration.styleSettings);

        break;
    }

    return success;
}