diff options
author | Ivan Kohler <ivan@freeside.biz> | 2022-08-26 12:23:43 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2022-08-26 12:23:43 -0700 |
commit | b3b6d0750030d08032756ad4a6969e193a65a928 (patch) | |
tree | 24918c1ec8c2ed0878e1eebc952c45ce71efea23 /FS | |
parent | 86fb4649060ed26420bb1931481885064e76abc5 (diff) |
add shapefile, kmz and geojson export to deployment zones, RT#86460
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/Mason.pm | 6 | ||||
-rw-r--r-- | FS/FS/deploy_zone.pm | 71 |
2 files changed, 76 insertions, 1 deletions
diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index 8dd72ac79..ebd40adda 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -85,6 +85,7 @@ if ( -e $addl_handler_use_file ) { die $@ if $@; } use Text::CSV_XS; + use Archive::Zip; use Spreadsheet::WriteExcel; use Spreadsheet::WriteExcel::Utility; use OLE::Storage_Lite; @@ -120,7 +121,10 @@ if ( -e $addl_handler_use_file ) { use Locale::Currency::Format; use Number::Phone::Country qw( noexport ); use Business::US::USPS::WebTools::AddressStandardization; - use Geo::GoogleEarth::Pluggable; + use Geo::GoogleEarth::Pluggable 0.16; + use Geo::Shapelib; + use Geo::JSON; + use Geo::JSON::FeatureCollection; use LWP::UserAgent; use Storable qw( nfreeze thaw ); use FS; diff --git a/FS/FS/deploy_zone.pm b/FS/FS/deploy_zone.pm index 723b491c8..16ba5ddf3 100644 --- a/FS/FS/deploy_zone.pm +++ b/FS/FS/deploy_zone.pm @@ -10,9 +10,14 @@ use Cpanel::JSON::XS; use LWP::UserAgent; use HTTP::Request::Common; +use Geo::JSON::Polygon; +use Geo::JSON::Feature; + # update this in 2020, along with the URL for the TIGERweb service our $CENSUS_YEAR = 2010; +our $tech_label = FS::part_pkg_fcc_option->technology_labels; + =head1 NAME FS::deploy_zone - Object methods for deploy_zone records @@ -275,6 +280,27 @@ sub deploy_zone_vertex { }); } +=item shapefile_add SHAPEFILE + +Adds this deployment zone to the supplied Geo::Shapelib shapefile. + +=cut + +sub shapefile_add { + my( $self, $shapefile ) = @_; + + my @coordinates = map { [ $_->longitude, $_->latitude, 0, 0 ] } + $self->deploy_zone_vertex; + push @coordinates, $coordinates[0]; + + push @{$shapefile->{Shapes}}, { 'Vertices' => \@coordinates }; + push @{$shapefile->{ShapeRecords}}, [ $tech_label->{$self->technology}, + $self->adv_speed_down, + $self->adv_speed_up, + ]; + ''; +} + =item vertices_json Returns the vertex list for this zone, as a JSON string of @@ -289,6 +315,51 @@ sub vertices_json { encode_json(\@vertices); } +=item geo_json_feature + +Returns this zone as a Geo::JSON::Feature object + +=cut + +sub geo_json_feature { + my $self = shift; + + my @coordinates = map { [ $_->longitude, $_->latitude ] } + $self->deploy_zone_vertex; + push @coordinates, $coordinates[0]; + + Geo::JSON::Feature->new({ + geometry => Geo::JSON::Polygon->new({ coordinates => [ \@coordinates ] }), + properties => { 'Technology' => $tech_label->{$self->technology}, + 'Down' => $self->adv_speed_down, + 'Up' => $self->adv_speed_up, + }, + }) +} + +=item kml_add + +Adds this deployment zone to the supplied Geo::GoogleEarth::Pluggable object. + +=cut + +sub kml_polygon { + my( $self, $kml ) = @_; + + my $name = $self->description. ' ('. $self->adv_speed_down. '/'. + $self->adv_speed_up. ')'; + + $kml->Polygon( 'name' => $name, + 'coordinates' => [ [ #outerBoundary + map { [ $_->longitude, $_->latitude, 0 ] } + $self->deploy_zone_vertex + ], + #[ #innerBoundary + #] + ] + ); +} + =head2 SUBROUTINES =over 4 |