line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::MapInfo::MIF; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
36712
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
80
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
74
|
|
5
|
2
|
|
|
2
|
|
2937
|
use File::Slurp; |
|
2
|
|
|
|
|
40672
|
|
|
2
|
|
|
|
|
177
|
|
6
|
2
|
|
|
2
|
|
2704
|
use Text::CSV; |
|
2
|
|
|
|
|
37780
|
|
|
2
|
|
|
|
|
16
|
|
7
|
2
|
|
|
2
|
|
2454
|
use Params::Util qw{_INSTANCE}; |
|
2
|
|
|
|
|
7263
|
|
|
2
|
|
|
|
|
156
|
|
8
|
2
|
|
|
2
|
|
16
|
use File::Basename; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2797
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
0
|
0
|
my $class = shift; |
14
|
0
|
|
|
|
|
0
|
return bless {}, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub trim($) { |
18
|
2
|
|
|
2
|
0
|
7
|
my $string = shift; |
19
|
2
|
|
|
|
|
13
|
$string =~ s/^\s+//; |
20
|
2
|
|
|
|
|
13
|
$string =~ s/\s+$//; |
21
|
2
|
|
|
|
|
22
|
return $string; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub read_files { |
25
|
1
|
|
|
1
|
1
|
121
|
my $mif_file = ""; |
26
|
1
|
|
|
|
|
3
|
my $mid_file = ""; |
27
|
|
|
|
|
|
|
#check which file is which |
28
|
|
|
|
|
|
|
#fileparse("/foo/bar/baz.txt", qr/\.[^.]*/); |
29
|
1
|
|
|
|
|
98
|
my($filename, $directories, $suffix) = fileparse($_[0], qr/\.[^.]*/); |
30
|
1
|
50
|
|
|
|
10
|
if ($suffix =~ /mif/i) { |
31
|
1
|
|
|
|
|
3
|
$mif_file = $_[0]; |
32
|
1
|
50
|
|
|
|
35
|
if (-e $directories.$filename.".mid") { |
|
|
0
|
|
|
|
|
|
33
|
1
|
|
|
|
|
3
|
$mid_file = $directories.$filename.".mid"; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
elsif (-e $directories.$filename.".MID") { |
36
|
0
|
|
|
|
|
0
|
$mid_file = $directories.$filename.".MID"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
0
|
|
|
|
|
0
|
die "Cannot find the mid file.\n$filename\n$suffix\n$directories\n"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
else { |
43
|
0
|
0
|
|
|
|
0
|
if (-e $directories.$filename.".mif") { |
|
|
0
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
$mid_file = $directories.$filename.".mif"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif (-e $directories.$filename.".MIF") { |
47
|
0
|
|
|
|
|
0
|
$mid_file = $directories.$filename.".MIF"; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
0
|
|
|
|
|
0
|
die "Cannot find the mif file,\n"; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
0
|
$mid_file = $_[0]; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
7
|
my @mif_lines = File::Slurp::read_file($mif_file); |
56
|
1
|
|
|
|
|
6426
|
my @mid_lines = File::Slurp::read_file($mid_file); |
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
|
|
189
|
my @answer = (\@mif_lines, \@mid_lines); |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
7
|
return @answer; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub read_mif_file { |
64
|
0
|
|
|
0
|
0
|
0
|
my ($mif_file) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
0
|
my @mif_lines = File::Slurp::read_file($mif_file); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
return @mif_lines; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub get_mif_info { |
73
|
1
|
|
|
1
|
1
|
52
|
my %mif_info; |
74
|
1
|
|
|
|
|
522
|
my @mif_lines = @_; |
75
|
1
|
|
|
|
|
4
|
my $i=0; |
76
|
1
|
|
|
|
|
3
|
do { |
77
|
15
|
100
|
|
|
|
116
|
if ($mif_lines[$i] =~ /(version)(\s+)(\d+)/gi) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
78
|
1
|
|
|
|
|
8
|
$mif_info{Version} = $3; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
elsif ($mif_lines[$i] =~ /(charset)(\s+)(.+)/gi) { |
81
|
1
|
|
|
|
|
4
|
$mif_info{Charset} = $3; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
elsif ($mif_lines[$i] =~ /(delimiter)(\s+)(.+)/gi) { |
84
|
1
|
|
|
|
|
4
|
$mif_info{Delimiter} = $3; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
elsif ($mif_lines[$i] =~ /(unique)(\s+)(.+)/gi) { |
87
|
0
|
|
|
|
|
0
|
$mif_info{Unique} = $3; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
elsif ($mif_lines[$i] =~ /(coordsys)(\s+)(.+)/gi) { |
90
|
1
|
|
|
|
|
4
|
$mif_info{Coordsys} = $3; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif ($mif_lines[$i] =~ /(transform)(\s+)(.+)/gi) { |
93
|
0
|
|
|
|
|
0
|
$mif_info{Transform} = $3; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
elsif ($mif_lines[$i] =~ /(columns)(\s+)(\d+)/gi) { |
96
|
1
|
|
|
|
|
10
|
for (my $j = 1; $j <= $3; $j++) { |
97
|
9
|
|
|
|
|
33
|
$mif_lines[$i+$j] =~ /\d*(\w+)\s+([a-zA-z_\(\)0-9]+)/g; |
98
|
9
|
|
|
|
|
49
|
$mif_info{Columns}[$j-1] = $1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
} |
101
|
15
|
|
|
|
|
43
|
$i++; |
102
|
|
|
|
|
|
|
} until ($mif_lines[$i] =~ m/data/gi); |
103
|
1
|
|
|
|
|
150
|
return %mif_info; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub process_regions { |
107
|
1
|
|
|
1
|
1
|
10
|
my $column = $_[0]; |
108
|
1
|
|
|
|
|
2
|
my @mif_lines = @{$_[1]}; |
|
1
|
|
|
|
|
495
|
|
109
|
1
|
|
|
|
|
5
|
my @mid_lines = @{$_[2]}; |
|
1
|
|
|
|
|
4
|
|
110
|
1
|
|
|
|
|
3
|
my %regions; |
111
|
1
|
|
|
|
|
3
|
my $current_mid_row = 0; |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
12
|
my $csv = Text::CSV->new(); |
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
113
|
for (my $i = 0; $i < $#mif_lines; $i++) { |
116
|
20
|
100
|
|
|
|
91
|
if ($mif_lines[$i] =~ /\s*region\s*(\d+)/i) { |
117
|
1
|
|
|
|
|
7
|
my $mid_row = $csv->parse($mid_lines[$current_mid_row++]); |
118
|
1
|
|
|
|
|
791
|
my @mid_row_array = $csv->fields; |
119
|
1
|
|
|
|
|
13
|
my $no_regions = $1; |
120
|
1
|
|
|
|
|
31
|
for (my $k = 0; $k < $no_regions; $k++) { |
121
|
1
|
|
|
|
|
5
|
my $no_rows = trim($mif_lines[++$i]); |
122
|
1
|
|
|
|
|
3
|
my @region = ""; |
123
|
1
|
|
|
|
|
5
|
for (my $j = $i+1; $j < $i+1+$no_rows; $j++) { |
124
|
4316
|
|
|
|
|
12307
|
my @temp = split(/\s+/, $mif_lines[$j]); |
125
|
4316
|
|
|
|
|
12716
|
$region[$j-$i-1] = \@temp; |
126
|
|
|
|
|
|
|
} |
127
|
1
|
|
|
|
|
4
|
$i = $i + $no_rows; |
128
|
1
|
|
|
|
|
2
|
push @{$regions{trim($mid_row_array[$column])}}, \@region; |
|
1
|
|
|
|
|
7
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} |
132
|
1
|
|
|
|
|
293
|
return %regions; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |