Example #1
0
        /// <summary>
        /// Will take a given polygon and 'cookie cut' it into the chosen layer
        /// </summary>
        /// <param name="homesite_polygon"></param>
        private void StampPolygonIntoHomesiteLayer(IPolygon homesite_polygon)
        {
            try
            {
                IFeatureLayer featureLayer = _utilitiesArcMap.FeatureLayer(cbo_featureclass.Text);
                IFeatureClass featureClass = featureLayer.FeatureClass;

                _editor.StartOperation();

                ISpatialFilter spatialFilter = new SpatialFilter();
                spatialFilter.GeometryField = featureClass.ShapeFieldName;
                spatialFilter.Geometry      = homesite_polygon;
                spatialFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;
                IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);
                IFeature       feature       = null;

                while ((feature = featureCursor.NextFeature()) != null)
                {
                    ITopologicalOperator topologicalOperator = feature.Shape as ITopologicalOperator;
                    IGeometry            geometry            = topologicalOperator.Difference(homesite_polygon);
                    IPolygon             polygon             = geometry as IPolygon;


                    IFeature newFeature = featureClass.CreateFeature();
                    newFeature.Shape = polygon as IPolygon;

                    // This caused a problem with memory allocation. It would not delete the orignal data.
                    ArrayList fields = _utilitiesArcMap.NumberFieldsWithDomain(featureLayer);

                    // Set the attribute back to the old ones.
                    foreach (string field in fields)
                    {
                        newFeature.set_Value(newFeature.Fields.FindField(field), feature.get_Value(feature.Fields.FindField(field)));
                    }


                    newFeature.Store();
                    feature.Delete();
                }

                IFeature homesite = featureClass.CreateFeature();
                homesite.Shape = homesite_polygon;
                homesite.Store();

                _editor.StopOperation("Homesite");
            } catch (Exception ex)
            {
                RS_Tools.Utilities.Utilities_MessageBox.ErrorBox(ex.Message, MB_TITLE);
            }
        }