public bool TryOpen(string filename, byte[] bytes, params object[] args) { _filename = filename; if (!filename.ToUpper().EndsWith(".SHP")) { return(false); } if (string.IsNullOrEmpty(filename)) { throw new NullReferenceException("new ShapeFilesReader(null)"); } if (!File.Exists(filename)) { throw new FileNotFoundException(filename); } string mainFile = filename; string dir = Path.GetDirectoryName(filename); string shxFile = Path.Combine(dir, Path.GetFileNameWithoutExtension(filename) + ".shx"); if (!File.Exists(shxFile)) { throw new FileNotFoundException(shxFile); } _dbffile = Path.Combine(dir, Path.GetFileNameWithoutExtension(filename) + ".dbf"); if (!File.Exists(_dbffile)) { throw new FileNotFoundException(_dbffile); } string prjFile = Path.Combine(dir, Path.GetFileNameWithoutExtension(filename) + ".prj"); if (File.Exists(prjFile)) { ParseProjectionInfo(prjFile); } // _fields = ParseDbfToDataTable.GetFields(_dbffile); _fsMainFile = new FileStream(mainFile, FileMode.Open, FileAccess.Read); _brMainFile = new BinaryReader(_fsMainFile); _fsShxFile = new FileStream(shxFile, FileMode.Open, FileAccess.Read); _brShxFile = new BinaryReader(_fsShxFile); //查看对应的注记文件是否存在 try { string anndbf = Path.Combine(Path.GetDirectoryName(_dbffile), Path.GetFileNameWithoutExtension(_dbffile) + "_注记.dbf"); if (File.Exists(anndbf)) { _annReader = new AnnotationDbfReader(anndbf); } } catch (Exception ex) { Log.WriterException("EsriShapeFilesReader", "TryOpen", ex); } //读文件头 ReadHeader(); // return(true); }
public float Estimate(string filename, out int featureCount, out int fieldCount) { featureCount = 0; fieldCount = 0; if (!filename.ToUpper().EndsWith(".SHP")) { return(0); } if (string.IsNullOrEmpty(filename)) { throw new NullReferenceException("new ShapeFilesReader(null)"); } if (!File.Exists(filename)) { throw new FileNotFoundException(filename); } string mainFile = filename; string dir = Path.GetDirectoryName(filename); string shxFile = Path.Combine(dir, Path.GetFileNameWithoutExtension(filename) + ".shx"); if (!File.Exists(shxFile)) { throw new FileNotFoundException(shxFile); } string dbffile = Path.Combine(dir, Path.GetFileNameWithoutExtension(filename) + ".dbf"); if (!File.Exists(dbffile)) { throw new FileNotFoundException(dbffile); } string[] fields = ParseDbfToDataTable.GetFields(dbffile); fieldCount = fields != null ? fields.Length : 0; float memorySize = ComputeSizeAndCount(mainFile, shxFile, out featureCount); memorySize += fieldCount * 100; //100 bytes per fieldvalue + fieldName return(memorySize / 1024f / 1024f); }