/// <summary> /// Prints initialized Ogr drivers. /// </summary> private static void PrintDriversOgr() { if (!Usable) { throw new Exception(string.Format(Strings.UnableToPrintDrivers, "OGR")); } int driverCount = Ogr.GetDriverCount(); for (int index = 0; index < driverCount; index++) { try { using (OSGeo.OGR.Driver driver = Ogr.GetDriver(index)) { Console.WriteLine($"OGR {index}: {driver.GetName()}", "Debug"); } } catch (Exception exception) { throw new Exception(string.Format(Strings.UnableToPrintDrivers, "OGR"), exception); } } }
public static List <string> OGRInfo(string datasourceFileLocation) { List <string> info = new List <string>(); Ogr.RegisterAll(); DataSource ds = Ogr.Open(datasourceFileLocation, 0); if (ds == null) { info.Add("Couldn not open vector data source."); return(info); } OSGeo.OGR.Driver drv = ds.GetDriver(); if (drv == null) { info.Add("Could not find driver to open vector data source."); return(info); } info.Add("Using driver: " + drv.GetName()); ///Iterating through layers for (int iLayer = 0; iLayer < ds.GetLayerCount(); iLayer++) { Layer layer = ds.GetLayerByIndex(iLayer); if (layer == null) { info.Add("Could not find layers in the vector data source."); return(info); } FeatureDefn def = layer.GetLayerDefn(); info.Add("Layer name: " + def.GetName()); info.Add("Feature count: " + layer.GetFeatureCount(1)); Envelope ext = new Envelope(); layer.GetExtent(ext, 1); info.Add("Extent: " + ext.MinX + ", " + ext.MinY + ", " + ext.MaxX + ", " + ext.MaxY); ///Reading the spatial reference OSGeo.OSR.SpatialReference sr = layer.GetSpatialRef(); string srs_wkt = string.Empty; if (sr != null) { sr.ExportToPrettyWkt(out srs_wkt, 1); } else { srs_wkt = "(unknow)"; } info.Add("Layer SRS WKT: " + srs_wkt); ///Reading the fields info.Add("Field Names (type): "); for (int iAttr = 0; iAttr < def.GetFieldCount(); iAttr++) { FieldDefn fdef = def.GetFieldDefn(iAttr); info.Add(fdef.GetName() + " (" + fdef.GetFieldTypeName(fdef.GetFieldType()) + ")"); } } ds.Dispose(); return(info); }