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 /httemplate | |
parent | 86fb4649060ed26420bb1931481885064e76abc5 (diff) |
add shapefile, kmz and geojson export to deployment zones, RT#86460
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/browse/deploy_zone.html | 63 | ||||
-rw-r--r-- | httemplate/view/deploy_zone-geojson.cgi | 42 | ||||
-rw-r--r-- | httemplate/view/deploy_zone-kmz.cgi | 42 | ||||
-rw-r--r-- | httemplate/view/deploy_zone-shp.cgi | 76 |
4 files changed, 217 insertions, 6 deletions
diff --git a/httemplate/browse/deploy_zone.html b/httemplate/browse/deploy_zone.html index 5514d7db8..33724e59f 100644 --- a/httemplate/browse/deploy_zone.html +++ b/httemplate/browse/deploy_zone.html @@ -19,6 +19,21 @@ 'Contractual Mbps', 'Vertices', 'Census blocks', + 'Shapefile', + 'KMZ', + 'GeoJSON', + ], + footer => [ '', + 'All fixed zones', + '', + '', + '', + '', + '', + '', + '<A HREF="'. $fixed_shp. '">download</A>', + '<A HREF="'. $fixed_kmz. '">download</A>', + '<A HREF="'. $fixed_json. '">download</A>', ], fields => [ 'zonenum', 'description', @@ -48,6 +63,18 @@ sub { my $self = shift; FS::deploy_zone_block->count('zonenum = '.$self->zonenum) }, + sub { my $self = shift; + FS::deploy_zone_vertex->count('zonenum = '.$self->zonenum) + ? 'download' : '' + }, + sub { my $self = shift; + FS::deploy_zone_vertex->count('zonenum = '.$self->zonenum) + ? 'download' : '' + }, + sub { my $self = shift; + FS::deploy_zone_vertex->count('zonenum = '.$self->zonenum) + ? 'download' : '' + }, ], sort_fields => [ 'zonenum', 'description', @@ -56,7 +83,7 @@ '(adv_speed_down, adv_speed_up)', '(cir_speed_down, cir_speed_up)', ], - links => [ $link_fixed, $link_fixed, ], + links => [ $link_fixed, $link_fixed, '', '', '', '', '', '', $link_shp, $link_kmz, $link_json, ], align => 'cllllrrr', nohtmlheader => 1, disable_maxselect => 1, @@ -79,6 +106,9 @@ 'Service Type', 'Advertised Mbps', 'Vertices', # number of vertices? not so useful + 'Shapefile', + 'KMZ', + 'GeoJSON', ], fields => [ 'zonenum', 'description', @@ -101,6 +131,18 @@ sub { my $self = shift; FS::deploy_zone_vertex->count('zonenum = '.$self->zonenum) }, + sub { my $self = shift; + FS::deploy_zone_vertex->count('zonenum = '.$self->zonenum) + ? 'download' : '' + }, + sub { my $self = shift; + FS::deploy_zone_vertex->count('zonenum = '.$self->zonenum) + ? 'download' : '' + }, + sub { my $self = shift; + FS::deploy_zone_vertex->count('zonenum = '.$self->zonenum) + ? 'download' : '' + }, ], sort_fields => [ 'zonenum', 'description', @@ -109,7 +151,7 @@ '(is_voice is not null, is_broadband is not null)', '(adv_speed_down, adv_speed_up)', ], - links => [ '', $link_mobile, ], + links => [ $link_mobile, $link_mobile, '', '', '', '', '', '', $link_shp, $link_kmz, $link_json, ], align => 'clllllr', nohtmlheader => 1, disable_maxselect => 1, @@ -120,15 +162,24 @@ <& /elements/footer.html &> <%init> + my $curuser = $FS::CurrentUser::CurrentUser; my $acl_edit = $curuser->access_right('Edit FCC report configuration'); my $acl_edit_global = $curuser->access_right('Edit FCC report configuration for all agents'); die "access denied" unless $acl_edit or $acl_edit_global; -my $link_fixed = [ $p.'edit/deploy_zone-fixed.html?', 'zonenum' ]; -my $link_mobile= [ $p.'edit/deploy_zone-mobile.html?', 'zonenum' ]; +my $link_fixed = [ $p.'edit/deploy_zone-fixed.html?', 'zonenum' ]; +my $link_mobile = [ $p.'edit/deploy_zone-mobile.html?', 'zonenum' ]; +my $link_shp = [ $p.'view/deploy_zone-shp.cgi?', 'zonenum' ]; +my $link_kmz = [ $p.'view/deploy_zone-kmz.cgi?', 'zonenum' ]; +my $link_json = [ $p.'view/deploy_zone-geojson.cgi?', 'zonenum' ]; + +my $fixed_shp = $p.'view/deploy_zone-shp.cgi?zonetype=B'; +my $fixed_kmz = $p.'view/deploy_zone-kmz.cgi?zonetype=B'; +my $fixed_json = $p.'view/deploy_zone-geojson.cgi?zonetype=B'; + +my $tech_label = FS::part_pkg_fcc_option->technology_labels; +my $spec_label = FS::part_pkg_fcc_option->spectrum_labels; -my $tech_label = FS::part_pkg_fcc_option->technology_labels; -my $spec_label = FS::part_pkg_fcc_option->spectrum_labels; </%init> diff --git a/httemplate/view/deploy_zone-geojson.cgi b/httemplate/view/deploy_zone-geojson.cgi new file mode 100644 index 000000000..0c9d19353 --- /dev/null +++ b/httemplate/view/deploy_zone-geojson.cgi @@ -0,0 +1,42 @@ +<% $content %>\ +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; +my $acl_edit = $curuser->access_right('Edit FCC report configuration'); +my $acl_edit_global = $curuser->access_right('Edit FCC report configuration for all agents'); +die "access denied" + unless $acl_edit or $acl_edit_global; + +my($name, $content); + +my($query) = $cgi->keywords; +if ( $query =~ /^(\d+)$/ || $cgi->param('zonenum') =~ /^(\d+$)/ ) { + my $zonenum = $1; + $name = $zonenum; + my $deploy_zone = qsearchs('deploy_zone', { 'zonenum' => $zonenum }) + or die 'unknown zonenum'; + + $content = $deploy_zone->geo_json_feature->to_json; + +} elsif ( $cgi->param('zonetype') =~ /^(\w)$/ ) { + my $zonetype = $1; + $name = $zonetype; + my @deploy_zone = qsearch('deploy_zone', { 'zonetype' => $zonetype, + 'disabled' => '', }); + + my $fc = Geo::JSON::FeatureCollection->new({ + features => [ map $_->geo_json_feature, @deploy_zone ], + }); + + $content = $fc->to_json; + +} else { + die "no zonenum or zonetype\n"; +} + +http_header('Content-Type' => 'application/geo+json' ); +http_header('Content-Disposition' => "filename=$name.geojson" ); +http_header('Content-Length' => length($content) ); +http_header('Cache-control' => 'max-age=60' ); + +</%init> diff --git a/httemplate/view/deploy_zone-kmz.cgi b/httemplate/view/deploy_zone-kmz.cgi new file mode 100644 index 000000000..d2af171e5 --- /dev/null +++ b/httemplate/view/deploy_zone-kmz.cgi @@ -0,0 +1,42 @@ +<% $content %>\ +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; +my $acl_edit = $curuser->access_right('Edit FCC report configuration'); +my $acl_edit_global = $curuser->access_right('Edit FCC report configuration for all agents'); +die "access denied" + unless $acl_edit or $acl_edit_global; + +my $kml = Geo::GoogleEarth::Pluggable->new; + +my $name; + +my($query) = $cgi->keywords; +if ( $query =~ /^(\d+)$/ || $cgi->param('zonenum') =~ /^(\d+$)/ ) { + my $zonenum = $1; + $name = $zonenum; + my $deploy_zone = qsearchs('deploy_zone', { 'zonenum' => $zonenum }) + or die 'unknown zonenum'; + + $deploy_zone->kml_polygon($kml); + +} elsif ( $cgi->param('zonetype') =~ /^(\w)$/ ) { + my $zonetype = $1; + $name = $zonetype; + my @deploy_zone = qsearch('deploy_zone', { 'zonetype' => $zonetype, + 'disabled' => '', }); + + $_->kml_polygon($kml) foreach @deploy_zone; + +} else { + die "no zonenum or zonetype\n"; +} + +my $content = $kml->archive; + +http_header('Content-Type' => 'application/vnd.google-earth.kmz' ); #kmz +http_header('Content-Disposition' => "filename=$name.kmz" ); +http_header('Content-Length' => length($content) ); +http_header('Cache-control' => 'max-age=60' ); + +</%init> diff --git a/httemplate/view/deploy_zone-shp.cgi b/httemplate/view/deploy_zone-shp.cgi new file mode 100644 index 000000000..4b5dfbbc6 --- /dev/null +++ b/httemplate/view/deploy_zone-shp.cgi @@ -0,0 +1,76 @@ +<% $content %>\ +<%init> + +my $curuser = $FS::CurrentUser::CurrentUser; +my $acl_edit = $curuser->access_right('Edit FCC report configuration'); +my $acl_edit_global = $curuser->access_right('Edit FCC report configuration for all agents'); +die "access denied" + unless $acl_edit or $acl_edit_global; + +my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc; + +my %shapelib_opts = ( + Shapetype => Geo::Shapelib::POLYGON, + FieldNames => [ 'Tech', 'Down', 'Up' ], + FieldTypes => [ 'String:32', 'Double', 'Double' ], +); + +my( $name, $shapefile ); + +my($query) = $cgi->keywords; +if ( $query =~ /^(\d+)$/ || $cgi->param('zonenum') =~ /^(\d+$)/ ) { + my $zonenum = $1; + $name = $zonenum; + my $deploy_zone = qsearchs('deploy_zone', { 'zonenum' => $zonenum }) + or die 'unknown zonenum'; + + $shapefile = new Geo::Shapelib { + Name => "$dir/$zonenum-$$", + %shapelib_opts + }; + + $deploy_zone->shapefile_add($shapefile); + +} elsif ( $cgi->param('zonetype') =~ /^(\w)$/ ) { + my $zonetype = $1; + $name = $zonetype; + my @deploy_zone = qsearch('deploy_zone', { 'zonetype' => $zonetype, + 'disabled' => '', }); + + $shapefile = new Geo::Shapelib { + Name => "$dir/$zonetype-$$", + %shapelib_opts + }; + + $_->shapefile_add($shapefile) foreach @deploy_zone; + +} else { + die "no zonenum or zonetype\n"; +} + +$shapefile->set_bounds; + +$shapefile->save; + +#slurp up .shp .shx and .dbf files and put them in a zip.. return that +#and delete the files + +my $content = ''; +open(my $fh, '>', \$content); + +my $zip = new Archive::Zip; +$zip->addFile("$dir/$name-$$.$_", "$name.$_") foreach qw( shp shx dbf ); +unless ( $zip->writeToFileHandle($fh) == Archive::Zip::AZ_OK() ) { + die "failed to create .shz file\n"; +} +close $fh; + +unlink("$dir/$name-$$.$_") foreach qw( shp shx dbf ); + +#http_header('Content-Type' => 'x-gis/x-shapefile' ); +http_header('Content-Type' => 'archive/zip' ); +http_header('Content-Disposition' => "filename=$name.shz" ); +http_header('Content-Length' => length($content) ); +http_header('Cache-control' => 'max-age=60' ); + +</%init> |