Aerial Photo displaying in wrong place

Topics: SharpMap v0.9 / v1.x
Dec 22, 2011 at 12:26 PM

   

I am having trouble loading the aerial photo – I use the following code in my program. The trouble occurs on the line AerialPhoto = New SharpMap.Layers.GdalRasterLayer(row("image"), FileName)


' Add the aerial photo 
Dim AerialPhoto As SharpMap.Layers.GdalRasterLayer
Dim FileName As String
For Each row In dt.Rows
   Dim box As New SharpMap.Geometries.BoundingBox(row("Xmin"), row("Ymin"), row("XMax"), row("YMax"))
   Dim VisibleMap As New SharpMap.Geometries.BoundingBox(Centre.X - HalfZoom, Centre.Y - HalfZoom, Centre.X + HalfZoom, Centre.Y + HalfZoom)
   If VisibleMap.Intersects(box) Then
       FileName = Strings.Replace(row("image"), "o:", "\\alpha\GISLayers$")
       AerialPhoto = New SharpMap.Layers.GdalRasterLayer(row("image"), FileName)
        ' Check if layers already loaded (will be SearchRd or SearchPt) If so, then insert 
        ' this layer so that it is always the bottom layer, otherwise just add as is the first layer
         With AerialPhoto
             .ShowClip = True
          End With
          If Map.Layers.Count = 0 Then
              Map.Layers.Add(AerialPhoto)
          Else
              Map.Layers.Insert(0, AerialPhoto)
          End If
          Map.ZoomToExtents()
   End If
 Next

When it enters the SharpMap code here, it has geoTrans[0] and geoTrans[3] = 0 so it performs the line geoTrans = new double[] { 999.5, 1, 0, 1000.5, 0, -1 }; - this causes the aerial photo to display in a strange manner and does not fit to the part of the screen that I am looking at.

If I use an old version of SharpMap this if statement is not true so it does not perform the above line and everything is OK (ie the aerial photo displays where it is supposed to display) - I do not know why the new version is setting these to 0

 

// get boundary of raster
    private SharpMap.Geometries.BoundingBox GetExtent()
    {
      if (_GdalDataset != null)
      {
        double right = 0, left = 0, top = 0, bottom = 0;
        double dblW, dblH;

        double[] geoTrans = new double[6];


        _GdalDataset.GetGeoTransform(geoTrans);

        // no rotation...use default transform
        if (!bUseRotation && !bHaveSpot || (geoTrans[0] == 0 && geoTrans[3] == 0))
          geoTrans = new double[] { 999.5, 1, 0, 1000.5, 0, -1 };

        GT = new GeoTransform(geoTrans);

        // image pixels
        dblW = imagesize.Width;
        dblH = imagesize.Height;

        left = GT.EnvelopeLeft(dblW, dblH);
        right = GT.EnvelopeRight(dblW, dblH);
        top = GT.EnvelopeTop(dblW, dblH);
        bottom = GT.EnvelopeBottom(dblW, dblH);

        return new SharpMap.Geometries.BoundingBox(left, bottom, right, top);
      }

      return null;
    }



Does anyone know why this is happening – I would appreciate your help as I do not really know the workings of SharpMap

Thank you



 

Coordinator
Dec 22, 2011 at 1:53 PM

To clarify, I need some more information:

  • About what kind of images are we talking?
  • What are the values of the envelope (row("Xmin") et. al)
  • What are the values of geoTrans after call to _GdalDataSet.GetGeoTransform(...)

cheers FObermaier

 

 

Dec 22, 2011 at 2:17 PM

They are Mr_Sid images (ESRI)

The values are as follows

Xmin: -0.15

XMax: 19390

YMin: -3314571

YMax: -3264693

I found the following in the documentation and when I checked this is exactly what I am getting back (0,1,0,0,0,1)

The default transform is (0,1,0,0,0,1) and should be returned even when a CE_Failure error is returned, such as for formats that don't support transformation to projection coordinates.

 

What I don't understand is that when I use the same program that uses an old version of sharpmap and exactly the same mr-sid files, it loads correctly, but as soon as I use the latest version of SharpMap it gets the wrong values back.

 

Thank you

Coordinator
Dec 22, 2011 at 2:29 PM

Have you updated your project to FWTools 2.4.7?

Possibly you are lacking support of osr_csharp.dll of FWTools. Reference that too, if you havn't already done so.

Hth FObermaier

Dec 22, 2011 at 2:40 PM

Yes, I am using FWTools 2.4.7

This is part of my webconfig file'

        -->
    <customErrors mode="Off" />
    <httpHandlers>
      <add path="GetMap.aspx" verb="*" type="SharpMap.Web.HttpHandler,SharpMap" />
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false" />
    </httpHandlers>
  </system.web>
  <location allowOverride="true" inheritInChildApplications="true">
    <!--
           I have copied all the files from C:\Program Files\FWTool2.4.7\bin directory to the Bin directory of this app and then
           point the FWToolBinPath to this - this is so that the libararies get installed with the program
        -->
    <appSettings>
      <add key="FWToolsBinPath" value="c:\Program Files\FWTools2.4.7\bin" />
      <add key="FWToolsProjLib" value="c:\Program Files\FWTools2.4.7\proj_lib"/>
      <add key="FWToolsGeoTiffCsv" value="c:\Program Files\FWTools2.4.7\data"/>
      <add key="FWToolsGdalData" value="c:\Program Files\FWTools2.4.7\data"/>
      <add key="FWToolsGdalDriver" value="c:\Program Files\FWTools2.4.7\plugins"/>
    </appSettings>
  </location>


Dec 22, 2011 at 2:41 PM

I also have osr_csharp.dll in my bin folder

Coordinator
Dec 23, 2011 at 7:35 AM

The old version did run on FWTools 2.4.7 as well, or was it FWTools 2.4.2?

Coordinator
Dec 23, 2011 at 7:45 AM

You should only need the

  • osr_csharp.dll,
  • gdal_csharp.dll and
  • ogr_csharp.dll 

in your bin folder. Then you need to point the web app to the native binaries to where they are installed.

Hth FObermaier

Dec 23, 2011 at 12:22 PM

Thank you for your help

 

The old version and new version are both using FWTools 2.4.7 - My application is the same one, I just change the files in the bin folder to the different version of Sharpmap

This is how I set it up

1. I use the Trunk version of SharpMap vs 2010 and rebuild the whole solution

2. I copy all the files from the bin folders of SharpMap, SharpMap.Extensions, SharpMap,UI, SharpMap.SqlServerSpatialObjects to the bin folder of my web app.

3. The web.config file points towards the FWTools 2.4.7 folder

When I run the Web App with the older version of SharpMap it works, however when I use the latest version it does not work.

I have tried the following.

1. I copied the osr_csharp.dll, gdal_csharp.dll, ogr_csharp.dll from FWTools 2.4.7 bin folder to the bin folder for latest SharpMap.Extensions and then rebuild the project and recopied the files to my web app bin, but I still get the same error.