Include object metadata using imposm?

I’m looking to import OSM data into a PostGIS database (for analysis, not rendering) using imposm. I’m interested in retaining some object metadata (version and timestamp). I can’t find any reference to this in the imposm documentation. Does imposm support retaining this information? Are there any alternatives besides osmosis to accomplish this?

1 Like

There may be a reason why you’re not using it, but osm2pgsql?

It’s very actively maintained and used, supports minutely updates, and very flexible, in that you can rewrite thing A as thing B when updating the database (via lua script).


There’s actually no reason other than me thinking osm2pgsql is only for rendering databases. I was just perusing the documentation and it looks like you can customize the schema quite a bit using Lua scripts. Not something I am too familiar with but it looks straightforward enough.

That said, if someone can help me out with a script that would just import highway=residential geometries with version, timestamp and changeset metadata, and name and tiger:reviewed tags, I’d be much obliged :slight_smile:

Not an answer to that question, but the “database reload” script I use here has pretty much everything you’d need in it. That uses “what columns to import” information from here and “what transformations to perform” here - but yours would be much simpler.

A couple of caveats - depending on what you mean by changeset metadata, it might be something you need to add after the event. If you want user info you can of course get that from Geofabrik, but I’ve never tried doing anything with that in lua. Some experimentation might be needed. Just in case you’re not aware, documentation is here.

There’s an example of importing roads for analysis in the osm2pgsql documentation. I’d start with that, and add in object.timestamp, object.version, and any other attributes from the parameter table that are relevant to you. You will need to use the -x|--extra-attributes command line flag, and, of course, the OSM extract needs to have the metadata.

This is also possible to do with older versions of osm2pgsql, going back about a decade, with the -x command line option and a suitable .style file, but I wouldn’t recommend that method for anything new, as the flex backend is more modern and has been around for long enough to be on all recent distributions.

You’d want something like

local tables = {}

tables.highways = osm2pgsql.define_way_table('highways', {
    { column = 'highway', type = 'text' },
    { column = 'name', type = 'text' },
    { column = 'tiger_reviewed', type = 'text' },
    { column = 'version', type = 'int' },
    { column = 'geom', type = 'linestring', projection = 4326 },

function osm2pgsql.process_way(object)
    if object.tags.highway then
        cols = {
          highway = object.tags["highway"],
          name = object.tags["name"],
          tiger_reviewed = object.tags["tiger_reviewed"],
          version = object.version}

Note: I’ve written this without running it, and you’ll have to double-check how to add timestamps. There might be a conversion needed to get it to timestamptz.

1 Like

I am not aware of any tool that imports changeset metadata into a database except this one which I created for some experiments and which is rather cryptic to use. Your mileage may vary. But you could use that in combination with the data imported with osm2pgsql if needed.

1 Like

I used GitHub - zhm/osmchanges-postgres: OpenStreetMap changeset sync to PostgreSQL using the minute diffs a long time ago, and even contributed some performance fixes. No idea if it’s still working today.

HOT is also processing changeset metadata for their hashtag based stats:

Imposm3 - metadata.
As I know - not yet implemented.

I made a half-finished patch back in the day, and it worked to some extent, so if anyone wants to continue, here’s the link:

Even though @SomeoneElse was the first to suggest it, I will mark @pnorman’s response as the “solution” because he provides more background and an example. Thanks all for your responses, I am getting somewhere with osm2pgsql and learning some basic Lua in the process :slight_smile: