简体   繁体   中英

Get the geometry (line/draw) of a road

How to get the geometry (line/draw) of a road in an array?

It's possible?

Thanks!

[Sorry my bad english]

This is not currently possible with Google Maps. Open-source web-services like OpenStreetMap are able to return the geometry of all roads in the database (which are pretty much all of them) inside a given bounds. This data can be retrieved in HTTP using an API called Overpass .

A query for finding all nodes that belong to a specific road could be:

way(s,w,n,e)["name"="Your Road Name"];out;

s,w,n,e are south, west, north, and east bounds for the data to come from.

You would need to know approximate bounds. This can be taken by a geocoding in Google for a road, and then expanding the returned coordinates by, say, 0.1 degrees.

This will return an XML document:

<osm version="0.6" generator="Overpass API">
<note>
The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.
</note>
<meta osm_base="2015-08-17T12:36:02Z"/>
<way id="16578496">
<nd ref="2399812387"/>
<nd ref="2399812388"/>
<nd ref="2399812389"/>
<nd ref="2399812390"/>
<nd ref="171131426"/>
<tag k="highway" v="residential"/>
<tag k="name" v="Halifax Court"/>
<tag k="tiger:cfcc" v="A41"/>
<tag k="tiger:county" v="Guilford, NC"/>
<tag k="tiger:name_base" v="Halifax"/>
<tag k="tiger:name_type" v="Ct"/>
<tag k="tiger:reviewed" v="no"/>
<tag k="tiger:zip_left" v="27265"/>
<tag k="tiger:zip_right" v="27265"/>
</way>
</osm>

After this, you can query all of the node refs by using:

node(2399812389);out;

You may only query one node at a time. This will return something like:

<osm version="0.6" generator="Overpass API">
<note>
The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.
</note>
<meta osm_base="2015-08-17T12:58:02Z"/>
<node id="2399812389" lat="36.0107609" lon="-79.9805742"/>
</osm>

After combining the latitude/longitude data for all of the points into a polyline, you have your road geometry.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM