/// <summary> /// Opens the datasource /// </summary> public virtual void Open(string path) { // Get a Connector. The connector returned is guaranteed to be connected and ready to go. // Pooling.Connector connector = Pooling.ConnectorPool.ConnectorPoolManager.RequestConnector(this,true); if (!File.Exists(path)) { log.Error("Could not find " + path); return; } if (!_IsOpen || this.path != path) { try { this.path = path; tree = null; //Initialize DBF string dbffile = GetDbaseFilePath(); if (File.Exists(dbffile)) { dbaseFile = new DbaseReader(dbffile); } //Parse shape header ParseHeader(); //Read projection file ParseProjection(); fsShapeIndex = new FileStream(GetIndexFilePath(), FileMode.Open, FileAccess.Read); brShapeIndex = new BinaryReader(fsShapeIndex, Encoding.Unicode); fsShapeFile = new FileStream(this.path, FileMode.Open, FileAccess.Read); brShapeFile = new BinaryReader(fsShapeFile); InitializeShape(this.path, _FileBasedIndex); if (dbaseFile != null) { dbaseFile.Open(); } _IsOpen = true; } catch (IOException e) { log.Error(e.Message); _IsOpen = false; } } }
/// <summary> /// Initializes a ShapeFile DataProvider. /// </summary> /// <remarks> /// <para>If FileBasedIndex is true, the spatial index will be read from a local copy. If it doesn't exist, /// it will be generated and saved to [filename] + '.sidx'.</para> /// <para>Using a file-based index is especially recommended for ASP.NET applications which will speed up /// start-up time when the cache has been emptied. /// </para> /// </remarks> /// <param name="filename">Path to shape file</param> /// <param name="fileBasedIndex">Use file-based spatial index</param> public ShapeFile(string filename, bool fileBasedIndex) { _Filename = filename; _FileBasedIndex = fileBasedIndex; //Initialize DBF string dbffile = _Filename.Substring(0, _Filename.LastIndexOf(".")) + ".dbf"; if (File.Exists(dbffile)) { dbaseFile = new DbaseReader(dbffile); } //Parse shape header ParseHeader(); //Read projection file ParseProjection(); }
/// <summary> /// Initializes a ShapeFile DataProvider. /// </summary> /// <remarks> /// <para>If FileBasedIndex is true, the spatial index will be read from a local copy. If it doesn't exist, /// it will be generated and saved to [filename] + '.sidx'.</para> /// <para>Using a file-based index is especially recommended for ASP.NET applications which will speed up /// start-up time when the cache has been emptied. /// </para> /// </remarks> /// <param name="filename">Path to shape file</param> /// <param name="fileBasedIndex">Use file-based spatial index</param> public ShapeFile(string filename, bool fileBasedIndex) { _Filename = filename; _FileBasedIndex = (fileBasedIndex) && File.Exists(Path.ChangeExtension(filename, ".shx")); //Initialize DBF //string dbffile = _Filename.Substring(0, _Filename.LastIndexOf(".")) + ".dbf"; string dbffile = Path.ChangeExtension(filename, ".dbf"); if (File.Exists(dbffile)) { dbaseFile = new DbaseReader(dbffile); } //Parse shape header ParseHeader(); //Read projection file ParseProjection(); }
/// <summary> /// Opens the datasource /// </summary> public virtual void Open(string path) { // Get a Connector. The connector returned is guaranteed to be connected and ready to go. // Pooling.Connector connector = Pooling.ConnectorPool.ConnectorPoolManager.RequestConnector(this,true); logNoShapeFile = true; if (!_IsOpen || this.path != path) { if (!File.Exists(path)) { if (logNoShapeFile) { log.Error("Could not find " + path); logNoShapeFile = false; } return; } try { unsafe { this.path = path; //tree = null; //Initialize DBF string dbffile = GetDbaseFilePath(); if (File.Exists(dbffile)) { dbaseFile = new DbaseReader(dbffile); } //Parse shape header ParseHeader(); //Read projection file ParseProjection(); fsShapeIndex = new FileStream(GetIndexFilePath(), FileMode.Open, FileAccess.Read); brShapeIndex = new BinaryReader(fsShapeIndex, Encoding.Unicode); fsShapeFile = new FileStream(this.path, FileMode.Open, FileAccess.Read); brShapeFile = new BinaryReader(fsShapeFile); shpFileMemoryMap = NativeMethods.MapFile(fsShapeFile); shpFileMemoryMapView = NativeMethods.MapViewOfFile(shpFileMemoryMap, NativeMethods.FileMapAccess.FILE_MAP_READ, 0, 0, 0); zeroPtr = (byte *)shpFileMemoryMapView.ToPointer(); InitializeShape(this.path, _FileBasedIndex); if (dbaseFile != null) { dbaseFile.Open(); } _IsOpen = true; } } catch (IOException e) { log.Error(e.Message); _IsOpen = false; } } }