[gdal-dev] help needed with pygdaltools library, documentation sparse

Catania, Luke A ERDC-RDE-GRL-VA CIV Luke.A.Catania at erdc.dren.mil
Wed Oct 11 10:51:33 PDT 2023


I went with calling ogr2ogr through os.system, but another issue I have been having with the ogr2ogr is that my polygons are not converted to what I guess is considered in AutoCAD as hatches since that is the layer that is shown for those polygons when I open the DXF. I just get line features.  It basically creates a line feature out of the polygon, that is it  converts the triangle to a bisecting line.  I even specify the polygon in the command line options as opposed to linestring as well as tried just the geometry parameter you suggested and writing to a geopackage



DXF shown in DWG TrueView 2023
https://pasteboard.co/dit2y9zmJ5YT.png

DXF Converted by QGIS tool Import Layers from DWG/DXF
https://pasteboard.co/4XZwHus6NhAj.png


DXF Converted to Geopackage.
https://pasteboard.co/1wIMI9xRymkZ.png






-----Original Message-----
From: Rahkonen Jukka <jukka.rahkonen at maanmittauslaitos.fi<mailto:jukka.rahkonen at maanmittauslaitos.fi>>
Sent: Wednesday, October 11, 2023 2:12 AM
To: Catania, Luke A ERDC-RDE-GRL-VA CIV <Luke.A.Catania at erdc.dren.mil<mailto:Luke.A.Catania at erdc.dren.mil>>; Scott <public at postholer.com<mailto:public at postholer.com>>; gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>
Subject: Re: [gdal-dev] help needed with pygdaltools library, documentation sparse



Hi,



The actual error seems to be that you try to write some geometry that is not a linestring into a GeoPackage table that has created with a constraint that makes it accept only linestrings. You do that by using "-nlt linestring".

You have two options. The fast one is to use "-nlt geometry" that makes GeoPackage table to accept all kind of geometries. The other option is to filter the source data by geometry type and select only linestrings. Here is an example about how to do that with the OGR SQL dialect Blockedhttps://gdal.org/user/ogr_sql_dialect.html#ogr-geometryBlocked



Don't try to use "-nlt geometry" with shapefiles because that format does not support mixed geometrytypes.



-Jukka Rahkonen-



-----Alkuperäinen viesti-----

Lähettäjä: gdal-dev <gdal-dev-bounces at lists.osgeo.org<mailto:gdal-dev-bounces at lists.osgeo.org>> Puolesta Catania, Luke A ERDC-RDE-GRL-VA CIV via gdal-dev

Lähetetty: keskiviikko 11. lokakuuta 2023 8.59

Vastaanottaja: Scott <public at postholer.com<mailto:public at postholer.com>>; gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>

Aihe: Re: [gdal-dev] help needed with pygdaltools library, documentation sparse



I have not even gotten to see that anything is being ignored because I have not yet added any options.  My first attempt was with adding skipfailures, but I can't add any of the options I have listed because I have no idea how to.  I thought it would be gdal_tools.config_options() but I get pylint tells me it is not callable



-----Original Message-----

From: gdal-dev <gdal-dev-bounces at lists.osgeo.org<mailto:gdal-dev-bounces at lists.osgeo.org>> On Behalf Of Scott via gdal-dev

Sent: Wednesday, October 11, 2023 1:45 AM

To: gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>

Subject: Re: [gdal-dev] help needed with pygdaltools library, documentation sparse



-nln is being ignored because the data layer you're -updating -appending to exists. You can't rename a layer if it has a name. Remove -nln option



Next you are trying to write a collection as a linestring. Use -explodecollections (if exists in your install) and/or use -nlt PROMOTE_TO_MULTI



Try not to use -skipfailures



On 10/10/23 22:26, Catania, Luke A ERDC-RDE-GRL-VA CIV via gdal-dev wrote:

> I am running simple code to convert dxf to gpkg and I get the error

> below.  -am an trying to figure out how to add a bunch of options ( -f

> GPKG -append -update --config DXF_ENCODING CP1252 --config

> DXF_INCLUDE_RAW_CODE_VALUES TRUE --config

> DXF_TRANSLATE_ESCAPE_SEQUENCES FALSE --config

> DXF_MERGE_BLOCK_GEOMETRIES FALSE --config DXF_INLINE_BLOCKS TRUE -nlt

> LINESTRING -nln 32111_F)

