2

I am trying to use OGR2OGR to convert an .osm file to a .shp file:

ogr2ogr.exe --config OSM_USE_CUSTOM_INDEXING NO -skipfailures -f "ESRI Shapefile" output.shp input.osm

OGR2OGR does this pretty nicely, and converts the .osm file to four .shp files in the "output.shp" folder: lines.shp, multilinestrings.shp, multipolygons.shp, points.shp.

What I would like to do, is to force all four resulting .shp files to have equal number of attributes (or "keys" in openstreetmap terminology). For example, a polygon would certainly not have an attribute highway. While a line could have. But I still want to force the multipolygons.shp file to have the highway attribute. To make it clear, I am not interested in specific attributes. I would just want all of the upper 4 .shp files to have the same attributes, and the same number of attributes.

Can this be done somehow by editing the upper command? Or is this exclusively done by editing the osmconf.ini file? If yes, then how?

  • I suspect the answer is No and No, but I may be misunderstanding your question. To make it clearer can you provide more details about the attribute tables you are looking to be output from a couple of sample small inputs, please? – PolyGeo Oct 28 '16 at 2:26
  • 1
    You must just edit the osmconf.ini file to write the same set of attributes for all the layers. – user30184 Oct 28 '16 at 4:39
  • Thank you @user3018! PolyGeo: It can be any .osm file. Here is an example one from openstreetmap website: api.openstreetmap.org/api/0.6/map?bbox=11.54,48.14,11.543,48.145. I do not have any specific attributes in mind. Once the .osm file is converted to those 4 .shp files, I would just like for them to have equal attributes, and equal number of attributes. Not to have some specific attributes. – marco Oct 28 '16 at 12:31
3

The osmconf.ini file has a separate sections for defining the attributes for each layer (points, lines, multipolygons, multilinestrings, other_relations). This is the default setting for the "points" layer.

[points]
# common attributes
osm_id=yes
osm_version=no
osm_timestamp=no
osm_uid=no
osm_user=no
osm_changeset=no

# keys to report as OGR fields
attributes=name,barrier,highway,ref,address,is_in,place,man_made
# keys that, alone, are not significant enough to report a node as a OGR point
unsignificant=created_by,converted_by,source,time,ele,attribution
# keys that should NOT be reported in the "other_tags" field
ignore=created_by,converted_by,source,time,ele,note,openGeoDB:,fixme,FIXME
# uncomment to avoid creation of "other_tags" field
#other_tags=no
# uncomment to create "all_tags" field. "all_tags" and "other_tags" are exclusive
#all_tags=yes

If you copy-paste and use the same settings for all layer sections in osmconf.ini you will get the same set of attributes for all the layers.

2

The best way to get ALL attributes fields into GIS is using the QuickOSM plugin inside QGIS. It can work with pre-downloaded .osm files as well.

It creates geojson files, that can be converted into a spatialite database. That way you can preserve all key field names.

Using shapefile format, keys with : inside will be translated to _, and all field names will get truncated to 8 characters due to the shapefile format restriction. And the 2GB limit might hit you too.

You will not get all tables having the same number of attributes, since some attributes might apply to points only, or multipolygons only.

  • Thank you @AndreJ. I am limited with using GDAL libraries (OGR2OGR) only. And not calling them from QGIS. Thank you for the explanations of limitations of OGR2OGR. I didn't understand you this part: "You will not get all tables having the same number of attributes, since some attributes might apply to points only, or multipolygons only.". Does that mean that what user30184 suggested above will not work? Having the same settings for all layer sections in osmconf.ini will not result in having the same attributes? – marco Oct 28 '16 at 12:25
  • 1
    With osmconf.ini, you will get identical attribute lists, with my method not. – AndreJ Oct 28 '16 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.