Skip to content

Commit 1d0f0ef

Browse files
committed
Improve parsing of wkt for DotSpatialCoordinateSystemFactory
* null argument check for DotSpatialCoordinateTransformationFactory
1 parent 0421e3c commit 1d0f0ef

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

SharpMap.CoordinateSystems.DotSpatial/DotSpatialCoordinateSystemFactory.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,19 @@ public ICoordinateSystem CreateFromXml(string xml)
9898
public ICoordinateSystem CreateFromWkt(string wkt)
9999
{
100100
//Hack: DotSpatial.Projections does not handle Authority and AuthorityCode
101-
var pos1 = 10 + wkt.LastIndexOf("AUTHORITY[", StringComparison.InvariantCulture);
102-
var pos2 = wkt.IndexOf("]", pos1, StringComparison.InvariantCulture) - 1;
103-
var parts = wkt.Substring(pos1, pos2 - pos1 + 1).Split(',');
104-
105-
var auth = parts[0].Replace("\"", "").Trim();
106-
var code = int.Parse(parts[1].Replace("\"", ""), NumberStyles.Integer,
107-
NumberFormatInfo.InvariantInfo);
101+
var pos1 = wkt.LastIndexOf("AUTHORITY[", StringComparison.InvariantCulture);
102+
string auth = "EPSG";
103+
int code = 0;
104+
// If there is an Authority entry in the WKT, try to parse the values
105+
if (pos1 >= 0)
106+
{
107+
pos1 += 10;
108+
var pos2 = wkt.IndexOf("]", pos1, StringComparison.InvariantCulture) - 1;
109+
var parts = wkt.Substring(pos1, pos2 - pos1 + 1).Split(',');
108110

111+
auth = parts[0].Replace("\"", "").Trim();
112+
int.TryParse(parts[1].Replace("\"", ""), NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out code);
113+
}
109114
ProjectionInfo pi = null;
110115
try
111116
{
@@ -270,4 +275,4 @@ public IVerticalDatum CreateVerticalDatum(string name, DatumType datumType)
270275
throw new NotSupportedException();
271276
}
272277
}
273-
}
278+
}

SharpMap.CoordinateSystems.DotSpatial/Transformations/DotSpatialCoordinateTransformationFactory.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public class DotSpatialCoordinateTransformationFactory : ICoordinateTransformati
2727
/// </remarks>
2828
public ICoordinateTransformation CreateFromCoordinateSystems(ICoordinateSystem sourceCS, ICoordinateSystem targetCS)
2929
{
30+
if (sourceCS == null || targetCS == null)
31+
return null;
32+
3033
var source = sourceCS as DotSpatialCoordinateSystem ??
3134
new DotSpatialCoordinateSystem(ProjectionInfo.FromEsriString(sourceCS.WKT));
3235

0 commit comments

Comments
 (0)