[gdal-dev] ogr2ogr with append fails to convert truncated fields

Tamas Szekeres szekerest at gmail.com
Mon Feb 25 10:53:22 PST 2013


So we seem to have 3 divergent options to provide a work around:

1. Expose fieldmap setting to let the user decide the order of the fields
to be copied.
2. Modify GetFieldIndex to provide the name based lookup by the truncated
name (for the shape driver specifically)
3. Provide an option to instruct ogr2ogr to consider the source and the
destination has the same field structure (order).

Which would be the most reasonable?

I personally in favour of #3 or #1.  #3 is easier to implement, but #1 is
more customizable.
With regards to #2 we might continue to encounter non trivial matches.

Best regards,

Tamas





2013/2/25 Even Rouault <even.rouault at mines-paris.org>

> Le lundi 25 février 2013 16:57:08, Tamas Szekeres a écrit :
> > Hi All,
> >
> > Related to issue #3247 <http://trac.osgeo.org/gdal/ticket/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, how
> > about exposing the field map itself as an option, something like:
> >
> > ogr2ogr -append -f "ESRI Shapefile" -fieldmap "0,1,2,3,4,5"
> destination.shp
> >  [source]
> >
> >
> > Would that workaround be sufficient?
>
> That would certainly work, although not particularly user friendly, but
> shapefiles are not that user friendly with their various limitations.
>
> Perhaps you could just work with spatialite DBs as intermediate and
> convert to
> shapefile at the end if it is really needed ?
>
> A potential alternative to -fieldmap would be to have :
>
> class OGRLayer:
> {
>    public:
>           virtual int GetFieldIndex(const char* pszFieldname);
> }
>
> int OGRLayer::GetFieldIndex(const char* pszFieldname)
> {
>         return GetLayerDefn()->GetFieldIndex(pszFieldname);
> }
>
> int OGRShapeLayer::GetFieldIndex(const char* pszFieldname)
> {
>         int idx = OGRLayer::GetFieldIndex(pszFieldname);
>         if( idx >= 0 )
>                 return idx;
>         /* otherwise implement here truncation logic to find best match */
>         /* caution: if there are several potential matches (for example
> verylongcolumnname1 being truncated to verylongna and verylongcolumnname2
> truncated to verylong~1) and you are looking for verylongcolumnXXX then
> return
> -1 */
> }
>
> >
> >
> > Best regards,
> >
> > Tamas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20130225/5777f5a9/attachment.html>


More information about the gdal-dev mailing list