line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: ShapeFile.pm,v 1.15 2004/08/21 04:13:28 asc Exp $ |
2
|
2
|
|
|
2
|
|
2351
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
157
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package XML::Generator::SVG::ShapeFile; |
5
|
2
|
|
|
2
|
|
11
|
use base qw (XML::SAX::Base); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2056
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
$XML::Generator::SVG::ShapeFile::VERSION = '0.2'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
XML::Generator::SVG::ShapeFile - Generate SAX2 events for an SVG rendering of an ESRI shapefile. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use PerlIO::gzip; |
16
|
|
|
|
|
|
|
use XML::SAX::Writer; |
17
|
|
|
|
|
|
|
use XML::Generator::SVG::ShapeFile; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# see CAVEATS below |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
open SVGZ, ">:gzip", "/path/to/my/output.svgz" |
22
|
|
|
|
|
|
|
|| die "do the right thing, luke"; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $writer = XML::SAX::Writer->new(Output => \*SVGZ); |
25
|
|
|
|
|
|
|
my $svg = XML::Generator::SVG::ShapeFile->new(Handler=>$writer); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$svg->set_width(1024); |
28
|
|
|
|
|
|
|
$svg->set_decimals(1); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$svg->set_title("You are here"); |
31
|
|
|
|
|
|
|
$svg->set_stylesheet("foo.css"); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$svg->add_point({lat=>"123",long=>"456"}); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$svg->render("/path/to/shapefile"); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Generate SAX2 events for an SVG rendering of an ESRI shapefile. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 CAVEATS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Depending on your input data, this package may generate huge |
44
|
|
|
|
|
|
|
SVG files if left uncompressed. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DOCUMENT STRUCTURE |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
+ svg |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
+ metadata |
51
|
|
|
|
|
|
|
+ rdf:Description [@rdf:about = '...'] |
52
|
|
|
|
|
|
|
~ dc:title |
53
|
|
|
|
|
|
|
~ dc:description |
54
|
|
|
|
|
|
|
~ dc:publisher |
55
|
|
|
|
|
|
|
~ dc:language |
56
|
|
|
|
|
|
|
- dc:date |
57
|
|
|
|
|
|
|
- dc:format |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
+ g [@id = 'map'] |
60
|
|
|
|
|
|
|
- rect [@id = 'canvas'] |
61
|
|
|
|
|
|
|
- path (+) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
~ g [@id = 'locations'] |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
+ g [@id = '...'] (+) |
66
|
|
|
|
|
|
|
- title |
67
|
|
|
|
|
|
|
-circle |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
use Geo::ShapeFile; |
72
|
|
|
|
|
|
|
use Date::Simple; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 PACKAGE METHODS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 __PACKAGE__->new(\%args) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Inherits from XML::SAX::Base, so constructor arguments |
81
|
|
|
|
|
|
|
are the same. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub new { |
86
|
|
|
|
|
|
|
my $pkg = shift; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $self = $pkg->SUPER::new(@_); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$self->{'__points'} = []; |
91
|
|
|
|
|
|
|
$self->{'__metadata'} = {}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$self->{'__css'} = undef; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$self->{'__min_x'} = 0; |
96
|
|
|
|
|
|
|
$self->{'__max_x'} = 0; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$self->{'__min_y'} = 0; |
99
|
|
|
|
|
|
|
$self->{'__max_y'} = 0; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$self->{'__height'} = 0; |
102
|
|
|
|
|
|
|
$self->{'__width'} = 0; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$self->{'__decimals'} = 0; |
105
|
|
|
|
|
|
|
$self->{'__scale'} = 0; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
return bless $self, $pkg; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 $obj->set_width($int) |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
I |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub set_width { |
121
|
|
|
|
|
|
|
my $self = shift; |
122
|
|
|
|
|
|
|
$self->{'__width'} = $_[0]; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 $obj->set_decimals($int) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
I |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub set_decimals { |
132
|
|
|
|
|
|
|
my $self = shift; |
133
|
|
|
|
|
|
|
$self->{'__decimals'} = $_[0]; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 $obj->set_uri($str) |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Set the URI used to identify the document in RDF metadata |
139
|
|
|
|
|
|
|
section. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Default is '#' |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub set_uri { |
146
|
|
|
|
|
|
|
my $self = shift; |
147
|
|
|
|
|
|
|
$self->{'__metadata'}->{'about'} = $_[0]; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 $obj->set_title($str) |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Set the title for the document's RDF metadata section. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub set_title { |
157
|
|
|
|
|
|
|
my $self = shift; |
158
|
|
|
|
|
|
|
$self->{'__metadata'}->{'title'} = $_[0]; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 $obj->set_description($str) |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Set the description for the document's RDF metadata section. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=cut |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub set_description { |
168
|
|
|
|
|
|
|
my $self = shift; |
169
|
|
|
|
|
|
|
$self->{'__metadata'}->{'description'} = $_[0]; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 $obj->set_publisher($str) |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Set the publisher for the document's RDF metadata section. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub set_publisher { |
179
|
|
|
|
|
|
|
my $self = shift; |
180
|
|
|
|
|
|
|
$self->{'__metadata'}->{'publisher'} = $_[0]; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 $obj->set_language($str) |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Set the language for the document's RDF metadata section. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub set_language { |
190
|
|
|
|
|
|
|
my $self = shift; |
191
|
|
|
|
|
|
|
$self->{'__metadata'}->{'language'} = $_[0]; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 $obj->set_stylesheet($str) |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Set the URI for the document's CSS stylesheet. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=cut |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub set_stylesheet { |
201
|
|
|
|
|
|
|
my $self = shift; |
202
|
|
|
|
|
|
|
$self->{'__css'} = $_[0]; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 $obj->add_point(\%args) |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Points are added as SVG I elements. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Valid arguments are : |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=over 4 |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item * B |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
The latitude, in decimal form, of the point you are adding. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
I |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * B |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
The longitude, in decimal form, of the point you are adding. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
I |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * B |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Default is 'id--', where decimal points are replaced |
228
|
|
|
|
|
|
|
by '-' |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * B |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
A label for the point you are adding. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item * B |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
The radius of the point you are adding. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Default is '1' |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item * B |