Hexagon Geospatial
MENU

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
dh
Occasional Contributor
Posts: 5
Registered: ‎06-27-2016
Accepted Solution

How to update geometry of feature programatically (C# API)?

I would like to update the geometry of a feature via a C# GeoMedia command. I am using GeoMedia 16.000 with PostGIS. What is the correct way to do this? I have created a button (which works) but I would like the geometry to refresh with the latest value in the database when the button is pressed. Here is what I have tried:

 

public void Activate()
{

    // ...

    Document doc = gobjGeoApp.Document as Document;
    Connections conList = doc.Connections as Connections;
    Connection connection = conList.Item(1); // returns the correct connection
    
    LegendEntry entry = null;
    var legendEntries = mapView?.Legend?.DisplayEntries;
    entry = legendEntries[1] as LegendEntry;  // returns the correct legendEntry
 
    OriginatingPipe pipe;
    connection.CreateOriginatingPipe(out pipe);
    pipe.GeometryFieldName = "Geometry"; // ???
    pipe.Table = "Table";
    pipe.Filter = "name = 'RecordName'";
   
    Intergraph.GeoMedia.PClient.GRecordset recordSet = pipe.OutputRecordset;
    entry.InputRecordset = (Intergraph.GeoMedia.GDO.GRecordset) recordSet; 

    entry.LoadData();
    mapView.Refresh();

}

 

This gives me error: "Invalid geometry field name XXX_geomedia for the given recordset"

 

The XXX is my geometry column which displays (until I run this command) and the XXX_geomedia is the associated bytea column. I have these setup using the Database Utilities and everything renders normally via Analysis->Queries.

 

Technical Evangelist
Posts: 487
Registered: ‎09-11-2015

Re: How to update geometry of feature programatically (C# API)?

Hi dh,

 

you cannot simply replace the InputRecordset of an existing legend entry.

 

To load changes made by a 3rd party application into GeoMedia, you must correctly fill the records in the ModifiedTables and ModificationLog tables. If you manage this, you then have two ways how to actually refresh the data in GeoMedia. You can either use the Connection.BroadcastDatabaseChanges, which reloads all changes detected in the ModificationLog table, or you can use the Notification object. The pseudocode using Notification object would look like this:

 

LegendEntry entry = ... get the correct legend entry;

GRecordset objRS = entry.InputRecordset;

Notification objN = objRS.GetExtension("Notification");

objRS.Close();

objN.Reopen();

 

This will refresh just one particular recordset. However, the overhead introduced by BroadcastDatabasChanges is usually negligible, so BroadcastDatabaseChanged should be the preferred method.

 

Pavel

dh
Occasional Contributor
Posts: 5
Registered: ‎06-27-2016

Re: How to update geometry of feature programatically (C# API)?

Hi Pavel! Thanks for the quick response! I will give that a try, but I have a technical requirement that I cannot use ModificationLog/ModificationTables. There is requirement to use third-party Notification as well (e.g. SignalR). Is it possible to update via an external request with possible external data as well?

Technical Evangelist
Posts: 487
Registered: ‎09-11-2015

Re: How to update geometry of feature programatically (C# API)?

Unfortunately, there is no way how to refresh data without modification log, except closing and reopening the whole connection. This is given by the GDO architecture. The data may be locally cached and there is no way to force GDO server to reload them without the modification log.

dh
Occasional Contributor
Posts: 5
Registered: ‎06-27-2016

Re: How to update geometry of feature programatically (C# API)?

Ok thanks I am using the modificationlog approach, and I am using a PostgreSQL trigger to insert updates using sessionid. Everything seems to work. However every time GeoMedia restarts it changes the sessionid. Is there a way to get a persistent sessionid or a way to store the current sessionid in the database to look it up?

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

Re: How to update geometry of feature programatically (C# API)?

You should get the session id from ExtendedPropertySet. The code would be like:

 

GDatabase objDB = myConn.Database;

ExtendedPropertySet objEPS = objDB.GetExtension("ExtendedPropertySet");

int iSessionId = objEPS.GetValue("SessionID");

 

However, when using myConn.BroadcastDatabaseChanges(false); the session id does not matter and you can put whatever you want in it.

 

Pavel

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.