Opened 7 years ago

Closed 7 years ago

#4458 closed defect (fixed)

[PATCH] FGDB driver does not ensure feature class names are valid

Reported by: ryanl Owned by: warmerdam
Priority: normal Milestone: 1.9.1
Component: OGR_SF Version: 1.9.0
Severity: normal Keywords: FileGDB, File Geodatabase
Cc: robert.coup@…

Description

If an input contains field names that are invalid in a FGDB the driver attempts to add them directly, error messages are displayed and the resulting database does not contain the fields.

ERROR 1: Error: Failed at creating Field for 9NUMBER (The name of the Field is invalid: valid names may contain letters, numbers or underscores.)
Warning 1: The output driver has claimed to have added the 9NUMBER field, but it did not!

The FGDB API also lets you create fields with reserved words but these will break when opened with ArcMap?, this will be fixed with the next API release apparently.

The attached patch cleans field names by changing invalid characters to "_", appending "_" to reserved words (similarly to ArcCatalog?), shrinks names to 64 characters and ensures uniqueness of the names. It also adds an alias to the original field name.

I have attached an example csv that contains several fields with invalid names and the expected output.

References:

Attachments (5)

cleanFields.diff (5.7 KB) - added by ryanl 7 years ago.
fix against r23761
tests.csv (616 bytes) - added by ryanl 7 years ago.
Data I used to check patch
tests.vrt (287 bytes) - added by ryanl 7 years ago.
Data I used to check patch
cleanFields.2.diff (5.8 KB) - added by ryanl 7 years ago.
Patch using jpalmer's idea to prefix fields starting with a number
keyword_case.patch (916 bytes) - added by jpalmer 7 years ago.
The current implementation does not do a case insensitive match. This patch fixes this.

Download all attachments as: .zip

Change History (10)

Changed 7 years ago by ryanl

Attachment: cleanFields.diff added

fix against r23761

Changed 7 years ago by ryanl

Attachment: tests.csv added

Data I used to check patch

Changed 7 years ago by ryanl

Attachment: tests.vrt added

Data I used to check patch

comment:1 Changed 7 years ago by jpalmer

Hi Ryan,

I would modify the patch to ensure that fields that start with a number get an underscore prefixed to the field name, rather than replacing the number character with an underscore. i.e "9NUMBER" becomes "_9NUMBER" rather than "_NUMBER". This way fields names have a better chance of remaining unique and the process won't error.

Cheers Jeremy

Changed 7 years ago by ryanl

Attachment: cleanFields.2.diff added

Patch using jpalmer's idea to prefix fields starting with a number

comment:2 Changed 7 years ago by Even Rouault

Milestone: 1.9.1
Resolution: fixed
Status: newclosed
Version: svn-trunk1.9.0

r23777 /trunk/ (6 files in 2 dirs): FileGDB: do compulsory field name laundering. Add a LAUNDER_RESERVED_KEYWORDS layer creation option, which defaults to YES, to control whether an optional laundering step should also be done (adapted from a patch by ryanl, #4458)

r23778 /branches/1.9/gdal/ogr/ogrsf_frmts/filegdb/ (5 files): FileGDB: do compulsory field name laundering. Add a LAUNDER_RESERVED_KEYWORDS layer creation option, which defaults to YES, to control whether an optional laundering step should also be done (adapted from a patch by ryanl, #4458)

comment:3 Changed 7 years ago by Even Rouault

r23787 /trunk/gdal/ogr/ogrsf_frmts/filegdb/drv_filegdb.html: FileGDB: un-document LAUNDER_RESERVED_KEYWORDS option. Setting it to NO isn't really usefull (#4458)

r23788 /branches/1.9/gdal/ogr/ogrsf_frmts/filegdb/drv_filegdb.html: FileGDB: un-document LAUNDER_RESERVED_KEYWORDS option. Setting it to NO isn't really usefull (#4458)

Changed 7 years ago by jpalmer

Attachment: keyword_case.patch added

The current implementation does not do a case insensitive match. This patch fixes this.

comment:4 Changed 7 years ago by jpalmer

Resolution: fixed
Status: closedreopened

comment:5 Changed 7 years ago by Even Rouault

Resolution: fixed
Status: reopenedclosed

Applied in trunk (r23858) and branches/1.9 (r23859)

Note: See TracTickets for help on using tickets.