public void FindCurves(string whereClause = null) { IMap pMap = ArcMap.Document.ActiveView.FocusMap; if (hasOpenJob()) return; IRelationshipClass relationshipClass = null; ISelectionSet relatedSelectionSet = null; myAOProgressor progressor = new myAOProgressor(); try { Finished = false; progressor.setStepProgressorProperties(1, "Initializing"); ICadastralFabricLayer CFLayer = GetFabricLayer(pMap); IFeatureLayer CFLineLayer = CFLayer.get_CadastralSubLayer(esriCadastralFabricRenderer.esriCFRLines); IFeatureLayer CFParcelLayer = CFLayer.get_CadastralSubLayer(esriCadastralFabricRenderer.esriCFRParcels); //for each CF line feature class IFeatureSelection CFLineFeatureSelection = (IFeatureSelection)CFLineLayer; IFeatureSelection CFParcelFeatureSelection = (IFeatureSelection)CFParcelLayer; ISelectionSet selectionSet = null; if (CFParcelFeatureSelection.SelectionSet.Count > 0) { //parcels selected //Create memory relationship class to help with the mapping IMemoryRelationshipClassFactory MemoryRCF = new MemoryRelationshipClassFactoryClass(); relationshipClass = MemoryRCF.Open("Parcel_Layer_Rel", CFParcelLayer.FeatureClass, "ObjectID", CFLineLayer.FeatureClass, "ParcelID", "forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany); //convert selection set to ISet of rows ISet polySet = new Set(); ICursor cursor; CFParcelFeatureSelection.SelectionSet.Search(null, false, out cursor); IRow row = null; while((row = cursor.NextRow()) != null) polySet.Add(row); polySet.Reset(); //use the relationship class to find related rows ISet lineSet = relationshipClass.GetObjectsRelatedToObjectSet(polySet); //convert set back to selection set lineSet.Reset(); //create an empty selection set (there should be a better way to do this.... //will only evaluate the lines related to the parcels that are selected //selectionSet = CFLineLayer.FeatureClass.Select(new QueryFilter() { WhereClause = "1=0" }, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, null); //will union the current line selection and the parcel selection relatedSelectionSet = CFLineFeatureSelection.SelectionSet.Select(null, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, null); while ((row = (IRow)lineSet.Next()) != null) { relatedSelectionSet.Add(row.OID); Marshal.ReleaseComObject(row); } Marshal.ReleaseComObject(lineSet); polySet.Reset(); while ((row = (IRow)polySet.Next()) != null) Marshal.ReleaseComObject(row); Marshal.ReleaseComObject(polySet); selectionSet = relatedSelectionSet; } else if (CFLineFeatureSelection.SelectionSet.Count > 0) { //lines selected selectionSet = CFLineFeatureSelection.SelectionSet; } else { if (DialogResult.OK != messageBox.Show("You are about to run the add-in on the entire feature class, this could take a long time. Proceeed?", "Long Operation", MessageBoxButtons.OKCancel)) return; } FindCurves(CFLineLayer.Name, CFLineLayer.FeatureClass, selectionSet, whereClause, progressor); if (Curves.Count == 0) { messageBox.Show("No inferred curved lines found."); return; } } catch (Exception Exx) { messageBox.Show(Exx.Message); if (relationshipClass != null) Marshal.ReleaseComObject(relationshipClass); if (relatedSelectionSet != null) Marshal.ReleaseComObject(relatedSelectionSet); } finally { progressor.Dispose(); Finished = true; } }
public void UpdateCurves(IEnumerable<InferredCurve> updateCurves = null) { if (updateCurves == null) updateCurves = Curves; if (m_pEd == null) throw new Exception("Curves can not be updates without an editing environmanet"); if (m_pEd.EditState == esriEditState.esriStateNotEditing) { messageBox.Show("Please start editing first, and try again."); return; } if (hasOpenJob()) return; IMap pMap = m_pEd.Map; myAOProgressor progressor = new myAOProgressor(); try { Finished = false; progressor.setStepProgressorProperties(1, "Initializing"); ICadastralFabricLayer CFLayer = GetFabricLayer(pMap); ICadastralFabric pCadFabric = CFLayer.CadastralFabric; IFeatureLayer CFLineLayer = CFLayer.get_CadastralSubLayer(esriCadastralFabricRenderer.esriCFRLines); IFeatureLayer CFParcelLayer = CFLayer.get_CadastralSubLayer(esriCadastralFabricRenderer.esriCFRParcels); if (updateCurves.Count() > 0) UpdateCurves(pCadFabric, CFLineLayer.FeatureClass, updateCurves, progressor); } catch (Exception Exx) { messageBox.Show(Exx.Message); if (m_pEd != null && m_pEd.HasEdits()) { m_pEd.AbortOperation(); } } finally { progressor.Dispose(); Finished = true; } }