Ejemplo n.º 1
0
        public void Dispose()
        {
            ComUtils.ReleaseComObject(_construction);

            _properties   = null;
            _construction = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BufferFactory"/> class.
        /// </summary>
        /// <param name="explodeBuffers">if set to <c>true</c> multipart buffers will be exploded.</param>
        /// <param name="densify">if set to <c>true</c> straight line segments are used to represent the buffer output (i.e. <see cref="GenerateCurves"/> is set to <c>false</c>). Otherwise, curve segments are used in the output.</param>
        /// <param name="densifyDeviation"> The maximum distance between a line connecting two buffer curve points and the true curve
        /// (defaults to -1, indicating 1000 * xy tolerance of spatial reference of input geometries ).</param>
        public BufferFactory(bool explodeBuffers     = false, bool densify = false,
                             double densifyDeviation = -1)
        {
            _construction = new BufferConstructionClass();
            _properties   = (IBufferConstructionProperties)_construction;

            _properties.ExplodeBuffers = explodeBuffers;

            if (densify)
            {
                _properties.GenerateCurves   = false;
                _properties.DensifyDeviation = densifyDeviation;
            }
        }
Ejemplo n.º 3
0
        private void Btnok_Click(object sender, EventArgs e)
        {
            if (m_mapControl.Map.SelectionCount == 0)
            {
                MessageBox.Show("请先选择待查询要素!");
                return;
            }
            IEnumFeature pEnumfeature;
            IFeature     pFeature;
            IFeature     newFeat;
            //ITopologicalOperator pToplogicalOper;
            //IPolygon pPolygon;
            double bufferDistence;

            if (m_mapControl.Map.SelectionCount == 0)
            {
                return;
            }
            bufferDistence = Convert.ToDouble(BufferText.Text);
            pEnumfeature   = m_mapControl.Map.FeatureSelection as IEnumFeature;
            pEnumfeature.Reset();
            pFeature = pEnumfeature.Next();
            IFeatureClass pFeatureclass;
            FileInfo      n        = new FileInfo(textBox1.Text);
            string        openpath = n.Directory.ToString();//取路径的父目录用于存新的layer

            pFeatureclass = CreatNewShapefile(openpath, n.Name, m_mapControl.SpatialReference);

            //IFeatureBuffer pFeatureBuffer = pFeatureclass.CreateFeatureBuffer();
            //IFeatureCursor pFeatureCursor = pFeatureclass.Insert(true);
            int iFieldAttribute = pFeatureclass.FindField("Text");
            //while (pFeature != null)
            //{
            //    pToplogicalOper = pFeature.Shape as ITopologicalOperator;
            //    pPolygon = new PolygonClass();
            //    pPolygon = pToplogicalOper.Buffer(bufferDistence) as IPolygon;
            //    pFeatureBuffer.Shape = pPolygon;
            //    //pFeatureBuffer.set_Value(iFieldAttribute, pFeature.OID);
            //    pFeatureCursor.InsertFeature(pFeatureBuffer);
            //    pFeature = pEnumfeature.Next();
            //}
            //pFeatureCursor.Flush();

            //ML修改代码
            IGeometryCollection inputGeom = new GeometryBagClass();
            IGeometryBag        geomBag   = inputGeom as IGeometryBag;
            object missing = Type.Missing;

            while (pFeature != null)
            {
                inputGeom.AddGeometry(pFeature.ShapeCopy, ref missing, ref missing);
                pFeature = pEnumfeature.Next();
            }



            IBufferConstruction           bfCon         = new BufferConstructionClass();
            IBufferConstructionProperties bfConProp     = bfCon as IBufferConstructionProperties;
            ISpatialReferenceFactory      spatialRefFac = new SpatialReferenceEnvironmentClass();

            bfConProp.EndOption               = esriBufferConstructionEndEnum.esriBufferRound;
            bfConProp.SideOption              = esriBufferConstructionSideEnum.esriBufferFull;
            bfConProp.ExplodeBuffers          = false;
            bfConProp.OutsideOnly             = false;
            bfConProp.GenerateCurves          = true;
            bfConProp.UnionOverlappingBuffers = true;
            bfConProp.DensifyDeviation        = -1;
            IGeometryCollection outGeom = new GeometryBagClass();

            bfCon.ConstructBuffers(inputGeom as IEnumGeometry, bufferDistence, outGeom);
            for (int i = 0; i < outGeom.GeometryCount; i++)
            {
                newFeat       = pFeatureclass.CreateFeature();
                newFeat.Shape = outGeom.get_Geometry(i);
                newFeat.Store();
            }
            newFeat = null;
            //添加图层进map
            IFeatureLayer pOutputFeatureLayer;

            pOutputFeatureLayer = new FeatureLayerClass();
            pOutputFeatureLayer.FeatureClass = pFeatureclass;
            pOutputFeatureLayer.Name         = pFeatureclass.AliasName;
            m_mapControl.Map.AddLayer(pOutputFeatureLayer);


            this.Dispose();
        }