[gdal-dev] Chinese Character for field name in ESRI Shapefile Problem

Even Rouault even.rouault at spatialys.com
Mon Oct 12 02:19:25 PDT 2015


Le lundi 12 octobre 2015 11:12:37, Jhon Chin a écrit :
> Thks a lot!!! Even, so I should avoid using Field name that counts more
> than 10 bytes, and there is no workaround ?

Yes.

Do you really need shapefile though ? If not, you could use more modern formats 
like GeoPackage or Spatialite that don't suffer from shapefile limitations : 
http://www.gdal.org/drv_geopackage.html , http://www.gdal.org/drv_sqlite.html

Potential idea if you need to stick with shapefiles: according to Google 
Translate this field name is translated in to English as Normalized Difference 
Vegetation Index, and in English it is often just abbreviated with its well-
known acronym NDVI. Perhaps there's the equivalent of acronyms in Chinese ?

Even

> 
>        your sincerely,
> 
>               Jhon Chin
> 
> On Mon, Oct 12, 2015 at 5:01 PM, Even Rouault <even.rouault at spatialys.com>
> 
> wrote:
> > Jhon Chin,
> > 
> > > Hi, everybody:
> > > 
> > > add one more question :
> > > 
> > > the field name can be read 10 ascii characters, the last characters
> > > would be trimmed,
> > 
> > Not necessarily 10 ascii characters, but 10 bytes. The number of
> > characters that can fit on 10 bytes depends on the encoding. 1 ASCII
> > character = 1 byte.
> > But for non ASCII characters such as Chinese characters, one character
> > fits on
> > several bytes.
> > 
> > > is there anyone encounter this problem?
> > 
> > Yes, everybody ! This is a limitation of the > 30 year old DBF format.
> > 
> > I've tried the following Python script that creates a shapefile with the
> > CP936
> > encoding.
> > 
> > {{{
> > # -*- coding: utf-8 -*-
> > 
> > from osgeo import ogr
> > 
> > ds = ogr.GetDriverByName('ESRI
> > Shapefile').CreateDataSource('test_cp936.dbf')
> > lyr = ds.CreateLayer('test_cp936', options = ['ENCODING=CP936'])
> > lyr.CreateField(ogr.FieldDefn("归一化植被指数",ogr.OFTInteger))
> > }}}
> > 
> > It emits a warning about truncation since the field name cannot fit on 10
> > bytes
> > once recoded in CP936.
> > 
> > Here's the result:
> > 
> > $ ogrinfo cp936.dbf -al
> > INFO: Open of `cp936.dbf'
> > 
> >       using driver `ESRI Shapefile' successful.
> > 
> > Layer name: cp936
> > 
> > Metadata:
> >   DBF_DATE_LAST_UPDATE=2015-10-12
> > 
> > Geometry: Line String
> > Feature Count: 0
> > Extent: (0.000000, 0.000000) - (0.000000, 0.000000)
> > Layer SRS WKT:
> > (unknown)
> > 归一化植被: Integer (9.0)
> > 
> > So the last 2 characters are lost.
> > 
> > > any help would be appreciated!
> > > 
> > >                Jhon Chen
> > > 
> > > On Mon, Oct 12, 2015 at 3:43 PM, Jhon Chin <giantchen2010 at gmail.com>
> > 
> > wrote:
> > > > Hi, everybody:
> > > > 
> > > > I'm now trying to write polygonized result into an esri shapefile,
> > > > and
> > 
> > I
> > 
> > > > tried
> > > > 
> > > > to add some field to the attribute table in the shapefile. But it
> > > > corrupted
> > > > 
> > > > when i was trying to create an *ogrfielddefn* instance.The code goes
> > > > 
> > > > like this:
> > > >            OGRFieldDefn oField("归一化植被指数",OFTInteger);
> > > >            if(poLayer->CreateField(&oField) != OGRERR_NONE)
> > > >            {
> > > >            
> > > >                 printf("create 归一化植被指数 failed!");
> > > >                 exit(1);
> > > >            
> > > >            }
> > 
> > --
> > Spatialys - Geospatial professional services
> > http://www.spatialys.com

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list