示例#1
0
        public void CopyFeatures(LoadTarget target)
        {
            IWorkspaceFactory sourceWsf;

            if (System.IO.Path.GetExtension(target.In_Directory).ToUpper().Equals(".GDB"))
            {
                sourceWsf = new FileGDBWorkspaceFactoryClass();
            }
            else
            {
                sourceWsf = new ShapefileWorkspaceFactoryClass();
            }
            IFeatureWorkspace sourceFeatWs       = sourceWsf.OpenFromFile(target.In_Directory, 0) as IFeatureWorkspace;
            IFeatureClass     sourceFeatureClass = sourceFeatWs.OpenFeatureClass(target.In_FileName);

            IWorkspaceFactory targetWsf;

            if (System.IO.Path.GetExtension(target.Out_Directory).ToUpper().Equals(".GDB"))
            {
                targetWsf = new FileGDBWorkspaceFactoryClass();
            }
            else
            {
                targetWsf = new ShapefileWorkspaceFactoryClass();
            }

            IWorkspace targetWs = targetWsf.OpenFromFile(target.Out_Directory, 0) as IWorkspace;

            string targetFileName;

            if (System.IO.Path.GetExtension(target.Out_Directory).ToUpper().Equals(".GDB"))
            {
                targetFileName = LoadHelper.GetNameGDB(target.Out_Directory, target.Out_FileName);
            }
            else
            {
                targetFileName = LoadHelper.GetNameShapeFile(target.Out_Directory, target.Out_FileName);
            }

            IFeatureWorkspace        targetFeatWs            = targetWs as IFeatureWorkspace;
            IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  objectClassDescription  = featureClassDescription as IObjectClassDescription;

            IFields         pFields         = sourceFeatureClass.Fields;
            IFieldChecker   pFieldChecker   = new FieldCheckerClass();
            IEnumFieldError pEnumFieldError = null;
            IFields         vFields         = null;

            pFieldChecker.ValidateWorkspace = targetWs as IWorkspace;
            pFieldChecker.Validate(pFields, out pEnumFieldError, out vFields);

            IFeatureClass sdeFeatureClass = null;

            if (sdeFeatureClass == null)
            {
                sdeFeatureClass = targetFeatWs.CreateFeatureClass(targetFileName, vFields,
                                                                  objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID,
                                                                  sourceFeatureClass.FeatureType, sourceFeatureClass.ShapeFieldName, "");
                IFeatureCursor featureCursor    = sourceFeatureClass.Search(null, true);
                IFeature       feature          = featureCursor.NextFeature();
                IFeatureCursor sdeFeatureCursor = sdeFeatureClass.Insert(true);
                IFeatureBuffer sdeFeatureBuffer;
                IQueryFilter   qf = new QueryFilterClass();
                target.Size = sourceFeatureClass.FeatureCount(qf);
                while (feature != null)
                {
                    sdeFeatureBuffer = sdeFeatureClass.CreateFeatureBuffer();
                    IField  shpField  = new FieldClass();
                    IFields shpFields = feature.Fields;
                    for (int i = 0; i < shpFields.FieldCount; i++)
                    {
                        shpField = shpFields.get_Field(i);
                        if (shpField.Name.ToLower().Contains("area") || shpField.Name.ToLower().Contains("leng") || shpField.Name.ToLower().Contains("fid") || shpField.Name.ToLower().Contains("objectid"))
                        {
                            continue;
                        }
                        int index = sdeFeatureBuffer.Fields.FindField(shpField.Name);
                        if (index != -1)
                        {
                            sdeFeatureBuffer.set_Value(index, feature.get_Value(i));
                        }
                    }
                    sdeFeatureCursor.InsertFeature(sdeFeatureBuffer);
                    sdeFeatureCursor.Flush();
                    feature = featureCursor.NextFeature();
                    target.Progress++;
                }
                featureCursor.Flush();
                target.IsFinished = true;
                target.IsBusy     = false;
            }
        }
示例#2
0
        public static void CopyRaster(IRaster sourceRaster, string sourceFileName, IWorkspace targetWs, string targetFileName, LoadTarget target)
        {
            //IRasterWorkspace2 targetRstWs = targetWs as IRasterWorkspace;
            //IRasterLayer rstlyr;

            //IRasterCursor rstCsr=sourceRaster.CreateCursor();
            //rstCsr.nn

            //IRaster sdeRaster = null;
            //if (sdeRaster == null)
            //{
            //    sdeRaster = targetRstWs.CreateRasterDataset(targetFileName,sdeRaster.
            //    IFeatureCursor featureCursor = sourceFeatureClass.Search(null, true);
            //    IFeature feature = featureCursor.NextFeature();
            //    IFeatureCursor sdeFeatureCursor = sdeRaster.Insert(true);
            //    IFeatureBuffer sdeFeatureBuffer;
            //    IQueryFilter qf = new QueryFilterClass();
            //    target.Size = sourceFeatureClass.FeatureCount(qf);
            //    while (feature != null)
            //    {
            //        sdeFeatureBuffer = sdeRaster.CreateFeatureBuffer();
            //        IField shpField = new FieldClass();
            //        IFields shpFields = feature.Fields;
            //        for (int i = 0; i < shpFields.FieldCount; i++)
            //        {
            //            shpField = shpFields.get_Field(i);
            //            if (shpField.Name.ToLower().Contains("area") || shpField.Name.ToLower().Contains("leng") || shpField.Name.ToLower().Contains("fid") || shpField.Name.ToLower().Contains("objectid")) continue;
            //            int index = sdeFeatureBuffer.Fields.FindField(shpField.Name);
            //            if (index != -1)
            //            {
            //                sdeFeatureBuffer.set_Value(index, feature.get_Value(i));
            //            }
            //        }
            //        sdeFeatureCursor.InsertFeature(sdeFeatureBuffer);
            //        sdeFeatureCursor.Flush();
            //        feature = featureCursor.NextFeature();
            //        target.Progress++;
            //    }
            //    featureCursor.Flush();
            //}
        }
示例#3
0
 public Target_NewFeatures()
 {
     InitializeComponent();
     Target = new LoadTarget();
 }
示例#4
0
 public Target_NewRaster()
 {
     InitializeComponent();
     Target = new LoadTarget();
 }
示例#5
0
文件: LoadHelper.cs 项目: jzChia/demo
 public LayerOperaEventArgs(LoadTarget target)
 {
     this.Target = target;
 }
示例#6
0
文件: LoadHelper.cs 项目: jzChia/demo
 public LoadHelper(LoadTarget target)
 {
     this.target = target;
 }