source: subversion/applications/rendering/wms/class.osmarender.php @ 28929

Last change on this file since 28929 was 9330, checked in by isortega, 11 years ago

WMS now features basic osmarender support (only z17), as well as more bugs.

  • Property svn:executable set to *
File size: 5.2 KB
Line 
1<?php
2
3/// @author Iván Sánchez Ortega <ivan@sanchezortega.es>
4
5/**
6    OSM WMS ("OpenStreetMap Web Map Service")
7    Copyright (C) 2008, Iván Sánchez Ortega
8
9    This program is free software: you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation, either version 3 of the License, or
12    (at your option) any later version.
13
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18
19    You should have received a copy of the GNU General Public License
20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
21*/   
22
23/// Osmarender class
24/// This will pass OSM data to osmarender, get the resulting .svg, rasterize it, return it to the client.
25
26
27class osmarender /* extends layer */
28{
29
30static public function GetCapabilities()
31{
32// return "
33//       <Layer queryable='0' opaque='0'>
34//         <Name>wireframe</Name>
35//         <Title>OSM Wireframe</Title>
36//         <EX_GeographicBoundingBox>
37//           <westBoundLongitude>-180</westBoundLongitude>
38//           <eastBoundLongitude>180</eastBoundLongitude>
39//           <southBoundLatitude>-90</southBoundLatitude>
40//           <northBoundLatitude>90</northBoundLatitude>
41//         </EX_GeographicBoundingBox>
42//         <Style>
43//           <Name>Default</Name>
44//           <Title>Default</Title>
45//         </Style>
46//       </Layer>
47// ";
48
49// Capabilities for WMS 1.1.0
50return "
51      <Layer queryable='0' opaque='0'>
52        <Name>osmarender</Name>
53        <Title>Osmarender</Title>
54        <Style>
55          <Name>Default</Name>
56          <Title>Default</Title>
57        </Style>
58      </Layer>
59";
60
61
62//      <BoundingBox SRS='EPSG:4326' minx='-180' miny='-90' maxx='180' maxy='90' />
63//      <BoundingBox SRS='EPSG:32630' minx='-1050000' miny='3000000' maxx='1150000' maxy='5000000' />
64
65
66}
67
68
69static public function GetMap($bbox,$crs,$height,$width,$format)
70{
71
72//      datafactory::get_parsed_data($bbox,$crs,$nodes,$ways,$relations);
73        /// TODO: check whether we're using UTM or not, set the factor if needed.
74        /// TODO: check osmarender's way of scaling things, to determine the right factor.
75        /// TODO: change the osmarender stylesheet depending on the layer's style.
76        $factor = 0.00001;
77
78        /// TODO: Generate unique temporal filenames
79        $filename_osm = "/tmp/wms_temp.osm";
80        $filename_svg = "/tmp/wms_temp.svg"; // osmarender will automatically generate this, no need to pass it on to it
81        $filename_png = "/tmp/wms_temp.png";
82        @unlink ($filename_osm);
83        @unlink ($filename_svg);
84        @unlink ($filename_png);
85
86
87        file_put_contents ( $filename_osm , datafactory::get_data_as_projected_osm($bbox,$crs,$factor));
88       
89        list ($outer_left,$outer_bottom,$outer_right,$outer_top) = datafactory::get_outerbounds();
90       
91        // call osmarender to generate the .svg
92        /// TODO: migrate to or/p
93        chdir ("osmarender6");  $osmarender_output = shell_exec("./osmarender $filename_osm");
94
95
96
97        // The SVG starts at 0,0 at the bottom left
98        // Get the width and height of the SVG (in SVG units)
99        // This may not work if inkscape cannot create some directories - check that /var/www/.gnome2 and /var/www/.inkscape are writable by www-data
100        $svg_width  = (float) shell_exec("inkscape -z -W $filename_svg");
101        $svg_height = (float) shell_exec("inkscape -z -H $filename_svg");
102
103//      var_dump($outer_left,$outer_bottom,$outer_right,$outer_top);
104//      var_dump($osmarender_output);
105
106
107
108        // Calculate the portion of the SVG to crop out
109
110// var_dump($bbox);
111        list($left,$bottom,$right,$top) = explode(',',$bbox);
112//      $width  = $right - $left;
113//      $height = $top - $bottom;
114        $outer_width = $outer_right - $outer_left;
115        $outer_height = $outer_top - $outer_bottom;
116        // inner bbox relative to the outer bbox
117        $left   -= $outer_left;
118        $right  -= $outer_left;
119        $top    -= $outer_bottom;
120        $bottom -= $outer_bottom;
121
122        $x_factor = $svg_width  / $outer_width;
123        $y_factor = $svg_height / $outer_height;
124
125        // inner bbox relative to the outer bbox, factored
126        $left   *= $x_factor;
127        $right  *= $x_factor;
128        $top    *= $y_factor;
129        $bottom *= $y_factor;
130
131// var_dump($left,$bottom,$right,$top);
132// var_dump("$outer_left,$outer_bottom,$outer_right,$outer_top");
133
134// var_dump($x_factor,$y_factor);
135// var_dump($svg_width,$svg_height);
136// var_dump($left,$bottom,$right,$top);
137
138
139
140        // Custom background color?
141        if (isset($_REQUEST['BGCOLOR']))
142                $bgcolor = escapeshellarg($_REQUEST['BGCOLOR']);
143        else
144                $bgcolor = "#f8f8f8";
145//      $bgcolor = "transparent";
146
147        // Transparency??
148        if (isset($_REQUEST['TRANSPARENT']))
149                $transparency = " --export-background-opacity=0.0";
150        else
151                $transparency = " --export-background-opacity=1.0";
152
153
154
155        // call inkscape to rasterize the .svg
156
157        exec("inkscape -z -w $width -h $height --export-background=$bgcolor $transparency --export-area=$left:$bottom:$right:$top --export-png=$filename_png $filename_svg ");
158
159//      echo("inkscape -z -w $width -h $height --export-background=$bgcolor $transparency --export-area=$left:$bottom:$right:$top --export-png=$filename_png $filename_svg ");
160// --export-background=$bgcolor
161
162        fpassthru(fopen($filename_png,'r'));
163       
164//      unlink ($filename_osm);
165//      unlink ($filename_svg);
166//      unlink ($filename_png);
167       
168       
169}
170
171}
Note: See TracBrowser for help on using the repository browser.