Esempio n. 1
0
        protected async void CopyLineFeaturesToParcelType()
        {
            #region 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.GetParcelTypeNames();
                    foreach (string parcelTypeNm in parcelTypeNames)
                    {
                        var polygonLyrParcelTypeEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeName(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.GetParcelLineLayerByTypeName(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.");
            }
            #endregion
        }
Esempio n. 2
0
        private async Task <Tuple <string, int> > ImportPlatAsync(CancelableProgressorSource cps)
        {
            var result = await QueuedTask.Run <Tuple <string, int> >(async() =>
            {
                // first we  create a 'legal record' for the plat
                Dictionary <string, object> RecordAttributes = new Dictionary <string, object>();
                string sNewRecordName = $@"Plat {_selectedZone}-{_selectedSection}-{_selectedPlat}";
                int importedCount     = 0;
                try
                {
                    var editOper = new EditOperation()
                    {
                        Name            = $@"Create Parcel Fabric Record: {sNewRecordName}",
                        ProgressMessage = "Create Parcel Fabric Record...",
                        ShowModalMessageAfterFailure = false,
                        SelectNewFeatures            = false,
                        SelectModifiedFeatures       = false
                    };
                    cps.Progressor.Value += 1;
                    if (cps.Progressor.CancellationToken.IsCancellationRequested)
                    {
                        editOper.Abort();
                        return(new Tuple <string, int> ("Cancelled", importedCount));
                    }
                    cps.Progressor.Status  = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed";
                    cps.Progressor.Message = editOper.ProgressMessage;
                    RecordAttributes.Add(FieldNameName, sNewRecordName);
                    RecordAttributes.Add(FieldNameZone, _selectedZone);
                    RecordAttributes.Add(FieldNameSect, _selectedSection);
                    RecordAttributes.Add(FieldNamePlat, _selectedPlat);
                    var editRowToken = editOper.CreateEx(_recordLayer, RecordAttributes);
                    if (!editOper.Execute())
                    {
                        return(new Tuple <string, int>($@"Error [{editOper.Name}]: {editOper.ErrorMessage}", importedCount));
                    }

                    // now make the record the active record
                    var defOID = -1;
                    var lOid   = editRowToken.ObjectID ?? defOID;
                    await _parcelFabricLayer.SetActiveRecordAsync(lOid);
                }
                catch (Exception ex)
                {
                    return(new Tuple <string, int>($@"Error [Exception]: {ex.Message}", importedCount));
                }
                try
                {
                    // Copy the selected set of polygons into the Tax Parcels
                    // However, since we need to set the polygon attributes manually we need to add each
                    // parcel one at a time
                    var qry     = $@"{FieldNameZone} = {_selectedZone} and {FieldNameSect} = {_selectedSection} and {FieldNamePlat} = '{_selectedPlat}'";
                    var lstTmks = GetDistinctValues(_importParcelLineLayer, qry, FieldNameTmk);
                    lstTmks.Sort();
                    foreach (var selectedTmk in lstTmks)
                    {
                        importedCount++;
                        qry     = $@"{FieldNameTmk} = {selectedTmk}";
                        var cnt = SelectSet(_importParcelLineLayer, qry);
                        cps.Progressor.Value += cnt;
                        if (cps.Progressor.CancellationToken.IsCancellationRequested)
                        {
                            return(new Tuple <string, int>("Cancelled", importedCount));
                        }
                        cps.Progressor.Status  = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed";
                        cps.Progressor.Message = $@"Process parcel no: {selectedTmk}";
                        var editOper           = new EditOperation()
                        {
                            Name            = $@"Copy new parcel lines for: {sNewRecordName}",
                            ProgressMessage = "Create Parcel lines ...",
                            ShowModalMessageAfterFailure = false,
                            SelectNewFeatures            = false,
                            SelectModifiedFeatures       = false
                        };
                        var ids = new List <long>(_importParcelLineLayer.GetSelection().GetObjectIDs());
                        if (ids.Count == 0)
                        {
                            return(new Tuple <string, int>($@"Error [{editOper.Name}]: No selected lines were found. Please select line features and try again.", importedCount));
                        }
                        var parcelEditTkn = editOper.CopyLineFeaturesToParcelType(_importParcelLineLayer, ids, _taxLayerLines, _taxLayerPolys);
                        if (!editOper.Execute())
                        {
                            return(new Tuple <string, int>($@"Error [{editOper.Name}]: {editOper.ErrorMessage}", importedCount));
                        }

                        // Update the names for all new parcel features
                        var createdParcelFeatures = parcelEditTkn.CreatedFeatures;
                        var editOperUpdate        = editOper.CreateChainedOperation();
                        // note: this only works for single parcels
                        Dictionary <string, object> ParcelAttributes = new Dictionary <string, object>();
                        // collect the attribute to be used for the polygon
                        // unfortunately the polygon attributes are not autopopulated so we have to do this here
                        foreach (KeyValuePair <MapMember, List <long> > kvp in createdParcelFeatures)
                        {
                            if (cps.Progressor.CancellationToken.IsCancellationRequested)
                            {
                                editOperUpdate.Abort();
                                return(new Tuple <string, int>("Cancelled", importedCount));
                            }
                            var mapMember = kvp.Key;
                            if (mapMember.Name.EndsWith("_Lines"))
                            {
                                var oids = kvp.Value;
                                foreach (long oid in oids)
                                {
                                    var insp = new Inspector();
                                    insp.Load(mapMember, oid);
                                    var tmk = insp[FieldNameTmk];
                                    if (tmk != null)
                                    {
                                        var sTmk = tmk.ToString();
                                        if (sTmk.Length > 6)
                                        {
                                            var selectedIsland  = sTmk.Substring(0, 1);
                                            var selectedZone    = sTmk.Substring(1, 1);
                                            var selectedSection = sTmk.Substring(2, 1);
                                            var selectedPlat    = sTmk.Substring(3, 3);
                                            ParcelAttributes.Add(FieldNameName, $@"{sTmk.Substring(0, 1)}-{sTmk.Substring(1, 1)}-{sTmk.Substring(2, 1)}-{sTmk.Substring(3, 3)}-{sTmk.Substring(6)}");
                                            ParcelAttributes.Add(FieldNameTmk, tmk);
                                            ParcelAttributes.Add(FieldNameIsland, selectedIsland);
                                            ParcelAttributes.Add(FieldNameZone, selectedZone);
                                            ParcelAttributes.Add(FieldNameSect, selectedSection);
                                            ParcelAttributes.Add(FieldNamePlat, selectedPlat);
                                            ParcelAttributes.Add(FieldNameParcel, insp[FieldNameParcel]);
                                            ParcelAttributes.Add(FieldNameLink, insp[FieldNameLink]);
                                            break;
                                        }
                                    }
                                }
                            }
                            if (ParcelAttributes.Count > 0)
                            {
                                break;
                            }
                        }
                        foreach (KeyValuePair <MapMember, List <long> > kvp in createdParcelFeatures)
                        {
                            if (cps.Progressor.CancellationToken.IsCancellationRequested)
                            {
                                editOperUpdate.Abort();
                                return(new Tuple <string, int>("Cancelled", importedCount));
                            }
                            var mapMember = kvp.Key;
                            if (!mapMember.Name.EndsWith("_Lines"))
                            {
                                var oids = kvp.Value;
                                foreach (long oid in oids)
                                {
                                    editOperUpdate.Modify(mapMember, oid, ParcelAttributes);
                                }
                            }
                        }
                        if (!editOperUpdate.Execute())
                        {
                            return(new Tuple <string, int>($@"Error [{editOperUpdate.Name}]: {editOperUpdate.ErrorMessage}", importedCount));
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(new Tuple <string, int>($@"Error [Exception]: {ex.Message}", importedCount));
                }
                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(new Tuple <string, int>("Cancelled", importedCount));
                    }
                    cps.Progressor.Status  = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed";
                    cps.Progressor.Message = editOper.ProgressMessage;
                    editOper.BuildParcelsByRecord(_parcelFabricLayer, guid);
                    if (!editOper.Execute())
                    {
                        return(new Tuple <string, int>($@"Error [{editOper.Name}]: {editOper.ErrorMessage}", importedCount));
                    }
                }
                catch (Exception ex)
                {
                    return(new Tuple <string, int>($@"Error [Exception]: {ex.Message}", importedCount));
                }
                return(new Tuple <string, int>(string.Empty, importedCount));
            }, cps.Progressor);

            return(result);
        }
Esempio n. 3
0
        protected async void CopyLineFeaturesToParcelType()
        {
            #region Copy standard line features into a parcel type

            await QueuedTask.Run(async() =>
            {
                // check for selected layer
                if (MapView.Active.GetSelectedLayers().Count == 0)
                {
                    System.Windows.MessageBox.Show("Please select a target parcel polygon layer in the table of contents", "Copy Line Features To");
                    return;
                }

                //first get the feature layer that's selected in the table of contents
                var destPolygonL      = MapView.Active.GetSelectedLayers().First() as FeatureLayer; //a parcel polygon feature layer
                var fcDefinition      = destPolygonL.GetFeatureClass().GetDefinition();
                GeometryType geomType = fcDefinition.GetShapeType();
                if (geomType != GeometryType.Polygon)
                {
                    System.Windows.MessageBox.Show("Please select a target parcel polygon layer in the table of contents", "Copy Line Features To");
                    return;
                }

                if (!await destPolygonL.IsControlledByParcelFabric(ParcelFabricType.ParcelFabric))
                {
                    System.Windows.MessageBox.Show("Please select a target parcel polygon layer in the table of contents", "Copy Line Features To");
                    return;
                }

                var srcFeatLyr          = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(l => l.Name == "Lines");
                var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ParcelLayer>().FirstOrDefault();

                string destLineLyrName1 = destPolygonL.Name + "_Lines";
                string destLineLyrName2 = destPolygonL.Name + " Lines";
                string destLineLyrName3 = destPolygonL.Name + "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);
                }

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

                if (!await destLineL.IsControlledByParcelFabric(ParcelFabricType.ParcelFabric))
                {
                    return;
                }

                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;
                }
                //add the standard feature line layers source, and their feature ids to a new KeyValuePair
                var ids = new List <long>((srcFeatLyr as FeatureLayer).GetSelection().GetObjectIDs());

                if (ids.Count == 0)
                {
                    System.Windows.MessageBox.Show("No selected lines were found. Please select line features and try again.", "Copy Line Features To");
                    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
                };

                editOper.CopyLineFeaturesToParcelType(srcFeatLyr, ids, destLineL, destPolygonL);
            });

            #endregion
        }