Exemple #1
0
        public void TestEsriJsonSqlGeometryConversion()
        {
            try
            {
                var point2D   = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(point2DJson);
                var point3D   = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(point3DJson);
                var pointNull = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(pointNullJson);
                var pointNaN  = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(pointNaNJson);

                var multipoint2D    = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(multipoint2DJson);
                var multipoint3D    = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(multipoint3DJson);
                var multipointEmpty = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(multipointEmptyJson);

                var polyline2D    = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(polyline2DJson);
                var polyline3D    = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(polylineMJson);
                var polylineEmpty = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(polylineEmptyJson);

                var polygon2D    = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(polygon2DJson);
                var polygon3D    = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(polygon3DJson);
                var polygonEmpty = Newtonsoft.Json.JsonConvert.DeserializeObject <EsriJsonGeometry>(polygonEmptyJson);

                SqlSpatialExtensions.Parse(point2D.AsWkt()).ParseToEsriJsonGeometry();
                SqlSpatialExtensions.Parse(point3D.AsWkt()).ParseToEsriJsonGeometry();
                SqlSpatialExtensions.Parse(pointNull.AsWkt()).ParseToEsriJsonGeometry();
                SqlSpatialExtensions.Parse(pointNaN.AsWkt()).ParseToEsriJsonGeometry();

                SqlSpatialExtensions.Parse(multipoint2D.AsWkt()).ParseToEsriJsonGeometry();
                SqlSpatialExtensions.Parse(multipoint3D.AsWkt()).ParseToEsriJsonGeometry();
                SqlSpatialExtensions.Parse(multipointEmpty.AsWkt()).ParseToEsriJsonGeometry();

                SqlSpatialExtensions.Parse(polyline2D.AsWkt()).ParseToEsriJsonGeometry();
                SqlSpatialExtensions.Parse(polyline3D.AsWkt()).ParseToEsriJsonGeometry();
                SqlSpatialExtensions.Parse(polylineEmpty.AsWkt()).ParseToEsriJsonGeometry();

                SqlSpatialExtensions.Parse(polygon2D.AsWkt()).ParseToEsriJsonGeometry();
                SqlSpatialExtensions.Parse(polygon3D.AsWkt()).ParseToEsriJsonGeometry();
                SqlSpatialExtensions.Parse(polygonEmpty.AsWkt()).ParseToEsriJsonGeometry();
            }
            catch (Exception ex)
            {
                Assert.Fail();
            }
        }
Exemple #2
0
        protected string GetCommandString(string wktGeometryFilter, bool returnOnlyGeometry = true)
        {
            var srid = GetSrid();

            var wkbArray = SqlSpatialExtensions.Parse(wktGeometryFilter).STAsBinary().Value;

            var wkbString = Common.Helpers.HexStringHelper.ByteToHexBitFiddle(wkbArray, true);

            if (returnOnlyGeometry)
            {
                return(FormattableString.Invariant($@"
                DECLARE @filter GEOMETRY;
                SET @filter = GEOMETRY::STGeomFromWKB({wkbString},{srid});
                SELECT {_spatialColumnName} FROM {GetTable()} WHERE {_spatialColumnName}.STIntersects(@filter)=1"));
            }
            else
            {
                return(FormattableString.Invariant($@"
                DECLARE @filter GEOMETRY;
                SET @filter = GEOMETRY::STGeomFromWKB({wkbString},{srid});
                SELECT * FROM {GetTable()} WHERE {_spatialColumnName}.STIntersects(@filter)=1"));
            }
        }