GDALRaster layer

Topics: SharpMap v0.9 / v1.x
Apr 25, 2013 at 8:22 PM
If I have a Geotiff raster layer,( elevation values), how do I get the data into a featureset so I can do a IntersectionQuery
Apr 26, 2013 at 8:54 AM
What do you want to achieve?
GdalRasterLayer implements ICanQueryLayer, therefor your can perform ExecuteIntersectionQuery on it.
I must admit it is very limited though, it reports the value of the raster at the center of the queryied bounding box, IIRC.

Hth FObermaier
Apr 26, 2013 at 11:16 AM
Edited Apr 26, 2013 at 11:17 AM
The value at the center of the box is exactly what I want, but how do I write a query without a FeatureDataSet?
Apr 26, 2013 at 11:33 AM
You don't have to set up a special FeatureDataSet. This will do:
// p = some coordinate
var fds = new FeatureDataSet();
gdalLayer.ExecuteIntersectionQuery(new Envelope(p.X, p.Y), fds);
var fdt = fds.Tables[0];
var fdr = (FeatureDataRow)fdt.Rows[0];
Hth FObermaier
Apr 26, 2013 at 1:02 PM
That is what I tried, but it throws an exception because fds is empty. I have tried it with only the GDAL layer loaded and the same thing happens.
Apr 26, 2013 at 2:03 PM
I suppose there is something wrong with your input coordinate / envelope.
If it is not within the raster bounds, no table will be added to the FeatureDataSet.
Maybe you have not taken into account a CoordinateTransformation?
Hth FObermaier
Apr 26, 2013 at 2:35 PM
I am using worldpos and i can see the raster. Here is the complete sub
 Private Sub MapBox1_MouseMove(worldPos As GeoAPI.Geometries.Coordinate, imagePos As System.Windows.Forms.MouseEventArgs) Handles MapBox1.MouseMove
        Dim lat, lon, elev As Double
        Dim latStr, lonStr As String
        myWorldpos = worldPos
        Dim displayDMS As Boolean = True
        lat = worldPos.Y
        lon = worldPos.X
       dim fds =new FeatureDataSet
     Dim box As New GeoAPI.Geometries.Envelope(worldPos)

            If Not IsNothing(worldPos) And Not (IsNothing(fds)) Then

                Elevationlayer.ExecuteIntersectionQuery(New Envelope(worldPos), fds)
                Dim fdt = fds.Tables(0)
                Dim fdr = DirectCast(fdt.Rows(0), FeatureDataRow)

                elev = Convert.ToDouble(fdr)
            End If

            elev = Math.Round(Meter2Feet(elev), 1)
        Catch ex As Exception
            MsgBox(ex.Message & " Mousemove")
        End Try

        If displayDMS Then
            latStr = lat2DMS(lat)
            lonStr = long2DMS(lon)
            mapStatusLabel.Text = "Latitude: " & latStr & " Longitude: " & lonStr & " " & "Elevation: " & elev & "'"
            mapStatusLabel.Text = "Latitude: " & lat & " " & "Longitude: " & lon & " " & "Elevation: " & elev & "'"
        End If

    End Sub
Apr 29, 2013 at 6:05 AM
I've looked at the code and noticed that there currently is an issue with it, as a class wide varibale is not initialized.
I'll submit a patch asap. In the meanwhile, you should get by with calling
with some random (small) viewport once in order to have that varibale initialized.

Hth FObermaier
Apr 29, 2013 at 1:58 PM
GetNonRotatedPreview is a private sub and I can't access it. even if I knew what a "viewpoint" was. I will just wait until you get the patch done. Thanks.
Apr 29, 2013 at 7:16 PM
Seems I don't know the api well enough, sorry