protected async void BuildParcels() { await QueuedTask.Run(() => { var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ParcelLayer>().FirstOrDefault(); var theActiveRecord = myParcelFabricLayer.GetActiveRecord(); myParcelFabricLayer.SetActiveRecord(theActiveRecord); var guid = theActiveRecord.Guid; if (myParcelFabricLayer == null) { return; } #region Build parcels var editOper = new EditOperation() { Name = "Build Parcels", ProgressMessage = "Build Parcels...", ShowModalMessageAfterFailure = true, SelectNewFeatures = true, SelectModifiedFeatures = true }; editOper.BuildParcelsByRecord(myParcelFabricLayer, guid); editOper.Execute(); #endregion }); }
protected async void BuildParcels() { string errorMessage = await QueuedTask.Run(() => { #region Build parcels try { var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ParcelLayer>().FirstOrDefault(); if (myParcelFabricLayer == null) { return("Parcel layer not found in map."); } var theActiveRecord = myParcelFabricLayer.GetActiveRecord(); var guid = theActiveRecord.Guid; var editOper = new EditOperation() { Name = "Build Parcels", ProgressMessage = "Build Parcels...", ShowModalMessageAfterFailure = true, SelectNewFeatures = true, SelectModifiedFeatures = true }; editOper.BuildParcelsByRecord(myParcelFabricLayer, guid); if (!editOper.Execute()) { return(editOper.ErrorMessage); } } catch (Exception ex) { return(ex.Message); } return(""); #endregion }); if (!string.IsNullOrEmpty(errorMessage)) { MessageBox.Show(errorMessage, "Build Parcels."); } }
public void BuildParcelsByRecord() { QueuedTask.Run(() => { try { var layers = MapView.Active.Map.GetLayersAsFlattenedList(); var pfL = layers.FirstOrDefault(l => l is ParcelLayer) as ParcelLayer; var pRec = pfL.GetActiveRecord(); pfL.SetActiveRecord(pRec); var guid = pRec.Guid; if (pfL == null) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Cannot Build Parcels. No Active Record.", "Error", System.Windows.MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } var editOperation = new EditOperation() { Name = "Build Parcels", ProgressMessage = "Build Parcels...", ShowModalMessageAfterFailure = true, SelectNewFeatures = true, SelectModifiedFeatures = true }; // Run build parcels by record editOperation.BuildParcelsByRecord(pfL, guid); editOperation.ExecuteAsync(); } catch (Exception exc) { // Catch any exception found and display in a message box ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Exception caught: " + exc.Message); return; } }); }
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); }
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); }