I am trying to convert an OpenStreetMap file into a shapefile, but I am having problems with the "tags" field being cut-off after 80 characters. With QGIS 1.4, I use the OpenStreetMap plugin to 'Load OSM from file'. The file loads in QGIS. If I right-click on the 'lines' layer and select 'Save as shapefile', I end up with a shapefile but one that has an 80 char limit on "tags". How can I increase this 80 character limit?
QGIS OpenStreetMap – How to Overcome Field Truncation When Converting OSM to Shapefile
openstreetmapqgis
Related Solutions
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.
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
If you have your data in a QGIS layer, and a separate layer from a postgis table visible, you can always
- zoom to the extent of the QGIS layer
- select all features with a rectangle
- make the postgis layer editable
- Edit -> Insert the objects
- Save the postgis layer
- Toggle Edit mode of the postgis table off
Best Answer
You can also import the data into a PostgreSQL/Postgis database and you will not have that limit. Use the osm2pgsql utility
http://wiki.openstreetmap.org/wiki/Osm2pgsql