GVKun编程网logo

在不更改 PATH 的情况下下载 OpenStreetMap 图像

13

如果您对在不更改PATH的情况下下载OpenStreetMap图像感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解在不更改PATH的情况下下载OpenStreetMap图像的各种细节,此外还有关

如果您对在不更改 PATH 的情况下下载 OpenStreetMap 图像感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解在不更改 PATH 的情况下下载 OpenStreetMap 图像的各种细节,此外还有关于4.OpenStreetMap Data Model、android-更改位置,并在openstreetmap中单击以放置标记、angular – 如何在不更改NGX Translate中的当前语言的情况下检索已翻译的值?、c – 在不更改接口的情况下向对象添加功能的实用技巧。

本文目录一览:

在不更改 PATH 的情况下下载 OpenStreetMap 图像

在不更改 PATH 的情况下下载 OpenStreetMap 图像

如何解决在不更改 PATH 的情况下下载 OpenStreetMap 图像?

我使用的是 Windows 计算机,我希望能够从 OpenStreetMap 中提取 jpg 格式的地图。但是,由于它是一台工作计算机,因此我无法将 geckodriver/chromedriver 添加到其路径中。因此,我无法使用可以在此处找到的基于 Selenium 的方法。

我该如何解决这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

4.OpenStreetMap Data Model

4.OpenStreetMap Data Model

http://www.jianshu.com/p/e84814b3b429


OpenStreetMap 是一个开源项目,旨在为用户免费创建生成世界各的地图。



OpenStreetMap 数据以 OSM XML 文件(.osm 文件)的形式出现。

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.0.2">
 <bounds minlat="54.0889580" minlon="12.2487570" maxlat="54.0913900" maxlon="12.2524800"/>
 <node id="298884269" lat="54.0901746" lon="12.2482632" user="SvenHRO" uid="46882" visible="true" version="1" changeset="676636" timestamp="2008-09-21T21:37:45Z"/>
 <node id="261728686" lat="54.0906309" lon="12.2441924" user="PikoWinter" uid="36744" visible="true" version="1" changeset="323878" timestamp="2008-05-03T13:39:23Z"/>
 <node id="1831881213" version="1" changeset="12370172" lat="54.0900666" lon="12.2539381" user="lafkor" uid="75625" visible="true" timestamp="2012-07-20T09:43:19Z">
  <tag k="name" v="Neu Broderstorf"/>
  <tag k="traffic_sign" v="city_limit"/>
 </node>
 ...
 <node id="298884272" lat="54.0901447" lon="12.2516513" user="SvenHRO" uid="46882" visible="true" version="1" changeset="676636" timestamp="2008-09-21T21:37:45Z"/>
 <way id="26659127" user="Masch" uid="55988" visible="true" version="5" changeset="4142606" timestamp="2010-03-16T11:47:08Z">
  <nd ref="292403538"/>
  <nd ref="298884289"/>
  ...
  <nd ref="261728686"/>
  <tag k="highway" v="unclassified"/>
  <tag k="name" v="Pastower Straße"/>
 </way>
 <relation id="56688" user="kmvar" uid="56190" visible="true" version="28" changeset="6947637" timestamp="2011-01-12T14:23:49Z">
  <member type="node" ref="294942404" role=""/>
  ...
  <member type="node" ref="364933006" role=""/>
  <member type="way" ref="4579143" role=""/>
  ...
  <member type="node" ref="249673494" role=""/>
  <tag k="name" v="Küstenbus Linie 123"/>
  <tag k="network" v="VVW"/>
  <tag k="operator" v="Regionalverkehr Küste"/>
  <tag k="ref" v="123"/>
  <tag k="route" v="bus"/>
  <tag k="type" v="route"/>
 </relation>
 ...
</osm>

XML 文件包含几个元素类型,这些元素类型对您要编写的代码很重要:节点、方式和关系。

节点

节点是 OpenStreetMap 数据模型中最基本的元素之一。每个节点指示一个具有标识符 id、纬度 lat 和经度 lon 的点。node 元素中还有其他与此项目无关的 XML 属性,例如将节点添加到数据集中时的用户 id 和时间戳。另外,一个节点可以有多个标签来提供附加信息。

道路

道路是表示地图中某个要素的有序节点列表。这个特征可以是道路,公园的边界,或者地图上的其他特征。每种道路至少有一个标记,该标记表示关于该道路的一些信息,并且每种道路还属于至少一个关系,如下所述。

关系

