public void ReadFeatureClassFromSdeFileTest() { new ArcEngineLicense(); var fc = DataActions.GetFeatureClass(@"C:\OCNwork\东莞\dggisdata02.sde", DataSourceType.SdeFilePath, "GUIDAO_ZQ"); LogActions.LogFeatureClass(fc); }
public void TestReadGdeFeatureClass() { new ArcEngineLicense(); //FileGDBWorkspaceFactory fileGDBWorkspaceFactory = new FileGDBWorkspaceFactoryClass(); //var workspace = fileGDBWorkspaceFactory.OpenFromFile(@"C:\OCNwork\东莞\20181022\YDYZT (WGS84)\WGS84.gdb", 0); //var fc = ((IFeatureWorkspace)workspace).OpenFeatureClass("城际轨道站点"); //Trace.WriteLine($"{ fc.FeatureCount(null)}"); var fc = DataActions.GetFeatureClass(@"C:\OCNwork\东莞\20181022\YDYZT (WGS84)\WGS84.gdb", WorkspaceType.Gdb, "城际轨道站点"); Trace.WriteLine(fc.FeatureCount(null)); }
/// <summary> /// 数据源图层名 /// </summary> public void OnExecute() { switch (ActionArgument) { case ActionTypes.Adjust: { new ArcEngineLicense(); SpatialAdjust.Adjust(); break; } case ActionTypes.ImportData: { if (new string[] { Datasource, LayerName, OutDatasource, OutLayerName, ControlPoints }.Any(s => s == null)) { Console.WriteLine("参数没有写全"); break; //throw new Exception("参数没有写全"); } new ArcEngineLicense(); SpatialAdjust sa = null; try { sa = new SpatialAdjust(controlPointsFile: ControlPoints, controlPointsInputType: ControlPointsInputType, spatialAdjustMethodType: SpatialAdjustMethodType); } catch (Exception ex) { sa = null; } var inFc = DataActions.GetFeatureClass(Datasource, DataSourceType, LayerName); ESRI.ArcGIS.Geodatabase.IFeatureClass outFc; try { outFc = DataActions.GetFeatureClass(OutDatasource, OutDatasourceType, OutLayerName); } catch (Exception) { outFc = DataActions.CreateFeatureClass(DataActions.GetWorkspace(OutDatasource, OutDatasourceType), "", OutLayerName, inFc); } //Console.WriteLine($"将使用{ SpatialAdjust.transformMethodMap[sa.SpatialAdjustMethodType].Name} 偏移"); DataActions.CoverFeatureClassWithFeatureClass(inFc, outFc, sa); break; } case ActionTypes.LogLayer: { new ArcEngineLicense(); LogActions.LogFeatureClass(Datasource, DataSourceType, LayerName); } break; case ActionTypes.BatchImport: { new ArcEngineLicense(); var layerNames = LayerName.Split(','); List <string> finalNameStringList = new List <string>(); var workspace = DataActions.GetWorkspace(Datasource, DataSourceType); var featureWorkspace = (IFeatureWorkspace)workspace; layerNames.ToList().ForEach((name) => { try { featureWorkspace.OpenFeatureClass(name); finalNameStringList.Add(name); } catch (Exception) { try { var dataset = featureWorkspace.OpenFeatureDataset(name); var subs = dataset.FeatureDatasetsInFeatureDataset(); subs.ToList().ForEach(sub => finalNameStringList.Add(sub.Name)); } catch (Exception) { } } }); finalNameStringList.ForEach((finalName) => { new CommandLineController() { ActionArgument = ActionTypes.ImportData, Datasource = Datasource, DataSourceType = DataSourceType, LayerName = finalName, OutDatasource = OutDatasource, OutDatasourceType = OutDatasourceType, OutLayerName = $"{finalName.Split('.').Last()}_adjusted", ControlPoints = ControlPoints, ControlPointsInputType = ControlPointsInputType, SpatialAdjustMethodType = SpatialAdjustMethodType }.OnExecute(); }); } break; case ActionTypes.GenerateBatch: { new ArcEngineLicense(); var batchFileName = String.Empty; //var dtn = DateTime.Now.ToFullTimeSecondString(); if (String.IsNullOrEmpty(BatchFileName)) { var dtn = DateTime.Now; var s = dtn.ToBinary(); batchFileName = $"bat{s}.bat"; } else { batchFileName = BatchFileName; } var layerNames = LayerName.Split(','); List <string> finalNameStringList = new List <string>(); var workspace = DataActions.GetWorkspace(Datasource, DataSourceType); var featureWorkspace = (IFeatureWorkspace)workspace; layerNames.ToList().ForEach((name) => { try { featureWorkspace.OpenFeatureClass(name); finalNameStringList.Add(name); } catch (Exception) { try { var dataset = featureWorkspace.OpenFeatureDataset(name); var subs = dataset.FeatureDatasetsInFeatureDataset(); subs.ToList().ForEach(sub => finalNameStringList.Add(sub.Name)); } catch (Exception) { } } }); using (StreamWriter sw = new StreamWriter(batchFileName, true, Encoding.Default)) //using (StreamWriter sw = File.AppendText(batchFileName)) { var text = String.Empty; finalNameStringList.ToList().ForEach((layerName) => { //System.Reflection.Assembly.GetExecutingAssembly().FullName; //sw.WriteLine( $"AoCli.exe " ) sw.WriteLine($@"AoCli.exe BatchImport -ln {layerName} -ds {Datasource} -dst {DataSourceType} -ods {OutDatasource} -odst {OutDatasourceType} -oln {OutLayerName} -cp {ControlPoints} -samt {SpatialAdjustMethodType}" + " \n"); //text += $@"AoCli.exe BatchImport -ln {layerName} -ds {Datasource} -dst {DataSourceType} -ods {OutDatasource} -oln {OutLayerName} -cp {ControlPoints} -samt {SpatialAdjustMethodType}"; //text += "\n"; }); sw.Write(text); Console.WriteLine("Batch file generated"); } } break; case ActionTypes.GPTest: { new Test.MyTestClass().ShapeInWhereTest3(); } break; default: break; } }