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); }
/// <summary> /// Initializes a new instance of the <see cref="ShapefileEnumerator" /> class. /// </summary> /// <param name="shapefile"></param> public ShapefileEnumerator(ShapefileReader shapefile) { _parent = shapefile; // create a file stream for each enumerator that is given out. This allows the same file // to have one or more enumerator. If we used the parents stream - than only one IEnumerator // could be given out. var stream = shapefile._shapeStreamProviderRegistry[StreamTypes.Shape].OpenRead(); _shpBinaryReader = new BigEndianBinaryReader(stream); // skip header - since parent has already read this. _shpBinaryReader.ReadBytes(100); var type = _parent._mainHeader.ShapeType; _handler = Shapefile.GetShapeHandler(type); if (_handler == null) { throw new NotSupportedException("Unsuported shape type:" + type); } }
/// <summary> /// Reads the shapefile and returns a GeometryCollection representing all the records in the shapefile. /// </summary> /// <returns>GeometryCollection representing every record in the shapefile.</returns> public IGeometryCollection ReadAll() { var list = new List <IGeometry>(); ShapeGeometryType type = _mainHeader.ShapeType; ShapeHandler handler = Shapefile.GetShapeHandler(type); if (handler == null) { throw new NotSupportedException("Unsupported shape type:" + type); } int i = 0; foreach (IGeometry geometry in this) { list.Add(geometry); i++; } IGeometry[] geomArray = GeometryFactory.ToGeometryArray(list); return(_geometryFactory.CreateGeometryCollection(geomArray)); }