From f395d9989b1591d1a553cf811e2f218493055937 Mon Sep 17 00:00:00 2001 From: Bryce Nordgren Date: Thu, 8 Dec 2016 14:13:02 +0000 Subject: [PATCH] contours working with remote postgis db and GridFloat format NED files --- NED.py | 17 +++++++++-------- common.py | 2 +- env.py | 5 +++++ set-toposm-env.templ | 1 + 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/NED.py b/NED.py index 3b44f12..257b585 100644 --- a/NED.py +++ b/NED.py @@ -22,7 +22,7 @@ def getTilepath(basename): return os.path.join( - NED13DIR, basename + '.tif') + NED13DIR, "float{0}_13.flt".format(basename)) def getTiles(envLL): """Gets the (basename, Box2d) of all (existing) 1/3 NED tiles @@ -96,16 +96,17 @@ def analyzeContoursTable(): runSql(sql) def prepDataFile(basename, env): - geotiff = getTilepath(basename) + nedfile = getTilepath(basename) # split the GeoTIFF, since it's often too large otherwise for y in numpy.arange(env.miny, env.maxy, STEP): for x in numpy.arange(env.minx, env.maxx, STEP): nedslice = getSlice('ned', x, y) if not path.isfile(nedslice): - print ' Cutting geotiff slice...' - cmd = 'gdalwarp -q -te %f %f %f %f "%s" "%s"' % \ - (x, y, x+STEP, y+STEP, geotiff, nedslice) + print ' Cutting NED slice...' + cmd = 'gdalwarp -te %f %f %f %f "%s" "%s"' % \ + (x, y, x+STEP, y+STEP, nedfile, nedslice) + print cmd os.system(cmd) contourbasefile = path.join(TEMPDIR, 'contours_' + str(x) + '_' + str(y)) @@ -120,14 +121,14 @@ def prepDataFile(basename, env): print ' Reprojecting contour lines...' # NOTE: The s_srs is not required with most GDAL/OGR versions cmd = 'ogr2ogr -s_srs "%s" -t_srs "%s" -f "ESRI Shapefile" "%s" "%s"' % \ - (NAD83_PROJECTION_DEF, MERCATOR_PROJECTION_DEF, \ + (NAD83_PROJECTION_DEF, MT_STATE_PROJECTION_DEF, \ contourfileproj, contourfile) os.system(cmd) print ' Importing contour lines...' # NOTE: this assumes that the table is already set up - cmd = 'shp2pgsql -a -g way "%s" "%s" | psql -q "%s"' % \ - (contourfileproj, CONTOURS_TABLE, DATABASE) + cmd = 'shp2pgsql -a -g way "%s" "%s" | psql -q -U %s -h %s "%s"' % \ + (contourfileproj, CONTOURS_TABLE, DB_USER, DB_HOST, DATABASE) os.system(cmd) # Clear contents (but keep file to prevent us from importing diff --git a/common.py b/common.py index d888a8c..f48db2a 100644 --- a/common.py +++ b/common.py @@ -61,7 +61,7 @@ def writeEmpty(filename): open(filename, 'w').close(); def runSql(sql): - command = "psql -d %s -q -c \"%s\"" % (DATABASE, sql) + command = "psql -h %s -U %s -d %s -q -c \"%s\"" % (DB_HOST, DB_USER, DATABASE, sql) print command os.system(command) diff --git a/env.py b/env.py index 979760f..b9f531c 100644 --- a/env.py +++ b/env.py @@ -20,6 +20,8 @@ BASE_TILE_DIR = os.environ['BASE_TILE_DIR'] CONTOURS_TABLE = os.environ['CONTOURS_TABLE'] DATABASE = os.environ['DB_NAME'] +DB_USER = os.environ['DB_USER'] +DB_HOST = os.environ['DB_HOST'] TEMPDIR = os.environ['TEMP_DIR'] NED13DIR = os.environ['NED13_DIR'] COLORFILE = os.environ['COLORFILE'] @@ -62,6 +64,9 @@ REFERENCE_TILESET = 'composite_h' LATLONG_PROJECTION_DEF = "+proj=latlong" +MT_STATE_PROJECTION_DEF = "+proj=lcc +lat_1=49 +lat_2=45 +lat_0=44.25 " + \ + "+lon_0=-109.5 +x_0=600000 +y_0=0 +ellps=GRS80 +datum=NAD83 " + \ + "+units=m +no_defs" MERCATOR_PROJECTION_DEF = "+proj=merc +a=6378137 +b=6378137 " + \ "+lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m " + \ "+nadgrids=@null +no_defs +over" diff --git a/set-toposm-env.templ b/set-toposm-env.templ index 0013304..ae57d70 100644 --- a/set-toposm-env.templ +++ b/set-toposm-env.templ @@ -10,6 +10,7 @@ export DB_PORT=5432 # local postgres port export DB_PREFIX="planet_osm" # prefix for all tables export DB_USER="mapnik" # username export DB_PASS="mapnik" +export PGPASSWORD=$DB_PASS export CONTOURS_DB="ned" export CONTOURS_TABLE="contours" export NHD_DB="nhd"