/// <summary> /// Gets the spatial analysis string. /// </summary> /// <param name="geometry">The geometry.</param> /// <param name="analysis">The analysis.</param> /// <param name="extraArgument">The extra argument.</param> /// <returns></returns> public virtual SqlString GetSpatialAnalysisString(object geometry, SpatialAnalysis analysis, object extraArgument) { switch (analysis) { case SpatialAnalysis.ConvexHull: return(new SqlStringBuilder() .AddObject(geometry) .Add(".STConvexHull()") .ToSqlString()); case SpatialAnalysis.Distance: case SpatialAnalysis.Buffer: case SpatialAnalysis.Difference: case SpatialAnalysis.Intersection: case SpatialAnalysis.SymDifference: case SpatialAnalysis.Union: if (analysis == SpatialAnalysis.Buffer && !(extraArgument is Parameter || new SqlString(Parameter.Placeholder).Equals(extraArgument))) { extraArgument = Convert.ToString(extraArgument, NumberFormatInfo.InvariantInfo); } return(new SqlStringBuilder() .AddObject(geometry) .Add(".ST") .Add(analysis.ToString()) .Add("(") .AddObject(extraArgument) .Add(")") .ToSqlString()); default: throw new ArgumentException("Invalid spatial analysis argument"); } }
/// <summary> /// Gets the spatial analysis string. /// </summary> /// <param name="geometry">The geometry.</param> /// <param name="analysis">The analysis.</param> /// <param name="extraArgument">The extra argument.</param> /// <returns></returns> public SqlString GetSpatialAnalysisString(object geometry, SpatialAnalysis analysis, object extraArgument) { switch (analysis) { case SpatialAnalysis.Buffer: if (!(extraArgument is Parameter || SqlString.Parameter.Equals(extraArgument))) { extraArgument = Convert.ToString(extraArgument, System.Globalization.NumberFormatInfo.InvariantInfo); } return(new SqlStringBuilder() .Add(DialectPrefix) .Add("Buffer(") .AddObject(geometry) .Add(", ") .AddObject(extraArgument) .Add(")") .ToSqlString()); case SpatialAnalysis.ConvexHull: return(new SqlStringBuilder() .Add(DialectPrefix) .Add("ConvexHull(") .AddObject(geometry) .Add(")") .ToSqlString()); case SpatialAnalysis.Difference: case SpatialAnalysis.Distance: case SpatialAnalysis.Intersection: case SpatialAnalysis.SymDifference: return(new SqlStringBuilder() .Add(DialectPrefix) .Add(analysis.ToString()) .Add("(") .AddObject(geometry) .Add(",") .AddObject(extraArgument) .Add(")") .ToSqlString()); case SpatialAnalysis.Union: return(new SqlStringBuilder() .Add(DialectPrefix) .Add("GeomUnion(") .AddObject(geometry) .Add(",") .AddObject(extraArgument) .Add(")") .ToSqlString()); default: throw new ArgumentException("Invalid spatial analysis argument"); } }
/// <summary> /// Initializes a new instance of the <see cref="SpatialAnalysisFunction"/> class. /// </summary> /// <param name="spatialDialect">The spatial dialect.</param> /// <param name="analysis">The analysis.</param> public SpatialAnalysisFunction(ISpatialDialect spatialDialect, SpatialAnalysis analysis) : base(analysis.ToString(), (analysis == SpatialAnalysis.Distance ? NHibernateUtil.Double : spatialDialect.GeometryType)) { this.spatialDialect = spatialDialect; this.analysis = analysis; if (this.analysis == SpatialAnalysis.ConvexHull) { this.allowedArgsCount = 1; } else { this.allowedArgsCount = 2; } }
/// <summary> /// Initializes a new instance of the <see cref="SpatialAnalysisFunction"/> class. /// </summary> /// <param name="spatialDialect">The spatial dialect.</param> /// <param name="analysis">The analysis.</param> public SpatialAnalysisFunction(ISpatialDialect spatialDialect, SpatialAnalysis analysis) : base(analysis.ToString(), (analysis == SpatialAnalysis.Distance ? NHibernateUtil.Double : spatialDialect.GeometryType) ) { this.spatialDialect = spatialDialect; this.analysis = analysis; if (this.analysis == SpatialAnalysis.ConvexHull) { this.allowedArgsCount = 1; } else { this.allowedArgsCount = 2; } }
private void RegisterSpatialFunction(SpatialAnalysis analysis) { RegisterFunction(SpatialDialect.HqlPrefix + analysis.ToString(), new SpatialAnalysisFunction(this, analysis)); }
/// <summary> /// Gets the spatial analysis string. /// </summary> /// <param name="geometry">The geometry.</param> /// <param name="analysis">The analysis.</param> /// <param name="extraArgument">The extra argument.</param> /// <returns></returns> public SqlString GetSpatialAnalysisString(object geometry, SpatialAnalysis analysis, object extraArgument) { switch (analysis) { case SpatialAnalysis.Buffer: if (!(extraArgument is Parameter || SqlString.Parameter.Equals(extraArgument))) { extraArgument = Convert.ToString(extraArgument, System.Globalization.NumberFormatInfo.InvariantInfo); } return new SqlStringBuilder() .Add(DialectPrefix) .Add("Buffer(") .AddObject(geometry) .Add(", ") .AddObject(extraArgument) .Add(")") .ToSqlString(); case SpatialAnalysis.ConvexHull: return new SqlStringBuilder() .Add(DialectPrefix) .Add("ConvexHull(") .AddObject(geometry) .Add(")") .ToSqlString(); case SpatialAnalysis.Difference: case SpatialAnalysis.Distance: case SpatialAnalysis.Intersection: case SpatialAnalysis.SymDifference: return new SqlStringBuilder() .Add(DialectPrefix) .Add(analysis.ToString()) .Add("(") .AddObject(geometry) .Add(",") .AddObject(extraArgument) .Add(")") .ToSqlString(); case SpatialAnalysis.Union: return new SqlStringBuilder() .Add(DialectPrefix) .Add("GeomUnion(") .AddObject(geometry) .Add(",") .AddObject(extraArgument) .Add(")") .ToSqlString(); default: throw new ArgumentException("Invalid spatial analysis argument"); } }
public void RegisterSpatialFunction(SpatialAnalysis analysis) { adaptor.RegisterFunction(SpatialDialect.HqlPrefix + analysis.ToString(), new SpatialAnalysisFunction(this, analysis)); }
/// <summary> /// Gets the spatial analysis string. /// </summary> /// <param name="geometry">The geometry.</param> /// <param name="analysis">The analysis.</param> /// <param name="extraArgument">The extra argument.</param> /// <returns></returns> public SqlString GetSpatialAnalysisString(object geometry, SpatialAnalysis analysis, object extraArgument) { switch (analysis) { case SpatialAnalysis.ConvexHull: return new SqlStringBuilder() .AddObject(geometry) .Add(".STConvexHull()") .ToSqlString(); case SpatialAnalysis.Buffer: case SpatialAnalysis.Difference: case SpatialAnalysis.Distance: case SpatialAnalysis.Intersection: case SpatialAnalysis.SymDifference: case SpatialAnalysis.Union: if (analysis == SpatialAnalysis.Buffer && !(extraArgument is Parameter || new SqlString(Parameter.Placeholder).Equals(extraArgument))) { extraArgument = Convert.ToString(extraArgument, NumberFormatInfo.InvariantInfo); } return new SqlStringBuilder() .AddObject(geometry) .Add(".ST") .Add(analysis.ToString()) .Add("(") .AddObject(extraArgument) .Add(")") .ToSqlString(); default: throw new ArgumentException("Invalid spatial analysis argument"); } }