///// <summary> ///// Loads a Ogr datasource with the specified layer ///// </summary> ///// <param name="filename">datasource</param> ///// <param name="layerName">name of layer</param> /////If you want this functionality use /////<example> /////SharpMap.Data.Providers.Ogr prov = new SharpMap.Data.Providers.Ogr(datasource); /////prov.LayerName = layerName; /////</example> //[Obsolete("This constructor does not work well with VB.NET. Use LayerName property instead")] //public Ogr(string filename, string layerName) //{ // Filename = filename; // _ogrDataSource = OgrOgr.Open(filename, 1); // _ogrLayer = _ogrDataSource.GetLayerByName(layerName); // OsrSpatialReference spatialReference = _ogrLayer.GetSpatialRef(); // if (spatialReference != null) // SRID = spatialReference.AutoIdentifyEPSG(); //} /// <summary> /// Loads a Ogr datasource with the specified layer /// </summary> /// <param name="filename">datasource</param> /// <param name="layerNum">number of layer</param> public Ogr(string filename, int layerNum) { Filename = filename; ConnectionID = filename; _ogrDataSource = OgrOgr.OpenShared(filename, 0); using (var ogrLayer = GetLayer(layerNum)) { OsrSpatialReference spatialReference = ogrLayer.GetSpatialRef(); if (spatialReference != null) { SRID = spatialReference.AutoIdentifyEPSG(); } } _layerIndex = layerNum; }
/// <summary> /// Method to get a layer based on a private copy of the data source /// </summary> /// <param name="layerIndex">The layer index</param> /// <param name="ogrDataSource">The data source</param> /// <returns></returns> private OgrLayer GetLayer(int layerIndex, out OgrDataSource ogrDataSource) { ogrDataSource = OgrOgr.OpenShared(Filename, 0); return(ogrDataSource.GetLayerByIndex(layerIndex)); }