Skip to content

Instantly share code, notes, and snippets.

@dkuida
Last active February 9, 2019 17:54
Show Gist options
  • Select an option

  • Save dkuida/1e7e108f5e116522d4a7603c25d35cc1 to your computer and use it in GitHub Desktop.

Select an option

Save dkuida/1e7e108f5e116522d4a7603c25d35cc1 to your computer and use it in GitHub Desktop.

Revisions

  1. dkuida revised this gist Feb 9, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MapSteps.cs
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ public class MapSteps
    public ILayerManagement ParcelLayerManager { private get; set; } = new LayerManagement(ParcelLayer);
    private readonly IMap _activeMap;

    public MapSteps(UINotifier notifier, CadasterModuleStore appStore, IMap activeMap)
    public MapSteps(CadasterModuleStore appStore, UINotifier notifier, IMap activeMap)
    {
    _notifier = notifier;
    _appStore = appStore;
  2. dkuida revised this gist Feb 9, 2019. 3 changed files with 5 additions and 42 deletions.
    24 changes: 2 additions & 22 deletions ActiveMap.cs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@

    namespace CadasterFlows.Vertices
    namespace Example
    {
    public class ActiveMap : IMap
    {
    @@ -20,31 +20,11 @@ public IReadOnlyList<Layer> GetLayersAsFlattenedList()

    return QueuedTask.Run(() =>
    {
    List<Geometry> parcelGeometries = new List<Geometry>();
    List<Geometry> sideWalkGeometries = new List<Geometry>();

    var selection = MapView.Active.Map.GetSelection();
    selection
    .ForEachWithIndex((mapElement, index) =>
    {
    var featureLayer = mapElement.Key as FeatureLayer;
    var lyrDefn = featureLayer?.GetFeatureClass().GetDefinition();
    string shapeField = lyrDefn?.GetShapeField();
    var shapeIndex = lyrDefn.FindField(shapeField);
    QueryFilter filter = new QueryFilter {ObjectIDs = mapElement.Value};
    var rowCursor = featureLayer?.Search(filter);
    while (rowCursor.MoveNext())
    {
    var geometry = (Geometry) rowCursor.Current.GetOriginalValue(shapeIndex);
    if (featureLayer.Name == ParcelToolConfig.SideWalkLayer)
    {
    sideWalkGeometries.Add(geometry);
    }
    else
    {
    parcelGeometries.Add(geometry);
    }
    }
    // logic
    });
    return (parcelGeometries, sideWalkGeometries);
    });
    21 changes: 2 additions & 19 deletions MapSteps.cs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    namespace CadasterFlows.Parcel
    namespace Example
    {
    public class MapSteps
    {
    @@ -24,24 +24,7 @@ public MapSteps(UINotifier notifier, CadasterModuleStore appStore, IMap activeMa
    {
    switch (state.FlowCurrentStep)
    {
    case FlowStep.NotStarted:
    await CleanWorkspace();
    break;
    case FlowStep.SelectSource:
    await Start();
    break;
    case FlowStep.EditParcel:
    await CreateParcel();
    break;
    case FlowStep.SaveParcel:
    var success = await SaveParcel();
    if (success)
    {
    _appStore.ParcelProcessState.Dispatch(
    new StopParcelProcessAction());
    }

    break;
    // UI update logic
    }
    }
    catch (Exception e)
    2 changes: 1 addition & 1 deletion UINotifier.cs
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    using ArcGIS.Desktop.Framework.Dialogs;

    namespace CadasterFlows.Utils
    namespace Example
    {
    public interface UINotifier
    {
  3. dkuida revised this gist Feb 8, 2019. 1 changed file with 55 additions and 0 deletions.
    55 changes: 55 additions & 0 deletions ActiveMap.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@

    namespace CadasterFlows.Vertices
    {
    public class ActiveMap : IMap
    {
    private readonly Map _map;

    public ActiveMap(Map map)
    {
    _map = map;
    }

    public IReadOnlyList<Layer> GetLayersAsFlattenedList()
    {
    return _map.GetLayersAsFlattenedList();
    }

    public Task<(List<Geometry>, List<Geometry>)> GetSelectedGeometries()
    {

    return QueuedTask.Run(() =>
    {
    List<Geometry> parcelGeometries = new List<Geometry>();
    List<Geometry> sideWalkGeometries = new List<Geometry>();

    var selection = MapView.Active.Map.GetSelection();
    selection
    .ForEachWithIndex((mapElement, index) =>
    {
    var featureLayer = mapElement.Key as FeatureLayer;
    var lyrDefn = featureLayer?.GetFeatureClass().GetDefinition();
    string shapeField = lyrDefn?.GetShapeField();
    var shapeIndex = lyrDefn.FindField(shapeField);
    QueryFilter filter = new QueryFilter {ObjectIDs = mapElement.Value};
    var rowCursor = featureLayer?.Search(filter);
    while (rowCursor.MoveNext())
    {
    var geometry = (Geometry) rowCursor.Current.GetOriginalValue(shapeIndex);
    if (featureLayer.Name == ParcelToolConfig.SideWalkLayer)
    {
    sideWalkGeometries.Add(geometry);
    }
    else
    {
    parcelGeometries.Add(geometry);
    }
    }
    });
    return (parcelGeometries, sideWalkGeometries);
    });


    }
    }
    }
  4. dkuida revised this gist Feb 8, 2019. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions UINotifier.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    using ArcGIS.Desktop.Framework.Dialogs;

    namespace CadasterFlows.Utils
    {
    public interface UINotifier
    {
    void Notify(string message);
    }

    public class MessageBoxNotifier : UINotifier
    {
    public void Notify(string message)
    {
    MessageBox.Show(message);
    }
    }
    }
  5. dkuida created this gist Feb 8, 2019.
    54 changes: 54 additions & 0 deletions MapSteps.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    namespace CadasterFlows.Parcel
    {
    public class MapSteps
    {
    private readonly UINotifier _notifier;
    private readonly CadasterModuleStore _appStore;
    private const string ParcelLayerWorkspace = "temp_parcels";
    private const string ParcelLayer = "Parcels";

    public ILayerManagement ParcelWorkspaceLayerManager { private get; set; } =
    new LayerManagement(ParcelLayerWorkspace);

    public ILayerManagement ParcelLayerManager { private get; set; } = new LayerManagement(ParcelLayer);
    private readonly IMap _activeMap;

    public MapSteps(UINotifier notifier, CadasterModuleStore appStore, IMap activeMap)
    {
    _notifier = notifier;
    _appStore = appStore;
    _activeMap = activeMap;
    _appStore.ParcelProcessState.Subscribe(async state =>
    {
    try
    {
    switch (state.FlowCurrentStep)
    {
    case FlowStep.NotStarted:
    await CleanWorkspace();
    break;
    case FlowStep.SelectSource:
    await Start();
    break;
    case FlowStep.EditParcel:
    await CreateParcel();
    break;
    case FlowStep.SaveParcel:
    var success = await SaveParcel();
    if (success)
    {
    _appStore.ParcelProcessState.Dispatch(
    new StopParcelProcessAction());
    }

    break;
    }
    }
    catch (Exception e)
    {
    LoggerSingleton.Instance.Logger.Warn(e);
    }
    });
    }
    }
    }