public DataTable Query(Envelope extents) { DataTable table = this.GetDataTable(); ArrayList indexes = new ArrayList(_spatialIndex.query(extents).toArray()); // Sort the results so we can go through the files sequentially indexes.Sort(); ShapeHandler handler = null; switch (_type) { case ShapeType.Point: handler = new PointHandler(); break; case ShapeType.Arc: handler = new MultiLineHandler(); break; case ShapeType.Polygon: handler = new PolygonHandler(); break; } using (BinaryReader dbfReader = new BinaryReader(File.OpenRead(Path.Combine(Path.GetDirectoryName(_path), Path.GetFileNameWithoutExtension(_path) + ".dbf")))) using (BigEndianBinaryReader shpReader = new BigEndianBinaryReader(File.OpenRead(_path))) { foreach (ShapefileRecordPointer pointer in indexes) { ArrayList record = new ArrayList(); // Step 1: Get the geometry // NOTE: We add 8 here to skip the content length and record numer - we // already have that information in the pointer object. shpReader.BaseStream.Position = pointer.GeometryOffset + 8; record.Add(handler.Read(shpReader, _factory)); // Step 2: Get the attributes dbfReader.BaseStream.Position = pointer.AttributesOffset; record.AddRange(DbaseFileReader.ReadRecord(dbfReader, _dbfHeader)); table.Rows.Add(record.ToArray()); } } return(table); }
public DataTable Query(Envelope extents) { DataTable table = this.GetDataTable(); ArrayList indexes = new ArrayList(_spatialIndex.query(extents).toArray()); // Sort the results so we can go through the files sequentially indexes.Sort(); ShapeHandler handler = null; switch (_type) { case ShapeType.Point: handler = new PointHandler(); break; case ShapeType.Arc: handler = new MultiLineHandler(); break; case ShapeType.Polygon: handler = new PolygonHandler(); break; } using (BinaryReader dbfReader = new BinaryReader(File.OpenRead(Path.Combine(Path.GetDirectoryName(_path), Path.GetFileNameWithoutExtension(_path) + ".dbf")))) using (BigEndianBinaryReader shpReader = new BigEndianBinaryReader(File.OpenRead(_path))) { foreach (ShapefileRecordPointer pointer in indexes) { ArrayList record = new ArrayList(); // Step 1: Get the geometry // NOTE: We add 8 here to skip the content length and record numer - we // already have that information in the pointer object. shpReader.BaseStream.Position = pointer.GeometryOffset + 8; record.Add(handler.Read(shpReader, _factory)); // Step 2: Get the attributes dbfReader.BaseStream.Position = pointer.AttributesOffset; record.AddRange(DbaseFileReader.ReadRecord(dbfReader, _dbfHeader)); table.Rows.Add(record.ToArray()); } } return table; }