This project is read-only.

raster reprojection

Jun 8, 2012 at 6:36 PM
Edited Jun 12, 2012 at 8:24 PM

Hi there,

When I substitute the ".shp" files on the Tutorial #5 ( Projection Explorer in DotSpatial ) with ".bgd" files I got this message:

"Object reference not set to an instance of an object."

Here is the code:

//define the projection
map1.Projection = KnownCoordinateSystems.Projected.UtmNad1983.NAD1983UTMZone12N;
//add layer to map1
FeatureSet featureSet1 = new FeatureSet();
string sT = @"C:\DELETE1\20110103.bgd";
featureSet1 = (FeatureSet)DotSpatial.Data.FeatureSet.Open(sT);
//set the projection map1
featureSet1.Reproject(map1.Projection);  //here is where the error message is highlighted

Am I missing something?, does the DotSpatial library can reproject on the fly .bgd files as with .shp files?

Notice that I tested the .bgd file with MapWindowGIS so the there is no problem with the file itself

Thanks a lot





Jun 8, 2012 at 8:48 PM

A bgd file is a raster and not a FeatureSet. 


You may find Analyze Vector and Raster Data and Raster data operations in DotSpatial helpful.

Jun 8, 2012 at 9:21 PM

Thanks for your reply mudnug.

After modifying the code (below) I was able to display the rasters, BUT no matter the projection there is no change on the maps, I mean there is no rotation or distortion of the rasters regardless of the projection.

Please give me more hints.

Thanks a lot



//define the projections

map1.Projection = KnownCoordinateSystems.Projected.UtmNad1983.NAD1983UTMZone12N;
map2.Projection = KnownCoordinateSystems.Projected.NorthAmerica.CanadaAlbersEqualAreaConic;
//add layer to first map
map1.AddLayer( @"C:\DELETE1\20110103.bgd");
MapRasterLayer mrl_1 = (MapRasterLayer)map1.Layers[0];
//add layer to second map
MapRasterLayer mrl_2 = (MapRasterLayer)map2.Layers[0];

Jun 8, 2012 at 10:07 PM
Edited Jun 8, 2012 at 10:08 PM

I think the Reproject method should not be needed (and that the layer should conform to the map (or mapframe) projection. So, there may be a bug in the projection system, or it may not be setup to reproject rasters, yet. 

Jun 8, 2012 at 11:28 PM
Edited Jun 8, 2012 at 11:29 PM

I hate to be this insisting mudnug but could you (or someone) confirm that the reproject method doesn't work with rasters?



Jun 12, 2012 at 5:58 PM

Hi.   I have tested reproject a tiff using the Projected.NorthAmerica.CanadaAlbersEqualAreaConic, but it is not working

It works with a shapefile.

Jun 12, 2012 at 6:58 PM

Hi there,

I kindly request patience and help from the developers/advanced users.

It would be good if we can state clearly and definitely if the DotSpatial library can reproject raster files, maybe it can reproject rasters but not "on the fly", we don't know.

This is a related question: what is the InRamImageData format?, and how is related to the raster display?, I may be wrong but it seems all the rasters became at some point  InRamImageData

Any sample code is of course more than welcome

Thanks a lot


Jun 12, 2012 at 9:11 PM

I don't use the raster capabilities of DotSpatial, but I think the DotSpatial.Projections.Reproject.ReprojectAffine method is key here.  I notice it is referenced in the DotSpatial.Data.RasterBoundDataSet.Reproject method. I would look into that area to see why or why not reprojection is working.  Note that this is not rigorous reprojection but simply approximates with an affine transform which is what is specified at draw time in GDI+.



        /// <summary>
        /// This method reprojects the affine transform coefficients.  This is used for projection on the fly,
        /// where image transforms can take advantage of an affine projection, but does not have the power of
        /// a full projective transform and gets less and less accurate as the image covers larger and larger
        /// areas.  Since most image layers represent small rectangular areas, this should not be a problem in
        /// most cases.  the affine array should be ordered as follows:
        /// X' = [0] + [1] * Column + [2] * Row
        /// Y' = [3] + [4] * Column + [5] * Row
        /// </summary>
        /// <param name="affine">The array of double affine coefficients.</param>
        /// <param name="numRows">The number of rows to use for the lower bounds.  Value of 0 or less will be set to 1.</param>
        /// <param name="numCols">The number of columns to use to get the right bounds.  Values of 0 or less will be set to 1.</param>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        /// <returns>The transformed coefficients</returns>
        public static double[] ReprojectAffine(double[] affine, double numRows, double numCols, ProjectionInfo source, ProjectionInfo dest)