-1

Looking for an open source solution to extract CAD annotations to one or several common OGR vector formats (DXF, Geopackage, shapefile ..). Output data must contains at least text and rotation.

  • possible duplicated gis.stackexchange.com/questions/63274/… – Fran Raga May 1 at 18:40
  • It gives solutions using FME or ArcMAP. Looking for an open source solution, the whole point is to avoid proprietary software. – nicolasPrl May 1 at 19:01
  • DWG to DXF conversion with TeighaFileConverter (now ODA File Converter ?), then conversion in SHP or other format with OGR. The resulting file may have the text, but no other features like rotation. – nicolasPrl May 1 at 22:12
0

QGIS has a plugin named, dxf2shape. There is an option to convert Cad Text to shapefile Points. Each point will be located at the Text origin and contain the Cad Text string in an attribute. Shapefiles cannot store Annotation.

  • It works. What i did: DWG to DXF conversion using TeighaFileConverter CLI ; DXF import and SHP transformation using the dxf2shape plugin. The point shapefile has among other fields: text, style, size and angle. Perfect, thanks. – nicolasPrl May 1 at 22:25
  • I also recommend the plugin Another DXF to Shapefile Converter – she_weeds May 1 at 22:28
0

QGIS 3.x comes with an in built dwg to gpkg converter under Project > Import (something like that, will edit this comment). This saves you the step of needing another program to save the dwg as a dxf.

  • This is great too! thank you. Quick test and comparison with the dxf2shape plugin: pros -> GPKG. Straight conversion, no need to save as DXF first. cons -> with my sample data, some annotation are missing after the import. Some block are incomplete. I can import only one DWG, whereas the plugin allows several DXF. – nicolasPrl May 1 at 22:54
  • Yes I generally prefer to use the dxf plugins. DWG support is limited in the FOSS GIS world as it is a proprietary binary format unlike dxf (which is actually a readable text file!) – she_weeds May 2 at 0:10
0

After playing a bit ... OGR does have solutions to extract more informations from DXF.

See : https://www.gdal.org/ogr_feature_style.html

Using OGR_STYLE with ogrinfo/ogr2ogr CLI

ogrinfo PROJET.dxf -sql "select OGR_STYLE from entities where Layer = '3ZONCOMMTEX'"

Style = LABEL(f:"Arial",t:"Route",p:1,a:32.1,s:2.5g,c:#000000)

GetStyleString() function (OGR Python Binding)

import ogr

driver = ogr.GetDriverByName("DXF")
source = driver.Open("PROJET.dxf")
layer = source.GetLayer()
fields = layer.GetLayerDefn()

for feat in layer:
    style = feat.GetStyleString()
    print(style)
    # LABEL(f:"Arial",t:"Route",p:1,a:32.1,s:2.5g,c:#000000)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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