GdalRasterLayer problem opening is not a physical file.

Topics: SharpMap Project
May 6, 2011 at 9:38 AM
Edited May 6, 2011 at 9:39 AM

In the constructor GdalRasterLayer if information about the projections are not found in GdalDataset, verifies the presence of a file. prj

// have gdal read the projection
_projectionWkt = _gdalDataset.GetProjectionRef();

// no projection info found in the image...check for a prj
if (_projectionWkt == "" &&
File.Exists(imageFilename.Substring(0, imageFilename.LastIndexOf(".")) + ".prj"))

But imageFilename may not be a physical file name (for example, Oracle georaster) and may not contain a "." As a result imageFilename.LastIndexOf (".") returns -1, and imageFilename.Substring an exception. For these data sources do not make sense to look for a file ". prj". Therefore, we must add an additional condition for verification, for example, check a ".":

if (_projectionWkt == "" && imageFilename .Contains(".")
File.Exists(imageFilename.Substring(0, imageFilename.LastIndexOf(".")) + ".prj"))

or check the existence of a file imageFilename:

if (_projectionWkt == "" && File.Exists(imageFilename)
File.Exists(imageFilename.Substring(0, imageFilename.LastIndexOf(".")) + ".prj"))

or even how to check something that imageFilename physical file name.