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

The TN 911 Project – The Garage.

The TN 911 Project – The Garage.

I've been trying to write more as I get into this "New Life" thing since January. I'm not a developer. There was a time I did give it a go and it wasn't my thing. I can write small programs that scratch an itch but they aren't for mass consumption. I have found a...

I edited ArcPy Code

I edited ArcPy Code

It made me sad. I'm working on a project involving 911 data and it's made me do quite a bit of thinking. The short story on this is it's not in Tennessee. I'm taking data in it's raw form and shoving it into that state's NG911 format. So I have about half of it...

Update on the TN 911 Database

After not saying much up here for the last month - here's an update on the TN 911 Database. To catch you up if you don't know - Tn has a NG911 setup and generally 97% of everyone is running ESRI Arc Something to input data. A few years ago I moved one county over to...