Class ShapeFile
Shapefile data provider
Inherited Members
Namespace: Mapsui.Nts.Providers.Shapefile
Assembly: Mapsui.Nts.dll
Syntax
public class ShapeFile : IProvider, IDisposable
Remarks
The ShapeFile provider is used for accessing ESRI ShapeFiles. The ShapeFile should at least contain the [filename].shp, [filename].idx, and if feature-data is to be used, also [filename].dbf file.
The first time the ShapeFile is accessed, Mapsui will automatically create a spatial index of the shp-file, and save it as [filename].shp.sidx. If you change or update the contents of the .shp file, delete the .sidx file to force Mapsui to rebuilt it. In web applications, the index will automatically be cached to memory for faster access, so to reload the index, you will need to restart the web application as well.
M and Z values in a shapefile is ignored by Mapsui.
Constructors
| Edit this page View SourceShapeFile(string, bool, bool, IProjectionCrs?)
Initializes a ShapeFile DataProvider.
Declaration
public ShapeFile(string filename, bool fileBasedIndex = false, bool readPrjFile = false, IProjectionCrs? projectionCrs = null)
Parameters
Type | Name | Description |
---|---|---|
string | filename | Path to shape file |
bool | fileBasedIndex | Use file-based spatial index |
bool | readPrjFile | Read the proj File and set the correct CRS |
IProjectionCrs | projectionCrs | Projection Crs |
Remarks
If FileBasedIndex is true, the spatial index will be read from a local copy. If it doesn't exist, it will be generated and saved to [filename] + '.sidx'.
Using a file-based index is especially recommended for ASP.NET applications which will speed up start-up time when the cache has been emptied.
Properties
| Edit this page View SourceCRS
Gets or sets the spatial reference ID (CRS)
Declaration
public string? CRS { get; set; }
Property Value
Type | Description |
---|---|
string |
Encoding
Gets or sets the encoding used for parsing strings from the DBase DBF file.
Declaration
public Encoding? Encoding { get; set; }
Property Value
Type | Description |
---|---|
Encoding |
Remarks
The DBase default encoding is UTF7"/>.
Filename
Gets or sets the filename of the shapefile
Declaration
public string Filename { get; set; }
Property Value
Type | Description |
---|---|
string |
Remarks
If the filename changes, indexes will be rebuilt
FilterDelegate
Filter Delegate Method for limiting the data source
Declaration
public ShapeFile.FilterMethod? FilterDelegate { get; set; }
Property Value
Type | Description |
---|---|
ShapeFile.FilterMethod |
ShapeType
Gets the shape geometry type in this shapefile.
Declaration
public ShapeType ShapeType { get; }
Property Value
Type | Description |
---|---|
ShapeType |
Remarks
The property isn't set until the first time the data source has been opened, and will throw an exception if this property has been called since initialization.
All the non-Null shapes in a shapefile are required to be of the same shape type.
Methods
| Edit this page View SourceDispose()
Disposes the object
Declaration
public void Dispose()
~ShapeFile()
Finalizes the object
Declaration
protected ~ShapeFile()
GetExtent()
Returns the extent of the data source
Declaration
public MRect? GetExtent()
Returns
Type | Description |
---|---|
MRect |
GetFeature(uint, List<GeometryFeature>?)
Gets a data row from the data source at the specified index belonging to the specified datatable
Declaration
public GeometryFeature? GetFeature(uint rowId, List<GeometryFeature>? features = null)
Parameters
Type | Name | Description |
---|---|---|
uint | rowId | |
List<GeometryFeature> | features | Data table to feature should belong to. |
Returns
Type | Description |
---|---|
GeometryFeature |
GetFeatureCount()
Returns the total number of features in the data source (without any filter applied)
Declaration
public int GetFeatureCount()
Returns
Type | Description |
---|---|
int |
GetFeaturesAsync(FetchInfo)
Declaration
public Task<IEnumerable<IFeature>> GetFeaturesAsync(FetchInfo fetchInfo)
Parameters
Type | Name | Description |
---|---|---|
FetchInfo | fetchInfo |
Returns
Type | Description |
---|---|
Task<IEnumerable<IFeature>> |
GetGeometriesInView(MRect)
Returns geometries whose bounding box intersects 'bbox'
Declaration
public Collection<Geometry> GetGeometriesInView(MRect bbox)
Parameters
Type | Name | Description |
---|---|---|
MRect | bbox |
Returns
Type | Description |
---|---|
Collection<Geometry> |
Remarks
Please note that this method doesn't guarantee that the geometries returned actually intersect 'bbox', but only that their BoundingBox intersects 'bbox'.
This method is much faster than the QueryFeatures method, because intersection tests are performed on objects simplified by their BoundingBox, and using the Spatial Index.
GetGeometry(uint)
Returns the geometry corresponding to the Object ID
Declaration
public Geometry? GetGeometry(uint oid)
Parameters
Type | Name | Description |
---|---|---|
uint | oid | Object ID |
Returns
Type | Description |
---|---|
Geometry | geometry |
GetObjectIDsInView(MRect)
Returns geometry Object IDs whose bounding box intersects 'bbox'
Declaration
public Collection<uint> GetObjectIDsInView(MRect bbox)
Parameters
Type | Name | Description |
---|---|---|
MRect | bbox |
Returns
Type | Description |
---|---|
Collection<uint> |
RebuildSpatialIndex()
Forces a rebuild of the spatial index. If the instance of the ShapeFile provider uses a file-based index the file is rewritten to disk.
Declaration
public void RebuildSpatialIndex()