Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapInfo Tab file GDAL "OGR_Dr_CopyDataSource" fucntion fails. #11693

Closed
vdrasutis opened this issue Jan 20, 2025 · 6 comments
Closed

MapInfo Tab file GDAL "OGR_Dr_CopyDataSource" fucntion fails. #11693

vdrasutis opened this issue Jan 20, 2025 · 6 comments

Comments

@vdrasutis
Copy link

What is the bug?

Hello.

We had GDAL build with some customizations. We recently used GDAL v3.5.1.
Now I build with GDAL v3.5.3.

We use this method to copy source data:

[DllImport(GdalWrapper.GdalDLL, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr OGR_Dr_CopyDataSource(IntPtr hDriver, IntPtr hSrcDs, string newName, string[] parameters);

Issue:
And now "OGR_Dr_CopyDataSource" copying data source fails with error: "CreateFeature() failed: invalid feature id 1".

Attached GDAL_tab.zip, which contains simple LinqPad (I am opening with LinqPad v7 x64) C# Program it uses GDAL nuget. Also added simple TAB file format results generated by our app which I want to clone/ export as TAB file format results.

Note:

  1. We do not use in app GDAL nuget and have own object mapping.
  2. I managed to repeat similar error when used CreateDataSource separately and populated each object reparately so when feature was created and I tried to SetFID it was throwind same/similar error (note tried to pass same option "FID_ASSIGNMENT=NO_AUTO" but it also did not worked):
// dstLayer.SetFIDAssignment(OGR.FID_ASSIGNMENT.FID_ASSIGN_AUTO);  // Enable automatic FID assignment
long dstFidBeforeSet = dstFeature.GetFID();
// Console.WriteLine($"FID before: {dstFidBeforeSet}."); 	// -1
dstFeature.SetFID(fid);		// But if I set FID from source I get error "Error cloning feature with ID 1: CreateFeature() failed: invalid feature id 1"
// long dstFidAfterSet = dstFeature.GetFID();          		// 1... and etc
// Console.WriteLine($"FID after: {dstFidAfterSet}.");

// Create feature in destination layer
int createResult = dstLayer.CreateFeature(dstFeature);

So would you suggest, how to fix "OGR_Dr_CopyDataSource" usage or need to manually create destination Data Source and copy objects/create from source?

Steps to reproduce the issue

GDAL_tab.zip

Versions and provenance

OS: Windows
App language: C#
GDAL: v3.5.3

Additional context

No response

@jratike80
Copy link
Collaborator

I don't program and I cannot read your code, but I tried to convert your data with GDAL version 3.11.0dev.

ogr2ogr -f "MapInfo File" test.tab LteMeasurementsEventLocationsLteConnectionSegments.tab -nln test
Conversion was successful and new tab file has IDs like Id (String) = 1256153380040253. Was your aim to keep the IDs of the source data, or to create new IDs?

@vdrasutis
Copy link
Author

Those IDs are the IDs of the data records, so the data should remain the same.

I do not know which functions ogr2ogr -f "MapInfo File" test.tab LteMeasurementsEventLocationsLteConnectionSegments.tab -nln test uses.

The issue, I think, is with the FID (Feature IDs). As I understand it, these are simple IDs ranging from 1 (or 0) to X. In my case, the original results have 10 records, so there will be 10 features with FIDs from 1 to 10.

The issue seems to occur when using the OGR_Dr_CopyDataSource PInvoke function (calling the GDAL C++ function from C#).

@jratike80
Copy link
Collaborator

I do not know which functions ogr2ogr -f "MapInfo File" test.tab LteMeasurementsEventLocationsLteConnectionSegments.tab -nln test uses.

As I told, I am not a programmer. The source code is available here https://github.com/OSGeo/gdal/blob/master/apps/ogr2ogr_bin.cpp and for a libraty version here
https://github.com/OSGeo/gdal/blob/master/apps/ogr2ogr_lib.cpp

I turned your data into MIF

ogr2ogr -f "MapInfo File" test.mif LteMeasurementsEventLocationsLteConnectionSegments.tab
This way it is easier to see the fields

Columns 10
  Id Char(254)
  Segment Integer
  Classification Char(254)
  Ts DateTime
  Confidence Char(254)
  EventType Char(254)
  PhysicalCellId Integer
  CellLabel Char(254)
  Technology Char(254)
  Ts_local DateTime

GDAL reads the FID from the "Id" field.

@rouault
Copy link
Member

rouault commented Jan 20, 2025

You're obviously using a patched version of GDAL, since your code passes a FID_ASSIGNMENT layer creation option that doesn't exist in upstream GDAL. Supporting unmodified GDAL is already a difficult enough task, so, sorry but we can't support people that are talented enough to patch GDAL...

@rouault rouault closed this as completed Jan 20, 2025
@vdrasutis
Copy link
Author

Tried "FID_ASSIGNMENT" parameter as AI suggested it :) - tried different params what I could find - sadly non of them helped. Simple try my LinqPad code which uses GDAL official nuget and I can repeate same issue when using "OGR_Dr_CopyDataSource" GDAL function.

@rouault
Copy link
Member

rouault commented Jan 20, 2025

Tried "FID_ASSIGNMENT" parameter as AI suggested it :)

Oh my god. Could people stop using that crap... Such a collective loss of time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants