public static SqlGeometry AsSqlGeometry(this BoundingBox boundingBox, int srid = 0)
        {
            //var result =
            //    SqlGeometry.Parse(
            //         string.Format(
            //                System.Globalization.CultureInfo.InvariantCulture,
            //                "POLYGON(({0} {1}, {0} {2}, {3} {2}, {3} {1}, {0} {1}))",
            //                boundingBox.XMin,
            //                boundingBox.YMin,
            //                boundingBox.YMax,
            //                boundingBox.XMax));

            //result.STSrid = srid;

            //return result;

            return(SqlGeometry.STPolyFromText(new System.Data.SqlTypes.SqlChars(boundingBox.AsWkt()), srid));
        }
Esempio n. 2
0
        //public static SqlServerScaleDependentDataSource CreateForQueryString(string connectionString, string queryString, string spatialColumnName, string labelColumnName = null)
        //{
        //    SqlServerScaleDependentDataSource result = new SqlServerScaleDependentDataSource(connectionString, null, spatialColumnName, labelColumnName, queryString);

        //    return result;
        //}

        //average latitude is assumed to be 30
        //public SqlServerScaleDependentDataSource(List<SqlGeometry> geometries)
        //{
        //    //source = new Dictionary<double, List<SqlGeometry>>();

        //    var boundingBox = geometries.GetBoundingBox();

        //    var fitLevel = IRI.Ham.SpatialBase.Mapping.GoogleMapsUtility.GetZoomLevel(Max(boundingBox.Width, boundingBox.Height));

        //    var simplifiedByAngleGeometries = geometries.Select(g => g.Simplify(.98, SqlServerSpatialExtension.Analysis.SimplificationType.AdditiveSimplifyByAngle)).Where(g => !g.IsNullOrEmpty()).ToList();

        //    for (int i = fitLevel; i < 18; i += 4)
        //    {
        //        var threshold = IRI.Ham.SpatialBase.Mapping.WebMercatorUtility.CalculateGroundResolution(i, 0);

        //        Debug.Print($"threshold: {threshold}, level:{i}");

        //        //var scale = IRI.Ham.SpatialBase.Mapping.WebMercatorUtility.CalculateMapScale(i, 30);
        //        var inverseScale = IRI.Ham.SpatialBase.Mapping.GoogleMapsUtility.ZoomLevels.Single(z => z.ZoomLevel == i).InverseScale;

        //        source.Add(inverseScale, simplifiedByAngleGeometries.Select(g => g.Simplify(threshold, SqlServerSpatialExtension.Analysis.SimplificationType.AdditiveSimplifyByArea)).Where(g => !g.IsNotValidOrEmpty()).ToList());
        //    }
        //}

        //POTENTIONALLY ERROR PRONE. What if geometries where in lat/long so ground distance is wrong for calcualting ZoomLevel
        public override List <SqlGeometry> GetGeometries(BoundingBox boundingBox)
        {
            var srid = GetSrid();

            var properLevel = Ham.SpatialBase.Mapping.WebMercatorUtility.GetZoomLevel(Max(boundingBox.Width, boundingBox.Height), 30, 1500);

            var levels = GetLevels();

            if (properLevel > levels.Max())
            {
                return(base.GetGeometries(boundingBox));
            }
            else
            {
                var wktBoundingBox = boundingBox.AsWkt();

                var query = $"SELECT Geo FROM {_tableName}_P WHERE Level = {properLevel} AND (MBB.STIntersects(GEOMETRY::STPolyFromText('{wktBoundingBox}',{srid})) = 1) ";

                return(this.SelectGeometries(query));
            }
        }
Esempio n. 3
0
 protected static string GetWhereClause(string spatialColumnName, BoundingBox boundingBox, int srid)
 {
     return(FormattableString.Invariant($" {spatialColumnName}.STIntersects(GEOMETRY::STPolyFromText('{boundingBox.AsWkt()}',{srid})) = 1 "));
 }