OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.82k stars 2.52k forks source link

when use ogr2ogr -f "DXF" i try to place a label with label style. But doesn't work #835

Open Tarot67 opened 6 years ago

Tarot67 commented 6 years ago

Hello,

I use a GPKG label_dxf.gpkg

layer of table named:label_dxf with attribute: nom : Text string geom: POINT name_layer: use with "As Layer"

when i try

ogr2ogr -f "DXF" label.dxf label_dxf.gpkg -sql "SELECT geom, 'LABEL(f:Arial,t:'||nom||')' AS OGR_STYLE, name_layer As LAYER FROM label_dxf

I try too ogr2ogr -f "DXF" label.dxf label_dxf.gpkg -sql "SELECT geom, nom, 'LABEL(f:Arial,t:'||nom||')' AS OGR_STYLE, name_layer As LAYER FROM label_dxf

He create the DXF well. But the label not display in Autocad (there are a lot of layer name with all "nom" attribute in table label_dxf). And no text.

I search a solution for i longtime! I search on Issue tracker closed ticket. But i found nothing.

I don't know if it possible to write a label directly from ogr2ogr -f "DXF" ?

Operating system

For example: Arch linux 64bits

GDAL version and provenance

GDAL 2.3.1 version from arch linux

Regard,

JeanSeb

rouault commented 6 years ago

CC @atlight

atlight commented 6 years ago

This is on Windows, but the same deal should apply:

C:\Users\Alan\Documents\Tools\GDAL\2.3.1>ogr2ogr --version
GDAL 2.3.1, released 2018/06/22

C:\Users\Alan\Documents\Tools\GDAL\2.3.1>ogr2ogr -f "DXF" ../label.dxf ../labelpoints.gpkg -sql "SELECT geom, 'LABEL(f:Arial,t:'||nom||')' AS OGR_STYLE, name_layer As LAYER FROM labelpoints"
ERROR 1: DXF layer does not support arbitrary field creation, field 'OGR_STYLE' not created.

C:\Users\Alan\Documents\Tools\GDAL\2.3.1>ogrinfo -al ../label.dxf
INFO: Open of `../label.dxf'
      using driver `DXF' successful.

