Sql 2008 查询问题 - 地理多边形中存在哪些 LatLong?
我有以下两个表:-
GeoShapes
- GeoShapeId INT IDENTITY
- Name VARCHAR(100)
- ShapeFile GEOGRAPHY [这是一个纬度/经度的闭合多边形]
CrimeLocations
- CrimeLocationId INT IDENTITY
- LatLong GEOGRAPHY [这是一个纬度/经度点]
现在,我有10K GeoShape 结果和大约 500 个犯罪地点。
我正在尝试找出所有 500 个犯罪纬度/经度点都存在于哪些 GeoShapes 中。
:( 我只是不明白!我正在尝试执行 STIntersects
在子查询上,但没有工作。
编辑
:我不能使用任何 GEOMETRY
函数..因为(如上所述)这些都是地理类型。
1 知道如何使用 STContains
和 STIntersects
。请不要提供这方面的基本示例,我更好奇的是如何使用上面的表结构进行复杂的查询。
i have the following two tables:-
GeoShapes
- GeoShapeId INT IDENTITY
- Name VARCHAR(100)
- ShapeFile GEOGRAPHY [ this is a closed Polygon of Lat/Longs ]
CrimeLocations
- CrimeLocationId INT IDENTITY
- LatLong GEOGRAPHY [ this is a Lat/Long Point ]
Now, i have around 10K GeoShape results and around 500CrimeLocations.
I'm trying to figure out which GeoShapes all 500 crime lat/long points exist inside of.
:( I just don't get it! I was trying to do an STIntersects
on a subquery but that didn't work. Any suggestions?
cheers!
EDIT 1: I cannot use any GEOMETRY
functions .. because (as stated above) these are all geography types.
EDIT 2: I know how to use STContains
and STIntersects
. Please don't provide basic examples of that. I'm more curious about to do a complex query with my table structure, above.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于您的“编辑”,您很少会看到包含“请不要提供...”的问题。 当然每一点都有帮助吗? 特别是因为您还没有实际向我们展示您对
STContains
或STIntersects
(或Filter()
)的了解。就此而言)...无论如何,我有一个方便的邮政编码和商店位置数据库,因此我重命名了表/列以匹配您的(然后我有 6,535 个 CrimeLocatoins 和 3,285 个 GeoShapes)。 我想您现在已经弄清楚了 - 但其他人可能会发现这很有用...
查询返回每个 GeoShapes.ShapeFile 中的 CrimeLocations 数量
以下 年龄(比如 20 分钟),因为我没有设置任何地理空间索引,并且我的 ShapeFile 具有很高的点计数,但它确实运行成功。 如果我想按照您的建议限制结果:
当然您不想对数字 500 进行硬编码 - 所以您可以在那里添加一个
COUNT(*) FROM CrimeLocations
子查询,或者一个带有来自单独查询的总计。这够复杂吗?
Regarding your 'edits', it's not often you see a question that includes "please don't provide...". Surely every little bit helps? Particularly since you haven't actually shown us what you do know about
STContains
orSTIntersects
(orFilter()
for that matter)...Anyway, I had a database of zipcodes and storelocations handy, so I renamed the tables/columns to match yours (I then have 6,535 CrimeLocatoins and 3,285 GeoShapes). I presume you've figured it out by now - but someone else might find this useful...
The following query returns the number of CrimeLocations in each GeoShapes.ShapeFile
It takes ages (like 20 mins) because I haven't setup any geospatial indexes and my ShapeFiles have a high point-count, but it does run successfully. If I wanted to restrict the results as you suggest:
Of course you don't want to hardcode the number 500 - so you could add a
COUNT(*) FROM CrimeLocations
subquery there, or a variable with the total from a separate query.Is that complex enough?