private static ICoordinateSystem GetCoordinateSystemForSrid(int srid)
{
if (srid <= 0)
{
return(null);
}
ICoordinateSystem res = null;
#if !DotSpatialProjections
if (_sridCoordinateSystem.TryGetValue(srid, out res))
{
return(res);
}
var wkt = Converters.WellKnownText.SpatialReference.SridToWkt(srid);
if (string.IsNullOrEmpty(wkt))
{
Logger.Error(fmh => fmh("No definition for SRID {0}!", srid));
return(null);
}
var csFactory = new CoordinateSystemFactory();
try
{
res = csFactory.CreateFromWkt(wkt);
}
catch (Exception)
{
Logger.Error(fmh => fmh("Could not parse definition for SRID {0}:\n{1}", srid, wkt));
return(null);
}
_sridCoordinateSystem.Add(srid, res);
#else
try
{
if (_sridDefinition != null)
{
string proj4;
if (_sridDefinition.TryGetValue(srid, out proj4))
{
res = ICoordinateSystem.FromProj4String(proj4);
}
}
if (res == null)
{
res = DotSpatial.Projections.ProjectionInfo.FromEpsgCode(srid);
}
}
catch (Exception)
{
Logger.Error(fmh => fmh("Could not get coordinate system for SRID {0}!", srid));
return(null);
}
#endif
return(res);
}