svnno****@sourc*****
svnno****@sourc*****
2010年 4月 26日 (月) 04:38:12 JST
Revision: 10 http://sourceforge.jp/projects/osmtools/svn/view?view=rev&revision=10 Author: argrath Date: 2010-04-26 04:38:12 +0900 (Mon, 26 Apr 2010) Log Message: ----------- リレーションを使うように変更 Modified Paths: -------------- ksj2/extract_lake.pl Modified: ksj2/extract_lake.pl =================================================================== --- ksj2/extract_lake.pl 2010-04-24 19:16:44 UTC (rev 9) +++ ksj2/extract_lake.pl 2010-04-25 19:38:12 UTC (rev 10) @@ -8,27 +8,17 @@ use Geo::KSJ; -#binmode(STDOUT, ':encoding(shift_jis)'); +my $ksj = Geo::KSJ->new_file('W09-05.xml', { + generator => 'extract_lake.pl', +}); my $x = XML::TreePP->new(); - -#my $h = $x->parsefile($ARGV[0]); -$x->set( force_array => [ 'jps:GM_Surface.patch' ] ); +$x->set( force_array => [ 'jps:GM_Surface.patch', 'jps:GM_SurfaceBoundary.exterior', 'jps:GM_SurfaceBoundary.interior' ] ); $x->set( utf8_flag => 1 ); -my $h = $x->parsefile('W09-05.xml'); # 湖沼 +my $h = $x->parse($ksj->xml); -#print Dumper($h); -#exit; - - -my $ksj = Geo::KSJ->new($h, { - generator => 'extract_lake.pl', -}); - my $base = $h->{"ksj:GI"}->{dataset}->{'ksj:object'}->{'ksj:AA01'}->{'ksj:OBJ'}; -#print Dumper($base); - my %point = %{$ksj->point}; my %curve = %{$ksj->curve}; my %pointid = %{$ksj->pointid}; @@ -51,42 +41,40 @@ } } - -my %surface_curve; +my %surface; { my $s = $base->{'jps:GM_Surface'}; -#print Dumper($s); - for (@$s){ + my %s; + my @inner = (); + my @outer = (); my $id = $_->{'-id'}; - my $v1 = $_->{'jps:GM_Surface.patch'}; - - for(@$v1){ - my $vals = $_->{'jps:GM_Polygon'}->{'jps:GM_Polygon.boundary'}-> - {'jps:GM_SurfaceBoundary'}->{'jps:GM_SurfaceBoundary.exterior'}-> - {'jps:GM_Ring'}->{'jps:GM_CompositeCurve.generator'}->{'-idref'}; - -# print $id . "\t" . $orientable_curve{$vals} . "\n"; - - $surface_curve{$orientable_curve{$vals}} = $id; + for (@{$_->{'jps:GM_Surface.patch'}}){ + my $v1 = $_->{'jps:GM_Polygon'}->{'jps:GM_Polygon.boundary'}-> + {'jps:GM_SurfaceBoundary'}; + for (@{$v1->{'jps:GM_SurfaceBoundary.exterior'}}){ + push @outer, $orientable_curve{$_->{'jps:GM_Ring'}->{'jps:GM_CompositeCurve.generator'}->{'-idref'}}; + } + for (@{$v1->{'jps:GM_SurfaceBoundary.interior'}}){ + push @inner, $orientable_curve{$_->{'jps:GM_Ring'}->{'jps:GM_CompositeCurve.generator'}->{'-idref'}}; + } } + $s{outer} = \@outer; + $s{inner} = \@inner; + $surface{$id} = \%s; } } -my %lake_name; +#my %lake_name; { my $s = $base->{'ksj:GC01'}; -#print Dumper($s); - for (@$s){ my $id = $_->{'ksj:ARE'}->{'-idref'}; my $val = $_->{'ksj:LPN'}; - -# print $id . "\t" . decode('shift_jis', $val) . "\n"; - $lake_name{$id} = $val; + $surface{$id}->{name} = $val; } } @@ -96,34 +84,62 @@ $ksj->put_point; -for (sort keys %curve){ - my $id = $_; - my %tag = ( - source => "MLIT, Japan", - 'source:ja' => "国土数値情報(湖沼データ)平成17年 国土交通省", - source_ref => 'http://nlftp.mlit.go.jp/ksj/jpgis/datalist/KsjTmplt-C23.html', - natural => 'water', -# natural => 'coastline', +my %tagbase = ( + source => "MLIT, Japan", + 'source:ja' => "国土数値情報(湖沼データ)平成17年 国土交通省", + source_ref => 'http://nlftp.mlit.go.jp/ksj/jpgis/datalist/KsjTmplt-W09.html', ); - if(defined $surface_curve{$id} && defined $lake_name{$surface_curve{$id}}){ -# $tag{name} = encode('utf-8', $lake_name{$surface_curve{$id}}); - $tag{name} = $lake_name{$surface_curve{$id}}; - } +for (sort keys %surface){ + my $s = $surface{$_}; + if($#{$s->{inner}} == -1 && $#{$s->{outer}} == 0 && $#{$curve{${$s->{outer}}[0]}} < 1950){ + my $id = $s->{outer}[0]; + my %tag = %tagbase; + $tag{natural} = 'water'; + $tag{'KSJ2:curve_id'} = $id; + if(defined $s->{name}){ + $tag{name} = $s->{name}; + } - my @c = @{$curve{$id}}; - while($#c >= 1600){ - my @nc = (); - for(my $i = 0; $i < 1500; $i++){ - my $x = shift @c; - push @nc, $x; + $ksj->put_curve_1($id, $newid--, $curve{$id}, \%tag); + } else + { + my @imem; + my @omem; + + my $id; + + + for (@{$s->{outer}}){ + $id = $_; + my %tag = %tagbase; + $tag{'KSJ2:curve_id'} = $id; + + my ($newnewid, $ids) = $ksj->put_curves($id, $newid, \%tag); + $newid = $newnewid; + push @omem, @$ids; } - push @nc, $c[0]; - $ksj->put_curve_1($id, $newid--, \@nc, \%tag); + + for (@{$s->{inner}}){ + $id = $_; + my %tag = %tagbase; + $tag{'KSJ2:curve_id'} = $id; + + my ($newnewid, $ids) = $ksj->put_curves($id, $newid, \%tag); + $newid = $newnewid; + push @imem, @$ids; + } + + { + my %tag = %tagbase; + $tag{natural} = 'water'; + if(defined $s->{name}){ + $tag{name} = $s->{name}; + } + + $ksj->put_relation($newid--, \@omem, \@imem, \%tag); + } } - - $ksj->put_curve_1($id, $newid--, \@c, \%tag); -# $ksj->put_curve_1($id, $newid--, $curve{$id}, \%tag); } $ksj->close;