Osmgraph.pm

From OpenStreetMap Wiki
Jump to: navigation, search

Introduction

Osmrender20BETA2.png
This is a PERL module with several functions for drawing simple maps. This page shows the functions of Version 2.0 of the module. The module is used by osmrender.pl and Mapping Quality i.e.
Version 2.0 also supports SVG maps with textPaths for street names.

Problems with special characters in SVG?

Edit the first line of the SVG-file: either use

  • encoding="utf-8" or
  • encoding="iso-8859-1"

Sometimes one or the other works. I haven't figured it out yet...

Functions

General

  • enableSVG ()
  • initGraph ($sizeX, $left, $bottom, $right, $top) - give real world coordinates, sizeX in pixels, Y is automatic
  • writeGraph ($fileName) - write drawn graphic to file in png format
  • writeSVG ($fileName) - write drawn graphic to file in SVG format

Map

  • drawArea ($color, @nodes) - color as string, nodes as array ($lon1, $lat1, $lon2, $lat2...)
  • drawNodeDot ($lon, $lat, $color, $size) - draws dot at real world position, size (1..5)
  • drawNodeCircle ($lon, $lat, $color, $size) - draws circle at real world position, size (1..5)
  • drawRuler ($color) - size and position is automatic, top right corner
  • drawTextPix ($x, $y, $text, $color, $size) - draws text at pixel position, size (1..5)
  • drawTextPos ($lon, $lat, $offX, $offY, $text, $color, $size) - draws text at real world coordinates, offsets can be given in pixels, $size (1..5)
  • drawWay ($color, $size, @nodes) - draws way given by nodes in array ($lon1, $lat1, $lon2, $lat2...), size = thickness
  • labelWay ($col, $size, $font, $text, $tSpan, @nodes) - labels a way with i.e. a street name. tSpan = offset to line/way (will only be drawn in SVG image!)

Information

  • drawHead ($text, $color, $size) - text for top left, size (1..5)
  • drawFoot ($text, $color, $size) - text for bottom left, size (1..5)
  • drawLegend ($size, @entries) - draw legend texts in different colors, size (1..5) Example: ("text2", "col1", "text1", "col2").

Geometry

  • drawCircleRadius ($lon, $lat, $radius, $size, $color) - draws circle at real world coordinates, radius in meters
  • drawCircleRadiusText ($lon, $lat, $radius, $size, $color, $text) - draws circle at real world coordinates, radius in meters, draws text below circle

Chart

  • drawChartColumns ($lon, $lat, $offX, $offY, $sizeY, $columnWidthPix, $yMax, $color, @values) - draws a chart at real world coordinates, offsets can be given. Size in height must be given, Max Y for this height as well. Column width must be given in pixels. Values as array (v1, v2...).

Colors

  • black
  • darkgray
  • gray
  • lightgray
  • white
  • red
  • orange
  • darkorange
  • tomato
  • yellow
  • blue
  • lightblue
  • pink
  • green
  • darkgreen
  • lightgreen
  • brown
  • lightbrown


Hint

The outcommented function nodes2Coordinates can be used in the main program to convert lists of nodeIds to lists of coordinate pairs.

Download

osmgraph.pm

Preview 2.0 BETA

Image is in SVG format!
Hof20BETA.svg