Show / Hide Table of Contents

    Class ShapeFile

    Shapefile dataprovider

    Inheritance
    System.Object
    ShapeFile
    Implements
    IProvider
    IDisposable
    Namespace: Mapsui.Desktop.Shapefile
    Assembly: Mapsui.Desktop.dll
    Syntax
    public class ShapeFile : object, 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.

    Examples

    Adding a datasource to a layer:

    Mapsui.Layers.VectorLayer myLayer = new Mapsui.Layers.VectorLayer("My layer");
    myLayer.DataSource = new Mapsui.Data.Providers.ShapeFile(@"C:\data\MyShapeData.shp");

    Constructors

    | Improve this Doc View Source

    ShapeFile(String, Boolean)

    Initializes a ShapeFile DataProvider.

    Declaration
    public ShapeFile(string filename, bool fileBasedIndex = false)
    Parameters
    Type Name Description
    System.String filename

    Path to shape file

    System.Boolean fileBasedIndex

    Use file-based spatial index

    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

    | Improve this Doc View Source

    CRS

    Gets or sets the spatial reference ID (CRS)

    Declaration
    public string CRS { get; set; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    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 .

    | Improve this Doc View Source

    Filename

    Gets or sets the filename of the shapefile

    Declaration
    public string Filename { get; set; }
    Property Value
    Type Description
    System.String
    Remarks

    If the filename changes, indexes will be rebuilt

    | Improve this Doc View Source

    FilterDelegate

    Filter Delegate Method for limiting the datasource

    Declaration
    public ShapeFile.FilterMethod FilterDelegate { get; set; }
    Property Value
    Type Description
    ShapeFile.FilterMethod
    Remarks
    Using an anonymous method for filtering all features where the NAME column starts with S:
    myShapeDataSource.FilterDelegate = new Mapsui.Data.Providers.ShapeFile.FilterMethod(delegate(Mapsui.Data.FeatureDataRow row) { return (!row["NAME"].ToString().StartsWith("S")); });
    Declaring a delegate method for filtering (multi)polygon-features whose area is larger than 5.
    myShapeDataSource.FilterDelegate = CountryFilter;
    [...]
    public static bool CountryFilter(Mapsui.Data.FeatureDataRow row)
    {
        if(row.Geometry.GetType()==typeof(Mapsui.Geometries.Polygon))
            return ((row.Geometry as Mapsui.Geometries.Polygon).Area>5);
        if (row.Geometry.GetType() == typeof(Mapsui.Geometries.MultiPolygon))
            return ((row.Geometry as Mapsui.Geometries.MultiPolygon).Area > 5);
        else return true;
    }
    See Also
    ShapeFile.FilterMethod
    | Improve this Doc View Source

    ShapeType

    Gets the ShapeType in this shapefile.

    Declaration
    public ShapeType ShapeType { get; }
    Property Value
    Type Description
    ShapeType
    Remarks

    The property isn't set until the first time the datasource 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

    | Improve this Doc View Source

    Dispose()

    Disposes the object

    Declaration
    public void Dispose()
    | Improve this Doc View Source

    Finalize()

    Finalizes the object

    Declaration
    protected void Finalize()
    | Improve this Doc View Source

    GetExtents()

    Returns the extents of the datasource

    Declaration
    public BoundingBox GetExtents()
    Returns
    Type Description
    BoundingBox
    | Improve this Doc View Source

    GetFeature(UInt32, IFeatures)

    Gets a datarow from the datasource at the specified index belonging to the specified datatable

    Declaration
    public IFeature GetFeature(uint rowId, IFeatures feature = null)
    Parameters
    Type Name Description
    System.UInt32 rowId
    IFeatures feature

    Datatable to feature should belong to.

    Returns
    Type Description
    IFeature
    | Improve this Doc View Source

    GetFeatureCount()

    Returns the total number of features in the datasource (without any filter applied)

    Declaration
    public int GetFeatureCount()
    Returns
    Type Description
    System.Int32
    | Improve this Doc View Source

    GetFeaturesInView(BoundingBox, Double)

    Declaration
    public IEnumerable<IFeature> GetFeaturesInView(BoundingBox box, double resolution)
    Parameters
    Type Name Description
    BoundingBox box
    System.Double resolution
    Returns
    Type Description
    IEnumerable<IFeature>
    | Improve this Doc View Source

    GetGeometriesInView(BoundingBox)

    Returns geometries whose bounding box intersects 'bbox'

    Declaration
    public Collection<IGeometry> GetGeometriesInView(BoundingBox bbox)
    Parameters
    Type Name Description
    BoundingBox bbox
    Returns
    Type Description
    Collection<IGeometry>
    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 simplifed by their boundingbox, and using the Spatial Index.

    | Improve this Doc View Source

    GetGeometry(UInt32)

    Returns the geometry corresponding to the Object ID

    Declaration
    public IGeometry GetGeometry(uint oid)
    Parameters
    Type Name Description
    System.UInt32 oid

    Object ID

    Returns
    Type Description
    IGeometry

    geometry

    | Improve this Doc View Source

    GetObjectIDsInView(BoundingBox)

    Returns geometry Object IDs whose bounding box intersects 'bbox'

    Declaration
    public Collection<uint> GetObjectIDsInView(BoundingBox bbox)
    Parameters
    Type Name Description
    BoundingBox bbox
    Returns
    Type Description
    Collection<System.UInt32>
    | Improve this Doc View Source

    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()

    Implements

    IProvider
    IDisposable
    • Improve this Doc
    • View Source
    Back to top Generated by DocFX