关系是记录其他数据元素之间关系的数据结构。来自 OpenStreetMap wiki 的示例包括:

  • 一种路线关系,列出形成主要公路、自行车道或公共汽车路线的方式。

  • 描述有孔区域的多多边形,该区域的外边界和内边界由两种方式给出。

IO2D 项目

https://github.com/cpp-io2d/P0267_RefImpl/tree/master/P0267_RefImpl/Samples/maps

代码结构

该项目的启动代码可在此处找到。
在仓库中,应该看到以下五个目录:

  • cmake

该目录包含一些 CMakeLists.txt 文件,这些文件是项目查找必要的库所必需的。无需为此项目使用此目录。

  • instructions

该目录包含一组练习的标记指令文件。同样,不需要在这里直接使用文件,但是在处理项目时,每组指令将显示在终端工作区中,以进行适当的练习。

  • src

该项目的源代码包含在此处

  • test

此目录包含使用 Google Test 框架实现的各种练习的单元测试。在开发代码时,查看此目录中的相关测试以查看预期的答案和相应的代码可能会有所帮助。如果代码未通过测试,则控制台将告诉哪个文件包含失败的测试。

  • thirdparty

此目录包含此项目已包含的第三方库。无需直接使用此代码

src


main.cpp 控制程序的流程,完成四个主要任务:

  • OSM 数据被读入程序。
  • 创建一个 RouteModel 对象,将 OSM 数据存储在可用的数据结构中。
  • RoutePlanner 对象是使用 RouteModel 创建的。此计划器最终将对模型数据执行 A * 搜索,并将搜索结果存储在 RouteModel 中。
  • RouteModel 数据是使用 IO2D 库呈现的。

model.h and model.cpp

这些文件来自 IO2D 示例代码。它们用于定义读取和存储 OSM 数据的数据结构和方法。OSM 数据存储在一个模型类中,该模型类包含节点、方法、道路和其他 OSM 对象的嵌套结构

RouteModel 类

Model 当前代码中存在的类并不包含执行 A * 搜索所需的所有数据或方法,因此我们将用一个 RouteModel 类扩展该类。

class RouteModel : public Model {

  public:
    //RouteModel 的 Node 也是继承的
    class Node : public Model::Node {
      public:
        // Add public Node variables and methods here.

        Node(){
            std::cout<<"RouteModel Init"<<"\n";
        }
        //因为有init 一个pointer parent_model, 因此一定要写成 initial list 的方式
        Node(int idx, RouteModel * search_model, Model::Node node) : Model::Node(node), parent_model(search_model), index(idx) {
            std::cout<<"RouteModel Init"<<"\n";
        }

      private:
        // Add private Node variables and methods here.
        int index;
        RouteModel * parent_model = nullptr;

    };

    // Add public RouteModel variables and methods here.
    RouteModel(const std::vector<std::byte> &xml);

    //这个 path 存结果
    std::vector<Node> path; // This variable will eventually store the path that is found by the A* search.

    //Task2:Add a public "getter" method SNodes. This method should return a reference to the vector of Nodes stored as m_Nodes.
    std::vector<Node>& SNodes(){
        return m_Nodes;
    }

  private:
    // Add private RouteModel variables and methods here.

    //Taks1:Add a private vector of Node objects named m_Nodes. This will store all of the nodes from the Open Street Map data.
    //m_Nodes 存所有open street map 的 data, 之后给Astar 用
    std::vector<Node> m_Nodes;
};

Node 类

Model::Node 当前代码中存在的类不包含执行 A * 搜索所需的所有数据。为了执行搜索,最理想的是每个节点至少包含以下信息:

  • 节点的 g 值。
  • 节点的 h 值。
  • 指示是否已访问该节点的布尔值。
  • 指向节点父节点的指针。
#include <limits>
#include <cmath>
#include <unordered_map>
#include "model.h"
#include <iostream>
//因為Model 裡面只有一個Node 的資訊, 要能做A*, 你需要所有的Node,
//因此我們繼承Model 來造一個RouteModel 準備收集所有要用的Node 給A*

/*
Task:
In route_model.h:

Add a private vector of Node objects named m_Nodes. This will store all of the nodes from the Open Street Map data.
Add a public "getter" method SNodes. This method should return a reference to the vector of Nodes stored as m_Nodes.



*/
class RouteModel : public Model {

  public:

