Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Contributor
Posts: 39
Registered: ‎11-02-2017

Create a WMS connection

[ Edited ]

Hello,

 

I am trying to connect to a WMS service that is working ok in GeoMedia:

 

https://www.gebco.net/data_and_products/gebco_web_services/web_map_service/mapserv?

 

I am using the following code, but I am getting the following result. What am I doing wrong? I feel there needs to be a transform somewhere but I am not sure how to do it. I want the MapView to be in projection mode.

 

Many thanks for your help!!!

 

Adrian

 

 

 

  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    EventControl.AddMapView(GMMapView1.Dispatch, _eventServer)

    Dim manager As New CoordSystemsMgr

    manager.CoordSystem.RefSpaceMgr.GeogSpace.GeodeticDatumVal = Intergraph.CoordSystems.Interop.CSGeodeticDatumConstants.csgdWGS84
    manager.CoordSystem.BaseStorageType = CSBaseStorageConstants.csbsProjected
    manager.CoordSystem.RefSpaceMgr.ProjSpace.ProjAlgorithmVal = Intergraph.CoordSystems.Interop.CSProjectionAlgorithmConstants.cspaMercator

    With GMMapView1
      .CoordSystemsMgr = manager
      .Legend = New PView.Legend
      .BackgroundColor = RGB(255, 255, 255)
    End With

    ' Create raster connection
    objConnEncrypted = New PClient.Connection

    With objConnEncrypted
      .Location = "NOCSFFOUND=SKIP;URI=https://www.gebco.net/data_and_products/gebco_web_services/web_map_service/mapserv?"
      .ConnectionName = "NOCSFFOUND=SKIP;URI=https://www.gebco.net/data_and_products/gebco_web_services/web_map_service/mapserv?"
      .ConnectInfo = "NOCSFFOUND=SKIP;URI=https://www.gebco.net/data_and_products/gebco_web_services/web_map_service/mapserv?"
      .Mode = PClient.ConnectionConstants.gmcModeReadOnly
      .Type = "WMS.GDatabase"
      .CoordSystemsMgr = GMMapView1.CoordSystemsMgr
      .Connect()
    End With

    ' Create recordset
    objConnEncrypted.CreateOriginatingPipe(objOPipe)
    objOPipe.Table = "GEBCO_08_GRID"
    objRS = objOPipe.OutputRecordset

    ' Create new legend entry
    objLE = CreateObject("Geomedia.LegendEntry")
    objLE.GeometryFieldName = "Geometry"

    '   Create a default title and subtytle
    Dim geoMediaProperty As PClient.GMProperty
    geoMediaProperty = New PClient.GMProperty
    geoMediaProperty.Name = "Title"
    geoMediaProperty.Value = "Gebco Title"
    objLE.PropertySet.Append(geoMediaProperty)

    geoMediaProperty = New PClient.GMProperty
    geoMediaProperty.Name = "Subtitle"
    geoMediaProperty.Value = "Gebco Subtitle"
    objLE.PropertySet.Append(geoMediaProperty)

    Dim transformPipe As PDBPipe.CSSTransformPipe
    transformPipe = New PDBPipe.CSSTransformPipe
    transformPipe.InputRecordset = objRS
    transformPipe.CoordSystemsMgr = GMMapView1.CoordSystemsMgr
    transformPipe.InputGeometryFieldName = objLE.GeometryFieldName
    transformPipe.OutputCSGUID = objRS.GFields("geometry").CoordSystemGUID

    objLE.InputRecordset = transformPipe.OutputRecordset

    Dim objstyleservice As New PView.StyleService
    Dim objStyle As PView.StyleDefinition = Nothing
    objstyleservice.GetStyle("Image Style", objStyle)
    objLE.Style = objStyle

    objLE.LoadData()
    GMMapView1.Legend.LegendEntries.Append(objLE, 1)

    GMMapView1.Fit()
    GMMapView1.Refresh(True)

  End Sub

 

It looks like this:

 

 

Untitled.png

 

 

It is meant to look like this:

 

Untitled1.png

Highlighted
Technical Evangelist
Posts: 557
Registered: ‎09-11-2015

Re: Create a WMS connection

Hi Adrian,

 

I think your code around the coordinate transformation is too complex and it is hard to guess what you actually want to achieve. If you create a new CoordSystemMgr object, it has already assigned the child CoordSystem object and initialized to wgs84 (lat,lon not projected coordinate system). If you want your data to be projected to something else, you must change the definition of the CoordSystemMgr.CoordSystem object. Far easiest way to do it is to use GeoMedia or "Define Coordinate System File" utility, set up your CS and save it as *.csf file. Then in your code just call CoordSystemMgr.CoordSystem.LoadFromFile() method. Of course, make sure through the Capabilities request that your WMS support that coordinate system.

 

