DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SpatialFunctionProvider.cs
Go to the documentation of this file.
1 using System;
2 
3 using Deveel.Data;
4 using Deveel.Data.Routines;
5 using Deveel.Data.Sql;
6 using Deveel.Data.Sql.Fluid;
7 using Deveel.Data.Types;
8 
9 namespace Deveel.Data.Spatial {
10  public sealed class SpatialFunctionProvider : FunctionProvider {
11  public override string SchemaName {
12  get { return SystemSchema.Name; }
13  }
14 
15  protected override ObjectName NormalizeName(ObjectName functionName) {
16  if (functionName.Parent == null)
17  functionName = new ObjectName(new ObjectName(SchemaName), functionName.Name);
18 
19  return base.NormalizeName(functionName);
20  }
21 
22  private static InvokeResult Simple(InvokeContext context, Func<DataObject[], DataObject> func) {
23  var args = context.EvaluatedArguments;
24  var funcResult = func(args);
25  return context.Result(funcResult);
26  }
27 
28  protected override void OnInit() {
29  Register(config => config.Named("from_wkb")
30  .WithParameter(p => p.Named("source").OfType(PrimitiveTypes.Binary()))
31  .WhenExecute(context => Simple(context, args => SpatialSystemFunctions.FromWkb(args[0])))
32  .ReturnsType(SpatialType.Geometry()));
33 
34  Register(config => config.Named("from_wkt")
35  .WithParameter(p => p.Named("source").OfType(PrimitiveTypes.String()))
36  .WhenExecute(context => Simple(context, args => SpatialSystemFunctions.FromWkt(context.Request, args[0])))
37  .ReturnsType(SpatialType.Geometry()));
38 
39  Register(config => config.Named("to_wkt")
40  .WithParameter(p => p.Named("g").OfType(SpatialType.Geometry()))
41  .WhenExecute(context => Simple(context, args => SpatialSystemFunctions.ToWkt(args[0])))
42  .ReturnsString());
43 
44  Register(config => config.Named("to_wkb")
45  .WithParameter(p => p.Named("g").OfType(SpatialType.Geometry()))
46  .WhenExecute(context => Simple(context, args => SpatialSystemFunctions.ToWkb(args[0])))
47  .ReturnsBinary());
48 
49  Register(config => config.Named("envelope")
50  .WithParameter(p => p.Named("g").OfType(SpatialType.Geometry()))
51  .WhenExecute(context => Simple(context, args => SpatialSystemFunctions.Envelope(args[0])))
52  .ReturnsType(SpatialType.Geometry()));
53 
54  Register(config => config.Named("distance")
55  .WithParameter(p => p.Named("g1").OfType(SpatialType.Geometry()))
56  .WithParameter(p => p.Named("g2").OfType(SpatialType.Geometry()))
57  .WhenExecute(context => Simple(context, args => SpatialSystemFunctions.Distance(args[0], args[1])))
58  .ReturnsNumeric());
59 
60  Register(config => config.Named("contains")
61  .WithSpatialParameter("g1")
62  .WithSpatialParameter("g2")
63  .WhenExecute(context => Simple(context, args => SpatialSystemFunctions.Contains(args[0], args[1])))
64  .ReturnsBoolean());
65 
66  Register(config => config.Named("area")
67  .WithSpatialParameter("g")
68  .WhenExecute(context => Simple(context, args => SpatialSystemFunctions.Area(args[0])))
69  .ReturnsSpatialType());
70 
71  Register(config => config.Named("boundary")
72  .WithSpatialParameter("g")
73  .WhenExecute(context => Simple(context, args => SpatialSystemFunctions.Boundary(args[0])))
74  .ReturnsSpatialType());
75 
76 
77  // TODO: Implement the functions
78  }
79  }
80 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static DataObject FromWkt(IRequest context, DataObject source)
static SqlGeometry FromWkb(SqlBinary source)
static SpatialType Geometry(int srid)
Definition: SpatialType.cs:31
static InvokeResult Simple(InvokeContext context, Func< DataObject[], DataObject > func)
static DataObject ToWkb(DataObject geometry)
static BinaryType Binary(int maxSize)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static DataObject Envelope(DataObject geometry)
Represents the result of the execution of a routine.
Definition: InvokeResult.cs:25
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
static DataObject Boundary(DataObject geometry)
Provides utilities and properties for handling the SYSTEN schema of a database.
Definition: SystemSchema.cs:37
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
static DataObject Distance(DataObject geometry, DataObject other)
InvokeResult Result(DataObject value)
string Name
Gets the name of the object being referenced.
Definition: ObjectName.cs:108
static SqlBoolean Contains(SqlGeometry geometry, SqlGeometry other)
static DataObject Area(DataObject geometry)
const string Name
The name of the system schema that contains tables referring to system information.
static SqlString ToWkt(SqlGeometry geometry)
override ObjectName NormalizeName(ObjectName functionName)