Shapefile geoprocessing

Functions

Shapefile Shapefile.AggregateShapes (bool selectedOnly, int fieldIndex)
 Creates a new shapefile by creating multi-part shapes from shapes with the same value of specified attribute. More...
 
Shapefile Shapefile.AggregateShapesWithStats (bool selectedOnly, int fieldIndex=-1, FieldStatOperations statOperations=null)
 Creates a new shapefile by creating multi-part shapes from shapes with the same value of specified attribute. More...
 
Shapefile Shapefile.BufferByDistance (double distance, int nSegments, bool selectedOnly, bool mergeResults)
 Creates a new shapefile by building a buffer around the shapes of the input shapefile. More...
 
void Shapefile.ClearCachedGeometries ()
 Clears GEOS geometries cached during certain geoprocessing tasks. More...
 
Shapefile Shapefile.Clip (bool selectedOnlySubject, Shapefile sfOverlay, bool selectedOnlyOverlay)
 Clips current shapefile by the definition shapefile. More...
 
Shapefile Shapefile.Difference (bool selectedOnlySubject, Shapefile sfOverlay, bool selectedOnlyOverlay)
 Calculates difference of 2 shapefiles. More...
 
Shapefile Shapefile.Dissolve (int fieldIndex, bool selectedOnly)
 Merges shapes of the input shapefile based on specified attribute. More...
 
Shapefile Shapefile.DissolveWithStats (int fieldIndex, bool selectedOnly, FieldStatOperations statOperations=null)
 Merges shapes of the input shapefile based on specified attribute. More...
 
Shapefile Shapefile.ExplodeShapes (bool selectedOnly)
 Creates a new instance of shapefile class with single-part shapes produced from the multi-part shapes of the input shapefile. More...
 
Shapefile Shapefile.ExportSelection ()
 Creates a new instance of the shapefile class and copies selected shapes of the input shapefile to it. More...
 
bool Shapefile.FixUpShapes (out Shapefile retval)
 Creates a new shapefile by fixing invalid shapes of the input shapefile. More...
 
bool Shapefile.GetClosestSnapPosition (double x, double y, double maxDistance, int shapeIndex, ref double foundX, ref double foundY, ref double foundDistance)
 Calculates the closest snap point (taking the snap mode in account) on (the boundary of) a shape. More...
 
Shapefile Shapefile.GetIntersection (bool selectedOnlyOfThis, Shapefile sf, bool selectedOnly, ShpfileType fileType, ICallback cBack)
 Calculates intersection of 2 input shapefiles. More...
 
Shapefile Shapefile.Merge (bool selectedOnlyThis, Shapefile sf, bool selectedOnly)
 Creates a new instance of shapefile class which holds shapes from 2 input shapefiles. More...
 
Shapefile Shapefile.Reproject (GeoProjection newProjection, ref int reprojectedCount)
 Creates a new shapefile by re-projecting the current one. More...
 
bool Shapefile.ReprojectInPlace (GeoProjection newProjection, ref int reprojectedCount)
 Reprojects shapes of the current shapefile. More...
 
Shapefile Shapefile.Segmentize (double metersTolerance=0.0)
 Splits polylines at intersection with any other polylines. Works for polyline shapefile only. More...
 
bool Shapefile.SelectByShapefile (Shapefile sf, tkSpatialRelation relation, bool selectedOnly, ref object result, ICallback cBack)
 aka SpatialQuery. Returns an array with indices of shapes of the current shapefile which are in the specified relation to the definition shapefile. More...
 
Shapefile Shapefile.SimplifyLines (double tolerance, bool selectedOnly)
 Creates a new shapefile by removing excessive vertices from the current shapefile More...
 
Shapefile Shapefile.Sort (int fieldIndex, bool @ascending)
 Sorts shapes in the shapefile based on the specified attribute. More...
 
Shapefile Shapefile.SymmDifference (bool selectedOnlySubject, Shapefile sfOverlay, bool selectedOnlyOverlay)
 Calculates symmetrical difference of the 2 shapefiles. More...
 
Shapefile Shapefile.Union (bool selectedOnlySubject, Shapefile sfOverlay, bool selectedOnlyOverlay)
 Calculates union of 2 shapefiles. More...
 

Properties

tkGeometryEngine Shapefile.GeometryEngine [get, set]
 Gets or sets the engine (library) to use for geoprocessing operations. More...
 

Detailed Description

Here is a list of methods to perform geoprocessing tasks using shapefile data. This module is a part of the documentation of Shapefile class.

Use GlobalSettings.MinAreaToPerimeterRatio and GlobalSettings.MinPolygonArea to tweak which polygon needs to be included in the output file.

dot_inline_dotgraph_28.png

Graph description

Function Documentation

