OSGeo / gdal

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

Failed to find template header file header.dxf for reading #8790

Closed michkowalczuk closed 12 months ago

michkowalczuk commented 12 months ago

Expected behavior and actual behavior.

Can not write a DXF file because of the following error:

[Wed Nov 22 19:13:20 2023].0540, 41.9040: GDAL: GDALDriver::Create(DXF,D:\GisData\geoportal\BDOT10k\warszawa\out\bridge.dxf,0,0,0,Unknown,0000000000000000)
[Wed Nov 22 19:13:20 2023].0550, 41.9050: CPLError: Failed to find template header file header.dxf for reading,
is GDAL_DATA set properly?
ERROR 4: Failed to find template header file header.dxf for reading,
is GDAL_DATA set properly?

Steps to reproduce the problem.

Furthermore, I programmatically set environmental variable using SetEnvironmentVariable from WIN API with no effect.

EDIT: I must add that using the same method I add PROJ_DATA and GDAL finds proj.db.

Operating system

Windows 11 x64

GDAL version and provenance

GDAL 3.7.2 C API

rouault commented 12 months ago

I suspect a usage issue. Are there non-ASCII characters in the value of GDAL_DATA? If so, you need to UTF-8 encode the string

michkowalczuk commented 12 months ago

I suspect a usage issue. Are there non-ASCII characters in the value of GDAL_DATA? If so, you need to UTF-8 encode the string

The actual string is "D:\Projects\geopackage\sp-geopackage-import\bin\share\gdal", so that's not the problem.

jratike80 commented 12 months ago

Can you write dxf with GDAL binaries? ogr2ogr -f dxf test.dxf test.json That works for me and my gdal_data seems to be GDAL_DATA=C:\OSGeo4W\apps\gdal\share\gdal Might be good to test if the issue affects also the binaries or just the code.

michkowalczuk commented 12 months ago

Can you write dxf with GDAL binaries? ogr2ogr -f dxf test.dxf test.json That works for me and my gdal_data seems to be GDAL_DATA=C:\OSGeo4W\apps\gdal\share\gdal Might be good to test if the issue affects also the binaries or just the code.

I use Conda distribution (not OSGeo4W) and using ogr2ogr by default get the same error. If I set GDAL_DATA environment variable in windows it fails with different error:

ERROR 1: DXF layer does not support arbitrary field creation, field 'EntityHand' not created.

This means that GDALCreate passes. (I use the same path as I try in the code.)

It also means that setting env variable manually is a solution for ogr2ogr but not dor using dlls.

jratike80 commented 12 months ago

How about backslashes, what if they are considered to mean escapes? Have you tried with forward ones, or with double \\?

michkowalczuk commented 12 months ago

How about backslashes, what if they are considered to mean escapes? Have you tried with forward ones, or with double \\?

Tested all possible combinations. As I mentioned at the beginning, GDAL can recognize PROJ_DATA path, but GDAL_DATAno in my case.

jratike80 commented 12 months ago

I would double check that PROJ_DATA works even if it is in D:\Projects\geopackage\sp-geopackage-import\bin\share\proj. Or maybe it is already, I just don't know.

michkowalczuk commented 12 months ago

I would double check that PROJ_DATA works even if it is in D:\Projects\geopackage\sp-geopackage-import\bin\share\proj. Or maybe it is already, I just don't know.

Yes, it is. I have 2 separate folders ...\share\proj (PROJ_DATA) and ...\share\gdal (GDAL_DATA).

michkowalczuk commented 12 months ago

Dose somebody know why GDAL uses "gdal" argument in CPLFindFile function, not "gdal_data" when looking for "header.dxf"? Maybe this is some clue?

image
rouault commented 12 months ago

Dose somebody know why GDAL uses "gdal" argument in CPLFindFile function,

No, this is normal. Cf https://github.com/OSGeo/gdal/blob/0fe09b61d751916623e53252e51047ec40853814/port/cpl_findfile.cpp#L166

Something's wrong in your setup, but I'm not sure what

michkowalczuk commented 12 months ago

Dose somebody know why GDAL uses "gdal" argument in CPLFindFile function,

No, this is normal. Cf

https://github.com/OSGeo/gdal/blob/0fe09b61d751916623e53252e51047ec40853814/port/cpl_findfile.cpp#L166

Something's wrong in your setup, but I'm not sure what

Yes, it looks strange. Notice that I did not get "Cannot find %s (GDAL_DATA is not defined)" error from 169 line. It means that CPLGetConfigOption("GDAL_DATA", nullptr)) returns something (True), so GDAL_DATA is probably set correctly...

michkowalczuk commented 12 months ago

I found it! The problem is on the string conversion side. I'm working on Delphi wrapper for GDAL and convert Delphi string to C char*.

So far the conversion below has worked: Result := PUTF8Char(AnsiString(aStr));

After changing the conversion function to use UTF8String instead of AnsiString, it started working. :-) Result := PUTF8Char(UTF8String(aStr));