Skip to main content
appended answer 477974 as supplemental
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I updated my code, but it still reports outofmemory error, which makes me more confused.

            IMap map = ArcMap.Document.ActiveView.FocusMap;
            IFeatureLayer flCrater = ClsShare.GetLayerFromName(map, comboBox1.Text) as IFeatureLayer;
            bool isPolygon = check_isPokygon.Checked;
            FrmAddField frmAddField = new FrmAddField(flCrater);
            int field_R = frmAddField.AddField("local_R", esriFieldType.esriFieldTypeDouble, true);
            IFeatureClass fcCrater = flCrater.FeatureClass;
            IGeoDataset geodataset = fcCrater as IGeoDataset;
            ISpatialReference spatialR_Crater = geodataset.SpatialReference;
            IGeographicCoordinateSystem geoSys = ClsShare.GetGeographicCoordinateSystem(spatialR_Crater);

            IFeatureCursor featureCursor = fcCrater.Update(null, true);
            IFeature feature = null;
            double dDiam = 0;
            double dR = 0;
            
            
            IPolyline polylineSrc = new PolylineClass();
            ISegmentCollection segs = polylineSrc as ISegmentCollection;
            
            while ((feature = featureCursor.NextFeature()) != null)
            {
                if (feature.OID < nMin || feature.OID > nMax)
                    continue;
                if (feature.Shape.IsEmpty) continue;
                // 将圆变成圆弧进行投影
                dDiam = GetDiameterFromFea(feature, geoSys, isPolygon);
                if (dDiam < 0) continue;

                dR = dDiam / 2.0;
                feature.set_Value(field_R,dR);
                featureCursor.UpdateFeature(feature);
                stepProg.Step();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);

'''


I updated my code, but it still reports outofmemory error, which makes me more confused.

            IMap map = ArcMap.Document.ActiveView.FocusMap;
            IFeatureLayer flCrater = ClsShare.GetLayerFromName(map, comboBox1.Text) as IFeatureLayer;
            bool isPolygon = check_isPokygon.Checked;
            FrmAddField frmAddField = new FrmAddField(flCrater);
            int field_R = frmAddField.AddField("local_R", esriFieldType.esriFieldTypeDouble, true);
            IFeatureClass fcCrater = flCrater.FeatureClass;
            IGeoDataset geodataset = fcCrater as IGeoDataset;
            ISpatialReference spatialR_Crater = geodataset.SpatialReference;
            IGeographicCoordinateSystem geoSys = ClsShare.GetGeographicCoordinateSystem(spatialR_Crater);

            IFeatureCursor featureCursor = fcCrater.Update(null, true);
            IFeature feature = null;
            double dDiam = 0;
            double dR = 0;
            
            
            IPolyline polylineSrc = new PolylineClass();
            ISegmentCollection segs = polylineSrc as ISegmentCollection;
            
            while ((feature = featureCursor.NextFeature()) != null)
            {
                if (feature.OID < nMin || feature.OID > nMax)
                    continue;
                if (feature.Shape.IsEmpty) continue;
                // 将圆变成圆弧进行投影
                dDiam = GetDiameterFromFea(feature, geoSys, isPolygon);
                if (dDiam < 0) continue;

                dR = dDiam / 2.0;
                feature.set_Value(field_R,dR);
                featureCursor.UpdateFeature(feature);
                stepProg.Step();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);

'''

deleted 51 characters in body; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

i want to update Updating about 700000 feature of a featureclass using arcengineArcGIS Engine & C#, but memory breakbreaks

I don't know whyWhy does this code getsget a memory overflow error for datasets with more than 20k of data. if anybody knows, thank you for your help.?

i want to update about 700000 feature of a featureclass using arcengine & C#, but memory break

I don't know why this code gets a memory overflow error for datasets with more than 20k of data. if anybody knows, thank you for your help.

Updating about 700000 feature of featureclass using ArcGIS Engine & C# but memory breaks

Why does this code get a memory overflow error for datasets with more than 20k of data?

added 78 characters in body
Source Link

