Opened 11 years ago

Closed 11 years ago

#5021 closed enhancement (fixed)

Implement fieldmap option in ogr2ogr

Reported by: tamas Owned by: tamas
Priority: normal Milestone: 1.10.0
Component: default Version: svn-trunk
Severity: normal Keywords:
Cc:

Description

Related to issue #3247 we experienced, that if we use ogr2ogr to append source data to a shapefile destination (by using the -append flag) and field name truncation is taking place, the corresponding values are not copied.

This is because when setting up the field index map (in ogr2ogr) the destination (truncated) field indexes are searched by the name of of the source fields (the long names).

Since it's not always trivial to find the correct fields by names, we implement a field map option, something like:

ogr2ogr -append -f "ESRI Shapefile" -fieldmap "0,1,2,3,4,5" destination.shp [source]

We could also simplify the setting when using indentity field order:

ogr2ogr -append -f "ESRI Shapefile" -fieldmap identity destination.shp [source]

Attachments (1)

ogr2ogr.cpp.patch (6.6 KB ) - added by tamas 11 years ago.
Added a new patch

Download all attachments as: .zip

Change History (6)

comment:1 by Even Rouault, 11 years ago

A few remarks :

  • a typo in the help of the option : "desitanion" --> "destination"
  • it could be useful to have a check after the parsing of options that checks that if -fieldmap is specified, -append is also specified.
  • ogr_utilities.dox should be extented with the new option
  • the description of -fieldmap is not entirey clear to someone who hasn't read the implementation of ogrfeature.cpp. I'm not sure how it could be phrased in a clear way. Perhaps "The (n)th value specified in the list is the index of the field in the target layer definition in which the n(th) field of the source layer must be copied. Index count starts at zero. There must be exactly as many values in the list as there are fields in the source layer.". I think that the best would be to add an example in the example section of ogr_utilities.dox : "-fieldmap 2,-1,4" : the first field of the source layer is used to fill the third field (index 2 = third field) of the target layer, the second field of the source layer is ignored, the third field of the source layer used to fill the fifth field of the target layer.
  • a test case in autotest/utilities/test_ogr2ogr.py would be welcome

comment:2 by Jukka Rahkonen, 11 years ago

For us who are not C-programmers it would be much more easy to avoid errors if "3" in the fieldmap list would mean the 3rd field, not the 4th. But I suppose that you, the developers, belong to those who have a big party at age of 49 because we all really were zero year old when we had the first birthdate.

by tamas, 11 years ago

Attachment: ogr2ogr.cpp.patch added

Added a new patch

comment:3 by tamas, 11 years ago

Added a new patch with a modified description. Hope that is better. The documentation and the test script will also be updated.

comment:4 by tamas, 11 years ago

Implemented in r25733 Autotest added in r25734

comment:5 by Even Rouault, 11 years ago

Milestone: 1.10.0
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.