diff --git a/autotest/ogr/data/prjwithutf8bom.dbf b/autotest/ogr/data/prjwithutf8bom.dbf new file mode 100644 index 000000000..8d550f629 Binary files /dev/null and b/autotest/ogr/data/prjwithutf8bom.dbf differ diff --git a/autotest/ogr/data/prjwithutf8bom.prj b/autotest/ogr/data/prjwithutf8bom.prj new file mode 100644 index 000000000..581fc21e7 --- /dev/null +++ b/autotest/ogr/data/prjwithutf8bom.prj @@ -0,0 +1 @@ +GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] diff --git a/autotest/ogr/data/prjwithutf8bom.shp b/autotest/ogr/data/prjwithutf8bom.shp new file mode 100644 index 000000000..fb5ddad95 Binary files /dev/null and b/autotest/ogr/data/prjwithutf8bom.shp differ diff --git a/autotest/ogr/data/prjwithutf8bom.shx b/autotest/ogr/data/prjwithutf8bom.shx new file mode 100644 index 000000000..34c494324 Binary files /dev/null and b/autotest/ogr/data/prjwithutf8bom.shx differ diff --git a/autotest/ogr/ogr_shape.py b/autotest/ogr/ogr_shape.py index 75084c669..b4f1d1062 100755 --- a/autotest/ogr/ogr_shape.py +++ b/autotest/ogr/ogr_shape.py @@ -3699,6 +3699,19 @@ def ogr_shape_75(): return 'success' +############################################################################### +# Test opening shapefile whose .prj has a UTF-8 BOM marker + +def ogr_shape_76(): + + ds = ogr.Open('data/prjwithutf8bom.shp') + lyr = ds.GetLayer(0) + sr = lyr.GetSpatialRef() + if sr.ExportToWkt().find('GEOGCS["GCS_North_American_1983"') != 0: + return 'failure' + + return 'success' + ############################################################################### # @@ -3810,6 +3823,7 @@ def ogr_shape_cleanup(): ogr_shape_73, ogr_shape_74, ogr_shape_75, + ogr_shape_76, ogr_shape_cleanup ] if __name__ == '__main__': diff --git a/gdal/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp b/gdal/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp index 3f95bc59f..4dbcfa81e 100644 --- a/gdal/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp +++ b/gdal/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp @@ -1824,6 +1824,14 @@ OGRSpatialReference *OGRShapeGeomFieldDefn::GetSpatialRef() osPrjFile = pszPrjFile; poSRS = new OGRSpatialReference(); + /* Remove UTF-8 BOM if found */ + /* http://lists.osgeo.org/pipermail/gdal-dev/2014-July/039527.html */ + if( ((unsigned char)papszLines[0][0] == 0xEF) && + ((unsigned char)papszLines[0][1] == 0xBB) && + ((unsigned char)papszLines[0][2] == 0xBF) ) + { + memmove(papszLines[0], papszLines[0] + 3, strlen(papszLines[0] + 3) + 1); + } if( poSRS->importFromESRI( papszLines ) != OGRERR_NONE ) { delete poSRS;