◆ AggregateShapes()

Shapefile Shapefile.AggregateShapes ( bool  selectedOnly,
int  fieldIndex 
)

Creates a new shapefile by creating multi-part shapes from shapes with the same value of specified attribute.

Parameters
selectedOnlyA boolean value which indicates whether all or only selected shapes will be processed.
fieldIndexThe index of field to group shapes by.
Returns
Reference to the shapefile on success or NULL reference on failure.
New API 4.8:
Added in version 4.8

◆ AggregateShapesWithStats()

Shapefile Shapefile.AggregateShapesWithStats ( bool  selectedOnly,
int  fieldIndex = -1,
FieldStatOperations  statOperations = null 
)

Creates a new shapefile by creating multi-part shapes from shapes with the same value of specified attribute.

See sample code in description of Shapefile.DissolveWithStats.

Parameters
selectedOnlyA value which indicates whether all or only selected shapes will be processed.
fieldIndexThe index of field to group shapes by.
statOperationsStatistic group operations to be calculated for fields of input shapefile and written to attribute table of output shapefile.
Returns
Reference to the shapefile on success or NULL reference on failure.
New API 4.9.1:
Added in version 4.9.1

◆ BufferByDistance()

Shapefile Shapefile.BufferByDistance ( double  distance,
int  nSegments,
bool  selectedOnly,
bool  mergeResults 
)

Creates a new shapefile by building a buffer around the shapes of the input shapefile.

Parameters
distanceThe distance to build buffer at.
nSegmentsNumber of segments to approximate a circular buffer.
selectedOnlyA value which indicates whether all only selected shapes of the shapefile will be processed.
mergeResultsA value which indicates whether overlapping buffered shapes will be merged into a single shapes.
Returns
A reference to the output shapefile or NULL reference on failure.
New API 4.8:
Added in version 4.8
Examples
CreateBuffer.cs.

◆ ClearCachedGeometries()

void Shapefile.ClearCachedGeometries ( )

Clears GEOS geometries cached during certain geoprocessing tasks.

Shapefile.GetRelatedShapes currently is the only method that uses such caching to improve performance if search is performed multiple times for different shapes.

New API 4.9.1:
Added in version 4.9.1

◆ Clip()

Shapefile Shapefile.Clip ( bool  selectedOnlySubject,
Shapefile  sfOverlay,
bool  selectedOnlyOverlay 
)

Clips current shapefile by the definition shapefile.

Parameters
selectedOnlySubjectA value which indicates whether all or only selected shape of this shapefile will be treated as input.
sfOverlayThe definition shapefile.
selectedOnlyOverlayA value which indicates whether all or only selected shape of the definition shapefile will be treated as input.
Returns
Reference to the output shapefile or NULL reference on failure.
New API 4.8:
Added in version 4.8

◆ Difference()

Shapefile Shapefile.Difference ( bool  selectedOnlySubject,
Shapefile  sfOverlay,
bool  selectedOnlyOverlay 
)

Calculates difference of 2 shapefiles.

Parameters
selectedOnlySubjectA value which indicates whether all or only selected shape of this shapefile will be treated as input.
sfOverlayThe overlay shapefile.
selectedOnlyOverlayA value which indicates whether all or only selected shape of the overlay shapefile will be treated as input.
Returns
Reference to the output shapefile or NULL reference on failure.
New API 4.8:
Added in version 4.8
Examples
CreateBuffer.cs.

◆ Dissolve()

Shapefile Shapefile.Dissolve ( int  fieldIndex,
bool  selectedOnly 
)

Merges shapes of the input shapefile based on specified attribute.

All shapes with the same value of the attribute will be merged in a single shape. If the shapes aren't adjacent, then multi-part shape will be created.

Parameters
fieldIndexAn index of field from attribute table of the shapefile to dissolve by.
selectedOnlyA boolean value which indicates whether all or only selected shapes will be processed.
Returns
Reference to the output shapefile or NULL reference on failure.
New API 4.8:
Added in version 4.8

◆ DissolveWithStats()

Shapefile Shapefile.DissolveWithStats ( int  fieldIndex,
bool  selectedOnly,
FieldStatOperations  statOperations = null 
)

Merges shapes of the input shapefile based on specified attribute.

All shapes with the same value of the attribute will be merged in a single shape. If the shapes aren't adjacent, then multi-part shape will be created.

