Programmatically Update Geometry of Polygon Feature

464
0
10-18-2018 07:57 AM
AndyWright
Occasional Contributor

I'm writing some code that is attempting to modify the geometry of an existing polygon feature, let's call it the parent, based on the extent of all of its children (collection of lines, points, or the combination of the two).  The parent/child relationship is just that, a relationship between two feature classes, but the extent of the parent needs to fully contain all the children.

The children of the parent are selected from the map.  The first time this happens the parent geometry is null because there are no children yet.  I select a bunch of lines and it creates the parent geometry correctly.  If I attempt to add more children lines by selecting other features from the map it appears to update/expand the parent geometry correctly in that session.  I can draw a graphic for that new geometry on the screen and it appears as it should.  I then close my application, log back in, and take a look at that parent geometry again and it is back to what it originally was after the first selection set was processed.  So it seems like it can update a polygon geometry if it is null to start with, but if there is already an existing polygon geometry it doesn't update it.  I don't get any errors during the update call though, so on the surface everything seems ok.

I update geometries for points in a similar manner and that works fine.  Am I missing something here or does updating polygon geometries work differently?  Here is the code I am using to update the polygon geometry.  This occurs after the selection of point/line features in the map (AdHocWorkFeatureList).  I feel like this is some sort of red herring, but haven't been able to figure it out yet.  Hopefully some more eyes on it will help.  Thanks ...

List<Feature> workFeatures = new List<Feature>();
DateTime snapshotDateTimeNow = DateTime.Now;

if (!m_SelectedWorkDownloadAreaGeodatabase.IsInTransaction)
  m_SelectedWorkDownloadAreaGeodatabase.BeginTransaction();

//  ADD ALL SELECTED MAP FEATURES TO A LIST

foreach (AdhocWorkFeature adhocWorkFeature in AdhocWorkFeatureList.Where(x => x.IsChecked))
{
  Feature aFeature = null;

  switch (adhocWorkFeature.Geometry.GeometryType)
  {
    case GeometryType.Point:
      aFeature = await AddWorkOrderPointForAdhocWorkOrderFeature(adhocWorkFeature, snapshotDateTimeNow);
      workFeatures.Add(aFeature);
      break;

    case GeometryType.Polyline:
      aFeature = await AddWorkOrderLineForAdhocWorkOrderFeature(adhocWorkFeature, snapshotDateTimeNow);
      workFeatures.Add(aFeature);
      break;
  }
}

//  UNION EXTENTS OF ALL SELECTED MAP FEATURES

Geometry newGeometry = GeometryEngine.Union(workFeatures.Select(f => f.Geometry.Extent));
Geometry newWorkOrderGeom = newGeometry;

//  IF PARENT GEOMETRY IS NOT NULL UNION PARENT GEOMETRY WITH UNION OF ALL SELECTED MAP FEATURES

if (SelectedWorkOrder.Geometry != null)
{
    newWorkOrderGeom = GeometryEngine.Union(newGeometry, SelectedWorkOrder.Geometry);
}

//  BUFFER NEW PARENT EXTENT
Geometry bufferedGeometry = GeometryEngine.Buffer(newWorkOrderGeom.Extent, ApplicationManager.ConfigManager.WorkManagementToolSettings.AdhocWorkOrderBufferInMeters);

//  ADD GRAPHIC TO MAP TO CHECK NEW EXTENT

Graphic gr = new Graphic(bufferedGeometry);
gr.Symbol = EpochUtils.GetPolygonHighlightSymbol();
m_WorkManagementToolAdHocWorkFeaturesGraphicsLayer.Graphics.Add(gr);

//  UPDATE GEOMETRY PROPERTIES FOR IN MEMORY PARENT

SelectedWorkOrder.Geometry = bufferedGeometry;
SelectedWorkOrder.GeodatabaseFeature.Geometry = bufferedGeometry;

//  GET FEATURE TABLE TO UPDATE

GeodatabaseFeatureTable workOrderFeatureTable = (GeodatabaseFeatureTable)SelectedWorkOrder.GeodatabaseFeature.FeatureTable;

//  GET FEATURE TO UPDATE
string whereClause = "GLOBALID = '{" + SelectedWorkOrder.GlobalId.ToString().ToUpper() + "}'";
FeatureQueryResult fqr = await m_LocalGDBStallion.QueryFeatureTable(workOrderFeatureTable, whereClause);
Feature actualFeature = fqr.ElementAt(0);

//  SET FEATURE GEOMETRY TO BUFFERED GEOMETRY AND UPDATE FEATURE

actualFeature.Geometry = bufferedGeometry;

await workOrderFeatureTable.UpdateFeatureAsync(actualFeature);

//  THIS RETURNS 1, SO UPDATE HAS OCCURRED

FeatureQueryResult fqrUpdate = await workOrderFeatureTable.GetUpdatedFeaturesAsync();

//  COMMIT TRANSACTION

if (m_SelectedWorkDownloadAreaGeodatabase.IsInTransaction)
  m_SelectedWorkDownloadAreaGeodatabase.CommitTransaction();

0 Kudos
0 Replies