Further when you create the CSSTransformPipe, don't assign the OutputCSGUID, this is confusing and difficult to say what should be your expected result (transforming the recordset the the same CS?). Setting the CoordSystemMgr should be fully sufficient.

 

Pavel

Highlighted
Contributor
Posts: 39
Registered: ‎11-02-2017

Re: Create a WMS connection

Hello,

 

Thank you for your feedback. I have been working on this all day and still no luck. I need to fix this otherwise GeoMedia is not a practical solution for our product. Does anybody else know how to get this code working?

 

My mapview is set up in projection because we always want the projection to be Mercator and our datum is WGS84. The WMS connection is WGS84 which is why this works with the mapview is set to Geographic.

 

I feel the problem is not necessarily a problem with a mapping on the input of the data but rather a problem specifying to the WMS connection the area of interest. That is why I don't think a CSF is going to help.

 

I am wondering if any GeoMedia experts out there have every had this working before? And if so can they provide the code that they used?

 

My code today is now:

 

  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    EventControl.AddMapView(GMMapView1.Dispatch, _eventServer)

    Dim manager As New CoordSystemsMgr

    manager.CoordSystem.BaseStorageType = CSBaseStorageConstants.csbsProjected
    manager.CoordSystem.RefSpaceMgr.GeogSpace.GeodeticDatumVal = Intergraph.CoordSystems.Interop.CSGeodeticDatumConstants.csgdWGS84
    manager.CoordSystem.RefSpaceMgr.ProjSpace.ProjAlgorithmVal = Intergraph.CoordSystems.Interop.CSProjectionAlgorithmConstants.cspaMercator

    With GMMapView1
      .CoordSystemsMgr = manager
      .Legend = New PView.Legend
      .BackgroundColor = RGB(255, 255, 255)
    End With

    objConnEncrypted = New PClient.Connection

    With objConnEncrypted
      .Location = "NOCSFFOUND=SKIP;URI=https://www.gebco.net/data_and_products/gebco_web_services/web_map_service/mapserv?"
      .ConnectionName = "NOCSFFOUND=SKIP;URI=https://www.gebco.net/data_and_products/gebco_web_services/web_map_service/mapserv?"
      .ConnectInfo = "NOCSFFOUND=SKIP;URI=https://www.gebco.net/data_and_products/gebco_web_services/web_map_service/mapserv?"
      .Mode = PClient.ConnectionConstants.gmcModeReadOnly
      .Type = "WMS.GDatabase"
      .Connect()
    End With

    objConnEncrypted.CreateOriginatingPipe(objOPipe)
    objOPipe.Table = "GEBCO_08_GRID"
    objRS = objOPipe.OutputRecordset

    objLE = CreateObject("Geomedia.LegendEntry")
    objLE.GeometryFieldName = "Geometry"

    Dim serverTransService As New PClient.ServerTransService
    Dim objAltTransform As Intergraph.CoordSystems.Interop.AltCoordSystemPath

    Dim cs As CoordSystem
    serverTransService.CreateCSFromGeometryField(objRS.GFields("Geometry"), cs)
    serverTransService.CreateSimpleTransFromCSMtoCS(manager, cs, objAltTransform)
    'serverTransService.CreateSimpleTransFromCSMtoGeometryField(manager, objRS.GFields("Geometry"), objAltTransform)
    'serverTransService.CreateSimpleTransFromCSMtoServer(manager, cs.GUID, objConnEncrypted.Database, objAltTransform)

    Dim transformPipe As New PDBPipe.CSSTransformPipe
    transformPipe.InputRecordset = objRS
    transformPipe.CoordSystemsMgr = manager
    transformPipe.InputGeometryFieldName = "Geometry"

    objLE.InputRecordset = transformPipe.OutputRecordset

    Dim objstyleservice As New PView.StyleService
    Dim objStyle As PView.StyleDefinition = Nothing
    objstyleservice.GetStyle("Image Style", objStyle)
    objLE.Style = objStyle

    objLE.LoadData()
    GMMapView1.Legend.LegendEntries.Append(objLE, 1)

    GMMapView1.Fit()
    GMMapView1.Refresh(True)

  End Sub

 

Many thanks for your help.

 

Adrian