/// <summary> /// This create new method implies that this provider has the priority for creating a new file. /// An instance of the dataset should be created and then returned. By this time, the fileName /// will already be checked to see if it exists, and deleted if the user wants to overwrite it. /// </summary> /// <param name="fileName">The string fileName for the new instance</param> /// <param name="featureType">Point, Line, Polygon etc. Sometimes this will be specified, sometimes it will be "Unspecified"</param> /// <param name="inRam">Boolean, true if the dataset should attempt to store data entirely in ram</param> /// <param name="progressHandler">An IProgressHandler for status messages.</param> /// <returns>An IRaster</returns> public virtual IFeatureSet CreateNew(string fileName, FeatureType featureType, bool inRam, IProgressHandler progressHandler) { if (featureType == FeatureType.Point) { PointShapefile ps = new PointShapefile(); ps.Filename = fileName; return(ps); } else if (featureType == FeatureType.Line) { LineShapefile ls = new LineShapefile(); ls.Filename = fileName; return(ls); } else if (featureType == FeatureType.Polygon) { PolygonShapefile ps = new PolygonShapefile(); ps.Filename = fileName; return(ps); } else if (featureType == FeatureType.MultiPoint) { MultiPointShapefile mps = new MultiPointShapefile(); mps.Filename = fileName; return(mps); } return(null); }
public void CanReadShapefileWithManyByteBlocks() { const string path = @"Data\Shapefiles\nos80k\nos80k.shp"; var target = new PolygonShapefile(path); Assert.IsNotNull(target); Assert.IsNotNull(target.ShapeIndices); }
public void CanReadShapefileWithManyByteBlocks() { const string Path = @"Data\Shapefiles\nos80k\nos80k.shp"; var target = new PolygonShapefile(Path); Assert.IsNotNull(target); Assert.IsNotNull(target.ShapeIndices); }
public void CanReadShapefileWithManyByteBlocks() { string path = Common.AbsolutePath(@"Data\Shapefiles\nos80k\nos80k.shp"); var target = new PolygonShapefile(path); Assert.IsNotNull(target); Assert.IsNotNull(target.ShapeIndices); }
/// <summary> /// Generates a default instance of the data type so that tools have something to write too. /// </summary> /// <param name="path">Path of the generated shapefile.</param> public override void GenerateDefaultOutput(string path) { FeatureSet addedFeatureSet = new PolygonShapefile { Filename = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + ModelName + ".shp" }; Value = addedFeatureSet; }
public void CanCreateMultiPartPolygons(string file) { var target = new RasterToPolygon(); var p = new GdalRasterProvider(); var raster = p.Open(file); var outShape = new PolygonShapefile { Filename = FileTools.GetTempFileName(".shp") }; target.Execute(raster, outShape, new MockProgressHandler()); FileTools.DeleteShapeFile(outShape.Filename); var mpCount = outShape.Features.Count(t => t.Geometry is MultiPolygon); Assert.That(mpCount > 0); }
public void EachHoleExistsOnlyOnce() { string filePath = Common.AbsolutePath(@"Data\Shapefiles\Multipolygon\PolygonInHole.shp"); // Replace with path to file using var file = new PolygonShapefile(filePath); Assert.AreEqual(1, file.Features.Count, "Expected the shapefile to have only 1 feature."); IFeature feature = file.GetFeature(0); Assert.AreEqual(2, feature.Geometry.NumGeometries, "Expect the feature to consist out of 2 geometries."); for (int i = 0; i < feature.Geometry.NumGeometries; i++) { var polygon = (Polygon)feature.Geometry.GetGeometryN(i); Assert.AreEqual(1, polygon.NumInteriorRings, "Expect each polygon part to have 1 hole."); } }
public void NoMultiPartPolygonsWithConnectionGrid(string rasterFile, string flowDirectionGridFile) { var p = new GdalRasterProvider(); var raster = p.Open(rasterFile); var flowDirectionGrid = p.Open(flowDirectionGridFile); var target = new RasterToPolygon(); var outShape = new PolygonShapefile { Filename = FileTools.GetTempFileName(".shp") }; target.Execute(raster, flowDirectionGrid, outShape, new MockProgressHandler()); FileTools.DeleteShapeFile(outShape.Filename); var mpCount = outShape.Features.Count(t => t.Geometry is MultiPolygon); Assert.That(mpCount == 0); }
/// <summary> /// Creates a new instance of <see cref="PolygonShapeFileReader"/>. /// </summary> /// <param name="filePath">The path to the shape file.</param> /// <exception cref="ArgumentException">Thrown when <paramref name="filePath"/> is invalid.</exception> /// <exception cref="CriticalFileReadException">Thrown when either: /// <list type="bullet"> /// <item><paramref name="filePath"/> points to a file that doesn't exist.</item> /// <item>The shapefile has non-polygon geometries in it.</item> /// <item>An unexpected error occurred when reading the shapefile.</item> /// </list> /// </exception> public PolygonShapeFileReader(string filePath) : base(filePath) { try { ShapeFile = new PolygonShapefile(filePath); } catch (ArgumentException e) { string message = new FileReaderErrorMessageBuilder(filePath) .Build(GisIOResources.PointShapeFileReader_File_contains_geometries_not_polygons); throw new CriticalFileReadException(message, e); } catch (IOException exception) { string message = new FileReaderErrorMessageBuilder(filePath).Build(CoreCommonUtilResources.Error_General_IO_Import_ErrorMessage); throw new CriticalFileReadException(message, exception); } }
private void BtnAddDataClick(object sender, EventArgs e) { ///////////////////////////////// //Replace with something that uses the default data provider SaveFileDialog sfd = new SaveFileDialog(); sfd.OverwritePrompt = true; sfd.Filter = "Shape Files|*.shp"; if (sfd.ShowDialog() == DialogResult.OK) { IFeatureSet addedFeatureSet = new PolygonShapefile(); addedFeatureSet.Filename = sfd.FileName; //This inserts the new featureset into the list textBox1.Text = Path.GetFileNameWithoutExtension(addedFeatureSet.Filename); Param.Value = addedFeatureSet; base.Status = ToolStatus.Ok; LightTipText = ModelingMessageStrings.FeaturesetValid; } }