I'm trying to convert closed polylines into polygons using ogr2ogr from dxf to mssql. Here It says that polylines are converted into POLYGON if they are closed, but I always get the type LINESTRING instead of POLYGON in the geometry type column. I also tried to convert DXF into Shapefile and into a MySQL database with same results. Converting Shapefiles with polygons into databases works well, so I think the problem is in the gdal dxf driver.
Can someone explain to me what I am doing wrong?
Here is the command I'm running
ogr2ogr -update -append -f MSSQL "MSSQL:server=.\SQLEXPRESS;database=testdb;trusted_connection=yes" test.dxf
Best Answer
You should send a small example of such DXF file. It looks like DXF driver really does not behave as documented. I made a simple test by digitizing a closing triangle with four coordinates as a polygon and as a linestring
I made a roundtrip by saving geometry into shapefile -> convert shapefile into DXF with ogr2ogr -> checking the DXF file with ogrinfo. If DXF driver behaves as documented both DXF files should contain a polygon. However, that is not the case with the closed linestring
Unfortunately this does not solve your problem but only confirms it. Moreover, the documentation of DXF driver seems to be wrong in other places as well. It claims that GDAL is writing polygons as LWPOLYLINE. However, from the DXF which I converted from the polygon shape I can find that entity HATCH is used:
This is how GDAL creates a polygon:
This is how a closed linestring was defined:
For me it feels like you don't do anything wrong and you should ask from the gdal-dev mailing list if you have found a bug in the DXF driver or in the documentation. Attach a small DXF sample, a closed triangle as I used in my test should be perfect.