Failing reprojection

Hi,

In our software we have the following settings:

    setting.ReprojectLayersOnAdding = true;
    setting.AllowProjectionMismatch = true;

We set a map projection and so any shapefiles added are reprojected to the map projection on adding. This is working sometimes but not always and in those cases I get e.success of false in the layer reprojected event, as you’d expect (last error code is 0).

An example is reprojecting WGS 84 UTM_60S (EPSG Code 32760) → British National Grid (EPSG Code 27700). This fails. I’ve also tried it going the other way, which does not work either.

I’ve included an example (with data) that illustrates the problem. I am using an older version of MapWinGIS day to day at the moment, but I have tested this in 5.2 with the same outcome.

I’ve used gdalsrsinfo to check the .prj files are sound and you’ll see from running the code MapWindow can import the projection from them, so all seems good there.

A separate issue I noticed when building the example is that if I set the map projection from importing the wkt then the “base” (British National Grid) shapefile polygon is slightly offset and in the incorrect position. If I use GrabProjectionFromData then the polygon is in the right place. We don’t have GrabProjectionFromData set in our production application and it appears in the correct place there, so not sure what is going on here. If I export the geoprojection created from importing the wkt and also the map projection created by using GrabProjectionFromData, they are almost exactly the same, except the imported one has:

DATUM["D_OSGB_1936",

and the map one has

DATUM["OSGB_1936",

I think this is unrelated to my reprojection issue. Looking at my example should hopefully make what I’m trying to explain a bit clearer.

Regards,

Rob HReprojectionProblem.zip (1.5 MB)

Hello Rob.

I appreciate the full VS Solution; this saved a lot of time for me. I’ve attached the Form file with updates.
ReprojectionProblemForm.zip (1.5 KB)

I don’t know why it’s not working using the WKT for the British National Grid, but if I changed it to Import the EPSG instead of the WKT, then the non-working code works.

//bool success = mapGP.ImportFromWKT(File.ReadAllText(Path.ChangeExtension(BaseShapefile, ".prj")));
bool success = mapGP.ImportFromEPSG(27700); // use EPSG code rather than WKT
this.axMap1.GeoProjection = mapGP; // - setting map projection like this offsets the shapefile, which is drawn slightly out of place

I can only speculate that there is some subtle difference in the WKT that is not quite right. You should be able to find a file in the MapWinGIS distribution, something like

C:\dev\MapWinGIS\src\bin\Win32\gdal-data\esri_epsg.wkt

In there, you will find the WKT definitions that shipped with the GDAL library, and in it you can find 27700. Perhaps you could compare that with your WKT and maybe something stands out as different? I don’t know.

Regarding the failed reprojection, there’s something about the coordinates that GDAL is unhappy with. Following the failure, I made a call to GdalLastErrorMsg, and it displays the following:

GdalLastErrorMsg: latitude or longitude exceeded limits

I’ve captured the points from the polyline below (assumed to be UTM 60 S). Perhaps you’ll see something.

image

That’s all I’ve got for now; perhaps adding more questions than answers…

Regards,
Jerry.