Gdal type provider
This is a starting point in developing a type provider for geospatial data files managed with the gdal library
1: 2: 3: 4: 5: 6: 7: 8: 9: |
|
The shape file itinerari.shp
contains the foot paths to the main peaks in the
Val Grande National Park.
To get the data from a file we can just call the type provider constructor giving the file path as the type parameter of the provider. Internally the provider calls the logic needed to configure the gdal library on the system and to initialize all the gdal data providers:
1:
|
|
The type provider provides two properties:
Values
which we can convert directly
to a deedle frame to explore immediately the data in the vector:
1:
|
|
ID |
CODE |
SUBCODE |
... |
DESCEND |
DISLIVELLO |
Geometry |
|
---|---|---|---|---|---|---|---|
0 |
1 |
1 |
... |
285 |
1180 |
OSGeo.OGR.Geometry |
|
1 |
4 |
4 |
... |
728 |
1556 |
OSGeo.OGR.Geometry |
|
2 |
2 |
2 |
b |
... |
1717 |
0 |
OSGeo.OGR.Geometry |
3 |
3 |
3 |
... |
526 |
619 |
OSGeo.OGR.Geometry |
|
4 |
5 |
5 |
... |
319 |
1376 |
OSGeo.OGR.Geometry |
|
5 |
6 |
6 |
... |
480 |
1543 |
OSGeo.OGR.Geometry |
|
6 |
12 |
12 |
... |
836 |
847 |
OSGeo.OGR.Geometry |
|
7 |
7 |
7 |
... |
441 |
1796 |
OSGeo.OGR.Geometry |
|
... |
... |
... |
... |
... |
... |
... |
... |
14 |
15 |
15 |
... |
311 |
1093 |
OSGeo.OGR.Geometry |
|
15 |
16 |
16 |
b |
... |
639 |
1482 |
OSGeo.OGR.Geometry |
16 |
17 |
17 |
a |
... |
610 |
1157 |
OSGeo.OGR.Geometry |
17 |
17 |
17 |
b |
... |
1010 |
1331 |
OSGeo.OGR.Geometry |
and Features
which we can iterate to get, for each feature, attributes and geometry
converted in dinamically created types that match the type of geometry and attributes
and come up directly with the intellisense in the iteractive editor:
1: 2: 3: |
|
|
We can also graphically visualize the features geometries using the plot
function
which is described in the Plot Geometries appendix:
1: 2: 3: 4: 5: 6: 7: |
|
With the deedle frame and gdal methods at hand we can do some calculations based on geometries. The data file contains hiking paths in the Big Valley and we can for example get the lenght of each with the gdal library methods and use the deedle functions to aggregate them.
1: 2: 3: 4: 5: 6: |
|
ID |
CODE |
SUBCODE |
... |
DISLIVELLO |
Geometry |
Length |
|
---|---|---|---|---|---|---|---|
0 |
1 |
1 |
... |
1180 |
OSGeo.OGR.Geometry |
5417 |
|
1 |
4 |
4 |
... |
1556 |
OSGeo.OGR.Geometry |
9408 |
|
2 |
2 |
2 |
b |
... |
0 |
OSGeo.OGR.Geometry |
1,087E+04 |
3 |
3 |
3 |
... |
619 |
OSGeo.OGR.Geometry |
4960 |
|
4 |
5 |
5 |
... |
1376 |
OSGeo.OGR.Geometry |
5198 |
|
5 |
6 |
6 |
... |
1543 |
OSGeo.OGR.Geometry |
7861 |
|
6 |
12 |
12 |
... |
847 |
OSGeo.OGR.Geometry |
8060 |
|
7 |
7 |
7 |
... |
1796 |
OSGeo.OGR.Geometry |
7393 |
|
... |
... |
... |
... |
... |
... |
... |
... |
14 |
15 |
15 |
... |
1093 |
OSGeo.OGR.Geometry |
6286 |
|
15 |
16 |
16 |
b |
... |
1482 |
OSGeo.OGR.Geometry |
9070 |
16 |
17 |
17 |
a |
... |
1157 |
OSGeo.OGR.Geometry |
8288 |
17 |
17 |
17 |
b |
... |
1331 |
OSGeo.OGR.Geometry |
9117 |
And just to do an aggregation:
1: 2: 3: |
|
|
namespace FSharp
--------------------
namespace Microsoft.FSharp
namespace FSharp.Data
--------------------
namespace Microsoft.FSharp.Data
Full name: Gdal-type-provider.vLayer
Full name: FSharp.Gdal.OgrTypeProvider
Full name: Gdal-type-provider.fmData
module Frame
from Deedle
--------------------
type Frame =
static member ReadReader : reader:IDataReader -> Frame<int,string>
static member CustomExpanders : Dictionary<Type,Func<obj,seq<string * Type * obj>>>
static member NonExpandableInterfaces : List<Type>
static member NonExpandableTypes : HashSet<Type>
Full name: Deedle.Frame
--------------------
type Frame<'TRowKey,'TColumnKey (requires equality and equality)> =
interface IDynamicMetaObjectProvider
interface INotifyCollectionChanged
interface IFsiFormattable
interface IFrame
new : names:seq<'TColumnKey> * columns:seq<ISeries<'TRowKey>> -> Frame<'TRowKey,'TColumnKey>
new : rowIndex:IIndex<'TRowKey> * columnIndex:IIndex<'TColumnKey> * data:IVector<IVector> * indexBuilder:IIndexBuilder * vectorBuilder:IVectorBuilder -> Frame<'TRowKey,'TColumnKey>
member AddColumn : column:'TColumnKey * series:ISeries<'TRowKey> -> unit
member AddColumn : column:'TColumnKey * series:seq<'V> -> unit
member AddColumn : column:'TColumnKey * series:ISeries<'TRowKey> * lookup:Lookup -> unit
member AddColumn : column:'TColumnKey * series:seq<'V> * lookup:Lookup -> unit
...
Full name: Deedle.Frame<_,_>
--------------------
new : names:seq<'TColumnKey> * columns:seq<ISeries<'TRowKey>> -> Frame<'TRowKey,'TColumnKey>
new : rowIndex:Indices.IIndex<'TRowKey> * columnIndex:Indices.IIndex<'TColumnKey> * data:IVector<IVector> * indexBuilder:Indices.IIndexBuilder * vectorBuilder:Vectors.IVectorBuilder -> Frame<'TRowKey,'TColumnKey>
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Full name: Gdal-type-provider.footPaths
type Geometry =
new : type:wkbGeometryType -> Geometry + 2 overloads
member AddGeometry : other:Geometry -> int
member AddGeometryDirectly : other_disown:Geometry -> int
member AddPoint : x:float * y:float * z:float -> unit
member AddPoint_2D : x:float * y:float -> unit
member Area : unit -> float
member AssignSpatialReference : reference:SpatialReference -> unit
member Boundary : unit -> Geometry
member Buffer : distance:float * quadsecs:int -> Geometry
member Centroid : unit -> Geometry
...
Full name: OSGeo.OGR.Geometry
--------------------
Geometry(type: wkbGeometryType) : unit
Geometry(cPtr: nativeint, cMemoryOwn: bool, parent: obj) : unit
Geometry(type: wkbGeometryType, wkt: string, wkb: int, wkb_buf: nativeint, gml: string) : unit
| wkbUnknown = 0
| wkbPoint = 1
| wkbLineString = 2
| wkbPolygon = 3
| wkbMultiPoint = 4
| wkbMultiLineString = 5
| wkbMultiPolygon = 6
| wkbGeometryCollection = 7
| wkbNone = 100
| wkbLinearRing = 101
...
Full name: OSGeo.OGR.wkbGeometryType
Full name: Plot-geometries.plot
Plots a geometry at a zoom of 80%
Full name: Gdal-type-provider.fmLengths
from Microsoft.FSharp.Collections
Full name: Microsoft.FSharp.Collections.Seq.mapi
Full name: Gdal-type-provider.fmWithLengths
member Frame.Join : colKey:'TColumnKey * series:Series<'TRowKey,'V> -> Frame<'TRowKey,'TColumnKey>
member Frame.Join : otherFrame:Frame<'TRowKey,'TColumnKey> * kind:JoinKind -> Frame<'TRowKey,'TColumnKey>
member Frame.Join : colKey:'TColumnKey * series:Series<'TRowKey,'V> * kind:JoinKind -> Frame<'TRowKey,'TColumnKey>
member Frame.Join : otherFrame:Frame<'TRowKey,'TColumnKey> * kind:JoinKind * lookup:Lookup -> Frame<'TRowKey,'TColumnKey>
member Frame.Join : colKey:'TColumnKey * series:Series<'TRowKey,'V> * kind:JoinKind * lookup:Lookup -> Frame<'TRowKey,'TColumnKey>
Full name: Gdal-type-provider.sumLenghts
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printf