宇宙DB:为什么地理和几何在ST_WITHIN下会有两种不同的结果?

问题描述 投票:0回答:1

我们最近在应用中遇到了一个问题,我们在前端使用了 leafletJs,在地图的一部分范围内有标记。我们在前端使用了 leafletJs,我们在地图的一部分范围内有标记。这些标记应该基于这些地图的边界进行过滤,但显然有些标记不见了。

我们调查了一下,直到我们的数据库。当我们使用这个网站 http:/geojson.io 来可视化我们在这些边界内的标记,我们可以看到边界内的标记。geojson.io

但是当我们在宇宙数据库中用ST_WITHIN查询给出这些坐标时,它返回false。ST_WITHIN返回false

查询。

SELECT ST_WITHIN({'type': 'Point', 'coordinates': [
            7.753310203552246,
            45.12137985229492
        ]},
    {'type': 'Polygon', 'coordinates': [[
    [30.805664062500004, 59.40036514079251],
    [-12.260742187500002, 59.40036514079251],
    [-12.260742187500002, 43.35713822211053],
    [30.805664062500004, 43.35713822211053],
    [30.805664062500004, 59.40036514079251]
]]})

然而,当我们在SQL数据库中做同样的操作时,它却返回了真。ST_WITHIN返回true查询。

SELECT geometry::STGeomFromText('POINT(7.753310203552246 45.12137985229492)', 4326).STWithin(geometry::STGeomFromText('POLYGON((
30.805664062500004 59.40036514079251,
-12.260742187500002 59.40036514079251,
-12.260742187500002 43.35713822211053,
30.805664062500004 43.35713822211053,
30.805664062500004 59.40036514079251))', 4326))

然后我们发现,我们可以在scale &settings选项卡下更改地理空间配置。当改成Geometry时,应用了边界框和地理空间索引后,效果很好。

然而,我们不清楚,为什么我们需要在地理数据(长、纬度)上使用几何图形。既然我们使用的是世界地图,为什么对地理配置不适用。

另外,文档中规定我们需要使用边界框。我们目前已经配置了一个,但是这样可以吗?边界框(Bounding Boxes.

配置。

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/*"
        }
    ],
    "excludedPaths": [
        {
            "path": "/\"_etag\"/?"
        }
    ],
    "spatialIndexes": [
        {
            "path": "/*",
            "types": [
                "Point",
                "Polygon",
                "MultiPolygon",
                "LineString"
            ],
            "boundingBox": {
                "xmin": -180,
                "ymin": -90,
                "xmax": 180,
                "ymax": 90
            }
        }
    ]
}

然而,当我们不这样做时,我们得到一个错误。

Failed to update container deviceLocations: 
{
  "code": 400,
  "body": {
    "code": "BadRequest",
    "message": "Message: {\"Errors\":[\"Required parameter 'boundingBox' for 'Geometry' collection is missing in spatial path '\\/*'\"]}\r\nActivityId: db41053e-d64a-4f58-ab5a-7b8ea90906a2, Request URI: /apps/18de512a-1eb7-4a07-a798-09120b362e04/services/9445748a-d086-4453-8c41-0adcfa7ddb0c/partitions/50e43654-77e3-424a-959f-fbac363f19cc/replicas/132355285759634497p, RequestStats: \r\nRequestStartTime: 2020-06-04T08:48:17.7891867Z, RequestEndTime: 2020-06-04T08:48:17.7992135Z, Number of regions attempted:1\r\nResponseTime: 2020-06-04T08:48:17.7992135Z, StoreResult: StorePhysicalAddress: rntbd://10.0.0.127:11300/apps/18de512a-1eb7-4a07-a798-09120b362e04/services/9445748a-d086-4453-8c41-0adcfa7ddb0c/partitions/50e43654-77e3-424a-959f-fbac363f19cc/replicas/132355285759634497p, LSN: 40, GlobalCommittedLsn: 40, PartitionKeyRangeId: , IsValid: True, StatusCode: 400, SubStatusCode: 0, RequestCharge: 1.24, ItemLSN: -1, SessionToken: -1#40, UsingLocalLSN: False, TransportException: null, ResourceType: Collection, OperationType: Replace\r\n, SDK: Microsoft.Azure.Documents.Common/2.11.0"
  },
  "headers": {
    "access-control-allow-credentials": "true",
    "access-control-allow-origin": "https://cosmos.azure.com",
    "content-location": "https://ac-cdb-t-app-10001211-atp.documents.azure.com/dbs/statisticsDB/colls/deviceLocations",
    "content-type": "application/json",
    "lsn": "40",
    "strict-transport-security": "max-age=31536000",
    "x-ms-activity-id": "db41053e-d64a-4f58-ab5a-7b8ea90906a2",
    "x-ms-cosmos-llsn": "40",
    "x-ms-cosmos-quorum-acked-llsn": "40",
    "x-ms-current-replica-set-size": "4",
    "x-ms-current-write-quorum": "3",
    "x-ms-gatewayversion": "version=2.11.0",
    "x-ms-global-committed-lsn": "40",
    "x-ms-last-state-change-utc": "Wed, 03 Jun 2020 20:51:02.831 GMT",
    "x-ms-number-of-read-regions": "0",
    "x-ms-quorum-acked-lsn": "40",
    "x-ms-request-charge": "1.24",
    "x-ms-schemaversion": "1.9",
    "x-ms-serviceversion": "version=2.11.0.0",
    "x-ms-session-token": "0:-1#40",
    "x-ms-transport-request-id": "96650",
    "x-ms-xp-role": "1",
    "x-ms-throttle-retry-count": 0,
    "x-ms-throttle-retry-wait-time-ms": 0
  },
  "activityId": "db41053e-d64a-4f58-ab5a-7b8ea90906a2"
}
azure azure-cosmosdb geospatial geojson azure-cosmosdb-sqlapi
1个回答
0
投票

坐标返回为false的原因是,在地理学上绘图是在一个圆形的地球上,而几何学是一个平面。

如果你把你的坐标并插入到 大圆环映射器 你可以看到它就在外面。

我会仔细检查你在SQL Server中的地理模式。你应该得到同样的结果。

希望这能帮到你。

© www.soinside.com 2019 - 2024. All rights reserved.