public List <Record <T> > GetShapes <T>(string sourceName, BaseShapeParser <T> parser) { var metadatas = ParseMetadatas(sourceName + ".dbf"); var shapes = ParseShp(sourceName + ".shp", parser); List <Record <T> > recordList = new List <Record <T> >(); for (int i = 0; i < shapes.Count; i++) { Record <T> newRecord = new Record <T>(i, shapes[i], metadatas[i]); recordList.Add(newRecord); } return(recordList); }
public Record <T> GetShape <T>(string sourceName, BaseShapeParser <T> parser, ShapeIndex index) { using (BinaryReader reader = new BinaryReader(File.OpenRead(sourceName + ".shp"))) { byte[] bytesHeader = new byte[8]; byte[] bytesRecord = new byte[2 * index.ContentLength]; reader.BaseStream.Seek(2 * index.Offset, SeekOrigin.Begin); reader.Read(bytesHeader, 0, 8); var recordNumber = ReadInt(bytesHeader, 0, false); var contentLength = ReadInt(bytesHeader, 4, false); reader.Read(bytesRecord, 0, 2 * index.ContentLength); T shape = parser.Parse(bytesRecord, ReadInt, ReadDouble); Record <T> record = new Record <T>(recordNumber, shape, index.Metadatas); return(record); } }
public List <T> ParseShp <T>(string shp, BaseShapeParser <T> parser) { List <T> shapes = new List <T>(); using (BinaryReader reader = new BinaryReader(File.OpenRead(shp))) { byte[] headerArray = new byte[100]; int read = reader.Read(headerArray, 0, 100); var fileCode = ReadInt(headerArray, 0, false); var fileLength = ReadInt(headerArray, 24, false); var version = ReadInt(headerArray, 28, true); var globalShapeType = ReadInt(headerArray, 32, true); var xMin = ReadDouble(headerArray, 36, true); var yMin = ReadDouble(headerArray, 44, true); var xMax = ReadDouble(headerArray, 52, true); var yMax = ReadDouble(headerArray, 60, true); var zMin = ReadDouble(headerArray, 68, true); var zMax = ReadDouble(headerArray, 76, true); var mMin = ReadDouble(headerArray, 84, true); var mMax = ReadDouble(headerArray, 92, true); if (globalShapeType != (int)parser.GeometryType) { throw new InvalidOperationException($"Invalid record shape type : expected {parser.GeometryType} but found {globalShapeType}"); } byte[] recordHeader = new byte[8]; while (reader.Read(recordHeader, 0, 8) != 0) { var recordNumber = ReadInt(recordHeader, 0, false); var contentLength = ReadInt(recordHeader, 4, false); byte[] recordContent = new byte[2 * contentLength]; reader.Read(recordContent, 0, 2 * contentLength); var recordShapeType = ReadInt(recordContent, 0, true); shapes.Add(parser.Parse(recordContent, new ReadIntDelegate(ReadInt), new ReadDoubleDelegate(ReadDouble))); } } return(shapes); }