public void WriteShouldWorkWithoutIndexFileWhenRequested() { var pt = GeometryFactory.Default.CreatePoint(new Coordinate(2, 3)); var attributes = new AttributesTable { { "Foo", "Bar" } }; Feature[] features = { new Feature(pt, attributes) }; string baseFileName = TestContext.CurrentContext.Test.ID; string shpFilePath = baseFileName + ".shp"; string dbfFilePath = baseFileName + ".dbf"; string shxFilePath = baseFileName + ".shx"; var reg = new ShapefileStreamProviderRegistry( shapeStream: new FileStreamProvider(StreamTypes.Shape, shpFilePath), dataStream: new FileStreamProvider(StreamTypes.Data, dbfFilePath), indexStream: null, validateShapeProvider: true, validateDataProvider: true, validateIndexProvider: false); var wr = new ShapefileDataWriter(reg, GeometryFactory.Default, CodePagesEncodingProvider.Instance.GetEncoding(1252)); wr.Header = ShapefileDataWriter.GetHeader(features[0], features.Length); wr.Write(features); Assert.True(File.Exists(shpFilePath)); Assert.True(File.Exists(dbfFilePath)); Assert.False(File.Exists(shxFilePath)); }
public static FeatureCollection GetFeatureCollectionWgs84(IFormFile file) { using (var stream = file.OpenReadStream()) using (var archive = new ZipArchive(stream)) { var shapeEntry = archive.Entries.FirstOrDefault(e => e.Name.Contains(".shp")); var indexEntry = archive.Entries.FirstOrDefault(e => e.Name.Contains(".shx")); var dbfEntry = archive.Entries.FirstOrDefault(e => e.Name.Contains(".dbf")); var projectionEntry = archive.Entries.FirstOrDefault(e => e.Name.Contains(".prj")); var dataEncodingEntry = archive.Entries.FirstOrDefault(e => e.Name.Contains(".cpg")); var spatialIndexEntry = archive.Entries.FirstOrDefault(e => e.Name.Contains(".sbn")); var spatialIndexIndexEntry = archive.Entries.FirstOrDefault(e => e.Name.Contains(".sbx")); var shapeStream = new ZipStreamProvider(StreamTypes.Shape, shapeEntry); var indexStream = new ZipStreamProvider(StreamTypes.Index, indexEntry); var dataStream = new ZipStreamProvider(StreamTypes.Data, dbfEntry); var projectionStream = projectionEntry == null ? null : new ZipStreamProvider(StreamTypes.Projection, projectionEntry); var dataEncodingStream = dataEncodingEntry == null ? null : new ZipStreamProvider(StreamTypes.DataEncoding, dataEncodingEntry); var spatialIndexStream = spatialIndexEntry == null ? null : new ZipStreamProvider(StreamTypes.SpatialIndex, spatialIndexEntry); var spatialIndexIndexStream = spatialIndexIndexEntry == null ? null : new ZipStreamProvider(StreamTypes.SpatialIndexIndex, spatialIndexIndexEntry); var registry = new ShapefileStreamProviderRegistry(shapeStream, dataStream, indexStream, true, true, true, dataEncodingStream, projectionStream, spatialIndexStream, spatialIndexIndexStream); var reader = new ShapefileDataReader(registry, new GeometryFactory()); var features = GetFeatureCollection(reader); var projection = GetProjection(projectionEntry); features = TransformProjection(features, projection, GeographicCoordinateSystem.WGS84); features.CRS = new NamedCRS("urn:ogc:def:crs:OGC:1.3:CRS84"); return(features); } }