I am attempting to project a geometry using the GDAL c# bindings and I'm getting a ArgumentOutOfRangeException ('Received NULL pointer') exception on the Transform methods of Geometry. I'm also getting the same exception when attempting to project a point using a OSGeo.OSR.CoordinateTransformation
(e.g. https://gis.stackexchange.com/a/61574/31).
I am using the DLL in FWTools 2.4.7\csharp.
Has anyone seen this before and know what the fix is?
Here's a test that creates the exception for me:
[TestMethod()]
public void TransformPolygonReturnGeoJSON()
{
string jsonLambert = string.Empty;
string projectedJson = string.Empty;
string wkt = "POLYGON ((1831321.945291 412165.262452,1831324.478486 412152.596478,1831312.445811 412108.265569,1831298.513239 412108.265569,1831287.747162 412108.265569,1831275.714486 412102.565881,1831271.914694 412100.032686,1831266.215006 412098.766089,1831253.549032 412188.694503,1831321.945291 412165.262452))";
int srid = 102009;
int outputSRID = 26918;
string sridWKT = string.Format("EPSG:{0}", srid);
string outsridWKT = string.Format("EPSG:{0}", outputSRID);
var g = Geometry.CreateFromWkt(wkt);
var sr = new OSGeo.OSR.SpatialReference(sridWKT);
g.AssignSpatialReference(sr);
jsonLambert = g.ExportToJson();
Assert.IsFalse(string.IsNullOrEmpty(jsonLambert));
var outSR = new OSGeo.OSR.SpatialReference(outsridWKT);
try
{
var result = g.TransformTo(outSR); // <--- Exception occurs here
Trace.WriteLine(string.Format("result={0}", result));
projectedJson = g.ExportToJson();
Assert.IsFalse(string.IsNullOrEmpty(projectedJson));
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
Trace.WriteLine(ex.StackTrace);
throw;
}
}