>

> But can't even figure out how to add the recommended skipfailures flag.

> I tried adding

>

> gdal_tools.config_options("-skipfailures")

>

> but I get pylint tells me it is not callable.

>

> Anyone use pygdaltools?  There is some documentation, but nothing

> showing you how to set these command line parameters.

>

> import gdaltools

>

> gdal_tools = gdaltools.ogr2ogr()

>

> gdal_tools.BASEPATH = r"C:\Program Files\QGIS 3.16.16\bin"

>

> gdal_tools.set_encoding("UTF-8")

>

> gdal_tools.set_input(self.dxf_out_path)

>

> gdal_tools.set_output(self.gpkg_out)

>

> gdal_tools.execute()

>

> And I get the ERROR:root:b"Warning 1: Layer creation options ignored

> since an existing layer is\r\n         being appended to.\r\nWarning 6:

> Normalized/laundered field name: 'EntityHandle' to

> 'EntityHa_2'\r\nERROR

> 1: Attempt to write non-linestring (GEOMETRYCOLLECTION) geometry to

> ARC type shapefile.\r\nERROR 1: Unable to write feature 0 from layer

> entities.\r\nERROR 1: Terminating translation prematurely after

> failed\r\ntranslation of layer entities (use -skipfailures to skip

> errors)\r\n"

>

> Traceback (most recent call last):

>

>    File

> "c:\Users\RDTECLAC\AppData\Roaming\QGIS\QGIS3\profiles\default\python\

> plugins\site_selection\tools\master_planning\load_mp_designs.py", line

> 227, in <module>

>

>      main()

>

>    File

> "c:\Users\RDTECLAC\AppData\Roaming\QGIS\QGIS3\profiles\default\python\

> plugins\site_selection\tools\master_planning\load_mp_designs.py", line

> 196, in main

>

>      mp_designs.gdal_convert()

>

>    File

> "c:\Users\RDTECLAC\AppData\Roaming\QGIS\QGIS3\profiles\default\python\

> plugins\site_selection\tools\master_planning\load_mp_designs.py", line

> 185, in gdal_convert

>

>      gdal_tools.execute()

>

>    File

> "C:\Users\RDTECLAC\AppData\Roaming\Python\Python39\site-packages\gdalt

> ools\ogr2ogrcmd.py", line 330, in execute

>

>      return self._do_execute(args)

>

>    File

> "C:\Users\RDTECLAC\AppData\Roaming\Python\Python39\site-packages\gdalt

> ools\basetypes.py", line 108, in _do_execute

>

>      raise GdalToolsError(rc, err)

>

> gdaltools.basetypes.GdalToolsError: (1, b"Warning 1: Layer creation

> options ignored since an existing layer is\r\n         being appended

> to.\r\nWarning 6: Normalized/laundered field name: 'EntityHandle' to

> 'EntityHa_2'\r\nERROR 1: Attempt to write non-linestring

> (GEOMETRYCOLLECTION) geometry to ARC type shapefile.\r\nERROR 1:

> Unable to write feature 0 from layer entities.\r\nERROR 1: Terminating

> translation prematurely after failed\r\ntranslation of layer entities

> (use -skipfailures to skip errors)\r\n")error:

>

>

> _______________________________________________

> gdal-dev mailing list

> gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>

> Blockedhttps://eur06.safelinks.protection.outlook.com/?url=https%3A%2F

> %2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fgdal-devBlocked&data=05%7C01

> %7Cjukka.rahkonen%40maanmittauslaitos.fi%7C476e640a44f14b283ee008dbca1

> f38eb%7Cc4f8a63255804a1c92371d5a571b71fa%7C0%7C0%7C638326007673488940%

> 7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik

> 1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=n2JmJTKxfldyTjy08p5bXOtMxMn

> Zw7iy2EwIYpfMnc4%3D&reserved=0

_______________________________________________

gdal-dev mailing list

gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>

Blockedhttps://lists.osgeo.org/mailman/listinfo/gdal-devBlocked

_______________________________________________

gdal-dev mailing list

gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>

Blockedhttps://lists.osgeo.org/mailman/listinfo/gdal-devBlocked


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231011/3d5062b9/attachment-0001.htm>


More information about the gdal-dev mailing list