3

I like to convert this DXF file to ESRI Shapefiles. I tried the following command:

ogr2ogr -f "ESRI Shapefile" test.shp Umweltzone-Neu-Ulm.dxf              

... which output the following warnings and errors:

Warning 6: Normalized/laundered field name: 'ExtendedEntity' to 'ExtendedEn'
Warning 6: Normalized/laundered field name: 'EntityHandle' to 'EntityHand'
ERROR 1: Attempt to write non-polygon (LINESTRING) geometry to POLYGON type shapefile.
ERROR 1: Unable to write feature 1 from layer entities.
ERROR 1: Terminating translation prematurely after failed translation of layer entities (use -skipfailures to skip errors)

Inspecting the file with ogrinfo does not give a helpful advice for me:

ogrinfo -so -al Umweltzone-Neu-Ulm.dxf 
INFO: Open of `Umweltzone-Neu-Ulm.dxf'
      using driver `DXF' successful.

Layer name: entities
Geometry: Unknown (any)
Feature Count: 3
Extent: (573038.389500, 5359699.934800) - (576023.432710, 5361356.286500)
Layer SRS WKT:
(unknown)
Layer: String (0.0)
SubClasses: String (0.0)
ExtendedEntity: String (0.0)
Linetype: String (0.0)
EntityHandle: String (0.0)
Text: String (0.0)

Also, from the Extent I am guessing that the EPSG code is different to 4326. But which?

What is the correct command to perform the conversion?

Related

2
  • 1
    You have mixed geometries that can't be saved to a single shapefile
    – Ian Turton
    Commented Jan 26, 2020 at 15:49
  • @IanTurton Is there anything I can do about this? Can I extract one geometry and then the other?
    – JJD
    Commented Jan 26, 2020 at 16:00

1 Answer 1

1

I guessed the SRS to EPSG:25832 (UTM 32N) by looking at the DXF file with QGIS.

With ogr2ogr:

ogr2ogr -f GeoJSON umweltzone.geojson Umweltzone-Neu-Ulm.dxf -limit 1 -s_srs EPSG:25832 -t_srs EPSG:4326
  • -f GeoJSON output format
  • umweltzone.geojson output file name
  • Umweltzone-Neu-Ulm.dxf input file name
  • -limit 1 output only one feature per layer
  • -s_srs EPSG:25832 source srs
  • -t_srs EPSG:4326 target srs

you can create a geojson file. Looking at the source file, it shows there are three features: a point, a linestring and a polygon.
Limiting the feature (and knowing the polygon is the first one) gives you the polygon. You can omit the limit parameter and you'll get all three features.

edit: with -f 'ESRI Shapefile' instead of GeoJson you will get a shapefile

edit: to create a Shapefile for each feature type you have to run ogr2ogr for each type

ogr2ogr -f "ESRI Shapefile" umweltzone_point.shp Umweltzone-Neu-Ulm.dxf -nlt Point  -s_srs EPSG:25832 -t_srs EPSG:4326 -skipfailures
ogr2ogr -f "ESRI Shapefile" umweltzone_line.shp Umweltzone-Neu-Ulm.dxf -nlt LINESTRING  -s_srs EPSG:25832 -t_srs EPSG:4326 -skipfailures
ogr2ogr -f "ESRI Shapefile" umweltzone_polygon.shp Umweltzone-Neu-Ulm.dxf -nlt POLYGON  -s_srs EPSG:25832 -t_srs EPSG:4326 -skipfailures

You have to use the -skipfailures parameter, because it is not possible to write different geometry types to one shapefile.

2
  • It's a stab at an answer, but it doesn't really address the issue. What if you want three shapefiles, one for each feature type (point, line, polygon)
    – nmtoken
    Commented Jan 28, 2020 at 19:22
  • you could also filter the geomtype for each shapefile, so you do not get so much error messages: -where "ogr_geometry = 'LINESTRING'
    – Thomas B
    Commented Mar 28 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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