Skip to content

Commit

Permalink
Improve parsing of wkt for DotSpatialCoordinateSystemFactory
Browse files Browse the repository at this point in the history
* null argument check for DotSpatialCoordinateTransformationFactory
  • Loading branch information
FObermaier committed Apr 21, 2022
1 parent 0421e3c commit 1d0f0ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Expand Up @@ -98,14 +98,19 @@ public ICoordinateSystem CreateFromXml(string xml)
public ICoordinateSystem CreateFromWkt(string wkt)
{
//Hack: DotSpatial.Projections does not handle Authority and AuthorityCode
var pos1 = 10 + wkt.LastIndexOf("AUTHORITY[", StringComparison.InvariantCulture);
var pos2 = wkt.IndexOf("]", pos1, StringComparison.InvariantCulture) - 1;
var parts = wkt.Substring(pos1, pos2 - pos1 + 1).Split(',');

var auth = parts[0].Replace("\"", "").Trim();
var code = int.Parse(parts[1].Replace("\"", ""), NumberStyles.Integer,
NumberFormatInfo.InvariantInfo);
var pos1 = wkt.LastIndexOf("AUTHORITY[", StringComparison.InvariantCulture);
string auth = "EPSG";
int code = 0;
// If there is an Authority entry in the WKT, try to parse the values
if (pos1 >= 0)
{
pos1 += 10;
var pos2 = wkt.IndexOf("]", pos1, StringComparison.InvariantCulture) - 1;
var parts = wkt.Substring(pos1, pos2 - pos1 + 1).Split(',');

auth = parts[0].Replace("\"", "").Trim();
int.TryParse(parts[1].Replace("\"", ""), NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out code);
}
ProjectionInfo pi = null;
try
{
Expand Down Expand Up @@ -270,4 +275,4 @@ public IVerticalDatum CreateVerticalDatum(string name, DatumType datumType)
throw new NotSupportedException();
}
}
}
}
Expand Up @@ -27,6 +27,9 @@ public class DotSpatialCoordinateTransformationFactory : ICoordinateTransformati
/// </remarks>
public ICoordinateTransformation CreateFromCoordinateSystems(ICoordinateSystem sourceCS, ICoordinateSystem targetCS)
{
if (sourceCS == null || targetCS == null)
return null;

var source = sourceCS as DotSpatialCoordinateSystem ??
new DotSpatialCoordinateSystem(ProjectionInfo.FromEsriString(sourceCS.WKT));

Expand Down

0 comments on commit 1d0f0ef

Please sign in to comment.