ThinkGeo.com    |     Documentation    |     Premium Support

Jpg Raster Overlay with Rotation

Hello,

I’m just getting started with the evaluation version of your product. I have a fairly simple task…need to overlay jpgs on a map (already have geo information and can provide as world files, affine transforms, you name it).

Using GdiPlusRasterLayer, I can get a non-rotated image with no problem. The difficulty seems to emerge when I try to use ImageSource.Projection =… Here is the code:

        winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
        winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

        WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsDesktopOverlay();
        winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);

        RectangleShape gRextent = new RectangleShape(-98.8, 33.36, -98.785, 33.345);
        GdiPlusRasterLayer gR = new GdiPlusRasterLayer(@"C:\Users\mnichols\Desktop\geotagged\rawJpgsX\IMG_2167_geotag.jpg",gRextent);
        gR.Open();
        gR.UpperThreshold = double.MaxValue;
        gR.LowerThreshold = double.MinValue;
        RotationProjection rr = new RotationProjection(20.0);
        rr.Open();
        gR.ImageSource.Projection = rr;
        
        LayerOverlay lOverlay = new LayerOverlay();
        
        lOverlay.Layers.Add("rrLayer",gR);

        winformsMap1.Overlays.Add("rasterOverlay",lOverlay);
        

        winformsMap1.CurrentExtent = new RectangleShape(-98.82, 33.38, -98.78, 33.3426);

        winformsMap1.Refresh()

If I comment out the lines "RotationProjection rr=… to gR.ImageSource.Projection=rr, the image displays but is obviously non-rotated. If I enter 0.0 in new RotationProjection(), I get a not implemented exception.

Any ideas? Really intrigued by the product so far, would just like to confirm this functionality before jumping all the way in.

Thanks,
Mark

So exploring more, when I use a world file “.jpw” in new GdiPlusRasterLayer(image file, world file), it appears that the rotation parameters are being ignored. I get this:

If rendered correctly, the images should look more like this:

If this functionality exists…this job will be very easy for me with your control.

Thanks,
Mark

To get the RotationProjection to work correctly you will need to define a PivotCenter Point. This is likely just the center point of the RasterLayer and can be done as below:

RotationProjection rr = new RotationProjection(180,GeographyUnit.DecimalDegree);
rr.PivotCenter = gR.GetBoundingBox().GetCenterPoint();
rr.Open();

Let me know how this works for you and if you need any other help.

-JD

Thanks for responding. If I do that, I get a NotImplementedException:

*An unhandled exception of type 'System.NotImplementedException' occurred in MapSuiteCore.dll*

*Additional information: Convert Raster to Exsternal Projection by default is not implemented, please override this method if needed.*

The exception comes in at winformsMap1.Refresh()

        InitializeComponent();

        

        winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
        winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

        WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsDesktopOverlay();
        worldMapKitDesktopOverlay.MapType = WorldMapKitMapType.AerialWithLabels;
        winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);

        
        RectangleShape gRextent = new RectangleShape(-98.8, 33.36, -98.785, 33.345);

        RectangleShape rRect = new RectangleShape(-98.9057987519464, 40.4832186395196, -98.9042454566421, 40.4824691551913);
        GdiPlusRasterLayer gR1 = new GdiPlusRasterLayer(@"C:\Users\mnichols\Desktop\geotagged\rawJpgsX\IMG_2167_geotag.jpg",rRect);
        gR1.Open();
        gR1.UpperThreshold = double.MaxValue;
        gR1.LowerThreshold = double.MinValue;
        RotationProjection rr = new RotationProjection(180, GeographyUnit.DecimalDegree);
        rr.PivotCenter = gR1.GetBoundingBox().GetCenterPoint();
        rr.Open();
        gR1.ImageSource.Projection = rr;
        
       



        LayerOverlay lOverlay = new LayerOverlay();
        
        lOverlay.Layers.Add("rrLayer1", gR1);

        winformsMap1.Overlays.Add("rasterOverlay",lOverlay);
        

        winformsMap1.CurrentExtent = new RectangleShape(-98.912923099994657, 40.485375292301178,
            -98.9008638882637, 40.479238398075104);
        winformsMap1.MapClick += WinformsMap1_MapClick;
        winformsMap1.Refresh();

Thanks,
Mark

I’m pretty sure that would be because you are using a Production Build of Map Suite and this is new functionality that we’ve added to the Development Builds of Map Suite since the last major release. If you switch to using the DLLs from Development you should no longer get that exception.

You can read more about the Prodcution/Development Builds here:
http://wiki.thinkgeo.com/wiki/Map_Suite_Daily_Builds_Guide#what_is_the_difference_between_the_production_and_development_daily_builds

-JD

Outstanding…thank you sir!

Result:

No Problem. I’m glad I was able to help you get it to work.

-JD