3

I trie to convert a DXF file into a GeoJSON file with:

ogr2ogr -f 'GeoJSON' -sql "SELECT * FROM entities WHERE layer = 'geom_test'" test.json dfxtest.dxf

Is it possible to convert only geometries with for example the type point?

Are there documentations or explanations on how to use ogr2ogr with dxf?

1 Answer 1

3

GDAL supports two SQL dialects: the default OGR dialect and an alternative SQLite (Spatialite) dialect. Both dialect support selecting geometries by geometry type. Ogrinfo tool is recommended for experiments because by using it the possible troubles with writing the result out can be avoided. If output from ogrinfo is good then the reading side is OK too.

http://www.gdal.org/ogr_sql.html

http://www.gdal.org/ogr_sql_sqlite.html

Making a selection by geometry type with the OGR SQL dialect:

ogrinfo -sql "select * from entities where Layer='New' and OGR_GEOMETRY='POINT'" dxftest.dxf

Making a selection by geometry type with the SQLite SQL dialect:

ogrinfo -dialect sqlite -sql "SELECT * FROM entities WHERE layer='New' and GeometryType(geometry)='POINT'" dxftest.dxf
9
  • I get an error that the column doesn't exist ERROR 1: In ExecuteSQL(): sqlite3_prepare(SELECT * from entities WHERE layer ='geom_test' and GeometryType='POINT'): no such column: GeometryType
    – Martin
    Nov 17, 2014 at 14:40
  • Sorry, I sent too early. Should work by using valid SQL and GeometryType(geometry)='POINT'
    – user30184
    Nov 17, 2014 at 14:51
  • With GeometryType(geometry) the function doesn't throw an error. But the json file is still nearly empty and doens't contain the features {"type": "FeatureCollection", "features": [ ] }
    – Martin
    Nov 17, 2014 at 15:02
  • I found only one simple .dxf file from my computer. Ogrinfo reports only one layer which is "entities". For that file this command gives a good result ogrinfo -dialect sqlite -sql "select * from entities where GeometryType(geometry)='POINT'" test_dxf.dxf
    – user30184
    Nov 17, 2014 at 15:06
  • I tried this for my test dxf. When I used WHERE = layer = 'geom_test' all the features are displayed with POINT as the geometry info. When I use WHERE GeometryType(geometry) = 'POINT' it finds nothing. Is probably the dxf broken?
    – Martin
    Nov 17, 2014 at 15:17

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.