const string filename = @"d:\counties.shp";
var sf = new Shapefile();
if (!sf.Open(filename, null))
{
MessageBox.Show("Failed to open shapefile");
}
else
{
const int stateNameFieldIndex = 1;
var operations = new FieldStatOperations();
operations.AddFieldName("SUB_REGION", tkFieldStatOperation.fsoMin);
operations.AddFieldName("sub_region", tkFieldStatOperation.fsoMax); // casing doesn't matter
operations.AddFieldName("pop1990", tkFieldStatOperation.fsoSum);
operations.AddFieldName("pop1990", tkFieldStatOperation.fsoAvg);
operations.AddFieldName("pop1990", tkFieldStatOperation.fsoWeightedAvg);
var result = sf.DissolveWithStats(stateNameFieldIndex, false, operations);
axMap1.RemoveAllLayers();
axMap1.AddLayer(result, true);
result.SaveAs(@"d:\dissolve_result.shp");
}
tkFieldStatOperation
Possible statistic operations for a field during grouping of shapes.
Definition: Enumerations.cs:1866
Defines group statistic operations for columns of shapefile attribute table.
Definition: FieldStatOperations.cs:49
Provides a functionality for accessing and editing ESRI shapefiles.
Definition: Shapefile.cs:72
Parameters
fieldIndexAn index of field from attribute table of the shapefile to dissolve by.
selectedOnlyA boolean value which indicates whether all or only selected shapes will be processed.
statOperationsStatistic group operations to be calculated for fields of input shapefile and written to attribute table of output shapefile.
Returns
Reference to the output shapefile or NULL reference on failure.
New API 4.9.1:
Added in version 4.9.1

◆ ExplodeShapes()

Shapefile Shapefile.ExplodeShapes ( bool  selectedOnly)

Creates a new instance of shapefile class with single-part shapes produced from the multi-part shapes of the input shapefile.

Single-part input shapes are moved to the output shapefile without changes. Attribute values are copied to the output shapefile without changes.

Parameters
selectedOnlyA value which indicates whether the operation will be applied to the selected shapes only.
Returns
A new instance of Shapefile class with resultant shapes or NULL reference on failure.
New API 4.8:
Added in version 4.8

◆ ExportSelection()

Shapefile Shapefile.ExportSelection ( )

Creates a new instance of the shapefile class and copies selected shapes of the input shapefile to it.

Returns
A new instance of shapefile class with selected shapes or NULL reference on failure.
New API 4.8:
Added in version 4.8

◆ FixUpShapes()

bool Shapefile.FixUpShapes ( out Shapefile  retval)

Creates a new shapefile by fixing invalid shapes of the input shapefile.

Parameters
retvalThe output shapefile.
Returns
True on successful fixing of all shapes and false if at least one shapes wasn't fixed.
New API 4.8:
Added in version 4.8

◆ GetClosestSnapPosition()

bool Shapefile.GetClosestSnapPosition ( double  x,
double  y,
double  maxDistance,
int  shapeIndex,
ref double  foundX,
ref double  foundY,
ref double  foundDistance 
)

Calculates the closest snap point (taking the snap mode in account) on (the boundary of) a shape.

Parameters
xinput x coordinate
yinput y coordinate
maxDistancemaximum distance beyond which no more snapping is performed
shapeIndexthe shape index to get a snap point for
foundXthe X coordinate of the snap point
foundYthe Y coordinate of the snap point
foundDistancethe distance of the snap point to the input coordinates
Returns
True if a snap point was found, false if not

◆ GetIntersection()

Shapefile Shapefile.GetIntersection ( bool  selectedOnlyOfThis,
Shapefile  sf,
bool  selectedOnly,
ShpfileType  fileType,
ICallback  cBack 
)

Calculates intersection of 2 input shapefiles.

Intersection can generate shapes of different types. For example, the intersection of 2 polygons can be a polygon, a polyline, a point or any combination of those. With SHP_NULLSHAPE fileType parameter the most obvious type will be used: for example SHP_POLYGON for 2 polygon shapefiles.

Parameters
selectedOnlyOfThisA value which indicates whether operation will be applied to the selected shapes of the current shapefile only.
sfThe second shapefile to perfrom intersection.
selectedOnlyA value which indicates whether operation will be applied to the selected shapes of the second shapefile only.
fileTypeThe type of output shapefiles. SHP_NULLSHAPE value should be passed for automatic choosing of type.
cBackAn instance of class implementing ICallback interface.
Returns
Reference to the output shapefile or NULL reference on failure.
New API 4.8:
Added in version 4.8

◆ Merge()

Shapefile Shapefile.Merge ( bool  selectedOnlyThis,
Shapefile  sf,
bool  selectedOnly 
)

Creates a new instance of shapefile class which holds shapes from 2 input shapefiles.

Both shapefiles must have the same ShpfileType. No changes to geometry of individual shapes are made. Attribute values of both input shapefile will be passed to the resulting one.

