Esempio n. 1
0
        protected async void CopyParcelLinesToParcelType()
        {
            #region Copy parcel lines to a parcel type
            string errorMessage = await QueuedTask.Run(async() =>
            {
                // check for selected layer
                if (MapView.Active.GetSelectedLayers().Count == 0)
                {
                    return("Please select a source parcel polygon feature layer in the table of contents.");
                }
                try
                {
                    var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ParcelLayer>().FirstOrDefault();
                    if (myParcelFabricLayer == null)
                    {
                        return("No parcel layer found in the map.");
                    }

                    //get the feature layer that's selected in the table of contents
                    var srcParcelFeatLyr     = MapView.Active.GetSelectedLayers().OfType <FeatureLayer>().FirstOrDefault();
                    string sTargetParcelType = "Tax";
                    var destLineLEnum        = await myParcelFabricLayer.GetParcelLineLayerByTypeName(sTargetParcelType);
                    if (destLineLEnum.Count() == 0)
                    {
                        return("");
                    }
                    var destLineL        = destLineLEnum.FirstOrDefault();
                    var destPolygonLEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeName(sTargetParcelType);
                    if (destPolygonLEnum.Count() == 0)
                    {
                        return("");
                    }
                    var destPolygonL = destPolygonLEnum.FirstOrDefault();
                    if (destLineL == null || destPolygonL == null)
                    {
                        return("");
                    }
                    var theActiveRecord = myParcelFabricLayer.GetActiveRecord();
                    if (theActiveRecord == null)
                    {
                        return("There is no Active Record. Please set the active record and try again.");
                    }
                    var editOper = new EditOperation()
                    {
                        Name            = "Copy Lines To Parcel Type",
                        ProgressMessage = "Copy Lines To Parcel Type ...",
                        ShowModalMessageAfterFailure = true,
                        SelectNewFeatures            = true,
                        SelectModifiedFeatures       = false
                    };
                    var ids = new List <long>(srcParcelFeatLyr.GetSelection().GetObjectIDs());
                    if (ids.Count == 0)
                    {
                        return("No selected parcels found. Please select parcels and try again.");
                    }
                    //add the standard feature line layers source, and their feature ids to a new KeyValuePair
                    var kvp = new KeyValuePair <MapMember, List <long> >(srcParcelFeatLyr, ids);
                    var sourceParcelFeatures = new List <KeyValuePair <MapMember, List <long> > > {
                        kvp
                    };
                    editOper.CopyParcelLinesToParcelType(myParcelFabricLayer, sourceParcelFeatures, destLineL, destPolygonL, true, false, true);
                    if (!editOper.Execute())
                    {
                        return(editOper.ErrorMessage);
                    }
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
                return("");
            });

            if (!string.IsNullOrEmpty(errorMessage))
            {
                MessageBox.Show(errorMessage, "Copy Parcel Lines To Parcel Type.");
            }
            #endregion
        }
Esempio n. 2
0
        private async Task <string> CopyParcelsToLotAsync(CancelableProgressorSource cps)
        {
            var error = await QueuedTask.Run <string>(() =>
            {
                // copy tax parcels to lot
                try
                {
                    if (_parcelFabricLayer == null)
                    {
                        return("There is no parcel fabric in the map.");
                    }
                    var theActiveRecord = _parcelFabricLayer.GetActiveRecord();
                    if (theActiveRecord == null)
                    {
                        return("There is no Active Record for the Parcel Fabric");
                    }
                }
                catch (Exception ex)
                {
                    return($@"Error [Exception]: {ex.Message}");
                }
                try
                {
                    // use CopyParcelLinesToParcelType to copy the tax parcels to the lot parcel type
                    var editOper = new EditOperation()
                    {
                        Name            = "Copy Lines To Lot Parcel Type",
                        ProgressMessage = "Copy Lines To Lot Parcel Type ...",
                        ShowModalMessageAfterFailure = false,
                        SelectNewFeatures            = false,
                        SelectModifiedFeatures       = false
                    };
                    var qry = $@"{FieldNameZone} = {_selectedZone} and {FieldNameSect} = {_selectedSection} and {FieldNamePlat} = '{_selectedPlat}'";
                    SelectSetAndZoomAsync(_taxLayerPolys, qry);
                    var ids = new List <long>(_taxLayerPolys.GetSelection().GetObjectIDs());
                    if (ids.Count == 0)
                    {
                        return("No selected parcels found. Please select parcels and try again.");
                    }
                    //add the standard feature line layers source, and their feature ids to a new KeyValuePair
                    var kvp = new KeyValuePair <MapMember, List <long> >(_taxLayerPolys, ids);
                    var sourceParcelFeatures = new List <KeyValuePair <MapMember, List <long> > > {
                        kvp
                    };
                    editOper.CopyParcelLinesToParcelType(_parcelFabricLayer, sourceParcelFeatures, _lotLayerLines, _lotLayerPolys, false, true, true);
                    if (!editOper.Execute())
                    {
                        return(editOper.ErrorMessage);
                    }
                }
                catch (Exception ex)
                {
                    return($@"Error [Exception]: {ex.Message}");
                }
                try
                {
                    // Build all Parcels for the Active record in the parcel fabric (set in step one)
                    var theActiveRecord = _parcelFabricLayer.GetActiveRecord();
                    var guid            = theActiveRecord.Guid;
                    var editOper        = new EditOperation()
                    {
                        Name            = "Build Parcels",
                        ProgressMessage = "Build Parcels...",
                        ShowModalMessageAfterFailure = true,
                        SelectNewFeatures            = true,
                        SelectModifiedFeatures       = true
                    };
                    cps.Progressor.Value += 1;
                    if (cps.Progressor.CancellationToken.IsCancellationRequested)
                    {
                        editOper.Abort();
                        return("Cancelled");
                    }
                    cps.Progressor.Status  = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed";
                    cps.Progressor.Message = editOper.ProgressMessage;
                    editOper.BuildParcelsByRecord(_parcelFabricLayer, guid);
                    if (!editOper.Execute())
                    {
                        return($@"Error [{editOper.Name}]: {editOper.ErrorMessage}");
                    }
                }
                catch (Exception ex)
                {
                    return($@"Error [Exception]: {ex.Message}");
                }
                return(string.Empty);
            }, cps.Progressor);

            return(error);
        }
Esempio n. 3
0
        protected async void CopyParcelLinesToParcelType()
        {
            await QueuedTask.Run(async() =>
            {
                // check for selected layer
                if (MapView.Active.GetSelectedLayers().Count == 0)
                {
                    System.Windows.MessageBox.Show("Please select a source parcel polygon feature layer in the table of contents", "Copy Parcel Lines To");
                    return;
                }

                //first get the feature layer that's selected in the table of contents
                var srcParcelFeatLyr = MapView.Active.GetSelectedLayers().OfType <FeatureLayer>().First();

                var fcDefinition      = srcParcelFeatLyr.GetFeatureClass().GetDefinition();
                GeometryType geomType = fcDefinition.GetShapeType();
                if (geomType != GeometryType.Polygon)
                {
                    System.Windows.MessageBox.Show("Please select a source parcel polygon layer in the table of contents", "Copy Line Features To");
                    return;
                }

                if (!await srcParcelFeatLyr.IsControlledByParcelFabric(ParcelFabricType.ParcelFabric))
                {
                    System.Windows.MessageBox.Show("Please select a source parcel polygon feature layer in the table of contents", "Copy Parcel Lines To");
                    return;
                }



                string sTargetParcelType = "Tax";

                if (sTargetParcelType.Trim().Length == 0)
                {
                    return;
                }

                var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ParcelLayer>().FirstOrDefault();

                string destLineLyrName1 = sTargetParcelType + "_Lines";
                string destLineLyrName2 = sTargetParcelType + " Lines";
                string destLineLyrName3 = sTargetParcelType + "Lines";

                var destLineL = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(l => l.Name == destLineLyrName1);
                if (destLineL == null)
                {
                    destLineL = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(l => l.Name == destLineLyrName2);
                }

                if (destLineL == null)
                {
                    destLineL = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(l => l.Name == destLineLyrName3);
                }

                var destPolygonL = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(l => l.Name == sTargetParcelType);

                if (myParcelFabricLayer == null || destLineL == null || destPolygonL == null)
                {
                    return;
                }

                #region Copy parcel lines to a parcel type
                var theActiveRecord = myParcelFabricLayer.GetActiveRecord();

                if (theActiveRecord == null)
                {
                    System.Windows.MessageBox.Show("There is no Active Record. Please set the active record and try again.", "Copy Line Features To");
                    return;
                }

                var editOper = new EditOperation()
                {
                    Name            = "Copy Lines To Parcel Type",
                    ProgressMessage = "Copy Lines To Parcel Type ...",
                    ShowModalMessageAfterFailure = true,
                    SelectNewFeatures            = true,
                    SelectModifiedFeatures       = false
                };

                var ids = new List <long>(srcParcelFeatLyr.GetSelection().GetObjectIDs());

                if (ids.Count == 0)
                {
                    System.Windows.MessageBox.Show("No selected parcels found. Please select parcels and try again.", "Copy Parcel Lines To");
                    return;
                }
                //add the standard feature line layers source, and their feature ids to a new KeyValuePair
                var kvp = new KeyValuePair <MapMember, List <long> >(srcParcelFeatLyr, ids);
                var sourceParcelFeatures = new List <KeyValuePair <MapMember, List <long> > > {
                    kvp
                };
                ParcelEditToken peToken    = editOper.CopyParcelLinesToParcelType(myParcelFabricLayer, sourceParcelFeatures, destLineL, destPolygonL, null, true, false, true);
                var createdIDsSelectionSet = peToken.CreatedFeatures;
                editOper.Execute();
                #endregion
            });
        }