ThinkGeo.com    |     Documentation    |     Premium Support

Overlay JPEG image over Worldmap layer

Hi,

I am overlaying JPEG image over base map and trying to fit it exactly with the base map which is in polar stereographic projection using RectangleShape(-140,20,55,20) as in below code ,but it is not exactly sitting on the base map as shown in the uploaded screenshot.

        GdiPlusRasterLayer gf3 = null;

        imgname = "PWA00_20WX.JPEG";
       
        imgname = DownloadData(imgname);
        if (imgname != null)
              gf3 = new GdiPlusRasterLayer(sMapDataPath + @"\MapData\charts\" + imgname + ".jpeg", _proj.ConvertToExternalProjection(new RectangleShap<img src="/uploads/default/original/3X/5/0/505753f76edcab6406016ea42c825bb1f59d4572.png" width="690" height="387">e(-140,20,55,20)));
         
        if (gf3 != null)
        {

            gf3.Transparency = 150;

            LayerOverlay test3q = new LayerOverlay();

            test3q.Layers.Add("gf3", gf3);
            if (winformsMap1.Overlays.Contains("test3q"))
                winformsMap1.Overlays.Remove("test3q");
            winformsMap1.Overlays.Add("test3q", test3q);
      
            if (test3q.Layers[0].IsOpen == false)
                test3q.Layers[0].Open();
            winformsMap1.CurrentExtent = test3q.Layers[0].GetBoundingBox();
            winformsMap1.Refresh();

        }

Can you please suggest me some solution to fix this problem.

Thanks,
Silpa.

Hi Silpa,

I can’t reproduce your issue, can you send your .JPG data, Shape file data and projection information to me?

Thanks,

Hi Don,

This is my JPEG image

and I am overlying it on Countries02.shp file setting internal projection 4326 and external projection to “+proj=stere +lat_0=90 +lon_0=-42 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs”; (Polar stereographic projection).

Thanks,
Silpa.

Hi Silpa,

I reproduced that, but because our reprojectioned shape can match with other image, so I am not sure whether that’s the problem of our projection.

Could you please double check two items as below:

  1. Whether the extent for this image is correct
  2. Whether the projection string is correct, because we tried to adjust the projection string, it changed the match status. I tried to query that but it looks there are many Polar stereographic projection, could you please make sure which one is you are using here: http://epsg.io/?q=Polar%20stereographic&page=1

Regards,

Don

Hi Don,

I am using EPSG 102018 (North Pole stereographic) projection .I am trying to fit the image RectangleShape(-140,20,55,20) with this extent but I don’t know at what extent it actually fits with the background map .

Thanks,
Silpa.

Hi Silpa,

For the http://epsg.io/102018, it looks if I used the standard projection string from this page, the image don’t match the shape at all.

And I found the standard projection have some different with the one you are using, so I think maybe you need do some adjust for some parameters to make that match.

And for the image bouding box, I think you should want to get it from the data provider, does the (-140,20,55,20) is provided by them?

Regards,

Don

Hi Don,

(-140,20,55,20) was not provided by the data provider.Based on the lat lon in the image I have taken this bounding box.

Thanks,
Silpa.

Hi Silpa,

I tried to modify the extent to make the image match, but unlucky I hadn’t succeed. Have you tried to remove the blank area around map and try it again? I am not sure whether the extent just works for the valid area on image.

Regards,

Don

Hi Don,
I tried by removing the blank area around the chart but hadn’t succeed.

According to Thinkgeo ,In RectangleShape(minX,maxY,maxX,minY) , (minX,maxY) is upper left most point and (maxX,minY) is lower Right most point of the image being overlayed, but by adjusting these corner lat lon, image doesn’t match with the map.

Can you please tell me which coordinates of the image should be adjusted to make it fit with the map and if possible can you provide me some sample on how to overlay images which are not in Spherical mercator projection in Thinkgeo.

Thanks,
Silpa.

Hi Slipa,

In fact we hadn’t met this scenario before, so I think we cannot provide you a sample because we don’t have a data like your image.

Just like I mentioned before, for your scenario, there are two variables:

  1. The image suitable what extent, if you cannot get that from data provider, it’s hard to be tested manual I think. You should want to build a small utility to adjust it if necessary, which can modify the extent value and refresh map from UI.

  2. Whether the projection string is correct, generally the projection string is provided by data provider, because if any parameter is modified, the base shape will be reprojection to other location.

And I suggest you can tested this image and data in some 3rd part GIS utility, to see whether that can be matched, so we can find which steps is the mainly problem in this process.

Please see this screen capture, some shapes looks move left and some shapes looks move right, the red circle part even the shape cannot be match. So I think both extent and projection should have problem, but both of them is hard to be get by try.

Test code as below:

        private void WpfMap_Loaded(object sender, RoutedEventArgs e)
    {
        Map1.MapUnit = GeographyUnit.Meter;

        ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp");
        worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(255, GeoColor.SimpleColors.Blue));

        ManagedProj4Projection proj4 = new ManagedProj4Projection();
        proj4.InternalProjectionParametersString = ManagedProj4Projection.GetDecimalDegreesParametersString();
        proj4.ExternalProjectionParametersString = "+proj=stere +lat_0=90 +lon_0=-42 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs";
        proj4.Open();

        worldLayer.FeatureSource.Projection = proj4;

        RectangleShape rect = new RectangleShape(-140, 20, 55, 20);
        RectangleShape convertedRect = proj4.ConvertToExternalProjection(rect);

        LayerOverlay overlay1 = new LayerOverlay();
        overlay1.Layers.Add(worldLayer);

        string imgname = @"D:\tmp3\8087.jpeg";
        GdiPlusRasterLayer gprl = new GdiPlusRasterLayer(imgname, convertedRect);
        gprl.Transparency = 150;
        LayerOverlay overlay2 = new LayerOverlay();
        overlay2.Layers.Add(gprl);

        Map1.Overlays.Add(overlay1);
        Map1.Overlays.Add(overlay2);

        Map1.CurrentExtent = convertedRect;
        Map1.Refresh();
    }

Regards,

Don