Exemple #1
0
        public static void CoverFeatureClassWithFeatureClass(IFeatureClass fromFeatureClass, IFeatureClass toFeatureClass, SpatialAdjust spatialAdjust)
        {
            //https://github.com/xinying180/ConvertingData
            ((ITable)toFeatureClass).DeleteSearchedRows(null);
            var count       = fromFeatureClass.FeatureCount(null);
            var breakpoints = new List <double>()
            {
                0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9
            };
            var progressDictionary = breakpoints.ToDictionary(d => d, d => false);


            var finishedCount = 0;

            Console.WriteLine($"{fromFeatureClass.FeatureCount(null)} 个要素待转换 在{((IDataset)fromFeatureClass).Name}");
            if (spatialAdjust != null)
            {
                Console.WriteLine($"使用 {spatialAdjust.TransformationMethod.Name} 方法偏移");
            }
            else
            {
                Console.WriteLine("不偏移");
            }
            Action <IFeature> action = (feature) =>
            {
                //esriFlowDirection.

                //UInt32.MaxValue
                //4294967295
                var createdFeature = toFeatureClass.CreateFeature();
                var copy           = feature.ShapeCopy;
                if (spatialAdjust != null && feature.Shape != null)
                {
                    //Console.WriteLine($"使用{ SpatialAdjust.transformMethodMap[spatialAdjust.SpatialAdjustMethodType].Name}来Spatial Adjustment");
                    var targetSr = createdFeature.Shape.SpatialReference;
                    try
                    {
                        copy.Project(targetSr);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        //throw;
                    }
                    var fromSr = feature.Shape.SpatialReference;
                    Trace.WriteLine($"{fromSr.Name} -> {targetSr.Name}");
                    spatialAdjust.AdjustGeometry(copy);
                    //SpatialActions.Adjust(@"C:\OCNwork\东莞\dgcps.txt", ControlPointsInputType.File, copy);
                }
                else
                {
                    //Console.WriteLine($"不做Spatial Adjustmnent");
                }
                createdFeature.Shape = copy;
                for (int i = 0; i < feature.Fields.FieldCount; i++)
                {
                    IField field = feature.Fields.get_Field(i);
                    if (field.Type != esriFieldType.esriFieldTypeOID && field.Type != esriFieldType.esriFieldTypeGeometry && field.Type != esriFieldType.esriFieldTypeGlobalID && field.Type != esriFieldType.esriFieldTypeGUID)
                    {
                        string fieldName = field.Name;
                        int    index     = createdFeature.Fields.FindField(fieldName);
                        if (index > -1 && fieldName != "Shape_Length" && fieldName != "Shape_Area" && field.Editable)
                        {
                            createdFeature.set_Value(index, feature.get_Value(i));
                        }
                    }
                }
                createdFeature.Store();
                finishedCount++;
                double progress = ((double)finishedCount) / ((double)count);
                progressDictionary.ToList().ForEach((kvp) =>
                {
                    if (progress > kvp.Key && kvp.Value == false)
                    {
                        progressDictionary[kvp.Key] = true;
                        Console.Write($"{kvp.Key} ");
                    }
                });
            };

            IFeatureCursor featureCursor = fromFeatureClass.Update(null, false);
            IFeature       targetFeature;

            while ((targetFeature = featureCursor.NextFeature()) != null)
            {
                action.Invoke(targetFeature);
            }

            //fromFeatureClass.
            //for (int i = 0; i < count; i++)
            //{
            //    fromFeatureClass.Update()
            //    action.Invoke(fromFeatureClass.GetFeature(i));
            //}


            //fromFeatureClass.Features().ToList().ForEach(action);
            Console.Write("\n");
            Console.WriteLine($"{toFeatureClass.FeatureCount(null)} 个要素在目标图层 在{((IDataset)toFeatureClass).Name}");
        }
Exemple #2
0
 public void AdjustTest()
 {
     new ArcEngineLicense();
     SpatialAdjust.Adjust();
 }