ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / ParcelFabricExtensions Class / GetParcelTypeNamesAsync Method
The parcel layer.
Example

In This Topic
    GetParcelTypeNamesAsync Method
    In This Topic
    Gets the parcel type names for the given parcel layer.
    Syntax
    public static Task<List<string>> GetParcelTypeNamesAsync( 
       ParcelLayer parcelLayer
    )
    Public Shared Function GetParcelTypeNamesAsync( _
       ByVal parcelLayer As ParcelLayer _
    ) As Task(Of List(Of String))

    Parameters

    parcelLayer
    The parcel layer.

    Return Value

    A Task to the set of parcel type names.
    Exceptions
    ExceptionDescription
    Insufficient license. This method requires a standard license.
    Example
    Copy standard line features into a parcel type
    string errorMessage = await QueuedTask.Run( async () =>
    {
      // check for selected layer
      if (MapView.Active.GetSelectedLayers().Count == 0)
        return "Please select a target parcel polygon layer in the table of contents.";
      //get the feature layer that's selected in the table of contents
      var destPolygonL = MapView.Active.GetSelectedLayers().OfType<FeatureLayer>().FirstOrDefault();
      try
      {
        var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<ParcelLayer>().FirstOrDefault();
        //if there is no fabric in the map then bail
        if (myParcelFabricLayer == null)
          return "There is no fabric in the map.";
        var pRec = myParcelFabricLayer.GetActiveRecord();
        if (pRec == null)
          return "There is no Active Record. Please set the active record and try again.";
        string ParcelTypeName = "";
        IEnumerable<string> parcelTypeNames = await myParcelFabricLayer.GetParcelTypeNamesAsync();
        foreach (string parcelTypeNm in parcelTypeNames)
        {
          var polygonLyrParcelTypeEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeNameAsync(parcelTypeNm);
          foreach (FeatureLayer lyr in polygonLyrParcelTypeEnum)
            if (lyr == destPolygonL)
            {
              ParcelTypeName = parcelTypeNm;
              break;
            }
        }
        if (String.IsNullOrEmpty(ParcelTypeName))
          return "Please select a target parcel polygon layer in the table of contents.";
        var srcFeatLyr = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(l => l.Name.Contains("MySourceLines") && l.IsVisible);
        if (srcFeatLyr == null)
          return "Looking for a layer named 'MySourceLines' in the table of contents.";
        //now get the line layer for this parcel type
        var destLineLyrEnum = await myParcelFabricLayer.GetParcelLineLayerByTypeNameAsync(ParcelTypeName);
        if (destLineLyrEnum.Count() == 0) //make sure there is one in the map
          return ParcelTypeName + " not found.";
        var destLineL = destLineLyrEnum.FirstOrDefault();
        if (destLineL == null || destPolygonL == null)
          return "";
        var editOper = new EditOperation()
        {
          Name = "Copy Line Features To Parcel Type",
          ProgressMessage = "Copy Line Features To Parcel Type...",
          ShowModalMessageAfterFailure = true,
          SelectNewFeatures = true,
          SelectModifiedFeatures = false
        };
        var ids = new List<long>((srcFeatLyr as FeatureLayer).GetSelection().GetObjectIDs());
        if (ids.Count == 0)
          return "No selected lines were found. Please select line features and try again.";
        editOper.CopyLineFeaturesToParcelType(srcFeatLyr, ids, destLineL, destPolygonL);
        if (!editOper.Execute())
          return editOper.ErrorMessage;
      }
      catch (Exception ex)
      {
        return ex.Message;
      }
      return "";
    });
    if (!string.IsNullOrEmpty(errorMessage))
      MessageBox.Show(errorMessage, "Copy Line Features To Parcel Type.");
    Set parcels historic
    string errorMessage = await QueuedTask.Run(async () =>
    {
      var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<ParcelLayer>().FirstOrDefault();
      if (myParcelFabricLayer == null)
        return "Please add a parcel fabric to the map";
      try
      {
        FeatureLayer destPolygonL = null;
        //find the first layer that is a parcel type, is non-historic, and has a selection
        bool bFound = false;
        var ParcelTypesEnum = await myParcelFabricLayer.GetParcelTypeNamesAsync();
        foreach (FeatureLayer mapFeatLyr in MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>())
        {
          foreach (string ParcelType in ParcelTypesEnum)
          {
            var layerEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeNameAsync(ParcelType);
            foreach (FeatureLayer flyr in layerEnum)
            {
              if (flyr == mapFeatLyr)
              {
                bFound = mapFeatLyr.SelectionCount > 0;
                destPolygonL = mapFeatLyr;
                break;
              }
            }
            if (bFound) break;
          }
          if (bFound) break;
        }
        if (!bFound)
          return "Please select parcels to set as historic.";
    
        var theActiveRecord = myParcelFabricLayer.GetActiveRecord();
        if (theActiveRecord == null)
          return "There is no Active Record. Please set the active record and try again.";
    
        var ids = new List<long>(destPolygonL.GetSelection().GetObjectIDs());
        //can do multi layer selection but using single per code above
        var sourceFeatures = new Dictionary<MapMember, List<long>>();
        sourceFeatures.Add(destPolygonL, ids);
        var editOper = new EditOperation()
        {
          Name = "Set Parcels Historic",
          ProgressMessage = "Set Parcels Historic...",
          ShowModalMessageAfterFailure = true,
          SelectNewFeatures = true,
          SelectModifiedFeatures = false
        };
        editOper.SetParcelHistoryRetired(myParcelFabricLayer, 
          SelectionSet.FromDictionary(sourceFeatures), theActiveRecord);
        if (!editOper.Execute())
          return editOper.ErrorMessage;
      }
      catch (Exception ex)
      {
        return ex.Message;
      }
      return "";
    });
    if (!string.IsNullOrEmpty(errorMessage))
      MessageBox.Show(errorMessage, "Set Parcels Historic.");
    Shrink parcels to seeds
    string errorMessage = await QueuedTask.Run(async () =>
    {
      var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<ParcelLayer>().FirstOrDefault();
      if (myParcelFabricLayer == null)
        return "Please add a parcel fabric to the map";
      try
      {
        FeatureLayer parcelPolygonLyr = null;
        //find the first layer that is a polygon parcel type, is non-historic, and has a selection
        bool bFound = false;
        var ParcelTypesEnum = await myParcelFabricLayer.GetParcelTypeNamesAsync();
        foreach (FeatureLayer mapFeatLyr in MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>())
        {
          foreach (string ParcelType in ParcelTypesEnum)
          {
            var layerEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeNameAsync(ParcelType);
            foreach (FeatureLayer flyr in layerEnum)
            {
              if (flyr == mapFeatLyr)
              {
                bFound = mapFeatLyr.SelectionCount > 0;
                parcelPolygonLyr = mapFeatLyr;
                break;
              }
            }
            if (bFound) break;
          }
          if (bFound) break;
        }
        if (!bFound)
          return "Please select parcels to shrink to seeds.";
        var editOper = new EditOperation()
        {
          Name = "Shrink Parcels To Seeds",
          ProgressMessage = "Shrink Parcels To Seeds...",
          ShowModalMessageAfterFailure = true,
          SelectNewFeatures = true,
          SelectModifiedFeatures = false
        };
        var ids = new List<long>(parcelPolygonLyr.GetSelection().GetObjectIDs());
        var sourceParcelFeatures = new Dictionary<MapMember, List<long>>();
        sourceParcelFeatures.Add(parcelPolygonLyr, ids);
        editOper.ShrinkParcelsToSeeds(myParcelFabricLayer,SelectionSet.FromDictionary(sourceParcelFeatures));
        if (!editOper.Execute())
          return editOper.ErrorMessage;
      }
      catch (Exception ex)
      {
        return ex.Message;
      }
      return "";
    });
    if (!string.IsNullOrEmpty(errorMessage))
      MessageBox.Show(errorMessage, "Shrink Parcels To Seeds.");
    Get parcel type name from feature layer
    private async Task<string> GetParcelTypeNameFromFeatureLayer(ParcelLayer myParcelFabricLayer, FeatureLayer featLayer, GeometryType geomType)
    {
      if (featLayer == null) //nothing to do, return empty string
        return String.Empty;
      IEnumerable<string> parcelTypeNames = await myParcelFabricLayer.GetParcelTypeNamesAsync();
      foreach (string parcelTypeName in parcelTypeNames)
      {
        if (geomType == GeometryType.Polygon)
        {
          var polygonLyrParcelTypeEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeNameAsync(parcelTypeName);
          foreach (FeatureLayer lyr in polygonLyrParcelTypeEnum)
            if (lyr == featLayer)
              return parcelTypeName;
    
          polygonLyrParcelTypeEnum = await myParcelFabricLayer.GetHistoricParcelPolygonLayerByTypeNameAsync(parcelTypeName);
          foreach (FeatureLayer lyr in polygonLyrParcelTypeEnum)
            if (lyr == featLayer)
              return parcelTypeName;
        }
        if (geomType == GeometryType.Polyline)
        {
          var lineLyrParcelTypeEnum = await myParcelFabricLayer.GetParcelLineLayerByTypeNameAsync(parcelTypeName);
          foreach (FeatureLayer lyr in lineLyrParcelTypeEnum)
            if (lyr == featLayer)
              return parcelTypeName;
    
          lineLyrParcelTypeEnum = await myParcelFabricLayer.GetHistoricParcelLineLayerByTypeNameAsync(parcelTypeName);
          foreach (FeatureLayer lyr in lineLyrParcelTypeEnum)
            if (lyr == featLayer)
              return parcelTypeName;
        }
      }
      return String.Empty;
    }
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also