Some Bits: Nelson's log

4 posts in November 2013

Schematic of rivers

Inspired by this discussion I tried to bang out a quick map of just the biggest rivers in the US in schematic form. My idea was to sort them all by length and draw them side by side, like this awesome 19th century visualization, but without straightening them first. I counted up which gnis_ids in NHDPlus had the most rows (as a proxy for river size), then made a special vector map source with just those rivers.

select geometry, name, strahler, huc8 from merged_rivers where gnis_id in (  354236, 591690, 465582, 1034981, 78762, 517018, 42838, 1384150, 517033, 400069, 201759, 1091369,  425264,  485443, 1035255,  835960, 1428399, 1101881,   78956, 1385432,  837263, 1533479, 1629903,   45730,  756398)

Sadly the resulting image (attached here) doesn’t really work. Some things are screwed up, like the Platte River in Nebraska which just kind of ends. Also you run into the question of defining what a river is; why do we call the Missouri a separate river as opposed to folding it into the MIssissippi? I could show every single watershed that has a unique drainage to the oceans, but then that’s a fanned out watershed map instead of a nice linear river map. Needs more thinking.

Screen Shot 2013-11-21 at 3.14.05 PM

Vector rivers update, NHDPlus / PostGIS problem

Boy, code rots. I tried to re-generate my vector rivers map from data. The project’s well documented, it should be easy, right! Ha.

My imports failed like this:

$ shp2pgsql -a -D -t 2d -s 4269 -W LATIN1 ./NHD/NHDPlusGB/NHDPlus16/NHDSnapshot/Hydrography/NHDFlowline.shp
Shapefile type: ArcZ
Postgis type: MULTILINESTRING[2]
Error in fread() reading object of size 1112 at offset 41917076 from .shp file
Error reading shape object 43130

I downloaded a new datafile from the source and now it works. The downloaded 7z archive is the same, I wonder if there was a problem when I extracted the data and an older version of shp2pgsql didn’t catch it? It’s not just that one file though, NHDPlusMS/NHDPlus05 is bugging out too.

Update yeah I must have had a problem extracting some of the files. Surprised my import script didn’t notice before. I wonder if earlier versions of shp2pgsql weren’t as meticulous about error reporting? Or maybe I had a clean extract last time I did a full import. The 7z archiver I have to use doesn’t handle being interrupted very well, I suspect it leaves behind incomplete files.

Address schema for OSM

It’s lovely that OpenStreetMap has such a.. diverse schema. But it makes it hard to figure out how to encode stuff sometimes. I’m looking at importing a bunch of address data from other sources. What’s the right format?

The source data is diverse, but a common thing seems to be a Point mapped to a street name. Ie, the SF address database I downloaded says POINT(-122.408292 37.747785) 660 PRECITA AVE. Cool! There’s a lot of other data and ambiguity about exactly what that POINT encodes (street front? centroid of parcel? building?). But that’s a good place to start.

The OSM schema for addresses is reasonably well defined. Here are the most important tags, based on the Wiki pages for key:addr and Karlsruhe Schema

  • Parsed address: addr:housenumber, addr:street
  • Unparsed address: addr:full
  • Larger scale data: addr:city, addr:state, addr:country, addr:postcode

There’s additional complications for buildings with multiple addresses, and regions that don’t use city/state addressing (ie, addr:subdistrict), and interpolation, etc. Gonna punt on that and focus to what’s relevant for major US cities.

Another significant question is whether you tag the address data onto a building, or do you create a separate standalone address node. The latter approach seems necessary in the US where we don’t have building footprints for so many places. Although MapBox’s analysis is that the majority of addresses are on buildings.

Here’s a list of top address keys culled from TagInfo. I’ll note the majority of these are tags on nodes, not ways.

  • 26M: addr:housenumber
  • 23M: addr:street
  • 18M: addr:city
  • 14M: addr:postcode
  • 13M: addr:country

There’s a second group of keys that have hundreds of thousands of entries, but many fewer than those top 5 above

  • 1967k: addr:conscriptionnumber. (German addresses?)
  • 1605k: addr:interpolation
  • 842k: addr:state
  • 608k: addr:place
  • 500k-600k: addr:street:name, addr:street:type, addr:street:prefix
  • 463k: addr:streetnumber
  • 3896: addr:full
  • 280k-370k: addr:region, addr:district, addr:suburb

Here’s a bunch of maps of address data that people have made that are relevant. Some of these may not be for public consumption.

I’d like to double back and see what they do in Denmark. That country has very good geocoding data and an ongoing process to sync up with the official government data.