/// <summary> /// 初始化:检查文件夹是否有子成员,有的话加入特殊节点 /// </summary> void Initialize() { if (Type == FileSystemObjectType.Folder && CheckChildObject()) { if (ShowFile.check_gdb(Path)) //对于gdb文件夹 { Geodatabase geo = Geodatabase.Open(Path); if (geo.GetChildDatasets(@"\", "Feature Class").Length != 0 || geo.GetChildDatasets(@"\", "Feature Dataset").Length != 0) { AddSpecialChild(); } geo.Close(); } else //对于普通文件夹 { AddSpecialChild(); } } if (Type == FileSystemObjectType.GDB) //对于GDB内feature dataset的文件夹 { Geodatabase geo = Geodatabase.Open(ParentPath); if (geo.GetChildDatasets(@Path, "Feature Class").Length != 0 || geo.GetChildDatasets(@Path, "Feature Dataset").Length != 0) { AddSpecialChild(); } geo.Close(); } }
public static bool ReadOnlyTheLyrs(string path, int i) { try { Geodatabase geodatabase = Geodatabase.Open(path); if (i == 1) { foreach (var ds in geodatabase.GetChildDatasets("\\", string.Empty)) { pointsChildDatasets.Add(ds.Substring(1)); } } else if (i == 2) { foreach (var ds in geodatabase.GetChildDatasets("\\", string.Empty)) { linesChildDatasets.Add(ds.Substring(1)); } } else if (i == 3) { foreach (var ds in geodatabase.GetChildDatasets("\\", string.Empty)) { PolygonsChildDatasets.Add(ds.Substring(1)); } } return(true); } catch (Exception) { return(false); } }
static void Main(string[] args) { Geodatabase geo = Geodatabase.Open(""); List <Table> tables = new List <Table>(); List <string> featureClasses = geo.GetChildDatasets("\\", "Feature Class").ToList(); foreach (string featureClassName in featureClasses) { tables.Add(geo.OpenTable(featureClassName)); } string createTableSqlCommand = CreateTableColumns(tables[0].FieldInformation); FieldInfo fieldInfo = tables[0].FieldInformation; var fields = new List <string>(); for (int i = 0; i < fieldInfo.Count; i++) { fields.Add(fieldInfo.GetFieldName(i)); } var countStatements = $"SELECT * FROM VAULTSCOT_AUTH_POINT_OCT18"; RowCollection rows = geo.ExecuteSQL(countStatements); WKBReader reader = new WKBReader(); foreach (Row row in rows) { MultiPointShapeBuffer geometry = row.GetGeometry(); var point = geometry.Points; //MULTIPOINT (295512,712727,0) throwing format exception - Resolved in upcoming commit. var geometryWKT = processMultiPointBuffer(geometry); } var countEnumerator = rows.GetEnumerator(); List <object> fieldValues = new List <object>(); if (rows != null) { countEnumerator.MoveNext(); var shape = countEnumerator.Current["Shape"]; for (int i = 0; i < fieldInfo.Count - 1; i++) { var count = countEnumerator.Current[fields[i]]; fieldValues.Add(count); } } InsertTableValues(fieldValues, fieldInfo); }
public ActionResult States() { try { var path = Server.MapPath("/App_Data/mvc_samples.gdb"); Geodatabase gdb = Geodatabase.Open(path); Table statesTable = gdb.OpenTable("\\us_states"); RowCollection rows = statesTable.Search("*", "STATE_NAME LIKE 'M%'", RowInstance.Recycle); var rval = rows.ToGeoJson(); gdb.Close(); //gdb.Dispose(); Response.ContentType = "application/json"; object result = this.Content(rval); return(result as ActionResult);; } catch { return(null); } }
static void Main(string[] args) { //var gdbPath = ConfigurationManager.AppSettings["gdb.path"]; var gdbPath = @"C:\temp\fgdb_test.gdb"; Geodatabase gdb = Geodatabase.Open(gdbPath); var rowCollection = gdb.ExecuteSQL(@"SELECT voiceZoneName.NAME_ID, voiceStreetAddress.NAME_ID FROM voiceZoneName, voiceStreetAddress WHERE voiceZoneName.NAME_ID = voiceStreetAddress.NAME_ID"); foreach (var row in rowCollection) { } }
//查看是否是geodatabase类型 public static bool check_gdb(string path) { if (FileSystemObjectViewModel.getextension(FileSystemObjectViewModel.GetFileName(path)) != "gdb") { return(false); } try { Geodatabase geo = Geodatabase.Open(@path); geo.Close(); return(true); } catch { return(false); } }
private void OpenGeodatabase() { if (_openedGeoDb) { return; } var fgdbPath = GetSetting("GDB_PATH"); if (fgdbPath == null) { throw new SettingsPropertyNotFoundException("The GDB_PATH setting was not found"); } _geodatabase = Geodatabase.Open(fgdbPath); _openedGeoDb = true; }
private static LogResult ListGdb(string gdbFileName) { var geodatabase = Geodatabase.Open(gdbFileName); var tableName = geodatabase .GetChildDatasets("\\", "Feature Class") .OrderBy(l => l.Length) .First(); var table = geodatabase.OpenTable(tableName); var definition = XDocument.Parse(table.Definition); var logResult = new LogResult( gdbFileName, tableName, FieldType(definition, OldCoda1), FieldType(definition, NewCoda2), FieldType(definition, OldCoda3), FieldType(definition, NewCoda4) ); table.Close(); geodatabase.Close(); return(logResult); }
private static void ModifyGdb(string gdbFileName) { _log($"Modifying {gdbFileName}"); var geodatabase = Geodatabase.Open(gdbFileName); var tableName = geodatabase .GetChildDatasets("\\", "Feature Class") .OrderBy(l => l.Length) .First(); var table = geodatabase.OpenTable(tableName); if (FieldsExist(table, new[] { OldCoda1, OldCoda3 })) { EnsureField(table, NewCoda2, FieldType.Integer); EnsureField(table, NewCoda4, FieldType.String); UpdateFields(table); EnsureFieldIsRemoved(table, OldCoda1); EnsureFieldIsRemoved(table, OldCoda3); } table.Close(); geodatabase.Close(); }
public void Open() { _geodatabase = Geodatabase.Open(Path); }
/// <summary> /// 节点被展开后的操作 /// </summary> protected virtual void OnExpanded() { //是否有特殊节点 if (HasSpecialChild) { //将要展开的节点拥有没有列举的子成员(第一次打开) //我们需要移除特殊节点,并将子文件夹加入到Children中 RemoveSpecialChild(); List <int> li = merge_file(); if (ShowFile.check_gdb(Path)) //对于geodatabase文件夹的处理 { Geodatabase geo = Geodatabase.Open(Path); foreach (var fc in geo.GetChildDatasets(@"\", "Feature Class")) { _Children.Add(new FileSystemObjectViewModel(fc, GetFileName(fc), FileSystemObjectType.File, Path)); } foreach (var fds in geo.GetChildDatasets(@"\", "Feature Dataset")) { _Children.Add(new FileSystemObjectViewModel(fds, GetFileName(fds), FileSystemObjectType.GDB, Path)); } geo.Close(); } else if (Type == FileSystemObjectType.GDB) //对于geodatabase内feature dataset 的处理 { Geodatabase geo = Geodatabase.Open(ParentPath); foreach (var fc in geo.GetChildDatasets(@Path, "Feature Class")) { _Children.Add(new FileSystemObjectViewModel(fc, GetFileName(fc), FileSystemObjectType.File, Path)); } foreach (var fds in geo.GetChildDatasets(Path, "Feature Dataset")) { _Children.Add(new FileSystemObjectViewModel(fds, GetFileName(fds), FileSystemObjectType.GDB, Path)); } geo.Close(); } else //对于其他普通文件的处理 { foreach (var dir in GetSubDirs()) { _Children.Add(new FileSystemObjectViewModel(dir, GetFileName(dir), FileSystemObjectType.Folder, "")); } IEnumerable <string> ss = GetSubFiles(); for (int i = 0; i < ss.Count(); i++) { bool b = false; for (int pos = 0; pos < li.Count(); pos++) { if (li.ElementAt(pos) == i) { b = true; break; } } if (!b) { _Children.Add(new FileSystemObjectViewModel(ss.ElementAt(i), GetFileName(ss.ElementAt(i)), FileSystemObjectType.File, "")); } } } } }
public static void ReadData(string path) { try { Geodatabase geodatabase = Geodatabase.Open(path); foreach (var ds in geodatabase.GetChildDatasets("\\", string.Empty)) { string sqlStatement = @"SELECT * FROM " + ds.Substring(1); foreach (Row attrQueryRow in geodatabase.ExecuteSQL(sqlStatement)) { for (int nFieldNumber = 0; nFieldNumber < attrQueryRow.FieldInformation.Count; nFieldNumber++) { string fieldName = attrQueryRow.FieldInformation.GetFieldName(nFieldNumber); if (attrQueryRow.IsNull(fieldName)) { continue; } switch (attrQueryRow.FieldInformation.GetFieldType(nFieldNumber)) { case FieldType.SmallInteger: attrQueryRow.GetShort(fieldName); break; case FieldType.Integer: attrQueryRow.GetInteger(fieldName); break; case FieldType.Single: attrQueryRow.GetFloat(fieldName); break; case FieldType.Double: attrQueryRow.GetDouble(fieldName); break; case FieldType.String: attrQueryRow.GetString(fieldName); break; case FieldType.Date: attrQueryRow.GetDate(fieldName).ToShortTimeString(); break; case FieldType.OID: attrQueryRow.GetOID(); break; case FieldType.Geometry: byte[] shapeBuffer = attrQueryRow.GetGeometry().shapeBuffer; double[] vs = new double[shapeBuffer.Length / 8]; for (int i = 0; i < vs.Length; i++) { vs[i] = BitConverter.ToDouble(shapeBuffer, i * 8); } break; case FieldType.GUID: attrQueryRow.GetGUID(fieldName).ToString(); break; case FieldType.GlobalID: attrQueryRow.GetGlobalID().ToString(); break; default: break; } } } } geodatabase.Close(); } catch (Exception) { return; } }