Introduction
This will likely require significant amount of manually work to detect and remove the duplicated data. When you're detecting and resolving the duplicate data; you'll want both sources to be in the same geo format: shapefile, PostGIS DBs, or as OSM data.
Workflow
The following workflow is based on having both sources of data as OSM before merging and resolving duplicate data.
There's a couple options to convert the data into OSM:
A]
- Convert the shapefile data into OSM however you'd like.
Versions of ogr2ogr released in 2013 or later (version 1.10 or later, IIRC) can also convert SHP to OSM. There's also
ogr2osm
as you had noted: there's a couple different versions of ogr2osm, no matter which one you use - I prefer pnorman's, it's the most up-to-date. No matter what, make sure the translation files are compatible with the version of ogr2osm that you're using (for the sake of simplicity, the ones that I've linked to should be compatible with the version of ogr2osm). See here as examples for translation files that are compatible with pnorman's ogr2osm.
Ensure the translation file is complete with of all the information that you want in your shapefile. The translation file will convert your Types and attributes of the shapefile into what OSM calls Tags, which consist of Keys and Values.
1a. run ogr2osm.
Open josm, download the conflation plugin
Your gov data is now a osm file. Open josm, File > open
Your data is there as a layer.
If you already have the OSM data locally stored on your computer, open it in josm, it will also open as a new layer.
Merging these two sources of data together and resolving the duplicate data is known as conflation. Run the conflation plugin and resolve all of the conflicts.
If JOSM runs out of memory (e.g., when using large files), separate the types of attributes and complete this workflow multiple times, each with a different kind of data (e.g. boundaries and land uses; highways; buildings), and then finally merge the osm files together using osmium or another tool.
B. JOSM can also read shapefiles although SHP support isn't perfect and this method assumes the shapefile can be loaded entirely into memory...
- Start JOSM.
- Open the shapefile (e.g.,
filename.shp
).
- Select all.
- In JOSM, Edit the attributes and properties that were imported from the SHP, and change them so each attribute corresponding an OSM tag.
- Save as OSM format.
- Continue from A4 and conflate
Import as OSM
Import the OpenStreetMap data into the system as follows:
- Change to the directory containing OpenStreetMap (OSM) files converted using JOSM.
- Execute the following commands in the database:
CREATE EXTENSION hstore;
osm2pgsql -j -W \
-d osm filename.osm
The -j
option is key as it instructions osm2pgsql to import the tags into an hstore
column, this preserving the underlying data structure and will import all tags into the database.
Create Mapnik Layer
To have the data appear on the map, add a layer and a style for that layer. This can be as simple as the following:
- Edit
mapnik-stylesheets/osm.xml
.
- Insert the following XML code before the closing
</Map>
tag...
...
<Layer name="prefix_zone" status="on" srs="&osm2pgsql_projection;">
<StyleName>zones</StyleName>
<Datasource>
<Parameter name="table">
(select way from prefix_line order by tags desc, z_order) as zones
</Parameter>
&datasource-settings;
</Datasource>
</Layer>
Create Mapnik Style
Continuing from the previous section:
- Find the last
</Style>
tag (around line 3350).
- Insert the following XML code before the
&layer-shapefiles;
directive:
...
<Style name="zones">
<Rule>
&maxscale_zoom1;
&minscale_zoom19;
<LineSymbolizer stroke="#0065BD" stroke-width="2.5" />
</Rule>
</Style>
Roadmatcher
roadmatcher is another tool that might be helpful
Best Answer
If you want to have the same look as the background tiles, you have to use the same toolchain.
That requires to have a Postgis database filled with osm2pgsql.
The Openstreetmap plugin of QGIS has some limitations in the correct creation of multipolygons (although much better than the old plugin had some yers ago), and the ogr2ogr data provider used by "Add vector layer" has too.
The shapefiles from geofabrik are only a subset of the OSM database, with attention to roads. It might be that some kind of strange forest multipolygons are dropped there.
See this example for relation 3541951 missing in geofabrik shapefile detmold-regbez-latest.shp.zip:
Tagged as landuse=forest, but not in the landuse or natural layer.