public ShapeReader(IStreamProviderRegistry streamProviderRegistry) { if (streamProviderRegistry == null) throw new ArgumentNullException("streamProviderRegistry"); m_StreamProviderRegistry = streamProviderRegistry; m_ShapeFileHeader = new ShapefileHeader(ShapeReaderStream); m_ShapeHandler = Shapefile.GetShapeHandler(ShapefileHeader.ShapeType); m_ShapeOffsetCache = new Lazy<long[]>(BuildOffsetCache, LazyThreadSafetyMode.ExecutionAndPublication); }
public ShapefileWriter(IGeometryFactory geometryFactory, IStreamProviderRegistry streamProviderRegistry, ShapeGeometryType geomType) : this(geometryFactory) { _shpStream = streamProviderRegistry[StreamTypes.Shape].OpenWrite(true); _shxStream = streamProviderRegistry[StreamTypes.Index].OpenWrite(true); _geometryType = geomType; _shpBinaryWriter = new BigEndianBinaryWriter(_shpStream); _shxBinaryWriter = new BigEndianBinaryWriter(_shxStream); WriteShpHeader(_shpBinaryWriter, 0, new Envelope(0, 0, 0, 0)); WriteShxHeader(_shxBinaryWriter, 0, new Envelope(0, 0, 0, 0)); _shapeHandler = Shapefile.GetShapeHandler(geomType); }
public ShapefileWriter(IGeometryFactory geometryFactory, string filename, ShapeGeometryType geomType) : this(geometryFactory) { var folder = Path.GetDirectoryName(filename) ?? "."; var file = Path.GetFileNameWithoutExtension(filename); if (string.IsNullOrEmpty(file)) throw new ArgumentException(string.Format("Filename '{0}' is not valid", filename), "filename"); filename = Path.Combine(folder, file); _shpStream = new FileStream(filename + ".shp", FileMode.Create); _shxStream = new FileStream(filename + ".shx", FileMode.Create); _geometryType = geomType; _shpBinaryWriter = new BigEndianBinaryWriter(_shpStream); _shxBinaryWriter = new BigEndianBinaryWriter(_shxStream); WriteShpHeader(_shpBinaryWriter, 0, new Envelope(0, 0, 0, 0), geomType); WriteShxHeader(_shxBinaryWriter, 0, new Envelope(0, 0, 0, 0), geomType); _shapeHandler = Shapefile.GetShapeHandler(geomType); }
public ShapeReader(string shapeFilePath) { if (shapeFilePath == null) { throw new ArgumentNullException("shapeFilePath"); } if (string.IsNullOrWhiteSpace(shapeFilePath)) { throw new ArgumentException("shapeFilePath", "Path to shapefile can't be empty"); } if (!File.Exists(shapeFilePath)) { throw new FileNotFoundException("Given shapefile doesn't exist", shapeFilePath); } m_ShapeFilePath = shapeFilePath; m_ShapeFileHeader = new ShapefileHeader(ShapeReaderStream); m_ShapeHandler = Shapefile.GetShapeHandler(ShapefileHeader.ShapeType); m_ShapeOffsetCache = new Lazy<long[]>(BuildOffsetCache, LazyThreadSafetyMode.ExecutionAndPublication); }
private static /*int*/ void WriteRecordToFile(BigEndianBinaryWriter shpBinaryWriter, BigEndianBinaryWriter shxBinaryWriter, ShapeHandler handler, IGeometry body, int oid) { if (body == null || body.IsEmpty) { WriteNullShapeRecord(shpBinaryWriter, shxBinaryWriter, oid); return; } // Get the length of each record (in bytes) var recordLength = handler.ComputeRequiredLengthInWords(body); // Get the position in the stream var pos = shpBinaryWriter.BaseStream.Position; shpBinaryWriter.WriteIntBE(oid); shpBinaryWriter.WriteIntBE(recordLength); // update shapefile index (position in words, 1 word = 2 bytes) var posWords = pos / 2; shxBinaryWriter.WriteIntBE((int)posWords); shxBinaryWriter.WriteIntBE(recordLength); handler.Write(body, shpBinaryWriter, body.Factory); /*return recordLength;*/ }