Skip to content

Commit

Permalink
Shape: support .prj files with UTF-8 BOM
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Jul 12, 2014
1 parent 4674e60 commit 87af4d1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
Binary file added autotest/ogr/data/prjwithutf8bom.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions autotest/ogr/data/prjwithutf8bom.prj
Original file line number Diff line number Diff line change
@@ -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]]
Binary file added autotest/ogr/data/prjwithutf8bom.shp
Binary file not shown.
Binary file added autotest/ogr/data/prjwithutf8bom.shx
Binary file not shown.
14 changes: 14 additions & 0 deletions autotest/ogr/ogr_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

###############################################################################
#

Expand Down Expand Up @@ -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__':
Expand Down
8 changes: 8 additions & 0 deletions gdal/ogr/ogrsf_frmts/shape/ogrshapelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 87af4d1

Please sign in to comment.