Parameters
selectedOnlyThisThe value which indicates whether the operation will be applied only to the selected shapes of the first shapefile.
sfThe second shapefile to take shapes from.
selectedOnlyA value which Indicates whether the operation will be applied only to the selected shapes of the second shapefile
Returns
Reference to the output shapefile or NULL reference on failure
New API 4.8:
Added in version 4.8

◆ Reproject()

Shapefile Shapefile.Reproject ( GeoProjection  newProjection,
ref int  reprojectedCount 
)

Creates a new shapefile by re-projecting the current one.

Parameters
newProjectionThe projection of the output shapefile.
reprojectedCountThe output value with the number of shapes successfully reprojected.
Returns
Reference to the output shapefile or NULL reference on failure.
New API 4.8:
Added in version 4.8

◆ ReprojectInPlace()

bool Shapefile.ReprojectInPlace ( GeoProjection  newProjection,
ref int  reprojectedCount 
)

Reprojects shapes of the current shapefile.

Parameters
newProjectionThe new projection.
reprojectedCountThe number of shapes successfully reprojected.
Returns
Returns true on success and false otherwise.
New API 4.8:
Added in version 4.8

◆ Segmentize()

Shapefile Shapefile.Segmentize ( double  metersTolerance = 0.0)

Splits polylines at intersection with any other polylines. Works for polyline shapefile only.

Parameters
metersTolerancePolyline endpoints within this tolerance will be 'snapped' to adjacent polylines.
Returns
Resulting shapefile or null if the operation wasn't successful.
New API 4.9.0:
Added in version 4.9.0

◆ SelectByShapefile()

bool Shapefile.SelectByShapefile ( Shapefile  sf,
tkSpatialRelation  relation,
bool  selectedOnly,
ref object  result,
ICallback  cBack 
)

aka SpatialQuery. Returns an array with indices of shapes of the current shapefile which are in the specified relation to the definition shapefile.

Parameters
sfThe definition shapefile.
relationThe target relation between shapes of the 2 shapefiles.
selectedOnlyThe value which indicates whether only selected shapes of the definition shapefile will be used.
resultThe resulting array of long data type with shape indices.
cBackA callback object for passing to the client the information about the progress and errors.
Returns
True in case at least one shape was selected and false otherwise.
New API 4.8:
Added in version 4.8

◆ SimplifyLines()

Shapefile Shapefile.SimplifyLines ( double  tolerance,
bool  selectedOnly 
)

Creates a new shapefile by removing excessive vertices from the current shapefile

Applicable to the polyline or polygon shapefiles only. The initial shapefile remains intact. Attribute values are copied to the output shapefile without changes.

Parameters
toleranceThe minimal distance between 2 succeeding points. A succeeding point lying closer than this value, will be removed.
selectedOnlyA value which indicates whether all or only selected shapes will be processed.
Returns
A reference to the output shapefile or NULL reference on failure.
New API 4.8:
Added in version 4.8

◆ Sort()

Shapefile Shapefile.Sort ( int  fieldIndex,
bool @  ascending 
)

Sorts shapes in the shapefile based on the specified attribute.

Parameters
fieldIndexThe index of field to set the sorting order.
ascendingA value which defines the sorting order.
Returns
Reference to the output shapefile or NULL reference on failure.
New API 4.8:
Added in version 4.8

◆ SymmDifference()

Shapefile Shapefile.SymmDifference ( bool  selectedOnlySubject,
Shapefile  sfOverlay,
bool  selectedOnlyOverlay 
)

Calculates symmetrical difference of the 2 shapefiles.

The operation consists of 2 mirror-like Difference operations. Attribute values of both shapefiles are passed to the output one without changes. Both input shapefiles remain intact.

Parameters
selectedOnlySubjectA value which indicates that only selected shapes of the first shapefile will be processed.
sfOverlayThe second shapefile.
selectedOnlyOverlayA value which indicates that only selected shapes of the second shapefile will be processed.
Returns
A reference to the output shapefile or NULL reference on failure.
New API 4.8:
Added in version 4.8

◆ Union()

Shapefile Shapefile.Union ( bool  selectedOnlySubject,
Shapefile  sfOverlay,
bool  selectedOnlyOverlay 
)

Calculates union of 2 shapefiles.

The operation consists of intersection operation and 2 mirror-like difference operations.

Parameters
selectedOnlySubjectThe value which indicates that only selected shapes of the first shapefile will be processed.
sfOverlayThe second shapefile.
selectedOnlyOverlayThe value which indicates that only selected shapes of the second shapefile will be processed.
Returns
A reference to the output shapefile or NULL reference on failure.
New API 4.8:
Added in version 4.8

Properties

◆ GeometryEngine

tkGeometryEngine Shapefile.GeometryEngine
getset

Gets or sets the engine (library) to use for geoprocessing operations.

The following methods are affected by this property.

New API 4.8:
Added in version 4.8