Exemplo n.º 1
0
        private void AssertThat(IGeometry geometry, SpatialRelation relation, IRavenIndexable geometry2, bool expected)
        {
            InitRaven(new TestIndex());
            var doc = new GeoDoc
            {
                Geometry = geometry
            };

            using (var session = Store.OpenSession())
            {
                session.Store(doc);
                session.SaveChanges();
            }
            using (var session = Store.OpenSession())
            {
                var result = session.Query <GeoDoc, TestIndex>()
                             .Geo(x => x.Geometry, x => x.RelatesToShape(geometry2, relation))
                             .Customize(x => x.WaitForNonStaleResults())
                             .Any();

                var  relationString = relation.ToString().ToLowerInvariant();
                bool s = false;
                if (relationString.EndsWith("s"))
                {
                    s = true;
                    relationString = relationString.Substring(0, relationString.Length - 1);
                }

                var msg = string.Format("Geometry {0}{1} {2} {3}", s ? "does" : "is", result ? "" : " not", relationString, _writer.Write(geometry2.GetSpatial4nShape()));

                Assert.That(result, Is.EqualTo(expected), msg);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SpatialRelationFunction"/> class.
 /// </summary>
 /// <param name="spatialDialect">The spatial dialect.</param>
 /// <param name="relation">The relation.</param>
 public SpatialRelationFunction(ISpatialDialect spatialDialect, SpatialRelation relation)
     : base(relation.ToString(), NHibernateUtil.Boolean)
 {
     this.spatialDialect   = spatialDialect;
     this.relation         = relation;
     this.allowedArgsCount = 2;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SpatialRelationFunction"/> class.
 /// </summary>
 /// <param name="spatialDialect">The spatial dialect.</param>
 /// <param name="relation">The relation.</param>
 public SpatialRelationFunction(ISpatialDialect spatialDialect, SpatialRelation relation)
     : base(relation.ToString(), NHibernateUtil.Boolean)
 {
     this.spatialDialect = spatialDialect;
     this.relation = relation;
     this.allowedArgsCount = 2;
 }
Exemplo n.º 4
0
        public virtual SqlString GetSpatialRelationString(object geometry, SpatialRelation relation, object anotherGeometry, bool criterion)
        {
            switch (relation)
            {
            case SpatialRelation.Covers:
                string[] patterns = new string[] {
                    "T*****FF*",
                    "*T****FF*",
                    "***T**FF*",
                    "****T*FF*",
                };
                SqlStringBuilder builder = new SqlStringBuilder();
                builder.Add("(CASE WHEN ");
                for (int i = 0; i < patterns.Length; i++)
                {
                    if (i > 0)
                    {
                        builder.Add(" OR ");
                    }
                    builder
                    .AddObject(geometry)
                    .Add(".STRelate(")
                    .AddObject(anotherGeometry)
                    .Add(", '")
                    .Add(patterns[i])
                    .Add("') = 1")
                    .ToSqlString();
                }
                builder.Add(" THEN 1 ELSE 0 END)");
                builder.Add(criterion ? " = 1" : "");
                return(builder.ToSqlString());

            case SpatialRelation.CoveredBy:
                return(GetSpatialRelationString(anotherGeometry, SpatialRelation.Covers, geometry, criterion));

            default:
                // NOTE: Cast is only required if "geometry" is passed in as a parameter
                //       directly, rather than as a column name. This is because parameter
                //       will be passed as binary and SQL Server can't call methods on
                //       binary data.
                return(new SqlStringBuilder()
                       .Add("CAST(")
                       .AddObject(geometry)
                       .Add(" AS ")
                       .Add(sqlTypeName)
                       .Add(")")
                       .Add(".ST")
                       .Add(relation.ToString())
                       .Add("(")
                       .AddObject(anotherGeometry)
                       .Add(")")
                       .Add(criterion ? " = 1" : "")
                       .ToSqlString());
            }
        }
Exemplo n.º 5
0
        public SqlString GetSpatialRelationString(object geometry, SpatialRelation relation, object anotherGeometry, bool criterion)
        {
            switch (relation)
            {
            case SpatialRelation.Covers:
                string[] patterns = new string[] {
                    "T*****FF*",
                    "*T****FF*",
                    "***T**FF*",
                    "****T*FF*",
                };
                SqlStringBuilder builder = new SqlStringBuilder();
                builder.Add("(");
                for (int i = 0; i < patterns.Length; i++)
                {
                    if (i > 0)
                    {
                        builder.Add(" OR ");
                    }
                    builder
                    .Add(SpatialDialect.IsoPrefix)
                    .Add("Relate")
                    .Add("(")
                    .AddObject(geometry)
                    .Add(", ")
                    .AddObject(anotherGeometry)
                    .Add(", '")
                    .Add(patterns[i])
                    .Add("')")
                    .ToSqlString();
                }
                builder.Add(")");
                return(builder.ToSqlString());

            case SpatialRelation.CoveredBy:
                return(GetSpatialRelationString(anotherGeometry, SpatialRelation.Covers, geometry, criterion));

            default:
                return(new SqlStringBuilder(6)
                       .Add(SpatialDialect.IsoPrefix)
                       .Add(relation.ToString())
                       .Add("(")
                       .AddObject(geometry)
                       .Add("::text")
                       .Add(", ")
                       .AddObject(anotherGeometry)
                       .Add("::text")
                       .Add(")")
                       .ToSqlString());
            }
        }
 public SqlString GetSpatialRelationString(object geometry, SpatialRelation relation, object anotherGeometry, bool criterion)
 {
     return(new SqlStringBuilder(8)
            .Add(DialectPrefix)
            .Add("[")
            .Add(relation.ToString())
            .Add("](")
            .AddObject(geometry)
            .Add(", ")
            .AddObject(anotherGeometry)
            .Add(")")
            .Add(criterion ? " = 1" : "")
            .ToSqlString());
 }
        public virtual SqlString GetSpatialRelationString(object geometry, SpatialRelation relation, object anotherGeometry, bool criterion)
        {
            switch (relation)
            {
            case SpatialRelation.Covers:
                string[] patterns = new string[] {
                    "T*****FF*",
                    "*T****FF*",
                    "***T**FF*",
                    "****T*FF*",
                };
                SqlStringBuilder builder = new SqlStringBuilder();
                builder.Add("(CASE WHEN ");
                for (int i = 0; i < patterns.Length; i++)
                {
                    if (i > 0)
                    {
                        builder.Add(" OR ");
                    }
                    builder
                    .AddObject(geometry)
                    .Add(".STRelate(")
                    .AddObject(anotherGeometry)
                    .Add(", '")
                    .Add(patterns[i])
                    .Add("') = 1")
                    .ToSqlString();
                }
                builder.Add(" THEN 1 ELSE 0 END)");
                builder.Add(criterion ? " = 1" : "");
                return(builder.ToSqlString());

            case SpatialRelation.CoveredBy:
                return(GetSpatialRelationString(anotherGeometry, SpatialRelation.Covers, geometry, criterion));

            default:
                return(new SqlStringBuilder(8)
                       .AddObject(geometry)
                       .Add(".ST")
                       .Add(relation.ToString())
                       .Add("(")
                       .AddObject(anotherGeometry)
                       .Add(")")
                       .Add(criterion ? " = 1" : "")
                       .ToSqlString());
            }
        }
 private void RegisterSpatialFunction(SpatialRelation relation)
 {
     RegisterFunction(SpatialDialect.HqlPrefix + relation.ToString(), new SpatialRelationFunction(this, relation));
 }
 public SqlString GetSpatialRelationString(object geometry, SpatialRelation relation, object anotherGeometry, bool criterion)
 {
     return new SqlStringBuilder(8)
         .Add(DialectPrefix)
         .Add("[")
         .Add(relation.ToString())
         .Add("](")
         .AddObject(geometry)
         .Add(", ")
         .AddObject(anotherGeometry)
         .Add(")")
         .Add(criterion ? " = 1" : "")
         .ToSqlString();
 }
Exemplo n.º 10
0
 public SqlString GetSpatialRelationString(object geometry, SpatialRelation relation, object anotherGeometry, bool criterion)
 {
     switch (relation)
     {
         case SpatialRelation.Covers:
             string[] patterns = new string[] {
                 "T*****FF*",
                 "*T****FF*",
                 "***T**FF*",
                 "****T*FF*",
             };
             SqlStringBuilder builder = new SqlStringBuilder();
             builder.Add("(");
             for (int i = 0; i < patterns.Length; i++)
             {
                 if (i > 0)
                     builder.Add(" OR ");
                 builder
                     .Add(SpatialDialect.IsoPrefix)
                     .Add("Relate")
                     .Add("(")
                     .AddObject(geometry)
                     .Add(", ")
                     .AddObject(anotherGeometry)
                     .Add(", '")
                     .Add(patterns[i])
                     .Add("')")
                     .ToSqlString();
             }
             builder.Add(")");
             return builder.ToSqlString();
         case SpatialRelation.CoveredBy:
             return GetSpatialRelationString(anotherGeometry, SpatialRelation.Covers, geometry, criterion);
         default:
             return new SqlStringBuilder(6)
                 .Add(SpatialDialect.IsoPrefix)
                 .Add(relation.ToString())
                 .Add("(")
                 .AddObject(geometry)
                 .Add("::text")
                 .Add(", ")
                 .AddObject(anotherGeometry)
                 .Add("::text")
                 .Add(")")
                 .ToSqlString();
     }
 }
Exemplo n.º 11
0
 private void RegisterSpatialFunction(SpatialRelation relation)
 {
     RegisterFunction(SpatialDialect.HqlPrefix + relation.ToString(), new SpatialRelationFunction(this, relation));
 }
 public void RegisterSpatialFunction(SpatialRelation relation)
 {
     adaptor.RegisterFunction(SpatialDialect.HqlPrefix + relation.ToString(), new SpatialRelationFunction(this, relation));
 }
Exemplo n.º 13
0
 public SqlString GetSpatialRelationString(object geometry, SpatialRelation relation, object anotherGeometry, bool criterion)
 {
     switch (relation)
     {
         case SpatialRelation.Covers:
             string[] patterns = new string[] {
                 "T*****FF*",
                 "*T****FF*",
                 "***T**FF*",
                 "****T*FF*",
             };
             SqlStringBuilder builder = new SqlStringBuilder();
             builder.Add("(CASE WHEN ");
             for (int i = 0; i < patterns.Length; i++)
             {
                 if (i > 0)
                     builder.Add(" OR ");
                 builder
                     .AddObject(geometry)
                     .Add(".STRelate(")
                     .AddObject(anotherGeometry)
                     .Add(", '")
                     .Add(patterns[i])
                     .Add("') = 1")
                     .ToSqlString();
             }
             builder.Add(" THEN 1 ELSE 0 END)");
             builder.Add(criterion ? " = 1" : "");
             return builder.ToSqlString();
         case SpatialRelation.CoveredBy:
             return GetSpatialRelationString(anotherGeometry, SpatialRelation.Covers, geometry, criterion);
         default:
             return new SqlStringBuilder(8)
                 .AddObject(geometry)
                 .Add(".ST")
                 .Add(relation.ToString())
                 .Add("(")
                 .AddObject(anotherGeometry)
                 .Add(")")
                 .Add(criterion ? " = 1" : "")
                 .ToSqlString();
     }
 }
 public void RegisterSpatialFunction(SpatialRelation relation)
 {
     adaptor.RegisterFunction(SpatialDialect.HqlPrefix + relation.ToString(), new SpatialRelationFunction(this, relation));
 }