source: subversion/applications/rendering/mapyrus/render.pl @ 29674

Last change on this file since 29674 was 1615, checked in by joerg, 13 years ago

insert search path and full name of OsmXML so perl can easily find it

  • Property svn:executable set to *
File size: 6.8 KB
Line 
1#!/usr/bin/perl
2
3BEGIN {
4    my $dir = $0;
5    $dir =~s,[^/]+/[^/]+$,,;
6    unshift(@INC,"$dir/perl");
7
8    unshift(@INC,"./perl");
9    unshift(@INC,"../perl");
10    unshift(@INC,"~/svn.openstreetmap.org/utils/perl");
11    unshift(@INC,"$ENV{HOME}/svn.openstreetmap.org/utils/perl");
12}
13
14use Geo::OSM::OsmXML;
15use Data::Dumper;
16
17# Definitions
18$OsmFile = "../Data/bedford.osm"; # Source OSM file
19$Filename = "osm.def"; # Temporary mapyrus file
20$MapFile = "output.eps"; # Output map file
21$OutputFormat = substr($MapFile, -3); # e.g. "eps","svg","png"
22$Java = "/usr/java/jre1.5.0_06/bin/java"; # Location of java 5
23$Mapyrus = "mapyrus.jar"; # Location of mapyrus
24
25print "Hello, world!\n";
26unlink $MapFile;
27
28open(STDOUT, ">", $Filename) || die($!);
29CreateMap($MapFile, $OutputFormat, $OsmFile);
30
31# Alternative: create a pipe to mapyrus, and use the -e command line options
32
33# render the file
34$RenderCommand = "$Java -classpath $Mapyrus org.mapyrus.Mapyrus $Filename";
35`$RenderCommand`;
36
37sub DrawUnclassified(){
38  print "linestyle .1, \"round\", \"round\"\n";
39  print "color '#666666'\nstroke\n";
40}
41sub DrawMotorway(){
42  print "begin mwayname name\n";
43  print "rotate -Mapyrus.rotation\n"; # Back to "upright" mode
44  print "box -3,-2,3,2\ncolor 'blue'\nfill\nclearpath\n";
45  print "color 'white'\njustify 'center'\nmove 0,-1\nlabel name\n";
46  print "end\n";
47 
48  print "linestyle .5, \"round\", \"round\"\n";
49  print "color '#44CCFF'\nstroke\n";
50  print "parallelpath -1, 1\n";
51  print "color '#44CCFF'\n";
52  print "linestyle 0.1, \"round\", \"round\"\n";
53  print "stroke\n";
54  print "samplepath 30, 9\n";
55  print "mwayname 'MW'\n";
56}
57sub DrawPrimary(){
58  print "linestyle .45, \"round\", \"round\"\n";
59  print "color 'black'\nstroke\n";
60 
61  print "linestyle .4, \"round\", \"round\"\n";
62  print "color '#FF4400'\nstroke\n";
63 
64}
65sub DrawSecondary(){
66  print "linestyle .3, \"round\", \"round\"\n";
67  print "color 'black'\nstroke\n";
68 
69  print "linestyle .25, \"round\", \"round\"\n";
70  print "color 'orange'\nstroke\n";
71
72}
73sub DrawRiver(){
74  print "linestyle 1.6, \"round\", \"round\"\n";
75  print "color '#8888FF'\nstroke\n";
76 
77  print "parallelpath -0.8, 0.8\n";
78  print "color '#0000CC'\n";
79  print "linestyle 0.1, \"round\", \"round\"\n";
80  print "stroke\n";
81
82}
83sub DrawPath(){
84  print "linestyle 0.1, \"butt\", \"bevel\", 0, 1, 1\n";
85  print "color '#008800'\nstroke\n";
86 
87  #print "begin arrow\nmove -1,-1\ndraw -1,1,2,0\nfill\nend\n";
88  #print "samplepath 20, 2.5\narrow\n";
89}
90sub DrawBike(){
91  print "linestyle 0.1, \"butt\", \"bevel\", 0, 1.5, 2\n";
92  print "color '#008800'\nstroke\n";
93 
94  #print "begin arrow\nmove -1,-1\ndraw -1,1,2,0\nfill\nend\n";
95  #print "samplepath 20, 2.5\narrow\n";
96}
97sub DrawCoast(){
98  print "linestyle 0.1, \"round\", \"round\"\n";
99  print "color 'blue'\nstroke\n";
100}
101sub DrawRail(){
102  # Solid line with white dashes on top
103  print "linestyle 0.5, \"round\", \"round\"\n";
104  print "color '#880088'\nstroke\n";
105  print "linestyle 0.4, \"round\", \"round\",0,2,2\n";
106  print "color '#FFFFFF'\nstroke\n";
107}
108sub CreateMap(){
109  my($MapFile, $OutputFormat, $OsmFile)  = @_;
110  my %Functions = (
111    "debug" => \&DrawUnclassified,
112    "unclassified" => \&DrawUnclassified,
113    "residential" => \&DrawUnclassified,
114    "minor" => \&DrawUnclassified,
115    "secondary" => \&DrawSecondary,
116    "primary" => \&DrawPrimary,
117    "motorway" => \&DrawMotorway,
118    "motorway_link" => \&DrawMotorway,
119    "river"=>\&DrawRiver,
120    "cycleway"=>\&DrawBike,
121    "bridleway"=>\&DrawBike,
122    "path"=>\&DrawPath,
123    "footpath"=>\&DrawPath,
124    "footway"=>\&DrawPath,
125    "coastline"=>\&DrawCoast,
126    "railway"=>\&DrawRail,
127    "rail"=>\&DrawRail,
128    );
129 
130
131  $OSM = new OsmXML();
132  $OSM->load($OsmFile);
133  ($S,$W,$N,$E) = OsmXML::bounds();
134
135  # Header
136  print "#" x 80 . "\n";
137  print "# This is map data from the OpenStreetMap project\n";
138  print "# Generated by $0, from $OsmFile\n";
139  print "# This data is licensed as Creative Commons CC-BY-SA 2.0\n";
140  print "# Render this file using Mapyrus (mapyrus.sourceforge.net)\n";
141  print "#" x 80 . "\n\n";
142 
143  # Output format
144  print "newpage \"$OutputFormat\", \"$MapFile\", 800, 800\n";
145 
146  # Drawing area
147  print "worlds $W, $S, $E, $N\n"; 
148  print "include symbols.mapyrus\n";
149 
150  #---------------- Ways --------------------
151  foreach $Way(%OsmXML::Ways){
152   
153     printf "clearpath\n";
154     
155    $Type = 
156      $Way->{"highway"} ||
157      $Way->{"railway"} ||
158      $Way->{"waterway"} ||
159      $Way->{"natural"} ||
160      $Way->{"class"} ||
161      "debug";
162     
163    @Segments = split(/,/,$Way->{"segments"});
164   
165    $LastId = -1;
166    foreach $SegmentID(@Segments){
167      $Segment = $OsmXML::Segments{$SegmentID};
168   
169      $Node1 = $OsmXML::Nodes{$Segment->{"from"}};
170      $Node2 = $OsmXML::Nodes{$Segment->{"to"}};
171   
172      if($Segment->{"from"} == $LastId){
173        printf ",%f,%f",
174          $Node2->{"lon"},
175          $Node2->{"lat"};
176      }
177      else
178      {
179        printf "\nmove %f,%f\ndraw %f,%f",
180          $Node1->{"lon"},
181          $Node1->{"lat"},
182          $Node2->{"lon"},
183          $Node2->{"lat"};
184      }
185      $LastId = $Segment->{"to"};
186       
187      } # Next segment
188    print "\n"; # End the list of vertices
189   
190   
191    $Functions{$Type}() if(exists $Functions{$Type});
192
193  } # Next way
194 
195  #---------------- Nodes --------------------
196  print "font 'Arial', 4\n";
197  foreach $Node(values %OsmXML::Nodes){
198    $Type = $Node->{"amenity"} || 
199      $Node->{"place"} || 
200      $Node->{"railway"} || 
201      $Node->{"place_of_worship"} || 
202      "";
203    if($Type =~ /(hospital|parking|church|school|library|lighthouse)/){
204      printf "clearpath\nmove %f,%f\n%s\n",
205        $Node->{"lon"},
206        $Node->{"lat"},
207        $Type;
208    }
209    if($Type && 0){
210     
211      printf "clearpath\ncolor 'black'\nmove %f,%f\nlabel '%s'\n",
212        $Node->{"lon"},
213        $Node->{"lat"},
214        $Type;
215      }
216  }
217 
218 
219  # Anything else
220  print "include scalebar.mapyrus\n";
221  printf "clearpath\nscalebar Mapyrus.worlds.scale, 'm', %f, %f\n",
222    0,
223    0;
224}
225
226
227=head1 NAME
228
229Rendering program for OpenStreetMap files, which uses Mapyrus
230
231=head1 AUTHOR
232
233Oliver White (oliver.white@blibbleblobble.co.uk)
234
235=head1 DESCRIPTION
236
237See http://wiki.openstreetmap.org/index.php/Mapyrus
238
239=head1 COPYRIGHT
240
241Copyright 2006, Oliver White
242
243This program is free software; you can redistribute it and/or
244modify it under the terms of the GNU General Public License
245as published by the Free Software Foundation; either version 2
246of the License, or (at your option) any later version.
247
248This program is distributed in the hope that it will be useful,
249but WITHOUT ANY WARRANTY; without even the implied warranty of
250MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
251GNU General Public License for more details.
252
253You should have received a copy of the GNU General Public License
254along with this program; if not, write to the Free Software
255Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
256
257=cut
Note: See TracBrowser for help on using the repository browser.