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
Contributor
Posts: 22
Registered: ‎04-04-2016

Adding Field Metadata for boolean field

Dear all,

 

I am implementing a custom command, where a new table can be created consisting of three fields:

  • A geometry field storing point geometries
  • An Autonumber field storing the id
  • A boolean field storing a value which can be true or false.

Because I am doing this programmatically, I first create the table with the fields, then I set the table metadata and finally I want to set the field metadata.

 

The first time I am creating such a table everything works fine.

But the second time creating such a table (of course with a different name) in the same database I can not set the field metadata for the boolean field, for all other fields it works fine.

I get the exception saying "Metadata already exists for feature", but I just created the table and the field metadata does clearly not exist.

If I delete the first created table, I can create a new one and it works perfectely, but the second time I again get the exception.

Also restarting GeoMedia or reloading the database does not help.

If I use a text field instead for a boolean field it also works fine and I can create as many tables I want to.

 

Does anyone have an idea about this behaviour?

I am grateful for any hints!

 

Best

Cecilia

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

Re: Adding Field Metadata for boolean field

Hello Cecilia,

 

I think you should include a code snippet, otherwise we are not able to help you.

 

Pavel

Contributor
Posts: 22
Registered: ‎04-04-2016

Re: Adding Field Metadata for boolean field

[ Edited ]

Here is my code. The second time I am trying to create such a table, I get the exception when trying to add the field metadata for the boolean field: objMetadataService.AddFieldMetadata(booleanFieldProp);

 

 

 

GDatabase objDatabase = (GDatabase) connection.Database;
            GTableDef gTableDef = objDatabase.CreateTableDef(tableName);
            gTableDef.Name = tableName;
  
//Create Id Field
      GField gField = gTableDef.CreateField("ID", 4);
                gField.Attributes = 16;              
                gField.Name = "ID";
                gField.Required = true;              
                gTableDef.GFields.Append(gField); 

//Create Boolean Field
      GField gField = gTableDef.CreateField("Activated", 1);
                gField.Attributes = 1;           
                gField.Name = "Activated";
                gField.Required = false;         
                gTableDef.GFields.Append(gField);
    
//Create Geometry Field
         GField gField = gTableDef.CreateField("Geometry", 32);
                gField.Attributes = 0;             
                gField.SubType = 10;
                gField.Name = "Geometry";
                gField.Required = true;             
                gField.CoordSystemGUID = coordSysGuid;
                gTableDef.GFields.Append(gField);
    
  objDatabase.GTableDefs.Append(gTableDef);
  
//Set Table Metadata
         MetadataService objMetadataService =
                (MetadataService) _gobjGeoApp.CreateService("GMService.MetadataService");
            objMetadataService.set_Connection(connection);
            objMetadataService.set_TableName(tableName);
            TableProperty tableProp = new TablePropertyClass();
            tableProp.set_Name(tableName);
            tableProp.set_Description("Points");
            tableProp.set_GeometryType(3);
            tableProp.set_PrimaryGeometryFieldName(geometryFieldName);

            objMetadataService.AddTableMetadata(tableProp);

            connection.ReloadDatabase();
   
//Set Field Metadata for id Field
         GField idField = gTableDef.GFields[0];
         FieldProperty fieldPropId = new FieldPropertyClass();
                fieldPropId.set_Name(idField.Name);
                fieldPropId.set_Description(idField.Name);
                fieldPropId.set_Key(true);
                fieldPropId.set_FieldType(idField.Type);
                fieldPropId.set_Displayable(true);

                objMetadataService.AddFieldMetadata(fieldPropId);
    
//Set Field Metadata for boolean Field
         GField booleanField = gTableDef.GFields[1];
         FieldProperty booleanFieldProp = new FieldPropertyClass();
                booleanFieldProp.set_Name(booleanField .Name);
                booleanFieldProp.set_Description(booleanField .Name);
                booleanFieldProp.set_Key(false);
                booleanFieldProp.set_FieldType(booleanField .Type);
                booleanFieldProp.set_Displayable(true);
    
    objMetadataService.AddFieldMetadata(booleanFieldProp);
    
//Set Field Metadata for geometry Field

          GField geometryField = gTableDef.GFields[2];
            FieldProperty geomFieldProp = new FieldPropertyClass();
            geomFieldProp.set_Name(geometryField .Name);
            geomFieldProp.set_Description(geometryField .Name);
            geomFieldProp.set_CoordSystemGUID(geometryField .CoordSystemGUID as string);
            geomFieldProp.set_GeometryType(geometryField .SubType);
            geomFieldProp.set_PrimaryGeometryFlag(true);
            geomFieldProp.set_Key(false);
            geomFieldProp.set_FieldType(geometryField .Type);
            geomFieldProp.set_Displayable(true);

 

            objMetadataService.AddFieldMetadata(geomFieldProp);

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

Re: Adding Field Metadata for boolean field

I think if you change the lines:

 

GField booleanField = gTableDef.GFields[0];

FieldProperty booleanFieldProp = new FieldPropertyClass();
                booleanFieldProp.set_Name(idField.Name);
                booleanFieldProp.set_Description(idField.Name);

to

 

GField booleanField = gTableDef.GFields[1];

FieldProperty booleanFieldProp = new FieldPropertyClass();
                booleanFieldProp.set_Name(booleanField.Name);
                booleanFieldProp.set_Description(booleanField.Name);

 

then it will work.

 

Pavel

Contributor
Posts: 22
Registered: ‎04-04-2016

Re: Adding Field Metadata for boolean field

Sorry, this was a copy and paste mistake. Of course the index increases.

Unfortunately this is not the problem,.... 

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

Re: Adding Field Metadata for boolean field

OK, in this case I propopse to post the correct code once again, just to be sure.

 

Pavel

Contributor
Posts: 22
Registered: ‎04-04-2016

Re: Adding Field Metadata for boolean field

I edited my code above, I hope that it is clear now.

 

Thanks!

Cecilia

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

Re: Adding Field Metadata for boolean field

Hi Cecilia,

 

in this case it looks fine. So the only other idea I have is to explicitly release all objects as soon as they go out of the scope using Marshal.ReleaseComObject method, namely the FieldProperty objects. Also the call to connection.ReloadDatabase() just after you create the table metadata seems to be useless and perhaps it might cause troubles.

 

Pavel

Contributor
Posts: 22
Registered: ‎04-04-2016

Re: Adding Field Metadata for boolean field

Hi Pavel,

 

thanks for your support!

I have now tried everything, but I still get the same error, so I think that there must be some GeoMedia bug.

 

Best Cecilia