EcohydroLib  1.29
Variables
GHCNDSetup Namespace Reference

Builds SQLite3/Spatialite database needed for querying NCDC Global Historical Climatology Network station metadata downloaded from http://www1.ncdc.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt. More...

Variables

string _sanitizeString = '[\'";]'
 
tuple SRS = int(4326)
 
string DB_NAME = 'GHCND.spatialite'
 
string URL = 'http://www1.ncdc.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt'
 
tuple parser = argparse.ArgumentParser(description='Build database of GHCN station metadata')
 
string help = 'Directory to which database named "GHCND.sqlite" should be placed'
 
tuple args = parser.parse_args()
 
tuple ghcnDB = os.path.join(args.outputDir, DB_NAME)
 
 url = URL
 
tuple conn = spatialite.connect(ghcnDB)
 
tuple cursor = conn.cursor()
 
tuple hasSpatial = cursor.fetchone()
 
tuple f = urllib.urlopen(url)
 
tuple line = f.readline()
 
tuple id = unicode(line[:11].strip(), errors='replace')
 
tuple lat = float(line[12:19].strip())
 
tuple lon = float(line[21:29].strip())
 
tuple elev = float(line[31:36].strip())
 
tuple name = unicode(line[41:70].strip(), errors='replace')
 
string sql = u"INSERT INTO ghcn_station (id,name,elevation_m,coord) VALUES ('%s','%s',%f,GeomFromText('POINT(%f %f)', %d) )"
 

Detailed Description

Builds SQLite3/Spatialite database needed for querying NCDC Global Historical Climatology Network station metadata downloaded from http://www1.ncdc.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt.

This database is indexed to allow fast spatial queries of station information.

Note
Requires pyspatialite 3.0.1.

This software is provided free of charge under the New BSD License. Please see the following license information:

Copyright (c) 2013, University of North Carolina at Chapel Hill All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Author
Brian Miles brian.nosp@m._mil.nosp@m.es@un.nosp@m.c.ed.nosp@m.u

Usage:

1 GHCNDSetup.py -o <output_dir>

Variable Documentation

string GHCNDSetup._sanitizeString = '[\'";]'
tuple GHCNDSetup.args = parser.parse_args()
tuple GHCNDSetup.conn = spatialite.connect(ghcnDB)
tuple GHCNDSetup.cursor = conn.cursor()
string GHCNDSetup.DB_NAME = 'GHCND.spatialite'
tuple GHCNDSetup.elev = float(line[31:36].strip())
tuple GHCNDSetup.f = urllib.urlopen(url)
tuple GHCNDSetup.ghcnDB = os.path.join(args.outputDir, DB_NAME)
tuple GHCNDSetup.hasSpatial = cursor.fetchone()
string GHCNDSetup.help = 'Directory to which database named "GHCND.sqlite" should be placed'
tuple GHCNDSetup.id = unicode(line[:11].strip(), errors='replace')
tuple GHCNDSetup.lat = float(line[12:19].strip())
tuple GHCNDSetup.line = f.readline()
tuple GHCNDSetup.lon = float(line[21:29].strip())
tuple GHCNDSetup.name = unicode(line[41:70].strip(), errors='replace')
tuple GHCNDSetup.parser = argparse.ArgumentParser(description='Build database of GHCN station metadata')
string GHCNDSetup.sql = u"INSERT INTO ghcn_station (id,name,elevation_m,coord) VALUES ('%s','%s',%f,GeomFromText('POINT(%f %f)', %d) )"
tuple GHCNDSetup.SRS = int(4326)
string GHCNDSetup.URL = 'http://www1.ncdc.noaa.gov/pub/data/ghcn/daily/ghcnd-stations.txt'
GHCNDSetup.url = URL