AnsweredAssumed Answered

Issues creating geometry for an in-memory feature class

Question asked by gbs522 on Mar 26, 2019
Latest reply on May 29, 2019 by gbs522

Hello,

 

I am writing functionality for my ArcGIS Pro add-in that generates a custom layer on the fly. I am trying to use the memory workspace (https://pro.arcgis.com/en/pro-app/help/analysis/geoprocessing/basics/the-in-memory-workspace.htm) to avoid creating a geodatabase on the disk, as the results of my tool are meant to be temporary and I would like them to disappear upon application close. 

 

So far, I've been able to successfully create the feature class and its fields through the Geoprocessing API. However, I'm getting stuck when trying to populate the layer with data. My code appears to work, and upon completion, the attribute table is populated with rows. However, there is no geometry for any of the rows (no features exist in the map at all).

 

Here is how I am populating my layer:

 

string errorMessages = string.Empty;
               using (FeatureClass layerAsFeatureClass = layer.GetTable() as FeatureClass)
               {
                    EditOperation op = new EditOperation();
                    op.Callback(context =>
                    {
                         foreach (var feature in features)
                         {
                              using (RowBuffer rowBuffer = layerAsFeatureClass.CreateRowBuffer())
                              {
                                   //Setting a bunch of attributes here...
                                   //
                                   //

                                   if (feature.Geometry == null)
                                   {
                                        continue;
                                   }

                                   //Now set the geometry
                                   rowBuffer[layerAsFeatureClass.GetDefinition().GetShapeField()] = feature.Geometry.ToEsriShape();

                                   using (Row row = layerAsFeatureClass.CreateRow(rowBuffer))
                                   {
                                        context.Invalidate(row);
                                   }
                              }
                         }
                    }, layerAsFeatureClass);

                    try
                    {
                         if (!op.Execute())
                         {
                              errorMessages = op.ErrorMessage;
                         }
                    }
                    catch (GeodatabaseException gEx)
                    {
                         errorMessages = gEx.Message;
                    }
                    catch (Exception ex)
                    {
                         errorMessages = ex.Message;
                    }
               }

 

"feature.Geometry" is a MapPoint. I found that setting the geometry without calling ".ToEsriShape()" resulted in errors. Is there another way that I should be setting the geometry for an in-memory feature class? I feel like I am missing something here. Any help would be appreciated.

Outcomes