Layer name: entities
Geometry: Unknown (any)
Feature Count: 3
Extent: (331115.494950, 5841329.180341) - (331141.128116, 5841350.829974)
Layer SRS WKT:
(unknown)
Layer: String (0.0)
SubClasses: String (0.0)
Linetype: String (0.0)
EntityHandle: String (0.0)
Text: String (0.0)
OGRFeature(entities):0
  Layer (String) = lyr1
  SubClasses (String) = AcDbEntity:AcDbMText
  EntityHandle (String) = 20000
  Text (String) = MyName
  Style = LABEL(f:"Arial",t:"MyName",c:#000000)
  POINT (331115.494950073 5841350.82997449)

OGRFeature(entities):1
  Layer (String) = lyr9
  SubClasses (String) = AcDbEntity:AcDbMText
  EntityHandle (String) = 20001
  Text (String) = SomeOtherName
  Style = LABEL(f:"Arial",t:"SomeOtherName",c:#000000)
  POINT (331141.128115765 5841350.31038329)

OGRFeature(entities):2
  Layer (String) = lyr9
  SubClasses (String) = AcDbEntity:AcDbMText
  EntityHandle (String) = 20002
  Text (String) = Whatever
  Style = LABEL(f:"Arial",t:"Whatever",c:#000000)
  POINT (331120.864059103 5841329.18034131)

The resulting DXF file indeed has three labels at the correct locations when viewed in Autodesk Viewer (the AutoCAD online viewer).

Can you please try uploading the file to the AutoCAD online viewer (you need to sign up with a free Autodesk account)? I'm not sure what else to suggest, since it works for me (on Windows).

Tarot67 commented 6 years ago

I try with three element

select layer As layer, 'LABEL(t:sting)' AS OGR_STYLE, geom from table

It work label as display correctly. My problem is simple i forgotten to declare "As layer" in my complex SQL request on some terms. Now it's almost OK.

But i have again a very strange problem. When i use several label with 'LABEL(t:string,s:xxxg,p:5)' AS OGR_STYLE. When i open the DXF file in libreCAD it's OK!. In QGis it's OK and when i open in AutoCAD the file not open!. I try to found exactly why. And i post the problem if i reproduce several time the problem.

Regard,

JeanSeb

Thank

Tarot67 commented 6 years ago

Ok. I found the problem

TEXT is not the problem!!!.

The problem come from "width" of PEN tools. When you tape a style like that:

'PEN(t:blabla,w:3g)' AUTOCAD doesn't open the file!!!!

when i try whithout

'PEN(t:blabla)' AUTOCAD open the file properly no problem

I think a good practice to remove w from style for PEN tools for DXF driver!!!.

If you want i can sent you the 2 files and you try your self

Thank you

JeanSeb

Tarot67 commented 6 years ago

I found another problem!.

The DXF open without problem with autocad 2015 and autocad map 3D 2015. But in 2019 the dxf must crash Autocad ;) i think there again something wrong but what ????. My collegue has huge works and it's difficulte to debug probleme for now.

I sent the dxf it's open without problem with autocad 2015 but not 2019. (I know that specifications of DWG in 2018 version has change but it's perharps change too DXF ???) reseau_CC48.zip

Tarot67 commented 6 years ago

Perhaps a solution is write DXF version 2010 in DXF file ???

I don't know

Tarot67 commented 6 years ago

I try to change $ACADVER to AC1024 (Ver 2010) and the file doesn't open in Autocad 2015. There something change in DXF version 2018! (I think!)

Tarot67 commented 6 years ago

I do a try!.

I open my dxf file with autocad 2015 and i save as DXF v2010 the size file has change. And the DXF open in Autocad 2019!.

I try to compare your DXF v2004 vs DXF v2010 generate by autocad 2015. Th begining of file has identical almost at line 114 there 425 line differentes. I suppose there some difference between dxf v2004 and DXF v2010!. I'm stop here!. I try to save with autocad 2015 in DXF v2004 and try again. I search the difference

atlight commented 6 years ago

AutoCAD is notoriously fussy about which DXF files it will open. It's unsurprising that things have broken from one version to the next. Unfortunately I don't have access to AutoCAD 2019 at this time, so debugging this issue is going to be problematic.

There is no t parameter for PEN style tools. Did you mean something else?

Here is a simple GeoPackage consisting of a single line:

pentest.zip

Could you please try running ogr2ogr -f "DXF" pentest.dxf pentest.gpkg -sql "SELECT geom, 'PEN(w:3g)' AS OGR_STYLE FROM pentest" on your system. Try opening this file in AutoCAD 2019. Also try opening it with 2015, and save it as DXF v2004. If you could upload the resulting file (DXF v2004) here, that would be great.

Tarot67 commented 6 years ago

I try with you gpkg and i apply your command line. when try to open in autocad 2015 doen't work!.

But in librecad it works very well!.

If you want i can do other test. But i m in holliday this night!. But i'm active. I have a friend who has autocad for test.

I search all difference between 2 files i found some difference

exemple in HATCH command There are systematicaly: "330 1F"

But it's not explain in website of autodesk!!! http://help.autodesk.com/view/ACD/2017/ENU/?guid=GUID-7D07C886-FD1D-4A0C-A7AB-B4D21F18E484

HATCH 5

330 } not presente in gdal DXF 1F } not presente in GDAL DXF And some "block" are not same configuration ex: see between pictures below. the 8 batiments 62 }are in differente place in GDAL DXF 253 }are differente place in GDAL DXF somtimes i have a "0" in autocad rewrite i have "0.0" ???????? [difference_block](https://user-images.githubusercontent.com/35609968/43957490-48933092-9ca8-11e8-82df-b5b68efbdb7b.png) Thank you for your help and your time.
Tarot67 commented 6 years ago

I demande to my friend to export any DWG in DXF i found the famous 330 1F i think perhaps a "strange" separator" ???

I see in another LWPOLYLINE In autocad rewrite file

AUTOCAD

LWPOLYLINE 5

330 1F or sometimes 22EA ?? 100 AcDbEntity 8 NAME_OF_LAYER 62 253 AcDbEntity 8 NAME_OF_LAYER **in GDAL** LWPOLYLINE 5 8 NAME_OF_LAYER 100 AcDbEntity 70 0 There are some big block absent in GDAL but it's only simple variable ?? it's really necessary ??? JeanSeb
Tarot67 commented 6 years ago

I understand something when i see in autodesk https://www.autodesk.com/techpubs/autocad/acad2000/dxf/lwpolyline_dxf_06.htm

the commande 90,70 etc... are in SAME ORDER IN autocad DXF! but not in GDAL!! Hmmm!.

some commande are not on same place ex: "62 253" are not in AcDbEntitty but AcDbPolyline i compare with 3 DXF write by Autocad 2015 and GDAL DXF.

see in picture lwpolyline

Sorry for 2 pictures left GDAL version right Autocad version

You are right Autocad is very very fuzzy!!

Tarot67 commented 6 years ago

sorry i forgottent the second picture difference_block

Tarot67 commented 6 years ago

In GDAL you don't have this big block:

toto.txt

Tarot67 commented 6 years ago

And another very BIG block named ACAD_CIP_PREVIOUS_PRODUCT_INFO at END of DXF. I think not necessary!. it's probably wrote by Autocad for another Autocad can display like old version or something like that!!

Tarot67 commented 6 years ago

There 9houre difference between Melbourne (Aus) and Molsheim (Fr). I set my watch. I think 15h for you it's tme good for me ;)

atlight commented 6 years ago

There are a number of worrying differences between GDAL and AutoCAD there. I don't have time to investigate this any further right now, but it will need to be looked at.

Tarot67 commented 6 years ago

I see on code source juste for try something to test (i probably Break my local GDAL! ;). For now it works on librecad and recent version of Autocad. If someone have a problem open DXF i send a gpkg or shp! too bad for them. (I passed alot of time to create DXF file. But DXF is not a geodesic file standard format!, like gpkg, shp geojson). The file format DWG/DXF is much use in FRANCE! GRrrrrrrrr! by enterprises who do public work (on road, way, water network, and so on)

But!. I stay avaible for test!. And if you need to DXF conversion something like that!.

Regard,

JeanSeb

Tarot67 commented 6 years ago

like -> as Grrr! sorry

Tarot67 commented 6 years ago

I tested the dxf drivers succesfull

with Autocad 2015, Autocad MAP 3D 2015, brycsCAD linux v17, libreCAD.

not tested GstarCAD (i waiting resulte) ZWcad

Tarot67 commented 6 years ago

GstarCAD 2019 no problem at all

Tarot67 commented 6 years ago

DXF open without problem with ZWCAD PRO 2019

The problem appear in Autocad 2016 unitil 2019. With Autocad 2015 it work's!

Conclusion: the DXF with actual driver open good with Autocad until 2015 GStarCAD 2019 ZWCAD 2019 libreCAD

Tarot67 commented 6 years ago

I forgotten BrycsCAD !!

Tarot67 commented 6 years ago

With actual driver DXF in GDAL i succed to open dxf generate by GDAL drivers with this software list:

Conclusion: Autocad until 2015 GStarCAD 2019 ZWCAD 2019 libreCAD BricsCAD Draftsight 2018 (from Dassault System)

Tarot67 commented 5 years ago

for @atlight

Ok! I think i found a solution to problem. They are a python module "ezdxf". When i use in python and save it. It change a littlebit file (He add this famous 330,1F...) and now Autocad 2019 open DXF file!. The module are write by MOZMAN git URL: https://github.com/mozman/ezdxf

I sent several file to my contacts. I waiting again some answers.

regards,

JeanSeb

Tarot67 commented 5 years ago

@atlight

confirm gdal dxf file open with ezdxf (it's works with autocad 2016 until 2019!)

before install ezdxf: install ezdxf pip install ezdxf

python

import ezdxf g=ezdxf.readfile('dxffile') g.saveas('dxffile1')

and now dxffile1 open with autocad 2016 upto 2019!.

faridcher commented 4 years ago

This is on Windows, but the same deal should apply:

C:\Users\Alan\Documents\Tools\GDAL\2.3.1>ogr2ogr --version
GDAL 2.3.1, released 2018/06/22

C:\Users\Alan\Documents\Tools\GDAL\2.3.1>ogr2ogr -f "DXF" ../label.dxf ../labelpoints.gpkg -sql "SELECT geom, 'LABEL(f:Arial,t:'||nom||')' AS OGR_STYLE, name_layer As LAYER FROM labelpoints"
ERROR 1: DXF layer does not support arbitrary field creation, field 'OGR_STYLE' not created.

C:\Users\Alan\Documents\Tools\GDAL\2.3.1>ogrinfo -al ../label.dxf
INFO: Open of `../label.dxf'
      using driver `DXF' successful.

Layer name: entities
Geometry: Unknown (any)
Feature Count: 3
Extent: (331115.494950, 5841329.180341) - (331141.128116, 5841350.829974)
Layer SRS WKT:
(unknown)
Layer: String (0.0)
SubClasses: String (0.0)
Linetype: String (0.0)
EntityHandle: String (0.0)
Text: String (0.0)
OGRFeature(entities):0
  Layer (String) = lyr1
  SubClasses (String) = AcDbEntity:AcDbMText
  EntityHandle (String) = 20000
  Text (String) = MyName
  Style = LABEL(f:"Arial",t:"MyName",c:#000000)
  POINT (331115.494950073 5841350.82997449)

OGRFeature(entities):1
  Layer (String) = lyr9
  SubClasses (String) = AcDbEntity:AcDbMText
  EntityHandle (String) = 20001
  Text (String) = SomeOtherName
  Style = LABEL(f:"Arial",t:"SomeOtherName",c:#000000)
  POINT (331141.128115765 5841350.31038329)

OGRFeature(entities):2
  Layer (String) = lyr9
  SubClasses (String) = AcDbEntity:AcDbMText
  EntityHandle (String) = 20002
  Text (String) = Whatever
  Style = LABEL(f:"Arial",t:"Whatever",c:#000000)
  POINT (331120.864059103 5841329.18034131)

The resulting DXF file indeed has three labels at the correct locations when viewed in Autodesk Viewer (the AutoCAD online viewer).

Can you please try uploading the file to the AutoCAD online viewer (you need to sign up with a free Autodesk account)? I'm not sure what else to suggest, since it works for me (on Windows).

Does it mean the error is completely irrelevant here? I am facing the same issue now. Why not to make the error message disappear because ogr2ogr produce the correct dxf file?

Although ogr2ogr succeeds at converting the file even with the error message, this error prevents me from creating the dxf file from sf (R binding for GDAL):

> st_write(x,'b-sf.dxf', driver='DXF', dataset_options=c("HEADER=b.dxf", "TRAILER=b.dxf"), delete_dsn=TRUE)
Deleting source `b-sf.dxf' failed
options:        HEADER=b.dxf TRAILER=b.dxf 
Writing layer `b-sf' to data source `b-sf.dxf' using driver `DXF'
Creating field OGR_Style failed.
Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  : 
  Layer creation failed.
In addition: Warning messages:
1: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 4: Unable to open b-sf.dxf to obtain file list.
2: In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options),  :
  GDAL Error 1: DXF layer does not support arbitrary field creation, field 'OGR_Style' not created.