Opened 12 years ago

Closed 12 years ago

#4743 closed defect (fixed)

[PATCH] Recoding shapefile that has "8859x" in the cpg file is not correct.

Reported by: akaginch Owned by: warmerdam
Priority: normal Milestone: 1.9.2
Component: OGR_SF Version: unspecified
Severity: normal Keywords: Shapefile, cpg, recoding
Cc:

Description

If GDAL is linked with the iconv library, recoding a shapefile dataset that has "8859x" in the cpg file is not correct.

I saw ogrshapelayer.cpp and tested iconv in the shell as below.

$ iconv -f UTF-8 -t ISO88591 test.txt
iconv: conversion to ISO88591 unsupported

$ iconv -f UTF-8 -t ISO8859-1 test.txt
Hello!

$ iconv -f UTF-8 -t ISO-8859-1 test.txt
Hello!

In addition, CPL_ENC_ISO8859_1 is defined as below(cpl_string.h).

#define CPL_ENC_ISO8859_1  "ISO-8859-1"

So, I made a patch.

--- ogrshapelayer_org.cpp
+++ ogrshapelayer.cpp
@@ -280,7 +280,7 @@
     }
     if( EQUALN(pszCodePage,"8859",4) )
     {
-        osEncoding.Printf( "ISO%s", pszCodePage );
+        osEncoding.Printf( "ISO-%.4s-%s", pszCodePage, pszCodePage + 4 );
         return osEncoding;
     }
     if( EQUALN(pszCodePage,"UTF-8",5) )

Change History (3)

comment:1 by Even Rouault, 12 years ago

Summary: Recoding shapefile that has "8859x" in the cpg file is not correct.[PATCH] Recoding shapefile that has "8859x" in the cpg file is not correct.

Seems reasonable, except that we should probably validate more the string. For example, I'm wondering if someone couldn't write 8859-1 in the .cpg (although this does not seem to be documented in http://resources.arcgis.com/fr/content/kbase?fa=articleShow&d=21106), in which case the suggested formatting wouldn't work

comment:2 by akaginch, 12 years ago

Yes, it's a user-friendly idea. I rewrite the code as below.

osEncoding.Printf( "ISO-%.4s-%s", pszCodePage, pszCodePage + 4 + ( *(pszCodePage + 4) == '-' ? 1 : 0 ) );

comment:3 by Even Rouault, 12 years ago

Milestone: 1.9.2
Resolution: fixed
Status: newclosed

r24680 /trunk/gdal/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp: Shape: correctly deal with .cpg files containing 8859xx string (#4743)

r24681 /branches/1.9/gdal/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp: Shape: correctly deal with .cpg files containing 8859xx string (#4743)

Note: See TracTickets for help on using tickets.