[Gdal-dev] GDAL with VB.net (VS 2005 Express)

Tamas Szekeres szekerest at gmail.com
Wed Mar 28 19:19:57 EDT 2007


Milo,

I guess it might be a visual basic related issue since when doing the
same in C# the array size is not altered. AFAIK, VB uses 1 based
arrays so it might allocate the array with size+1 by default. However
I will try this if I have time.


Best regards,

Tamas


2007/3/28, Milo van der Linden <milo at 3dsite.nl>:
>
>  Hello Tamas and Frank,
>
>  Again thank you for the responses! I pretty much figured things out,  but I
> still don't know why I get an array of 4 doubles returned from the
> TransformPoint function, can it be that the return values are:
>  X, Y, relative-height between fromEllipsoide - toEllipsoide, absolute
> height?
>
>  I also found out that the way the developers at MapWindow implemented this
> is not correct, they do not take action on the towgs84 when the source
> ellipsoid is different from the target ellipsoid. They also work only with
> shape files, which I think is a missed change with the wonderful generic
> options that ogr offers!
>
>  Right now I use the fourth value in the array as my Z-value, because it
> seems to represent absolute height, since I drape my layer on the terrain in
> GoogleEarth, this is appropriate enough. Attached you will find a small
> sample file in kml format. If you load it in Google Earth, you will see the
> shift.
>
>  Here is a (VB.net) code snippet (put a reference in your project to
> ogr_csharp, no other references are needed):
>
>  'Add the next lines in the top of the module:
>  Imports OGR
>  Imports OGR.ogr
>
>  'In the calling subroutine, I open a GIS layer with Ogr.ogr.open:
>
>                      ds = OGR.ogr.Open(sFile, 0)
>                      Dim drv As OGR.Driver = ds.GetDriver()
>                      For j = 0 To ds.GetLayerCount - 1
>                      Dim lyr As Layer = ds.GetLayerByIndex(j)
>
>                      Dim RDproj4 = "+proj=stere +lat_0=52.156160556
> +lon_0=5.387638889 +k=0.999908 +x_0=155000 +y_0=463000 +ellps=bessel
> +towgs84=593,26,478,0,0,0,0 +units=m +no_defs"
>                      Dim WGS84proj4 As String = "+proj=longlat +ellps=WGS84
> +datum=WGS84 +no_defs"
>
>  'Get the source SpatialReference from the layer
>              Dim sr1 As SpatialReference = lyr.GetSpatialRef
>
>   'Create the destination Spatialreference for GoogleEarth
>              Dim sr2 As New SpatialReference("")
>              sr2.ImportFromProj4(WGS84proj4)
>
>  'I can call my TransFormPoint Function in 2 ways:
>
>  result = TransFormPoint(sr1, sr2, myPnt)
>  'or
>  result = TransFormPoint(RDproj4, WGS84proj4, myPnt)
>
>  'the Point is in an internal Geometry class, not the ogr geometry class.
>
>  'both methods give the exact same result, and it seems to be the right
> result! There is still a shift when presenting the results in Google Earth,
> but this can also be because the imagery is shifted, I am in contact with
> Aerodata in order to get the answer whether the image-shift is there on
> purpose.
>
>  'I use two constructors for the TransformPoint:
>
>  Public Function TransformPoint(ByVal srcSR As SpatialReference, ByVal dstSR
> As SpatialReference, ByVal pnt As Geometry.Point) As Geometry.Point
>  'Reads the SpatialReference from the source GIS file
>
>          Dim tPnt As New Geometry.Point
>          Dim ct As CoordinateTransformation
>          '/*
> --------------------------------------------------------------------
> */
>          '/*      making the transform
>                       */
>          '/*
> --------------------------------------------------------------------
> */
>
>          ct = New CoordinateTransformation(srcSR, dstSR)
>          Dim p(3) As Double
>          p(0) = pnt.x
>          p(1) = pnt.y
>          p(2) = pnt.z
>          ct.TransformPoint(p)
>          Debug.Print("x:" & p(0) & " y:" & p(1) & " z:" & p(3))
>          'The Z value has to remain relative to the terrain
>          tPnt.x = p(0)
>          tPnt.y = p(1)
>          tPnt.z = p(3)
>          'tPnt.z = pnt.z
>          Return tPnt
>  End Function
>
>  Public Function TransformPoint(ByVal src As String, ByVal dst As String,
> ByVal pnt As Geometry.Point) As Geometry.Point
>          Dim tPnt As New Geometry.Point
>          Dim dstSR As SpatialReference
>          Dim srcSR As SpatialReference
>          Dim ct As CoordinateTransformation
>          '/*
> --------------------------------------------------------------------
> */
>          '/*      Initialize srs
>                       */
>          '/*
> --------------------------------------------------------------------
> */
>
>          srcSR = New SpatialReference("")
>          srcSR.ImportFromProj4(src)
>          Debug.Print("SOURCE IsGeographic:" & srcSR.IsGeographic().ToString
> & " IsProjected:" & srcSR.IsProjected().ToString)
>
>          dstSR = New SpatialReference("")
>          dstSR.ImportFromProj4(dst)
>          Debug.Print("DEST IsGeographic:" & dstSR.IsGeographic().ToString &
> " IsProjected:" & dstSR.IsProjected().ToString)
>
>          '/*
> --------------------------------------------------------------------
> */
>          '/*      making the transform
>                       */
>          '/*
> --------------------------------------------------------------------
> */
>
>          ct = New CoordinateTransformation(srcSR, dstSR)
>          Dim p(3) As Double
>          p(0) = pnt.x
>          p(1) = pnt.y
>          p(2) = pnt.z
>          ct.TransformPoint(p)
>          Debug.Print("x:" & p(0) & " y:" & p(1) & " z:" & p(3))
>          'The Z value has to remain relative to the terrain
>          tPnt.x = p(0)
>          tPnt.y = p(1)
>          tPnt.z = p(3)
>          'tPnt.z = pnt.z
>          Return tPnt
>      End Function
>
>  Tamas Szekeres schreef:
> Milo,
>
>  I wonder why you have run into this issue. TransformPoint will not
>  alter the length of that array.
>  Would you post a sample to reproduce this problem?
>
>  Best regards,
>
>  Tamas
>
>
>  2007/3/28, Milo van der Linden <milo at 3dsite.nl>:
>
> Another thing:
>
>  The Transformpoint function takes an array of doubles. I input an array
>  of 3 values (x,y,z) and it returns 4 values. What do the four return
>  values mean?
>
>
>
>
>
>
>



More information about the Gdal-dev mailing list