| 1 |
using System; |
|---|
| 2 |
using System.IO; |
|---|
| 3 |
using OGR; |
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
/** |
|---|
| 7 |
|
|---|
| 8 |
* <p>Title: GDAL C# ogrinfo example.</p> |
|---|
| 9 |
* <p>Description: A sample app to dump information from a spatial data source.</p> |
|---|
| 10 |
* @author Tamas Szekeres (szekerest@gmail.com) |
|---|
| 11 |
* @version 1.0 |
|---|
| 12 |
*/ |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
/// <summary> |
|---|
| 17 |
/// A C# based sample to dump information from a data source. |
|---|
| 18 |
/// </summary> |
|---|
| 19 |
|
|---|
| 20 |
class OGRInfo { |
|---|
| 21 |
|
|---|
| 22 |
public static void usage() |
|---|
| 23 |
|
|---|
| 24 |
{ |
|---|
| 25 |
Console.WriteLine("usage: ogrinfo {data source name}"); |
|---|
| 26 |
System.Environment.Exit(-1); |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
public static void Main(string[] args) { |
|---|
| 30 |
|
|---|
| 31 |
if (args.Length != 1) usage(); |
|---|
| 32 |
|
|---|
| 33 |
// Using early initialization of System.Console |
|---|
| 34 |
Console.WriteLine(""); |
|---|
| 35 |
|
|---|
| 36 |
/* -------------------------------------------------------------------- */ |
|---|
| 37 |
/* Register format(s). */ |
|---|
| 38 |
/* -------------------------------------------------------------------- */ |
|---|
| 39 |
ogr.RegisterAll(); |
|---|
| 40 |
|
|---|
| 41 |
/* -------------------------------------------------------------------- */ |
|---|
| 42 |
/* Open data source. */ |
|---|
| 43 |
/* -------------------------------------------------------------------- */ |
|---|
| 44 |
DirectoryInfo dir = new DirectoryInfo(args[0]); |
|---|
| 45 |
|
|---|
| 46 |
FileInfo[] files = dir.GetFiles("*.000", SearchOption.AllDirectories); |
|---|
| 47 |
|
|---|
| 48 |
foreach (FileInfo file in files) |
|---|
| 49 |
{ |
|---|
| 50 |
DataSource ds = null; |
|---|
| 51 |
try |
|---|
| 52 |
{ |
|---|
| 53 |
ds = ogr.Open(file.FullName, 0); |
|---|
| 54 |
} |
|---|
| 55 |
catch(Exception e ) |
|---|
| 56 |
{ |
|---|
| 57 |
Console.WriteLine(e.Message); |
|---|
| 58 |
} |
|---|
| 59 |
if (ds == null) |
|---|
| 60 |
{ |
|---|
| 61 |
Console.WriteLine("Can't open " + file.FullName); |
|---|
| 62 |
//System.Environment.Exit(-1); |
|---|
| 63 |
} |
|---|
| 64 |
else |
|---|
| 65 |
{ |
|---|
| 66 |
/* -------------------------------------------------------------------- */ |
|---|
| 67 |
/* Get driver */ |
|---|
| 68 |
/* -------------------------------------------------------------------- */ |
|---|
| 69 |
using (Driver drv = ds.GetDriver()) |
|---|
| 70 |
{ |
|---|
| 71 |
|
|---|
| 72 |
if (drv == null) |
|---|
| 73 |
{ |
|---|
| 74 |
Console.WriteLine("Can't get driver."); |
|---|
| 75 |
//System.Environment.Exit(-1); |
|---|
| 76 |
} |
|---|
| 77 |
// TODO: drv.name is still unsafe with lazy initialization (Bug 1339) |
|---|
| 78 |
Console.WriteLine("Using driver " + drv.name); |
|---|
| 79 |
|
|---|
| 80 |
Layer coverage = ds.GetLayerByName("M_COVR"); |
|---|
| 81 |
|
|---|
| 82 |
Console.WriteLine(coverage.GetName()); |
|---|
| 83 |
} |
|---|
| 84 |
} |
|---|
| 85 |
} |
|---|
| 86 |
Directory.Delete(args[0], true); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
} |
|---|