Read/write Meta information in a gdb using gxnet

JohnPaine
JohnPaine Posts: 13 Calcite Rank Badge
edited February 2023 in GeoStudio
Hi,

I'm having difficulty in creating and writing information in the Metadata for a gdb. I followed the process used in the FileToandFromGDB.cs, but it doesn't work for me. The relevant (elided) code section is this:

hMETA = CMETA.Create();
hDB.GetMETA(hMETA);

var mcData = hMETA.ResolveUMN("CLASS:/Geosoft/Data");

var maSliceWidth = hMETA.ResolveUMN("ATTRIB:/Geosoft/Data/SliceWidth");

if (maSliceWidth == H_META_INVALID_TOKENConstant.H_META_INVALID_TOKEN)
{
// attribute doesn't exist, so create it

maSliceWidth = hMETA.CreateAttrib("ATTRIB:/Geosoft/Data/Time Slice Width", mcData, META_CORE_TYPEConstant.I4);
hMETA.SetAttribInt(mcData, maSliceWidth, iTimeSliceNum);

// save the modified meta data

hDB.SetMETA(hMETA);

return iTimeSliceNum;

}
else
{

// the attribute exists, so get the value

int iSliceWidth = 0;
hMETA.GetAttribInt(mcData, maSliceWidth, ref iSliceWidth);
return iSliceWidth;
}

Each of the steps seems to work fine and return valid responses. But if I create a gdb, add the SliceWidth attribute as above, then query the SliceWidth attribute again, it doesn't find it and repeats the creation code.

Many thanks
John Paine

Comments

  • Hi John,

    You can create the class and then the attribute like so:
    var mcData = hMETA.CreateClass("CLASS:/Geosoft/Data", GeoEngine.Core.GXNet.Constant.META_CORE_CLASS_Predefined);
    var maSliceWidth = hMETA.CreateAttrib("ATTRIB:/Geosoft/Data/SliceWidth", GeoEngine.Core.GXNet.Constant.META_CORE_CLASS_Predefined, META_CORE_TYPEConstant.I4);

    Then you should be able to see if it has a value:
    if (hMETA.iHasValue(mcData, maSliceWidth) != 1)


    I would also recommend to look at the CREG class to store and retrieve values.

    Regards,
    Joseph

  • Hi Joseph,

    Great, that fixed the problem and I can now read and write metadata values in the database.

    I checked the cs files gxnet/src folder and found the method I used in the FileToandFromGDB sample and that was why I tried to do it that way. I just checked and there don't appear to be any samples which use the method you supplied.

    Also, I had a look at the CREG class and it says:

    The REG class is used for storing and retrieving named variables. Many classes contain REG objects for storing information particular to the class. The META class supersedes the REG class and is gradually replacing the use of the REG class in newer applications.

    As I want these values to be parameters specific each database, I would expect that the Metadata is the better approach for storing the information.

    Best regards
    John

This discussion has been closed.