PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/GeoDataToolkit/GeoDataToolkit.FGDB/Accessors/FgdbDatasetRows.cs

https://github.com/PivotLogix/GeoDataToolkit
C# | 55 lines | 48 code | 7 blank | 0 comment | 7 complexity | f8279c485f9b046d988b6bf7854075f3 MD5 | raw file
Possible License(s): BSD-3-Clause, CC-BY-SA-3.0, Apache-2.0
  1. using GeoDataToolkit.Accessors;
  2. using GeoDataToolkit.Geometries;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Xml.Linq;
  7. using Esri.FileGDB;
  8. namespace GeoDataToolkit.FGDB.Accessors
  9. {
  10. internal class FgdbDatasetRows : IDatasetRows
  11. {
  12. private readonly Table _table;
  13. public FgdbDatasetRows(Table table)
  14. {
  15. _table = table;
  16. SpatialReference = GetSpatialReference(table.Definition);
  17. }
  18. public ISpatialReference SpatialReference { get; internal set; }
  19. public IEnumerable<IDatasetRow> GetFeatures()
  20. {
  21. var rows = _table.Search("*", "", RowInstance.Recycle);
  22. foreach (var row in rows)
  23. {
  24. yield return row.ToFeatureRow(SpatialReference);
  25. }
  26. }
  27. private static ISpatialReference GetSpatialReference(string tableDefinitionXml)
  28. {
  29. var elements = XElement.Parse(tableDefinitionXml);
  30. var spatialReference = elements.Elements().FirstOrDefault(x => x.Name == "SpatialReference");
  31. if (spatialReference == null)
  32. {
  33. return null;
  34. }
  35. var wkidNode = spatialReference.Elements().FirstOrDefault(x => x.Name == "WKID");
  36. if (wkidNode == null)
  37. {
  38. return null;
  39. }
  40. int wkid;
  41. if (int.TryParse(wkidNode.Value, NumberStyles.Integer, null, out wkid))
  42. {
  43. return new SpatialReference(wkid);
  44. }
  45. return null;
  46. }
  47. }
  48. }