Functions

bool Shapefile.HasInvalidShapes ()
 Checks whether there are invalid shapes within shapefile. More...
 

Properties

ShapeValidationInfo Shapefile.LastInputValidation [get]
 Gets results of input data validation for geoprocessing methods. More...
 
ShapeValidationInfo Shapefile.LastOutputValidation [get]
 Gets results of output data validation for geoprocessing methods. More...
 

Detailed Description

Here is a list of properties and methods for shapefile validation. This module is a part of the documentation of Shapefile class.

dot_inline_dotgraph_34.png

Graph description

Shapefile validation

Starting from version 4.9.1 built-in validation for input and output shapefiles passed to geoprocessing methods is used. During validation each shape within a shapefile is checked for validity with Shape.IsValid property and optionally an attempt is made to fix invalid shapes with Shape.FixUp. If the fixing wasn't successful, various actions may be taken:

Validation behaviors are specified in GlobalSettings.ShapeInputValidationMode and GlobalSettings.ShapeOutputValidationMode. See tkShapeValidationMode enumeration for possible behaviours. By default no validation is performed (tkShapeValidationMode.NoValidation), to preserve compatibility with previous versions of library.

The results of validation can be viewed via Shapefile.LastInputValidation and Shapefile.LastOutputValidation properties. Both return instance of ShapeValidationInfo class (see description for list of properties).
There is slight difference between input and output validation:

In this example a shapefile with invalid shape is created and then validated as input to Shapefile.AggregateShapes methods and as output in Shapefile.Save method.

// creating invalid shapefile
Extents ext = new Extents();
ext.SetBounds(100, 100, 0, 200, 200, 0);
Extents ext2 = new Extents();
ext2.SetBounds(200, 100, 0, 300, 200, 0);
// polygons will touch along the border after aggregation
var shp = ext.ToShape();
var shp2 = ext2.ToShape();
// make invalid by reversing order of points
var sf = new Shapefile();
sf.CreateNew("", ShpfileType.SHP_POLYGON);
int fieldIndex = sf.EditAddField("Id", FieldType.INTEGER_FIELD, 10, 10);
sf.EditAddShape(shp);
sf.EditAddShape(shp2);
sf.EditCellValue(fieldIndex, 0, 1);
sf.EditCellValue(fieldIndex, 1, 1);
// doing operation & validating
var gs = new GlobalSettings();
gs.ShapeInputValidationMode = tkShapeValidationMode.TryFixProceedOnFailure;
gs.ShapeOutputValidationMode = tkShapeValidationMode.TryFixProceedOnFailure;
var result = sf.AggregateShapes(false, fieldIndex);
if (sf.LastInputValidation != null)
Debug.Print("Input validation: " + sf.LastInputValidation.Status.ToString());
if (sf.LastOutputValidation != null)
Debug.Print("Output validation: " + sf.LastOutputValidation.Status.ToString());
Debug.Print("Input still has invalid shapes: " + sf.HasInvalidShapes());
Debug.Print("Output has invalid shapes: " + result.HasInvalidShapes());
sf.SaveAs(@"d:\validated.shp", null);
if (sf.LastInputValidation != null)
Debug.Print("Output validation (for Shapefile.Save): " + sf.LastInputValidation.Status.ToString());
Debug.Print("Shapefile still has invalid shapes: " + sf.HasInvalidShapes());
tkShapeValidationMode
Possible validation modes for shapefiles.
Definition: Enumerations.cs:1921
ShpfileType
The type of the shapefile.
Definition: Enumerations.cs:169
FieldType
The available types of fields of dbf table.
Definition: Enumerations.cs:34
Represents a rectangle on the map.
Definition: Extents.cs:49
Shape ToShape()
Creates a rectangular polygon matching current extents.
Definition: Extents.cs:214
void SetBounds(double xMin, double yMin, double zMin, double xMax, double yMax, double zMax)
Sets the bounds for the extents object.
Definition: Extents.cs:85
Holds global settings for MapWinGIS. Allows to retrieve GDAL errors.
Definition: GlobalSettings.cs:29
bool ReversePointsOrder(int partIndex)
Changes the order of points within shape part to the opposite.
Definition: Shape.cs:517
Provides a functionality for accessing and editing ESRI shapefiles.
Definition: Shapefile.cs:72
Extents Extents
Gets bounding box which encompass all the shapes in the shapefile.
Definition: Shapefile.cs:146

Output of the sample:

// Input validation: InvalidFixed
// Output validation: InvalidFixed
// Input still has invalid shapes: True
// Output has invalid shapes: False
// Output validation (for Shapefile.Save): InvalidFixed
// Shapefile still has invalid shapes: False

Here is list of methods with built-in shapefile validation: Shapefile.Clip, Shapefile.GetIntersection, Shapefile.Difference, Shapefile.SymmDifference, Shapefile.Union, Shapefile.ExplodeShapes, Shapefile.AggregateShapes, Shapefile.ExportSelection, Shapefile.Sort, Shapefile.Dissolve, Shapefile.BufferByDistance, Shapefile.Merge, Shapefile.Segmentize, Shapefile.SimplifyLines, Shapefile.Reproject, Shapefile.ReprojectInPlace (input validation only), Shapefile.Save (output validation), Shapefile.SaveAs (output validation), Shapefile.Dump (output validation), Utils.ReprojectShapefile, Utils.GridToShapefile, Utils.TinToShapefile, Utils.OgrLayerToShapefile, Utils.RemoveColinearPoints, Utils.ShapefileToGrid.

Function Documentation

◆ HasInvalidShapes()

bool Shapefile.HasInvalidShapes ( )

Checks whether there are invalid shapes within shapefile.

Returns
True if there invalid shapes and false otherwise.
New API 4.9.0:
Added in version 4.9.0

Properties

◆ LastInputValidation

ShapeValidationInfo Shapefile.LastInputValidation
get

Gets results of input data validation for geoprocessing methods.

Use GlobalSettings.ShapeInputValidationMode to change the settings.

New API 4.9.1:
Added in version 4.9.1

◆ LastOutputValidation

ShapeValidationInfo Shapefile.LastOutputValidation
get

Gets results of output data validation for geoprocessing methods.

Use GlobalSettings.ShapeOutputValidationMode to change the settings.

New API 4.9.1:
Added in version 4.9.1