package California;
$RCSID = "$Id:";

require Exporter;
use country;
@ISA         = qw(Exporter country);
@EXPORT      = qw(slurpList pathto_tif hello);
@EXPORT_OK   = qw();

sub new {
    $type = shift;
    $self = country->new;
    $self->{type} = $type; 
 
   $self->{revision} = '$Id: California.pm,v 1.9 2023/08/06 04:18:20 dkl Exp $';

    $self->{indexW} = 45;
    $self->{indexH} = 54;
    $self->{hilong} = 124; 
    $self->{lowlong} = 114;
    $self->{hilat} = 42; 
    $self->{lowlat} = 32;
    $self->{width} = 45;  
    $self->{height} = 54;
    $self->{minDPI} = 25;  
    $self->{maxDPI} = 200;
    $self->{origDPI} = 400;
    $self->{defaultDPI} = 25;
    $self->{teale}  = 1;
    $self->{flavor} = "usgs";

    $self->{proj} = "AEA";
    $self->{datum} = "NAD27";
    $self->{ellips} = "CLRK66";
    
    $self->{projargs} = ["+proj=aea", "+ellps=GRS80", "+datum=NAD83",
                  "+lat_1=34.0", "+lat_2=40.5", "+lon_0=-120.0", "+lon_0=120.0",
                  "+x_0=0", "+y_0=-4000000.0", "+units=m"];




   #
   # sample
   #
   #  http://atlas.ca.gov/casil/imageryBaseMapsLandCover/baseMaps/drg/7.5_minute_series_albers_nad83_untrimmed/32114/o32114f7.tif
   #
   #
   #$self->{maphomeorg} = "The California Spatial Information Library";
   #$self->{maphome} = "http://atlas.ca.gov/casil/imageryBaseMapsLandCover/baseMaps/drg/7.5_minute_series_albers_nad83_untrimmed";

   # http://gisarchive.cnra.ca.gov/iso/ImageryBaseMapsLandCover/BaseMaps/drg/7.5_minute_series_albers_nad83_untrimmed/34114/

   # seems like the data is still provided by CaSiL, but is now hosted at 
   # gisarchive.cnra or whatever
   #$self->{maphomeorg} = "The California Spatial Information Library";
   #$self->{maphome} = "http://gisarchive.cnra.ca.gov/iso/ImageryBaseMapsLandCover/BaseMaps/drg/7.5_minute_series_albers_nad83_untrimmed/";

   #
   #  Seems like the data is now provided by multiple organizatoipns
   #  one of which is archive.org 
   #  example:
   #  https://archive.org/details/usgs_drg_ca_37122_e3
   #
   $self->{maphomeorg} = "archive.org";
   $self->{maphomepage} = "https://archive.org/details/usgs_ca";
   $self->{maphome} = "https://archive.org/download/usgs_drg_ca_";
   $self->{ziphome} = "https://archive.org/compress/usgs_drg_ca_";

   $self->{filetypes} = ["tif", "tfw", "xml_meta", "xml_files"];

   return bless $self, $type;
}

sub pathto_xml_meta {
   my ($self, $quad) = @_;
   my $index = substr($quad,1,5);
   my $qu = substr($quad,6,7);
   return "$self->{maphome}${index}_$qu/usgs_drg_ca_${index}_${qu}_meta.xml";
}

sub pathto_xml_files {
   my ($self, $quad) = @_;
   my $index = substr($quad,1,5);
   my $qu = substr($quad,6,7);
   return "$self->{maphome}${index}_$qu/usgs_drg_ca_${index}_${qu}_files.xml";
}

sub pathto_tfw {
   my ($self, $quad) = @_;
   $index = substr($quad,1,5);
   my $qu = substr($quad,6,7);
   return "$self->{maphome}${index}_$qu/${quad}.tfw";
}

sub pathto_tif {
   my ($self, $quad) = @_;
   my $index = substr($quad,1,5);
   my $qu = substr($quad,6,7);
   return "$self->{maphome}${index}_$qu/${quad}.tif";
}

sub slurpList {
   $self = shift;
   $self->{total} = 0;
   $quadlist = "cdsort.pl";
   open(INPUT, "<$quadlist") or die "Can't get $quadlist\n";
   %quads = (); 
   %names = ();
   while (<INPUT>) {
      next if (/^#/);      # ignore comments
      @words = split (" ", $_);
      my $quad = $words[0];
      my $name = $words[3];
      for ($i = 4; $i < $#words - 7; $i++) {
          $name = $name . " " . $words[$i]; 
      }
	   $self->{abbr} = $words[$#words - 1];
	   #if ($abbr ne "CA") print $abbr,"\n";
      $quads{"$name"} = $quad;
      $names{"$quad"} = $name;
	   $self->{"$quad.abbr"} = $abbr;
      $self->{"$quad.name"} = $name;
      $self->{"$quad.SElong"} =
      $words[$#words - 4] ." ". $words[$#words - 3] ." ". $words[$#words - 2];
      $self->{"$quad.SElat"} = 
      $words[$#words - 7] ." ". $words[$#words - 6] ." ". $words[$#words - 5];
      $self->{total}++;
   }
   close (INPUT);
   #print qq|California:  found $self->{total} quads in $state\n|;
}

1;

__END__

=head1 NAME

country - Object to represent California index to USGS maps

=head1 SYNOPSIS

use California;

=head1 DESCRIPTION

This module contains support for manipulating USGS maps of California.

=head1 BUGS

Speling is horibl in this part.

=head1 AUTHOR

Douglas Landau

Copyright 1999-2022 Douglas Landau.  All rights reserved.