    //RouteModel 的 Node 也是繼承來的
    class Node : public Model::Node {
        /*
        The Node Class
        The Model::Node class that exists in the current code doesn''t contain all the data that would be needed to perfom an A* search.
        In order to perform a search, it would be ideal for each node to contain at least the following information:

            1.The g-value for the node.
            2.The h-value for the node.
            3.A boolean to indicate if the node has been visited.
            4.A pointer to the node''s parent.

        In this exercise, you will fill out the RouteModel::Node class in route_model.h, which will extend the Model::Node class
        so that the data above, along with a few other useful variables, can be included with each node.
        Note that the RouteModel::Node class already has the following private variables:

            1.An int index.
            2.A pointer to a RouteModel object named parent_model. This variable is important,
                as it allows each node to access data stored in the parent model that the node belongs to.

        To complete this exercise:
        Add the following public variables to the RouteModel::Node class:
            1.A Node pointer parent, which is initialized to a nullptr.
            2.A float h_value, which is initialized to the maximum possible: std::numeric_limits<float>::max().
            3.A float g_value, which is initialized to 0.0.
            4.A bool visited, which is initialized to false.
            5.A vector of Node pointers named neighbors.

        Pass testing:
            [==========] Running 2 tests from 1 test case.
            [----------] Global test environment set-up.
            [----------] 2 tests from RouteModelTest
            [ RUN      ] RouteModelTest.RouteModelData
            [       OK ] RouteModelTest.RouteModelData (67 ms)
            [ RUN      ] RouteModelTest.RouteModelNode
            RouteModel Init
            RouteModel Init
            [       OK ] RouteModelTest.RouteModelNode (61 ms)
            [----------] 2 tests from RouteModelTest (128 ms total)

            [----------] Global test environment tear-down
            [==========] 2 tests from 1 test case ran. (128 ms total)
            [  PASSED  ] 2 tests.


        */
      public:

        //Add
        Node * parent = nullptr;
        float h_value = std::numeric_limits<float>::max();
        float g_value = 0.0;
        bool visited = false;
        std::vector<Node*> neighbors;

        // Add public Node variables and methods here.
        Node(){
            std::cout<<"RouteModel Init"<<"\n";
        }
        //因為有init 一個pointer parent_model, 因此一定要寫成 initial list 的方式
        Node(int idx, RouteModel * search_model, Model::Node node) : Model::Node(node), parent_model(search_model), index(idx) {
            std::cout<<"RouteModel Init"<<"\n";
        }




      private:
        // Add private Node variables and methods here.

        //An int index.
        int index;
        //A pointer to a RouteModel object named parent_model. This variable is important,
        //as it allows each node to access data stored in the parent model that the node belongs to.
        RouteModel * parent_model = nullptr;

    };

    // Add public RouteModel variables and methods here.
    RouteModel(const std::vector<std::byte> &xml);

    //這個 path 最後會存著結果
    std::vector<Node> path; // This variable will eventually store the path that is found by the A* search.

    //Task2:Add a public "getter" method SNodes. This method should return a reference to the vector of Nodes stored as m_Nodes.
    std::vector<Node>& SNodes(){
        return m_Nodes;
    }

  private:
    // Add private RouteModel variables and methods here.

    //Taks1:Add a private vector of Node objects named m_Nodes. This will store all of the nodes from the Open Street Map data.
    //這個m_Nodes 會拿來存所有open street map 的 data, 之後給Astar 用
    std::vector<Node> m_Nodes;
};

this 指针

IncrementDistance () 方法隐式引用当前 Car 实例的 distance 属性:

// The Car class
class Car {
  public:
    // Method to print data.
    void PrintCarData() {
        cout << "The distance that the " << color << " car " << number << " has traveled is: " << distance << "\n";
    }

    // Method to increment the distance travelled.
    void IncrementDistance() {
        distance++;
    }

    // Class/object attributes
    string color;
    int distance = 0;
    int number;
};

可以通过使用 this 指向当前类实例的指针在 C ++ 中使其明确。使用 this 有时会有助于增加透明度,以更加复杂的代码:

// The Car class
class Car {
  public:
    // Method to print data.
    void PrintCarData() {
        cout << "The distance that the " << this->color << " car " << this->number << " has traveled is: " << this->distance << "\n";
    }

    // Method to increment the distance travelled.
    void IncrementDistance() {
        this->distance++;
    }

    // Class/object attributes
    string color;
    int distance = 0;
    int number;
};
创建 RouteModel 节点

