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:
<SPAN class="keyword token">string</SPAN> errorMessages <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">string</SPAN><SPAN class="punctuation token">.</SPAN>Empty<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> <SPAN class="punctuation token">(</SPAN>FeatureClass layerAsFeatureClass <SPAN class="operator token">=</SPAN> layer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetTable</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> FeatureClass<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
EditOperation op <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">EditOperation</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
op<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Callback</SPAN><SPAN class="punctuation token">(</SPAN>context <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> feature <SPAN class="keyword token">in</SPAN> features<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">using</SPAN> <SPAN class="punctuation token">(</SPAN>RowBuffer rowBuffer <SPAN class="operator token">=</SPAN> layerAsFeatureClass<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateRowBuffer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//Setting a bunch of attributes here...</SPAN>
<SPAN class="comment token">//</SPAN>
<SPAN class="comment token">//</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>feature<SPAN class="punctuation token">.</SPAN>Geometry <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">continue</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">//Now set the geometry</SPAN>
rowBuffer<SPAN class="punctuation token">[</SPAN>layerAsFeatureClass<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetDefinition</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetShapeField</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> feature<SPAN class="punctuation token">.</SPAN>Geometry<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToEsriShape</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> <SPAN class="punctuation token">(</SPAN>Row row <SPAN class="operator token">=</SPAN> layerAsFeatureClass<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateRow</SPAN><SPAN class="punctuation token">(</SPAN>rowBuffer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
context<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Invalidate</SPAN><SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN> layerAsFeatureClass<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">try</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="operator token">!</SPAN>op<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Execute</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
errorMessages <SPAN class="operator token">=</SPAN> op<SPAN class="punctuation token">.</SPAN>ErrorMessage<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">GeodatabaseException</SPAN> gEx<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
errorMessages <SPAN class="operator token">=</SPAN> gEx<SPAN class="punctuation token">.</SPAN>Message<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> ex<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
errorMessages <SPAN class="operator token">=</SPAN> ex<SPAN class="punctuation token">.</SPAN>Message<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>"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.