Skip to content

Commit

Permalink
contours working with remote postgis db and GridFloat format NED files
Browse files Browse the repository at this point in the history
  • Loading branch information
bnordgren committed Dec 8, 2016
1 parent e291e07 commit f395d99
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
17 changes: 9 additions & 8 deletions NED.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

5 changes: 5 additions & 0 deletions env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions set-toposm-env.templ
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f395d99

Please sign in to comment.