RouteModel 类,并且已经完成了 RouteModel::Node 嵌套类,可以创建 RouteModel 节点。
当 RouteModel 调用构造函数,它调用 Model 与开放街道地图数据的构造。发生这种情况时,Model:Node 将创建对象的集合。但是,为了执行 A * 搜索,将需要使用 RouteModel::Node 对象。
修改 RouteModel 构造函数。构造函数将使用 Model:Node 对象向量创建新 RouteModel::Node 对象。RouteModel::Node 然后,这些对象将存储在的 m_Nodes 向量中

  • 在 RouteModel 构造函数中 route_model.cpp,编写一个带计数器的 for 循环,以循环遍历由 Model::Node 给出的 s 的向量 this->Nodes ()。
  • 对于 Model 循环中的每个节点,使用 RouteModel::Node 构造函数创建一个新节点,并将新节点推到的后面 m_Nodes。
  • 使用 RouteModel::Node 接受三个参数的构造函数:Node(int idx, RouteModel * search_model, Model::Node node)



android-更改位置,并在openstreetmap中单击以放置标记

android-更改位置,并在openstreetmap中单击以放置标记

我是Open Street Map地图的新手.我想将标记放置在我点击过的地图上.我也想删除以前的标记.请帮我.
提前致谢.这是我的代码

Overlay touchOverlay = new Overlay(this) {
    ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay = null;

    @Override
    protected void draw(Canvas arg0, MapView arg1, boolean arg2) {

    }

    @Override
    public boolean onSingleTapConfirmed(final MotionEvent e,
            final MapView mapView) {
        Projection proj = mapView.getProjection();
        GeoPoint loc = (GeoPoint) proj.fromPixels((int) e.getX(),
                (int) e.getY());
        String longitude = Double
                .toString(((double) loc.getLongitudeE6()) / 1000000);
        String latitude = Double
                .toString(((double) loc.getLatitudeE6()) / 1000000);
        ArrayList<OverlayItem> overlayArray = new ArrayList<OverlayItem>();
        OverlayItem mapItem = new OverlayItem("", "", new GeoPoint(
                (((double) loc.getLatitudeE6()) / 1000000),
                (((double) loc.getLongitudeE6()) / 1000000)));
        Drawable marker = null;
        mapItem.setMarker(marker);
        overlayArray.add(mapItem);
        if (anotherItemizedIconOverlay == null) {
            anotherItemizedIconOverlay = new ItemizedIconOverlay<OverlayItem>(
                    getApplicationContext(), overlayArray, null);
            mapView.getoverlays().add(anotherItemizedIconOverlay);
            mapView.invalidate();
        } else {
            mapView.getoverlays().remove(anotherItemizedIconOverlay);
            mapView.invalidate();
            anotherItemizedIconOverlay = new ItemizedIconOverlay<OverlayItem>(
                    getApplicationContext(), overlayArray, null);
            mapView.getoverlays().add(anotherItemizedIconOverlay);
        }

        return true;
    }
};

解决方法:

终于我得到了这个问题的解决方案.这是我的答案.

@Override
    public boolean onSingleTapConfirmed(MotionEvent e, MapView mapView) {

        Projection proj = mapView.getProjection();
        p = (GeoPoint) proj.fromPixels((int) e.getX(), (int) e.getY());
         proj = mapView.getProjection();
         loc = (GeoPoint) proj.fromPixels((int) e.getX(), (int) e.getY());
         String longitude = Double
         .toString(((double) loc.getLongitudeE6()) / 1000000);
         String latitude = Double
         .toString(((double) loc.getLatitudeE6()) / 1000000);
         Toast toast = Toast.makeText(getApplicationContext(),
         "Longitude: "
         + longitude + " Latitude: " + latitude, Toast.LENGTH_SHORT);
         toast.show();
        return true;
    }

private void addLocation(double lat, double lng) {
    // ---Add a location marker---

    p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));

    Drawable marker = getResources().getDrawable(
            android.R.drawable.star_big_on);

    int markerWidth = marker.getIntrinsicWidth();
    int markerHeight = marker.getIntrinsicHeight();

    marker.setBounds(0, markerHeight, markerWidth, 0);

    ResourceProxy resourceProxy = new DefaultResourceProxyImpl(
            getApplicationContext());

    myitemizedoverlay = new Myitemizedoverlay(marker, resourceProxy);

    List<Overlay> listofOverlays = mapView.getoverlays();
    listofOverlays.clear();
    listofOverlays.add(myitemizedoverlay);

    mapView.invalidate();
}

angular – 如何在不更改NGX Translate中的当前语言的情况下检索已翻译的值?

angular – 如何在不更改NGX Translate中的当前语言的情况下检索已翻译的值?

我的问题是关于ngx翻译angular2.我的项目支持2种语言:英语和阿拉伯语,因此有en.json和ar.json文件.下面的代码将根据我当前的语言给出翻译的密钥值

this.translate.get('key').subscribe((msg: string) => {
    console.log(msg);
  }

问题:如何将特定语言作为输入传递并获取该特定语言的翻译?例如,我当前的语言是英语(并且不想更改当前语言),但是从ts文件中,我需要从ar.json检索键的阿拉伯语翻译而不更改当前语言.

解决方法

我建议不要将ngx翻译用于此特定要求. ngx translate的目的是将其绑定到视图并加载当前所选语言的JSON.另一种方法是简单地设置另一个服务,它通过传递一个字符串来加载你需要的json文件,例如’en’代表英语,’ar’代表阿拉伯语.然后,您可以根据需要在ts中使用该JSON.

c – 在不更改接口的情况下向对象添加功能

c – 在不更改接口的情况下向对象添加功能

我有一个对象作为接口的引用/指针.如果存在该方法,我想在具体对象上调用一个方法,而不需要更改接口,破坏封装或编写任何可怕的黑客攻击.怎么做到呢?

这是一个例子.

我有一个界面:

class IChatty{public:    virtual ~IChatty() {};    virtual std::string Speak() const = 0;};

并且这个界面的多个具体实现:

class SimpleChatty : public IChatty{public:    ~SimpleChatty() {};    virtual std::string Speak() const override    {        return "hello";    }};class SuperChatty : public IChatty{public:    void AddToDictionary(const std::string& word)    {        words_.insert(word);    }    virtual std::string Speak() const override    {        std::string ret;        for(auto w = words_.begin(); w != words_.end(); ++w )        {            ret += *w;            ret += " ";        }        return ret;    }private:    std::set<std::string> words_;};

SuperChatty :: AddToDictionary方法不存在于抽象的IChatty接口中,尽管它可以包含在另一个新接口中.

在现实世界中,这些对象是通过工厂构建的,它们本身是抽象接口的具体实例.然而,就我们的目的而言,这与手头的问题是正交的:

int main(){    IChatty* chatty = new SuperChatty;    chatty->AddToDictionary("foo");    std::cout << chatty->Speak() << std::endl;}

由于AddToDictionary不是IChatty接口的一部分(并且不能成为其中的一部分),我可以称之为.

如何在不破坏封装,写一些可怕的黑客或采取任何其他设计快捷方式的情况下在chatty指针上调用AddToDictionary?

注意:在现实世界中,字典是SuperChatty对象本身的一部分,不能与它分开.

注2:我不想向下倾斜到具体类型.

解决方法

将字典作为SuperChatty可以更新和引用的对象:
class Dictionary {public:    void add(const std::string& word);    const std::set<std::string>>& words() const;    //..};class SuperChatty : public IChatty{public:    SuperChatty(Dictionary& dictionary) :    dictionary(dictionary) {    }    virtual std::string Speak() const override    {        auto words = dictionary.words();        ostringstream oss;        copy(words.begin(),words.end(),ostream_iterator<string>(oss," "));        return oss.str();    }};

用法:

int main(){       Dictionary dictionary;    IChatty* chatty = new SuperChatty(dictionary);    dictionary.add("foo");    std::cout << chatty->Speak() << std::endl;}

编辑

好的,问题改变了.

如果你正确地做到这一点,你需要将自己与糟糕的底层系统隔离开来:

struct Dictionary {    virtual ~Dictionary () {}    virtual void add(const std::string& word) = 0;};struct Instrumenter {    virtual ~Instrumenter () {}    virtual void addDictionary(Dictionary& dictionary) = 0;};struct Chatter {    virtual ~Chatter() {}    virtual string speak() const = 0;    virtual void instrument(Instrumenter& instrumenter) = 0;};

这些实现如下:

class BasicChatter : public Chatter {    virtual string speak() const {        return chatty.Speak();    }    virtual void instrument(Instrumenter& instrumenter) {        // do nothing    }private:    SimpleChatty chatty;};class SuperChatter : public Chatter {    SuperChatter () : dictionary(chatty);    virtual void instrument(Instrumenter& instrumenter) {        instrumenter.addDictionary(dictionary);    }    virtual string speak() const {        return chatty.Speak();    }private:    SuperChatty chatty;    DictionaryImpl dictionary;};

今天关于在不更改 PATH 的情况下下载 OpenStreetMap 图像的分享就到这里,希望大家有所收获,若想了解更多关于4.OpenStreetMap Data Model、android-更改位置,并在openstreetmap中单击以放置标记、angular – 如何在不更改NGX Translate中的当前语言的情况下检索已翻译的值?、c – 在不更改接口的情况下向对象添加功能等相关知识,可以在本站进行查询。

本文标签: