//...cut... //Create the connection to the WMS server PClient.Connection conn = null; //connection to the WMS server MapviewLib.GMMapView map = (MapviewLib.GMMapView) mapWindow.MapView; conn = (PClient.Connection) this.Application.CreateService("GeoMedia.Connection"); conn.Name = "WMS"; conn.Type = "WMS.GDatabase"; conn.Mode = 0; conn.Description = "WMS"; conn.Location = "Not used"; conn.ConnectInfo = @"NOCSFFOUND=FAIL;URI=http://some.wms.com/wms.aspx"; conn.Connect(); //Now create a recordset to a WMS feature PClient.OriginatingPipe OP; conn.CreateOriginatingPipe(out OP); OP.Table = "Feature1"; //Build a transformation path to/fro the map view coordinate system and the WMS and store the paths in the map view's CoordSystemsMgr object PCSS.CoordSystem objCS = null; PClient.ServerTransService objSTS = (PClient.ServerTransService)this.Application.CreateService("GeoMedia.ServerTransService"); PCSS.AltCoordSystemPath objAltCoordSystemPath = null; PClient.GField objGeomFld = OP.OutputRecordset.GFields["Geometry"]; objSTS.CreateCSFromGeometryField( objGeomFld, out objCS); objSTS.CreateSimpleTransFromCSMtoCS(map.CoordSystemsMgr, objCS, out objAltCoordSystemPath); //Transform the WMS recordset to the map view's coordinate system PDBPipe.CSSTransformPipe objXPipe = (PDBPipe.CSSTransformPipe)this.Application.CreateService("GeoMedia.CSSTransformPipe"); objXPipe.InputRecordset = (PDBPipe.GRecordset) OP.OutputRecordset; objXPipe.InputGeometryFieldName = "Geometry"; objXPipe.CoordSystemsMgr = map.CoordSystemsMgr; objXPipe.OutputCSGUID = map.CoordSystemsMgr.CoordSystem.GUID; //Now we can use the transformed WMS recordset PDBPipe.GRecordset wmsRS = objXPipe.OutputRecordset //...etc...
Monday, June 13, 2011
GeoMedia C# code snippet to connect to a WMS server
Recently I was asked to look at some C# code to connect and display a feature from a Web Mapping Service (WMS) server. I wrote some driving GeoMedia code to test out the connection.
Please! Do you have an example using WFS with username and password?
ReplyDeleteI got an error in the 2nd Line that 'mapWindow" is doesnot exist in the current context. Can somebody tell me the solution ?
ReplyDeleteThank You!
Rutu