int nMax = (int)numFIDTo.Value; int nMin = (int)numFIDFrom.Value; IStepProgressor stepProg = ArcMap.Application.StatusBar.ProgressBar; stepProg.MinRange = 0; stepProg.MaxRange = nMax; stepProg.Position = 0; stepProg.Show(); try { IMap map = ArcMap.Document.ActiveViewI don't know why this code gets a memory overflow error for datasets with more than 20k of data.FocusMap; IFeatureLayer flCrater = ClsShare.GetLayerFromName(mapif anybody knows, comboBox1thank you for your help.Text) as IFeatureLayer;

int nMax = (int)numFIDTo.Value;
          bool isPolygon int nMin = check_isPokygon(int)numFIDFrom.Checked;
Value;
            FrmAddFieldIStepProgressor frmAddFieldstepProg = new FrmAddField(flCrater);ArcMap.Application.StatusBar.ProgressBar;
            int field_RstepProg.MinRange = frmAddField.AddField("local_R",0;
 esriFieldType.esriFieldTypeDouble, true);

          stepProg.MaxRange = 
 nMax;
            IFeatureClass fcCraterstepProg.Position = flCrater.FeatureClass;0;
            if stepProg.Show(fcCrater);
 == null)          try
            {
                IMap map = ArcMap.Document.ActiveView.FocusMap;
                IFeatureLayer flCrater = ClsShare.GetLayerFromName(map, comboBox1.Text) as IFeatureLayer;
                bool isPolygon = check_isPokygon.Checked;
                FrmAddField frmAddField = new FrmAddField(flCrater);
                int field_R = frmAddField.AddField("local_R", esriFieldType.esriFieldTypeDouble, true);
                IFeatureClass fcCrater = flCrater.FeatureClass;
                if (fcCrater == null)
                {
                    MessageBox.Show("撞击坑图层要素为空!");
                }
                IGeoDataset geodataset = fcCrater as IGeoDataset;
                ISpatialReference spatialR_Crater = geodataset.SpatialReference;
                IGeographicCoordinateSystem geoSys = ClsShare.GetGeographicCoordinateSystem(spatialR_Crater);
                IFeatureCursor featureCursor = fcCrater.Update(null, false);
                IFeature feature = null;
                double dDiam = 0;
                double dR = 0;
                IClone polyClone;
                IPolyline polylineClone;
                while ((feature = featureCursor.NextFeature()) != null)
                {
                    if (feature.OID < nMin || feature.OID > nMax)
                        continue;
                    if (feature.ShapeCopy.IsEmpty) continue;
                  
                    IPolygon polygonSrc = feature.ShapeCopy as IPolygon;
                    IPolyline polylineSrc = new PolylineClass();
                    polylineSrc.SpatialReference = polygonSrc.SpatialReference;
                    ISegmentCollection segs = polylineSrc as ISegmentCollection;
                    segs.AddSegmentCollection(polygonSrc as ISegmentCollection);
                    IPoint ptCenter = ClsShare.GetCenter(polygonSrc as IGeometry);
                    // 将中心点首先投影到地里坐标系上
                    ptCenter.Project(geoSys);
                    // 创建局部投影坐标系
                    IProjectedCoordinateSystem prjLocal = ClsShare.CreateLocalProjectedCoordinateSystem(
                    geoSys, 0, 0, 1.0, 0, ptCenter.X, ptCenter.Y);

            // 获取地理坐标系       polyClone  = polylineSrc as IClone;
            IGeoDataset geodataset       polylineClone = fcCraterpolyClone.Clone() as IGeoDataset;IPolyline;
            ISpatialReference spatialR_Crater = geodataset     polylineClone.SpatialReference;Project(prjLocal);
            IGeographicCoordinateSystem geoSys = ClsShare.GetGeographicCoordinateSystem     if (spatialR_CraterpolylineClone.IsEmpty); continue;

            IFeatureCursor featureCursor = fcCrater.Update(null, false);
            IFeature feature = null;
            double dDiam = 0;
            double dR = 0;
            IClone polyClone;
            IPolyline polylineClone;
            while ((feature = featureCursor.NextFeature()) != null)
            {
                if (feature.OID < nMin || feature.OID > nMax)
                    continue;
                if (feature.ShapeCopy.IsEmpty) continue;
                // 将圆变成圆弧进行投影
                IPolygon polygonSrc = feature.ShapeCopy as IPolygon;
                IPolyline polylineSrc = new PolylineClass();
                polylineSrc.SpatialReference = polygonSrc.SpatialReference;
                ISegmentCollection segs = polylineSrc as ISegmentCollection;
                segs.AddSegmentCollection(polygonSrc as ISegmentCollection);
                IPoint ptCenter = ClsShare.GetCenter(polygonSrc as IGeometry);
                // 将中心点首先投影到地里坐标系上
                ptCenter.Project(geoSys);
                // 创建局部投影坐标系
                IProjectedCoordinateSystem prjLocalgeoPoly = ClsShare.CreateLocalProjectedCoordinateSystem(
                geoSys, 0, 0, 1.0, 0,polylineClone ptCenter.X,as ptCenter.Y);IGeometry;

                polyClone  = polylineSrc as IClone;//!<得到圆的外包最长边作为圆直径
                polylineClone    dDiam = polyClone0.Clone0;
                    if (isPolygon) 
 as IPolyline;                  {
                polylineClone        //!<如果是提取任意多边形的最长直径,则要取矩形框的对角线长度作为最长值
                        dDiam = Math.ProjectSqrt(prjLocalgeoPoly.Envelope.Width * geoPoly.Envelope.Width + geoPoly.Envelope.Height * geoPoly.Envelope.Height);
                if    }
                    else
                    {
                        dDiam = Math.Max(polylineClonegeoPoly.IsEmptyEnvelope.Width, geoPoly.Envelope.Height);
 continue;                   }

                IGeometry geoPoly   dR = polylineClonedDiam as/ IGeometry;2.0;
                    feature.set_Value(field_R,dR);
                    featureCursor.UpdateFeature(feature);
                    stepProg.Step();

                //!<得到圆的外包最长边作为圆直径
                dDiam = 0System.0;Runtime.InteropServices.Marshal.ReleaseComObject(feature);
                if (isPolygon)
                {System.Runtime.InteropServices.Marshal.ReleaseComObject(polygonSrc);
                    //!<如果是提取任意多边形的最长直径,则要取矩形框的对角线长度作为最长值System.Runtime.InteropServices.Marshal.ReleaseComObject(polylineSrc);
                    dDiam = Math.Sqrt(geoPoly.Envelope.Width * geoPoly.Envelope.Width + geoPolySystem.EnvelopeRuntime.Height * geoPolyInteropServices.EnvelopeMarshal.HeightReleaseComObject(ptCenter);
                }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(prjLocal);
    else
                {System.Runtime.InteropServices.Marshal.ReleaseComObject(segs);
                    dDiam = Math.Max(geoPolySystem.EnvelopeRuntime.Width, geoPolyInteropServices.EnvelopeMarshal.HeightReleaseComObject(geoPoly);
                }

                dR = dDiam / 2.0;
                feature.set_Value(field_R,dR);
                featureCursor.UpdateFeature(feature);
                stepProg.Step();

                System.Runtime.InteropServices.Marshal.ReleaseComObject(feature);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(polygonSrc);
                System.Runtime.InteropServices.Marshal.ReleaseComObjectHide(polylineSrc);
                System.Runtime.InteropServices.MarshalMessageBox.ReleaseComObjectShow(ptCenter"撞击坑更新完成");
                System.Runtime.InteropServices.Marshal.ReleaseComObject(prjLocalfeatureCursor);
                System.Runtime.InteropServices.MarshalGC.ReleaseComObjectCollect(segs);
                System.Runtime.InteropServices.MarshalGC.ReleaseComObjectWaitForPendingFinalizers(geoPoly);
            }
            stepProg.Hide();
            MessageBox.Show("撞击坑更新完成");
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
           catch System.GC.Collect();
           Exception System.GC.WaitForPendingFinalizers(ex);
        }
        catch (Exception ex){
        {
            MessageBox.Show(ex.Message+"");
            }

int nMax = (int)numFIDTo.Value; int nMin = (int)numFIDFrom.Value; IStepProgressor stepProg = ArcMap.Application.StatusBar.ProgressBar; stepProg.MinRange = 0; stepProg.MaxRange = nMax; stepProg.Position = 0; stepProg.Show(); try { IMap map = ArcMap.Document.ActiveView.FocusMap; IFeatureLayer flCrater = ClsShare.GetLayerFromName(map, comboBox1.Text) as IFeatureLayer;

            bool isPolygon = check_isPokygon.Checked;

            FrmAddField frmAddField = new FrmAddField(flCrater);
            int field_R = frmAddField.AddField("local_R", esriFieldType.esriFieldTypeDouble, true);

            
 
            IFeatureClass fcCrater = flCrater.FeatureClass;
            if (fcCrater == null)
            {
                MessageBox.Show("撞击坑图层要素为空!");
            }

            // 获取地理坐标系
            IGeoDataset geodataset = fcCrater as IGeoDataset;
            ISpatialReference spatialR_Crater = geodataset.SpatialReference;
            IGeographicCoordinateSystem geoSys = ClsShare.GetGeographicCoordinateSystem(spatialR_Crater);

            IFeatureCursor featureCursor = fcCrater.Update(null, false);
            IFeature feature = null;
            double dDiam = 0;
            double dR = 0;
            IClone polyClone;
            IPolyline polylineClone;
            while ((feature = featureCursor.NextFeature()) != null)
            {
                if (feature.OID < nMin || feature.OID > nMax)
                    continue;
                if (feature.ShapeCopy.IsEmpty) continue;
                // 将圆变成圆弧进行投影
                IPolygon polygonSrc = feature.ShapeCopy as IPolygon;
                IPolyline polylineSrc = new PolylineClass();
                polylineSrc.SpatialReference = polygonSrc.SpatialReference;
                ISegmentCollection segs = polylineSrc as ISegmentCollection;
                segs.AddSegmentCollection(polygonSrc as ISegmentCollection);
                IPoint ptCenter = ClsShare.GetCenter(polygonSrc as IGeometry);
                // 将中心点首先投影到地里坐标系上
                ptCenter.Project(geoSys);
                // 创建局部投影坐标系
                IProjectedCoordinateSystem prjLocal = ClsShare.CreateLocalProjectedCoordinateSystem(
                geoSys, 0, 0, 1.0, 0, ptCenter.X, ptCenter.Y);

                polyClone  = polylineSrc as IClone;
                polylineClone = polyClone.Clone() as IPolyline;
                polylineClone.Project(prjLocal);
                if (polylineClone.IsEmpty) continue;

                IGeometry geoPoly = polylineClone as IGeometry;

                //!<得到圆的外包最长边作为圆直径
                dDiam = 0.0;
                if (isPolygon)
                {
                    //!<如果是提取任意多边形的最长直径,则要取矩形框的对角线长度作为最长值
                    dDiam = Math.Sqrt(geoPoly.Envelope.Width * geoPoly.Envelope.Width + geoPoly.Envelope.Height * geoPoly.Envelope.Height);
                }
                else
                {
                    dDiam = Math.Max(geoPoly.Envelope.Width, geoPoly.Envelope.Height);
                }

                dR = dDiam / 2.0;
                feature.set_Value(field_R,dR);
                featureCursor.UpdateFeature(feature);
                stepProg.Step();

                System.Runtime.InteropServices.Marshal.ReleaseComObject(feature);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(polygonSrc);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(polylineSrc);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ptCenter);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(prjLocal);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(segs);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(geoPoly);
            }
            stepProg.Hide();
            MessageBox.Show("撞击坑更新完成");
            System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
            System.GC.Collect();
            System.GC.WaitForPendingFinalizers();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message+"");
        }

I don't know why this code gets a memory overflow error for datasets with more than 20k of data. if anybody knows, thank you for your help.

int nMax = (int)numFIDTo.Value;
            int nMin = (int)numFIDFrom.Value;
            IStepProgressor stepProg = ArcMap.Application.StatusBar.ProgressBar;
            stepProg.MinRange = 0;
            stepProg.MaxRange = nMax;
            stepProg.Position = 0;
            stepProg.Show();
            try
            {
                IMap map = ArcMap.Document.ActiveView.FocusMap;
                IFeatureLayer flCrater = ClsShare.GetLayerFromName(map, comboBox1.Text) as IFeatureLayer;
                bool isPolygon = check_isPokygon.Checked;
                FrmAddField frmAddField = new FrmAddField(flCrater);
                int field_R = frmAddField.AddField("local_R", esriFieldType.esriFieldTypeDouble, true);
                IFeatureClass fcCrater = flCrater.FeatureClass;
                if (fcCrater == null)
                {
                    MessageBox.Show("撞击坑图层要素为空!");
                }
                IGeoDataset geodataset = fcCrater as IGeoDataset;
                ISpatialReference spatialR_Crater = geodataset.SpatialReference;
                IGeographicCoordinateSystem geoSys = ClsShare.GetGeographicCoordinateSystem(spatialR_Crater);
                IFeatureCursor featureCursor = fcCrater.Update(null, false);
                IFeature feature = null;
                double dDiam = 0;
                double dR = 0;
                IClone polyClone;
                IPolyline polylineClone;
                while ((feature = featureCursor.NextFeature()) != null)
                {
                    if (feature.OID < nMin || feature.OID > nMax)
                        continue;
                    if (feature.ShapeCopy.IsEmpty) continue;
                  
                    IPolygon polygonSrc = feature.ShapeCopy as IPolygon;
                    IPolyline polylineSrc = new PolylineClass();
                    polylineSrc.SpatialReference = polygonSrc.SpatialReference;
                    ISegmentCollection segs = polylineSrc as ISegmentCollection;
                    segs.AddSegmentCollection(polygonSrc as ISegmentCollection);
                    IPoint ptCenter = ClsShare.GetCenter(polygonSrc as IGeometry);
                    // 将中心点首先投影到地里坐标系上
                    ptCenter.Project(geoSys);
                    // 创建局部投影坐标系
                    IProjectedCoordinateSystem prjLocal = ClsShare.CreateLocalProjectedCoordinateSystem(
                    geoSys, 0, 0, 1.0, 0, ptCenter.X, ptCenter.Y);

                    polyClone  = polylineSrc as IClone;
                    polylineClone = polyClone.Clone() as IPolyline;
                    polylineClone.Project(prjLocal);
                    if (polylineClone.IsEmpty) continue;

                    IGeometry geoPoly = polylineClone as IGeometry;

                    //!<得到圆的外包最长边作为圆直径
                    dDiam = 0.0;
                    if (isPolygon) 
                    {
                        //!<如果是提取任意多边形的最长直径,则要取矩形框的对角线长度作为最长值
                        dDiam = Math.Sqrt(geoPoly.Envelope.Width * geoPoly.Envelope.Width + geoPoly.Envelope.Height * geoPoly.Envelope.Height);
                    }
                    else
                    {
                        dDiam = Math.Max(geoPoly.Envelope.Width, geoPoly.Envelope.Height);
                    }

                    dR = dDiam / 2.0;
                    feature.set_Value(field_R,dR);
                    featureCursor.UpdateFeature(feature);
                    stepProg.Step();

                    System.Runtime.InteropServices.Marshal.ReleaseComObject(feature);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(polygonSrc);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(polylineSrc);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(ptCenter);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(prjLocal);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(segs);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(geoPoly);
                }
                stepProg.Hide();
                MessageBox.Show("撞击坑更新完成");
                System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
                System.GC.Collect();
                System.GC.WaitForPendingFinalizers();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message+"");
            }
Source Link
Loading