Osm.pm

From OpenStreetMap Wiki
Jump to: navigation, search

Introduction

The osm.pm file is a PERL module that contains a lot of useful functions for the daily work with osm data files, the current version is Version 8.4.

Functions

File

The file functions will work with *.osm and *.osm.bz2.

  • openOsmFile ($file) - open osm file and $line is set to first node
  • closeOsmFile ()
  • stringFileInfo ($file) - gives you a string with file name and date
  • nextLine() -reads filehandle and returns next line
  • seek_to_way_section() -jumps node section and goes to the first way
  • seek_to_relation_section() - similarly to previous, this goes to relations

Nodes

  • skipNodes () - after open file you don't have to parse the nodes if you only want ways
  • getNode () - returns ($gId, $gLon, $gLat, $gU, \@gTags) and sets $line forward accordingly. returns (-1, -1, -1, -1, -1) if no more nodes.
  • getNode2 () - returns ($gId, $gLon, $gLat, $gU, $ref1) making use of readNode()
  • getNode3 () - returns ($ref0, $ref1) without further elaboration on property hash
  • readNode () - returns ($propRef, \@nodeTags) using getProperties()
  • getProperties () - parses node properties returning an hash
  • getNodeXml () - ($gId, $xml) returns id and xml of the node, advancing the line

Ways

  • skipWays () -
  • getWay () - returns ($gId, $gU, \@gNodes, \@gTags). returns (-1, -1, -1, -1, -1) if no more ways.
  • getWay2 () -
  • getWay3 () -
  • readWay () -
  • getWayXml () -
  • APIGetWay($wayId) - get way from OSM database

Relation

  • getRelation () - returns ($gId, $gU, \@gNodes, \@gTags). returns (-1, -1, -1, -1, -1) if no more ways.
  • getRelation3 () -
  • readRelation () -
  • getRelationXml () -


Geometry

  • crossing (g1x1,g1y1,g1x2,g1y2,g2x1,g2y1,g2x2,g2y2) - check for a crossing of two line segments. returns ($sx, $sy) (0,0) if no crossing was found.
  • hashValue ($lon, $lat) - returns a hashValue for coordinates, hash size 0.1 degrees
  • hashValue2 ($lon, $lat) -
  • angle (x1,y1,x2,y2) - gives you the angle from point one to point two. (N=0,E=90...)
  • project (x1, y1, angle, dist) - project a point from point 1 by distance and angle. returns (x2,y2)
  • distance (x1,y1,x2,y2) - returns $distance in km between two points
  • shortestDistance ($gx1, $gy1, $gx2, $gy2, $nx, $ny) - returns ROUGHLY the distance of node to segment in km
  • checkOverlap (w1xMin, w1yMin, w1xMax, w1yMax, w2xMin, w2yMin, w2xMax, w2yMax) - check if two areas overlap. 0=no overlap, 1=overlap

HTML output

  • analyzerLink($id) -url to relation analyzer
  • getBugs -
  • historyLink ($type, $key) - returns string which can be printed to HTML file. type = [way, node]
  • josmLink -DON'T USE
  • josmLinkDontSelect -
  • josmLinkSelectWay ($lon, $lat, $span, $wayId) - returns string which can be printed to HTML file
  • josmLinkSelectWays ($lon, $lat, $span, @ways) - returns string which can be printed to HTML file
  • josmLinkSelectNode ($lon, $lat, $span, $nodeId) - returns string which can be printed to HTML file
  • josmLinkSelectNodes ($lon, $lat, $span, @nodes) - returns string which can be printed to HTML file
  • osbLink ($lon, $lat) - returns string which can be printed to HTML file
  • osmLink ($lon, $lat) - returns string which can be printed to HTML file
  • osmLinkMarkerWay ($lon, $lat,$zoom,$way) - returns string which can be printed to HTML file
  • mapCompareLink ($lon,$lat,$zoom)-
  • picLinkMapnik ($lon, $lat, $zoom) - returns string which can be printed to HTML file
  • picLinkOsmarender ($lon, $lat, $zoom) - returns string which can be printed to HTML file
  • printHTMLCellCenter ($file, $value)
  • printHTMLCellLeft ($file, $value)
  • printHTMLCellLeftEM ($file, $value)
  • printHTMLCellLeftTwoValues ($file, $value)
  • printHTMLCellRight ($file, $value)
  • printHTMLFoot ($file)
  • printHTMLiFrameHeader ($file, $title)
  • printHTMLiFrame ($file, $title)
  • printHTMLHeader ($file, $title)
  • printHTMLRowStart ($file)
  • printHTMLRowEnd ($file)
  • printHTMLTableFoot ($file)
  • printHTMLTableHead ($file)
  • printHTMLTableHeadings ($file, @list)
  • printHTMLTableRowLeft ($file, @list)
  • printHTMLTableRowRight ($file, @list)
  • printNodeList ($file, @list) - prints a table of nodes given in @list with history link.
  • printWayList ($file, @list) - prints a table of ways given in @list with history link.

GPX

  • printGPXHeader ($file)
  • printGPXFoot ($file)
  • printGPXWaypoint ($file, $lon, $lat, $text)

Misc

  • tileNumber ($lat,$lon,$zoom) - returns the tile numbers ($xTile, $yTile) for osmarender or mapnik tiles
  • binSearch ($value, @ref) - looks for value in array and returns $index or -1 if not found
  • printProgress ($program, $osm, $startTime, $fullCount, $actualCount)
  • stringTimeSpent ($timeSpent in seconds) - gives a string with formatted time.
  • applyDiffFile($dbName,$fileName) - connect to a database and apply differences
  • convertToLatex($text) - convert text to latex
  • replaceHTMLCode($text) - replaces some HTML entities

Download

osm.pm