GVKun编程网logo

使用OpenStreetMap和OSMNX检索covid弹出式发布周期

22

如果您想了解使用OpenStreetMap和OSMNX检索covid弹出式发布周期的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析4.OpenStreetMapDataModel、androi

如果您想了解使用OpenStreetMap和OSMNX检索covid弹出式发布周期的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析4.OpenStreetMap Data Model、android – 点击地图获取坐标(openstreetmaps)、android-免费的离线地图提供程序(而非OpenStreetMap)、android-更改位置,并在openstreetmap中单击以放置标记的各个方面,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

使用OpenStreetMap和OSMNX检索covid弹出式发布周期

使用OpenStreetMap和OSMNX检索covid弹出式发布周期

意大利的OSM社区已开始使用许多管理部门创建的“紧急”或“弹出式”自行车道来更新OSM,以确保社会隔离,同时减少公共交通的使用。

这些自行车道通常只是涂上油漆,因此在OSM中这样标记它们(例如,街道右侧):

高速公路=辅助自行车道=左侧:share_busway,右侧:车道

我想使用OSMNX和custom_filter检索所有这些循环。我尝试了以下方法:

cf = '["cicleway[left side]"~"share_busway"]'

G = ox.graph_from_bbox(44.493251,44.488272,11.330840,11.301927,custom_filter=cf,simplify=True,truncate_by_edge=False)

但我得到回应:

osmnx.core.EmptyOverpassResponse: There are no data elements in the response JSON objects

我显然缺少如何正确查询的信息,但我不知道该怎么做。

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 – 点击地图获取坐标(openstreetmaps)

android – 点击地图获取坐标(openstreetmaps)

如何通过在开放的街道地图中点击它来获取点的坐标?

尝试:

public void onClick(View v) {
    Projection proj = mapView.getProjection();
    IGeoPoint p = proj.fromPixels(v.getX(),v.getY());
    System.out.println("x: "+ v.getX() + " y: "+ v.getY());
}

干杯,
Thanasio

解决方法

使用dispatchTouchEvent()方法.它的工作原理是因为MapActivity继承了dispatchTouch事件,而不是Activity类的OnTouchEvent.
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    int actionType = ev.getAction();
    switch (actionType) {
    case MotionEvent.ACTION_UP:
            Projection proj = mapView.getProjection();
            GeoPoint loc = proj.fromPixels((int)ev.getX(),(int)ev.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_LONG);
            toast.show();

    }
return super.dispatchTouchEvent(ev);
}

android-免费的离线地图提供程序(而非OpenStreetMap)

android-免费的离线地图提供程序(而非OpenStreetMap)

我正在为我的毕业设计制作一种价格低廉的导航设备,使用Android作为操作系统

我尝试了Google Native的Map-view控件,但它仅在Online上有效.
当然,我想存储地图以进行离线导航

所以..我想要一个地图提供者(例如OpenStreetMap):

>我可以离线使用
>包含可搜索的街道名称(不仅是渲染的图像)
>商业用途
>免费或低价

OpenStreetMap的问题在于它没有为埃及的大多数城市提供详细的地图.

解决方法:

您需要像MapDroyd这样的东西,也许可以和他们讨论使用他们的代码的问题.

另外,也可以从这里选择OpenStreetMap小部件http://code.google.com/p/osmdroid/
并添加一种缓存区域的方法.对于街道名称索引,您可以下载world.osm(或只是其中的一部分以节省时间),然后通过如下所示的python脚本运行它:

(请注意,这需要做一些工作:它不会处理重复的街道名称,因此您必须对其进行一些修改.它还会找到酒吧和自动柜员机.)

#!/usr/bin/python

from xml.dom import pulldom

doc = pulldom.parse("england.osm")
#outFile = open("england.txt", "w")

nodes = {}
ways = {}
pubs = []
atms = []

i = 0
for event, node in doc:
    if event == pulldom.START_ELEMENT:
        if node.localName == "node":
            doc.expandNode(node)

            nodeID = node.getAttribute("id")
            nodeLat = node.getAttribute("lat")
            nodeLon = node.getAttribute("lon")

            amenity = "";
            for tag in node.getElementsByTagName("tag"):
                if tag.getAttribute("k") == "amenity":
                    amenity = tag.getAttribute("v")

            nodes[int(nodeID)] = ( float(nodeLat), float(nodeLon) )

            if amenity == "pub":
                pubs.append(int(nodeID))
            elif amenity == "atm" or amenity == "bank":
                atms.append(int(nodeID))

        elif node.localName == "way":
            doc.expandNode(node)

            name = "";
            for tag in node.getElementsByTagName("tag"):
                if tag.getAttribute("k") == "name":
                    name = tag.getAttribute("v")
            if name == "":
                continue;

            wayName = name.encode("latin-1", "replace")
            refList = [nd.getAttribute("ref") for nd in node.getElementsByTagName("nd")]

            if ways.has_key(wayName):
                ways[wayName].append([int(x) for x in refList])
            else:
                ways[wayName] = [int(x) for x in refList]

        i = i + 1
        if i % 100 == 0:
            print(i / 100)

print(nodes)
print(ways)
print(pubs)
print(atms)

#outFile.close()

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();
}

我们今天的关于使用OpenStreetMap和OSMNX检索covid弹出式发布周期的分享已经告一段落,感谢您的关注,如果您想了解更多关于4.OpenStreetMap Data Model、android – 点击地图获取坐标(openstreetmaps)、android-免费的离线地图提供程序(而非OpenStreetMap)、android-更改位置,并在openstreetmap中单击以放置标记的相关信息,请在本站查询。

本文标签: