Loading a DEM into PostGIS

Nov 5, 2021 | 911, postgis, Projections

I haven’t mentioned the TN911 project in a while. Work happens on that when I have time or are motivated – I took a bit of a break to pursue some other tech rabbit holes. I ended up back on it due to some work with pyqgis/addressing questions which led me back to the TN 911 Standard.

My thought on the database is to let it do most of the work. There is some work that occurs in qgis but:

  • date attributes are assigned at the database
  • street concatenation happens there
  • a lot of quality control happens there

In the TN NG911 standard every point needs an elevation. TN also has LIDAR data to provide that elevation. Deriving the elevation with QGIS is easy enough – how hard would it be to store it all in PostGIS?

Not that hard. You can run this if you have postgis installed:

raster2pgsql -C -I -M -F -Y -l 5 -s 2274 -t 100x100 dem.tif tn911.dem > ng911_dem.sql

I leave it up to you to dig through all the commands in the raster2pgsql command.

Once loaded into the database with psql the DEM appears much like you’d expect in QGIS. I connect to the database and add it.

The nice thing is I can now update all the addresses and set up triggers to handle this with new addresses:

update tn911.address_points set z_val = round(st_value(rast, a.geom)/3.28081) from tn911.dem,tn911.address_points as a WHERE ST_Intersects(rast, a.geom)=true;

My biggest issue in doing this was actually the projection. The vector data is in EPSG:2274. The DEM data resides in EPSG:6576. I generally try to retain data projections – but I was having to transform (project on the fly) my calculations. Which made everything slower. So I moved the DEM to EPSG:2274.

Anyway – one more thing done for the standard. Next up some pyqgis and some data quality checks.

You may also like

NENA 911 Database in QGIS

NENA 911 Database in QGIS

I work with two counties in TN with the TN NG911 standard. Flash back 10 years ago and I hadn't really grasped how complicated address is. Do I like it? Mostly Yes. Occasionally I get questions from outside TN and I demo the two counties and how that works. A while...

Unintended Joy

Unintended Joy

I was originally going to call this unintended consequences but - there was a small amount of joy at the end. In Tennessee you have 6 layers that are required by the NG 911 group. So you end up with a lot of information depending on the county being poured into the...

Type in the TN NG911 Database

Type in the TN NG911 Database

THE PLAN.....there was a plan. Oh yes - the plan is to make editing and creating data in TN for the 911 addressing system to be as easy as possible. Menus and Triggers abound and now as two counties are using this with a third on the horizon - HOW do I make this...