Hi Javier,
I don't know much about DXF, but if you had a GeoJSON file named
styled_points.geojson with ("style" just an arbitrary field name):

{
"type": "FeatureCollection",
"name": "styled_points",
"features": [
{ "type": "Feature", "properties": { "style": "PEN(c:#00ff00)" },
"geometry": { "type": "Point", "coordinates": [ 1.0, 1.0 ] } },
{ "type": "Feature", "properties": { "style": "PEN(c:#ff0000)" },
"geometry": { "type": "Point", "coordinates": [ 1.0, 2.0 ] } },
{ "type": "Feature", "properties": { "style": "PEN(c:#0000ff)" },
"geometry": { "type": "Point", "coordinates": [ 1.0, 3.0 ] } }
]
}

then

$ ogr2ogr -of DXF -sql 'SELECT style as OGR_STYLE, "_ogr_geometry_" from
styled_points' styled_points.dxf styled_points.geojson

creates a DXF file showing

$ ogrinfo styled_points.dxf entities
INFO: Open of `styled_points.dxf'
      using driver `DXF' successful.

Layer name: entities
Geometry: Unknown (any)
Feature Count: 3
Extent: (1.000000, 1.000000) - (1.000000, 3.000000)
Layer SRS WKT:
(unknown)
Layer: String (0.0)
PaperSpace: Integer(Boolean) (0.0)
SubClasses: String (0.0)
Linetype: String (0.0)
EntityHandle: String (0.0)
Text: String (0.0)
OGRFeature(entities):0
  Layer (String) = 0
  SubClasses (String) = AcDbEntity:AcDbPoint
  EntityHandle (String) = 20000
  Style = PEN(c:#00ff00)
  POINT (1 1)

OGRFeature(entities):1
  Layer (String) = 0
  SubClasses (String) = AcDbEntity:AcDbPoint
  EntityHandle (String) = 20001
  Style = PEN(c:#ff0000)
  POINT (1 2)

OGRFeature(entities):2
  Layer (String) = 0
  SubClasses (String) = AcDbEntity:AcDbPoint
  EntityHandle (String) = 20002
  Style = PEN(c:#0000ff)
  POINT (1 3)



Chris Toney


On Thu, Apr 24, 2025 at 9:03 AM Javier Jimenez Shaw via gdal-dev <
gdal-dev@lists.osgeo.org> wrote:

> Hi
>
> I am trying to convert a GeoJSON to DXF with ogr2ogr. I have control over
> the GeoJSON: I can add whatever I want to the "properties", like "color:
> '#00ff00'"
>
> How can I make that color appear in the DXF? I know there are the OGR
> styles like
> PEN(c:#00ff00)
> (I can write that into the GeoJSON)
> but I do not know how to "transfer" the style automatically while
> using ogr2ogr.
> I guess I need some sql black magic there.
>
> Thanks
> Javier.
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev@lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>
_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to