[Osmtools-cvs:00008] [11] リファクタリング

Zurück zum Archiv-Index

svnno****@sourc***** svnno****@sourc*****
2010年 4月 26日 (月) 17:45:00 JST


Revision: 11
          http://sourceforge.jp/projects/osmtools/svn/view?view=rev&revision=11
Author:   argrath
Date:     2010-04-26 17:44:59 +0900 (Mon, 26 Apr 2010)

Log Message:
-----------
リファクタリング

Modified Paths:
--------------
    ksj2/Geo/KSJ.pm
    ksj2/extract_forest.pl
    ksj2/extract_lake.pl

Modified: ksj2/Geo/KSJ.pm
===================================================================
--- ksj2/Geo/KSJ.pm	2010-04-25 19:38:12 UTC (rev 10)
+++ ksj2/Geo/KSJ.pm	2010-04-26 08:44:59 UTC (rev 11)
@@ -219,6 +219,67 @@
     return $self->{fh};
 }
 
+sub surface {
+    my $self = shift;
+    return $self->{surface};
+}
+
+sub parse_orientable_curve {
+    my ($self, $base) = @_;
+
+    my %orientable_curve;
+
+    my $s = $base->{'jps:GM_OrientableCurve'};
+
+    for (@$s){
+	my $id = $_->{'-id'};
+	my $vals = $_->{'jps:GM_OrientablePrimitive.primitive'}->{'-idref'};
+
+	$orientable_curve{$id} = $vals;
+    }
+
+    $self->{orientable_curve} = \%orientable_curve;
+}
+
+sub parse_surface {
+    my ($self, $base) = @_;
+
+    my %surface;
+    my $orientable_curve = $self->{orientable_curve};
+
+    my $s = $base->{'jps:GM_Surface'};
+
+    for (@$s){
+	my %s;
+	my @inner = ();
+	my @outer = ();
+	my $id = $_->{'-id'};
+	for (@{$_->{'jps:GM_Surface.patch'}}){
+	    my $v1 = $_->{'jps:GM_Polygon'}->{'jps:GM_Polygon.boundary'}-> 
+	      {'jps:GM_SurfaceBoundary'};
+	    for (@{$v1->{'jps:GM_SurfaceBoundary.exterior'}}){
+		my $cid = $_->{'jps:GM_Ring'}->{'jps:GM_CompositeCurve.generator'}->{'-idref'};
+		if(defined $orientable_curve){
+		    $cid = $$orientable_curve{$cid};
+		}
+		push @outer, $cid;
+	    }
+	    for (@{$v1->{'jps:GM_SurfaceBoundary.interior'}}){
+		my $cid = $_->{'jps:GM_Ring'}->{'jps:GM_CompositeCurve.generator'}->{'-idref'};
+		if(defined $orientable_curve){
+		    $cid = $$orientable_curve{$cid};
+		}
+		push @inner, $cid;
+	    }
+	}
+	$s{outer} = \@outer;
+	$s{inner} = \@inner;
+	$surface{$id} = \%s;
+    }
+
+    $self->{surface} = \%surface;
+}
+
 sub filter_curve {
     my ($self, $used) = @_;
 

Modified: ksj2/extract_forest.pl
===================================================================
--- ksj2/extract_forest.pl	2010-04-25 19:38:12 UTC (rev 10)
+++ ksj2/extract_forest.pl	2010-04-26 08:44:59 UTC (rev 11)
@@ -13,44 +13,26 @@
 });
 
 my $x = XML::TreePP::KSJ->new();
-$x->set( force_array => [ 'jps:GM_SurfaceBoundary.interior' ] );
+#$x->set( force_array => [ 'jps:GM_SurfaceBoundary.interior' ] );
+$x->set( force_array => [
+    'jps:GM_Surface.patch',
+    'jps:GM_SurfaceBoundary.exterior',
+    'jps:GM_SurfaceBoundary.interior',
+    ] );
 $x->set( utf8_flag => 1 );
 my $h = $x->parse($ksj->xml); 
 
 my $base = $h->{"ksj:GI"}->{dataset}->{'ksj:object'}->{'ksj:AA01'}->{'ksj:OBJ'};
 
