Message Boards Message Boards

13
|
17090 Views
|
6 Replies
|
25 Total Likes
View groups...
Share
Share this post:

Wolfram Language OSM map extract

Posted 10 years ago
Attachments:
POSTED BY: David Gathercole
6 Replies

Very interesting! Do you think it is possible to overlay the OSMs somehow on GeoGraphics? Are they in the same geo-coordinate system?

POSTED BY: Sam Carrettie

Using GeoGraphics ?! Of course - great idea! Things then become even easier: The geographic coordinates (latitude/longitude) can be used directly as extracted from the osm-file, no further transformation is necessary. Some minimal code:

geoBuildingLines = << "geoBuildingLines.txt";
GeoGraphics[GeoPath[geoBuildingLines]]

Nice things are possible (here just an appetizer):

enter image description here

Henrik

Attachments:
POSTED BY: Henrik Schachner

OSM provides a handful of APIs. You can easily summon the relevant file in code, allowing work entirely in Wolfram Geo functions.

(* Establish area bounds *)
GeoLoc = FindGeoLocation[];
ValLoc = GeoLoc[[1]];
MetersRadius = MR = 1000;
Corners = ToString /@ Join[
  GeoDestination[GeoDestination[GeoLoc, {MR, 180}], {MR, 270}][[1]][[{2, 1}]], 
    GeoDestination[GeoDestination[GeoLoc, {MR, 0}], {MR, 90}][[1]][[{2, 1}]]];
(* request relevent map *)
ImportRegion = URLFetch[StringJoin[
  Flatten[{"http://api.openstreetmap.org/api/0.6/map?bbox=", 
    Transpose[{Corners, {",", ",", ",", ""}}]}]]];
(* previously seen unpackaging *)
nodes = {}; Importnodes[ImportRegion];
waylists = {}; taglists = {}; Importways[ImportRegion];
(* extract desired data *)
buildpolys = Quiet[Table[(node[#] & /@ 
  ToExpression[StringDrop[StringDrop[#, 8], -2] & /@ #[[2]]]) & /@ 
     waylists[[i]][[First /@ Position[If[MemberQ[#, "building"], 1] & /@ taglists[[i]],1]]], {i, 1, 2}]];
(* plot onto map *)
GeoGraphics[{GeoPath[Reverse /@ # & /@ buildpolys[[1]], "Rhumb"], GeoMarker[]}]

example output

POSTED BY: David Gathercole
Posted 10 years ago

Ha - very cool!

POSTED BY: Stephen Coast

Dear David,

thank you very much for sharing this really nice idea! I already had a lot of fun playing around with this new possibility! I would like to make some minor remarks:

  • I found the coding much easier when the osm-file is imported as "XML" (as it is) instead of "TXT";
  • a useful addition to your code above could be a transformation from geographic coordinates (latitude, longitude) to planimetric coordinates (e.g. UTM grid). For this I am using the following little functions:

.

(* get UTMZone from geographic longitude *)
getUTM[lon_] := Module[{x, index},
  x = If[lon > 180, lon - 360, lon];
  index = Round[(x + 3.)/6.] + 30;
  StringJoin["UTMZone", ToString[index]]]

(* calculate: grad to UTM *)   
grad2utm[latlong_List, utmZone_String] := 
 First@GeoGridPosition[GeoPosition[latlong, "WGS84"], 
   GeoProjectionData[utmZone]]

(* calculate: UTM to grad *)    
utm2grad[xy_List, utmZone_String] :=
 QuantityMagnitude@
  LatitudeLongitude[GeoGridPosition[xy, GeoProjectionData[utmZone]]]

Regards Henrik

POSTED BY: Henrik Schachner

Thanks for pointing out the XML basis of OSM files. I probably burnt a lot of time overall by not looking the format up properly, just hacking through it.

POSTED BY: David Gathercole
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract