public override void OnClick() { // i will reuse cursor false-> true IFeatureCursor feature1Cursor = pflayer1.FeatureClass.GetFeatures(idList, true); while (featureA != null) { // queryin again with same params makes forever loop // using only first feature from an array feature1Cursor = pflayer1.FeatureClass.GetFeatures(idList, true); featureA = feature1Cursor.NextFeature(); } //At this point it stops and leaves // because your code is not in try catch block and exception occured string elenco = String.Empty;
public string FeaturesEqual(IFeature pFeatureA, IFeature pFeatureB) { // if value is null you have exception use Convert.ToSring(pFeatureA.get_Value(i)); string valore1 = pFeatureA.get_Value(i).ToString(); // I intend to use System.Object.Equals didn't use ESRI's object before bool equal = ESRI.ArcGIS.Geodatabase.Object.Equals(pFeatureA.get_Value(i), pFeatureB.get_Value(i)); }
public override void OnClick() { IFeatureLayer pflayer1; IFeatureLayer pflayer2; IFeature featureA; IFeature featureB; pflayer1 = GetLayerByName("Shape1"); IFeatureSelection p1FlSelection = pflayer1 as IFeatureSelection; int[] idList = GetFidList(@D:\ShapeFile1).ToArray(); IFeatureCursor feature1Cursor = pflayer1.FeatureClass.GetFeatures(idList, false); featureA = feature1Cursor.NextFeature(); pflayer2 = GetLayerByName("Shape2"); int[] oidList = GetFidList(@D:\ShapeFile1).ToArray(); IFeatureCursor feature2Cursor = pflayer2.FeatureClass.GetFeatures(oidList, false); featureB = feature2Cursor.NextFeature(); List<int> fidList = new List<int>(); while (featureA != null) { while (featureB != null) { string risultato = FeaturesEqual(featureA, featureB); if (!String.IsNullOrEmpty(risultato)) fidList.Add(Convert.ToInt32(risultato)); featureB = feature2Cursor.NextFeature(); } feature2Cursor = pflayer2.FeatureClass.GetFeatures(oidList, false); featureB = feature2Cursor.NextFeature(); feature1Cursor = pflayer1.FeatureClass.GetFeatures(idList, false); featureA = feature1Cursor.NextFeature(); } //At this point it stops and leaves string elenco = String.Empty; foreach (int numero in fidList) { elenco += numero + ","; } elenco = elenco.Trim(','); IMap pMap = m_hookHelper.FocusMap; IActiveView pActiveView = (IActiveView)m_hookHelper.FocusMap; string where = "FID IN (" + elenco + ")"; SelectMapFeaturesByAttributeQuery(pActiveView, pflayer1, where); }
//Compare Features //temporarily I consider only attribute compare and not geometry public string FeaturesEqual(IFeature pFeatureA, IFeature pFeatureB) { // attribute equal test int diffCount = 0; for (int i = 2; i < pFeatureA.Fields.FieldCount; i++) { string valore1 = pFeatureA.get_Value(i).ToString(); string valore2 = pFeatureB.get_Value(i).ToString(); bool equal = ESRI.ArcGIS.Geodatabase.Object.Equals(pFeatureA.get_Value(i), pFeatureB.get_Value(i)); if (!equal) { diffCount++; } if (diffCount > 0) return pFeatureA.OID.ToString(); } return String.Empty; //// geometry equal test //IArea pAreaA = pFeatureA.Shape as IArea; //IArea pAreaB = pFeatureB.Shape as IArea; //if (pAreaA.Area != pAreaB.Area) //{ // diffCount++; //} //if (diffCount > 0) //{ // return false; //} //return true; } public static List<int> GetFidList(string path) { List<int> fidList = new List<int>(); String shapefileStringTemplate = "Provider=ESRI.GeoDB.OleDB.1;Data Source={0};" + "Extended Properties=workspacetype=esriDataSourcesFile.ShapefileWorkspaceFactory.1;Geometry={1}"; String connectionString = String.Format(shapefileStringTemplate, path, "Fabbricati"); OleDbConnection myOleDbConnection = new OleDbConnection(connectionString); OleDbCommand command = myOleDbConnection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = String.Format(@SELECT FID FROM FABBRICATI); try { myOleDbConnection.Open(); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read() == true) { fidList.Add( Convert.IsDBNull(reader["FID"]) ? 0 : Convert.ToInt32(reader["FID"]) ); } reader.Close(); return fidList; } catch (Exception) { throw; } finally { if (myOleDbConnection.State != ConnectionState.Closed) myOleDbConnection.Close(); } }
//before loop int equalFieldCount = 0; // in the loop bool equal = Object.Equal(pfeature1.getValue(i), pfeature2.getValue(i)) if(equal)[INDENT] equalFieldCount++; [/INDENT]// after loop bool allFieldsAreEqual = false; if(pfeature.fields.fieldsCount - "numberOfGeometryFields" == equalFieldCount)[INDENT] allFieldsAreEqual = true; [/INDENT]
IMxDocument itfMxDoc; IMap pmap; IFeatureCursor itfCursor1; IFeatureCursor itfCursor2; IFeature itfFeature1; IFeature itfFeature2; IFeatureLayer pflayer1; IFeatureLayer pflayer2; itfMxDoc = m_application.Document as IMxDocument; pmap = itfMxDoc.FocusMap; pflayer1 = GetLayerByName("Shp1"); IFeatureSelection pFlSelection = pflayer1 as IFeatureSelection; // get index from selected feature //but I will not select anything IEnumIDs itfListId = pFlSelection.SelectionSet.IDs; itfListId.Reset(); int Index = itfListId.Next(); itfFeature1 = pflayer1.FeatureClass.GetFeature(Index); // get your buffer ITopologicalOperator pTopo = itfFeature1.ShapeCopy as ITopologicalOperator; IPolygon pPolygon = pTopo.Buffer(1) as IPolygon; pflayer2 = GetLayerByName("Shp2"); ISpatialFilter itfFilter; itfFilter = new SpatialFilter(); itfFilter.Geometry = pPolygon as IGeometry; itfFilter.GeometryField = pflayer2.FeatureClass.ShapeFieldName; itfFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects; // get your points inside your buffer itfCursor2 = pflayer2.FeatureClass.Search(itfFilter, false); itfFeature2 = itfCursor2.NextFeature(); // Loop for each point in your buffer while (itfFeature2 != null) { // Get feature id from each feature to select later. itfFeature2 = itfCursor2.NextFeature(); }
ITopologicalOperator2 pTopOp = pFeature.ShapeCopy as ITopologicalOperator2; IGeometry differenceGeometry = pTopOp.Difference(pSegment); pTopOp = differenceGeometry as ITopologicalOperator2; pTopOp.IsKnownSimple_2 = false; pTopOp.Simplify(); pFeature.Shape = pTopOp as IGeometry; pFeature.Store();
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.