[GIS] Converting OpenStreetMap data to shapefile using OGR

gdalogropenstreetmapshapefile

How would I reliably convert OSM-data (.osm, .kml, .gpx or .geojson) to .shp?
ogr2ogr seems have issues:

geojson:

$ogr2ogr -f "ESRI Shapefile" destination_data.shp export.geojson   
ERROR 6: Can't create field alt_name31 in Shape DBF file. Maximum record length reached.    
Warning 6: Normalized/laundered field name: 'alt_name:fa' to 'alt_name31' 

kml, gpx:

$ogr2ogr -f "ESRI Shapefile" destination_data.shp export.kml  -lco ENCODING=UTF-8   
Warning 6: Normalized/laundered field name: 'Description' to 'Descriptio'   
Warning 1: Value '...' of field Descriptio has been truncated to 254 characters.

And encoding is off.

Best Answer

ESRI Shapefile's field name can be up to certain characters limitation. supposed if you try to convert from GeoJSON to Shapefile then try to change your geoJSON property "alt_name31" to "altnam" And try it.

But if you have *.osm file then bellow code may be easily doing your job.

 $ogr2ogr -f "ESRI Shapefile" destination_data.shp export.osm multipolygons

The OSM driver will categorize features into 5 layers: points, lines, multilinestrings, multipolygons, and other_relations. So you have to pass anyone at the end of the command which you desire.