ThinkGeo.com    |     Blog    |     Wiki    |     Support

Proj4Projection is not convering GDAL layer for WGS84

We have an application which uses MapSuite Winforms Edition currently built with version 10.3. I am trying to display a National Land Use Land Cover image over the standard WGS84 map layer. I am able to open the layer as a GdalRasterLayer and get the projection text from the file. I believe this file is an ERDAS raw image format (has suffix IMG with associated other files).

The raster layer returns the following projection text

“PROJCS[“Albers_Conical_Equal_Area”,GEOGCS[“WGS 84”,DATUM[“WGS_1984”,SPHEROID[“WGS 84”,6378137,298.257223563,AUTHORITY[“EPSG”,“7030”]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[“EPSG”,“6326”]],PRIMEM[“Greenwich”,0,AUTHORITY[“EPSG”,“8901”]],UNIT[“degree”,0.0174532925199433,AUTHORITY[“EPSG”,“9108”]],AUTHORITY[“EPSG”,“4326”]],PROJECTION[“Albers_Conic_Equal_Area”],PARAMETER[“standard_parallel_1”,29.5],PARAMETER[“standard_parallel_2”,45.5],PARAMETER[“latitude_of_center”,23],PARAMETER[“longitude_of_center”,-96],PARAMETER[“false_easting”,0],PARAMETER[“false_northing”,0],UNIT[“meters”,1]]”

I used Proj4Projection.ConvertPrjToProj4(projection); to convert this text to a projection string

“+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs”

I am using the following code to create a new Proj4Projection:

Proj4Projection proj4 = new Proj4Projection();
string projection = layer.GetProjectionText();
proj4.InternalProjectionParametersString = Proj4Projection.ConvertPrjToProj4(projection);
proj4.ExternalProjectionParametersString = Proj4Projection.GetWgs84ParametersString();
layer.ImageSource.Projection = proj4;

The image layer is displaying but it is not showing the correct size and boundaries.

Can anyone tell me what I need to do to get the image to show correctly for the WSG84 map in latitude and longitude.

Any help is greatly appreciated.

Richard Stye

Hi Richard,

From your description it looks your render logic is correct, I am not sure where is the problem, could you please upload the test project with the data, so we can look into it and see what’s the problem?

Regards,

Ethan

Here is a zipped file with a sample application to display the ERDAS Image file. RasterProjection.zip (15.3 KB)

Also is an a picture of the ERDAS Image display by QGIS Desktip 3.6.3

The ERDAS Image file is big - almost 2GB as a zipped file which expands to almost 20GB. It is available at https://www.mrlc.gov/data

The file I have downloaded is one of the "NLCD 2016 Land Cover (CONUS) " files.

Thank you for your help.

Richard Styer

Hi Richard,

I had started to download the data, but it looks the speed is really slow, I am trying to find a way make it faster.

After download succeed and test it I will update this topic.

Regards,

Ethan

Hi Richard,

I had downloaded the test data complete, but it looks it cannot be rendered succeed, I am not sure whether it’s because the data is too big, I will find some how to render it.

I also tried to open the data in QGIS, and it looks the default projection is a custom projection just like you mentioned.

I put another world border shape file as the back ground layer, and set the projection the same as it, but it looks the data cannot be covered at all, I am not sure whether that’s because the data is incorrect or its inner projection is not exact, you can also try that.

Any update I will let you know.

Regards,

Ethan

Ethan
Thanks for working on this. If the image is not being rendered, you might check if you have the colors set for the layer. I had to set the Red, Green, Blue colors in the layer object in order to see the data rendered on the Mapsuite winform. I don’t know what the optimal colors would be so I had started with something other than a gray,black,or white. I think I used Blue=128, Green=128, Red=64 or some combination like that. Since I have my Mapsuite winform control set up to show the map in Latitude-Longitude on WGS84, I set the projection to use the WGS84ParameterString. After adding these to the GDALRasterLayer, I could see the image being rendered but the size and shape of the image was not matching the usual shape or the Continental US. The east coast was too far east and the west coast too far west and distorted as it moved northward towards the Canadian border.

Rich

Hi Richard,

I had render that, and reproduced your problem.

We will look into it and see what’s the problem.

Any update we will let you know.

Regards,

Ethan

Thanks for your help.

I hope there is a solution.

Richard Styer

Hi Richard,

It looks that’s a projection issue with GdalRasterLayer, and it’t not easy to fix.

Our developer will go on working on it.

If your scenario is allowed, I think you can choose reproject your shape file from 4326 to “+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=23 +lon_0=-96 +x_0=0 +y_0=0 +ellps=WGS84 +towgs84=0,0,0,-0,-0,-0,0 +units=m +no_defs”, and it should match well.

Any update I will let you know.

Regards,

Ethan

Our application is using all the map layers with a “longlat” projection with the “units=degrees” like the default projection for GetWgs84ParametersString. I have tried adding the "+towgs84=0,0,0,-0,-0,-0,0 to a “longlat” type string but it has no affect on the display of the ERDAS image. Do you have a string suggestion that keeps the projection in “degrees”?

Thanks for all your help

Richard Styer

Hi Richard,

I don’t think modify the projection string can solved it, it looks when reproject to 4326, the image missed some parts.

Our developer will try to solve it, any update I will let you know.

Regards,

Ethan

Ethan

Do you know if it is possible to “warp” the projection for this ERDAS IMG layer from the “AEA” projection in meters to a “LatLong” projection? I tried QGIS Warp for raster files and it goes off an process for a long time but the file it produce doesn’t seem to work as a “LatLong” raster layer.

I haven’t been able to make any progress on displaying this data with MapSuite

Richard Styer

Hi Richard,

I tried to convert the img file into decimal degree via QGIS, it looks the speed slow is because the file size too big.

I hadn’t completed to convert it so don’t know whether it can render well, I will test that after convert and reply you.

Regards,

Ethan

Hi Richard,

I convert your data succeed and it looks render correct.

Here is the code and the result:

        GeoTiffRasterLayer tiffLayer = new GeoTiffRasterLayer(@"C:\Users\xxx\AppData\Local\Temp\processing_dab7f378d5254fc983dfe85d97288834\a66f5fe81bbb4f2f842cbe844b5c2271\OUTPUT.tif");
        tiffLayer.ColorMappings.Clear();
        tiffLayer.ColorMappings.Add(GeoColors.Black, GeoColors.Transparent); // Block to render the black part in image
        overlay2.Layers.Add(tiffLayer);

Here is how I convert it.

Wish that’s helpful.

Regards,

Ethan

ethan

Thanks for the quick response.

I was able to warp the IMG to the GeoTiff and it displays in QGIS browser. I still am not able to display it in our application but I need to do some more debugging/diagnostics for this.

Thanks again

Richard Styer

Hi Richard,

The screen shot under my test code is render it in our map control, you can view your exception to see what’s the problem.

Do you need my converted OUTPUT.tif file? Its size is big so I am not sure how long you can download it.

Regards,

Ethan