If you are doing any programming using GeoMedia, then it is possible that at some point you would need to determine the primary geometry field name by code. You can use the ExtendedPropertySet class to directly read the primary geometry field name of record sets generated through the originating pipe object. Failing that, you can loop through all the fields of the record set to find the fields of type gdbSpatial or gdbGraphic. An example C# method is shown below:
public static string GetGeometryFieldName(PClient.GRecordset rs)
{
string geomFieldName = string.Empty;
PClient.ExtendedPropertySet exPropSet;
PClient.GField field = null;
exPropSet = (PClient.ExtendedPropertySet)rs.GetExtension("ExtendedPropertySet");
geomFieldName = (string)exPropSet.GetValue("PrimaryGeometryFieldName");
if (geomFieldName.Length == 0)
{
foreach (PClient.GField fld in rs.GFields)
{
if (fld.Type == GDO.GConstants.gdbSpatial | fld.Type == GDO.GConstants.gdbGraphic)
{
geomFieldName = fld.Name;
break;
}
}
}
if (exPropSet != null) Marshal.FinalReleaseComObject(exPropSet);
if (field != null) Marshal.FinalReleaseComObject(field);
return geomFieldName;
}
No comments:
Post a Comment