Plot Geometries
This section defines a rudimentary plot function to give at least
some sort of graphical visualization of geometries.
To do this it makes use of FSharp.Charting's charts to plot the
coordinates of geometries in a cartesian plan. The main limit of the
function is that polygons are rendered as lines instead of full shapes.
1: 2: |
|
The coordinates function just extracts a list of tuples
made of the longitude and latitude of the corrdinates that consistute
the geometry.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: |
|
We need to set the space of the chart at a size that makes the shape visibile enough.
First with env we extract the bounding box of the geometry as an
OGR.Envelope
1: 2: 3: 4: 5: |
|
... then we resize it based on a choosen zoom as a percentage of the
shape size. If the geometry is made of just a point it has not a real size
so in this case we just calculate a margin based on the coordinate's magnitude.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: |
|
To properly draw the shapes in the cartesian space we need to choose a chart type that most fits with the geometry type to plot.
createChart creates a Chart.Point for points geometries while
Chart.Line is choosen for every other geometry types: as marked above
the main limit of this approach is that ploygons are still rendered as
lines but this at least gives an immage of the geometry.
1: 2: 3: 4: 5: 6: 7: |
|
Now we can define a plotAt function that plots the geometry at a specified
zoom.
Geomteries can be simple or compund. If geomis compound we need to recursively
traverse its structure till its simple components and populate a charts
list for each using the createChart function defined above.
The recursive part is made by the createCharts function taking advantage
of the functional nature of F#.
At the end we can Chart.Combine all the elements of the chart list setting the
cartesian plan's space at the proper size.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: |
|
Since normally a zoom at 80% of the shape size is enough to visualize the geometry
we define the final plot function to default at a 80% zoom not to have to specify
it each time:
1: 2: |
|
Finally a function to bypass the lack of a shape chart and fill polygons' areas with lines
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: |
|
namespace FSharp
--------------------
namespace Microsoft.FSharp
Full name: Plot-geometries.coordinates
Extracts the geometry's coordinates as a list of tuples made of
longitude and latitude.
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
--------------------
OGR.Geometry(type: OGR.wkbGeometryType) : unit
OGR.Geometry(cPtr: nativeint, cMemoryOwn: bool, parent: obj) : unit
OGR.Geometry(type: OGR.wkbGeometryType, wkt: string, wkb: int, wkb_buf: nativeint, gml: string) : unit
Full name: Plot-geometries.env
Extracs the bounding box of the geometry
type Envelope =
new : unit -> Envelope + 1 overload
member Dispose : unit -> unit
member MaxX : float with get, set
member MaxY : float with get, set
member MinX : float with get, set
member MinY : float with get, set
static member getCPtr : obj:Envelope -> HandleRef
static member getCPtrAndDisown : obj:Envelope * parent:obj -> HandleRef
static member getCPtrAndSetReference : obj:Envelope * parent:obj -> HandleRef
Full name: OSGeo.OGR.Envelope
--------------------
OGR.Envelope() : unit
OGR.Envelope(cPtr: nativeint, cMemoryOwn: bool, parent: obj) : unit
Full name: Plot-geometries.resize
Resizes the envelope based on a choosen zoom
Full name: Plot-geometries.createChart
Creates a chart for the geometry
| 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
static member Area : data:seq<#value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> GenericChart
static member Area : data:seq<#key * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> GenericChart
static member Bar : data:seq<#value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> GenericChart
static member Bar : data:seq<#key * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> GenericChart
static member BoxPlotFromData : data:seq<#key * #seq<'a2>> * ?Name:string * ?Title:string * ?Color:Color * ?XTitle:string * ?YTitle:string * ?Percentile:int * ?ShowAverage:bool * ?ShowMedian:bool * ?ShowUnusualValues:bool * ?WhiskerPercentile:int -> GenericChart (requires 'a2 :> value)
static member BoxPlotFromStatistics : data:seq<#key * #value * #value * #value * #value * #value * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string * ?Percentile:int * ?ShowAverage:bool * ?ShowMedian:bool * ?ShowUnusualValues:bool * ?WhiskerPercentile:int -> GenericChart
static member Bubble : data:seq<#value * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string * ?BubbleMaxSize:int * ?BubbleMinSize:int * ?BubbleScaleMax:float * ?BubbleScaleMin:float * ?UseSizeForLabel:bool -> GenericChart
static member Bubble : data:seq<#key * #value * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string * ?BubbleMaxSize:int * ?BubbleMinSize:int * ?BubbleScaleMax:float * ?BubbleScaleMin:float * ?UseSizeForLabel:bool -> GenericChart
static member Candlestick : data:seq<#value * #value * #value * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> CandlestickChart
static member Candlestick : data:seq<#key * #value * #value * #value * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:Color * ?XTitle:string * ?YTitle:string -> CandlestickChart
...
Full name: FSharp.Charting.Chart
static member Chart.Point : data:seq<#key * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:System.Drawing.Color * ?XTitle:string * ?YTitle:string * ?MarkerColor:System.Drawing.Color * ?MarkerSize:int -> ChartTypes.GenericChart
static member Chart.Line : data:seq<#value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:System.Drawing.Color * ?XTitle:string * ?YTitle:string -> ChartTypes.GenericChart
static member Chart.Line : data:seq<#key * #value> * ?Name:string * ?Title:string * ?Labels:#seq<string> * ?Color:System.Drawing.Color * ?XTitle:string * ?YTitle:string -> ChartTypes.GenericChart
Full name: Plot-geometries.createCharts
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member GetSlice : startIndex:int option * endIndex:int option -> 'T list
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
Full name: Microsoft.FSharp.Collections.List.concat
Full name: Plot-geometries.plotAt
Plots a geometry at a specified zoom
Full name: Plot-geometries.plot
Plots a geometry at a zoom of 80%
Full name: Plot-geometries.fill
Full name: Microsoft.FSharp.Core.Operators.ignore