-my %point = %{$ksj->point};
 my %curve = %{$ksj->curve};
-my %pointid = %{$ksj->pointid};
-my %pointname = %{$ksj->pointname};
 my $newid = $ksj->newid;
 
 ######################################################################
 
-my %surface;
-{
-    my $s = $base->{'jps:GM_Surface'};
+$ksj->parse_surface($base);
 
-    for (@$s){
-	my %s;
-	my @inner = ();
-	my $id = $_->{'-id'};
-#	my $v1 = $_->{'jps:GM_Surface.patch'}->{'jps:GM_Polygon'}->{'jps:GM_Polygon.boundary'}-> 
-#	      {'jps:GM_SurfaceBoundary'}->{'jps:GM_SurfaceBoundary.exterior'}-> 
-#		{'jps:GM_Ring'}->{'jps:GM_CompositeCurve.generator'}->{'-idref'};
-	my $v1 = $_->{'jps:GM_Surface.patch'}->{'jps:GM_Polygon'}->{'jps:GM_Polygon.boundary'}-> 
-	      {'jps:GM_SurfaceBoundary'};
-	$s{outer} = [$v1->{'jps:GM_SurfaceBoundary.exterior'}-> 
-		{'jps:GM_Ring'}->{'jps:GM_CompositeCurve.generator'}->{'-idref'}];
+my %surface = %{$ksj->surface};
 
-	for (@{$v1->{'jps:GM_SurfaceBoundary.interior'}}){
-	    push @inner, $_->{'jps:GM_Ring'}->{'jps:GM_CompositeCurve.generator'}->{'-idref'};
-	}
-	$s{inner} = \@inner;
-	$surface{$id} = \%s;
-    }
-}
-
 my %used_curve;
 {
     my $s = $base->{'ksj:BF01'};

Modified: ksj2/extract_lake.pl
===================================================================
--- ksj2/extract_lake.pl	2010-04-25 19:38:12 UTC (rev 10)
+++ ksj2/extract_lake.pl	2010-04-26 08:44:59 UTC (rev 11)
@@ -13,61 +13,28 @@
 });
 
 my $x = XML::TreePP->new();
-$x->set( force_array => [ 'jps:GM_Surface.patch', 'jps:GM_SurfaceBoundary.exterior', 'jps:GM_SurfaceBoundary.interior' ] );
+$x->set( force_array => [
+    'jps:GM_Surface.patch',
+    'jps:GM_SurfaceBoundary.exterior',
+    'jps:GM_SurfaceBoundary.interior',
+    ] );
 $x->set( utf8_flag => 1 );
 my $h = $x->parse($ksj->xml); 
 
 my $base = $h->{"ksj:GI"}->{dataset}->{'ksj:object'}->{'ksj:AA01'}->{'ksj:OBJ'};
 
-my %point = %{$ksj->point};
 my %curve = %{$ksj->curve};
-my %pointid = %{$ksj->pointid};
-my %pointname = %{$ksj->pointname};
 my $newid = $ksj->newid;
 
 ######################################################################
 
-my %orientable_curve;
-{
-    my $s = $base->{'jps:GM_OrientableCurve'};
+$ksj->parse_orientable_curve($base);
 
-#print Dumper($s);
+$ksj->parse_surface($base);
 
-    for (@$s){
-	my $id = $_->{'-id'};
-	my $vals = $_->{'jps:GM_OrientablePrimitive.primitive'}->{'-idref'};
+my %surface = %{$ksj->surface};
 
-	$orientable_curve{$id} = $vals;
-    }
-}
-
-my %surface;
 {
-    my $s = $base->{'jps:GM_Surface'};
-
-    for (@$s){
-	my %s;
-	my @inner = ();
-	my @outer = ();
-	my $id = $_->{'-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 $s = $base->{'ksj:GC01'};
 
     for (@$s){
@@ -109,7 +76,6 @@
 
 	my $id;
 
-
 	for (@{$s->{outer}}){
 	    $id = $_;
 	    my %tag = %tagbase;




Osmtools-cvs メーリングリストの案内
Zurück zum Archiv-Index