-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A quick and dirty script to generate polyline shapefiles of the rando…
…m allocation order. Updates issue #76
- Loading branch information
1 parent
663d2f8
commit c1ec4a4
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# utility script to to convert a label allocation order shapefile to a set of lines | ||
|
||
use 5.016; | ||
|
||
use Geo::ShapeFile; | ||
use Geo::Shapefile::Writer; | ||
|
||
my $in_file = shift; | ||
my $out_file = shift; | ||
|
||
my $shape_file = Geo::ShapeFile->new($in_file); | ||
|
||
# could add order as z | ||
my $shp_writer = Geo::Shapefile::Writer->new( $out_file, 'POLYLINE', | ||
[ label => 'C', 100 ], | ||
); | ||
|
||
my %points; | ||
|
||
# read them in | ||
foreach my $i (1 .. $shape_file->shapes()) { | ||
my $shape = $shape_file->get_shp_record($i); | ||
my %db = $shape_file->get_dbf_record($i); | ||
|
||
my $label = $db{KEY}; | ||
my $alloc = $db{VALUE}; | ||
|
||
# won't handle -1 if we end up using it to mark swapped cases | ||
$points{$label}[$alloc] = $shape; | ||
} | ||
|
||
foreach my $label (sort keys %points) { | ||
my @vertices; | ||
foreach my $i (1 .. $#{$points{$label}}) { | ||
my $shape = $points{$label}[$i]; | ||
my $points = $shape->points; # assuming only one part and one point | ||
push @vertices, [$points->[0]->X, $points->[0]->Y]; | ||
} | ||
$shp_writer->add_shape ([\@vertices], {label => $label}); | ||
} | ||
|
||
$shp_writer->finalize; |