在 PostGIS 中,大于半个世界的多边形被视为相反的多边形
我将 GeoDjango 与 PostGIS 结合使用,并尝试使用多边形从数据库中获取属于其中的记录。
如果我定义一个大于地球面积一半的多边形,则假定多边形的“内部”是我打算作为“外部”的较小区域,并且仅返回其外部的结果。
我可以使用这个较小的错误区域来排除结果。 Polygon.area 似乎知道我的意图,因此我可以使用它来确定何时进行包含或排除搜索。我觉得这个问题可能很普遍,有没有更好的方法来解决?
更新:如果 180 度经度位于我的多边形内,则这根本不起作用。看来这次GEOS是罪魁祸首。这张图片显示了我认为的原因。绿色是我定义的多边形,红色是它似乎如何解释它。 这似乎又是一个问题这种情况经常会出现,而像 GEOS 这样的库就是为了处理这种情况而设计的。有办法吗?
I'm using GeoDjango with PostGIS and trying to use a polygon to get records from a database which fall inside it.
If I define a polygon which is bigger than half the area of the earth it assumes the 'inside' of my polygon is the smaller area which I intended as the 'outside' and returns only results which are outside it.
I can just use this smaller, wrong area to exclude results. Polygon.area seems to know what I intend so I can use this to determine when to make my search inclusive or exclusive. I feel like this problem is probably common, is there a better way to solve it?
Update: If 180 degrees longitude is inside my polygon this doesn't work at all. It seems GEOS is to blame this time. This image shows what I believe is the reason. Green is the polygon I define, Red is how it seems to be interpreting it. Again this seems like a problem which would crop up often and one that libraries like GEOS are made to deal with. Is there a way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,没有答案。这就是我所做的。
因为 GEOS 不喜欢穿过 180 度子午线的东西:
首先检查多边形是否穿过第 180 条经线 - 如果是,则沿该线将其分成 2 个多边形。
因为 PostGIS 假设多边形尽可能小,所以您无法使一个多边形覆盖超过一半的世界,因此:
检查多边形或每个分割的多边形是否覆盖了世界的一半或更多 - 如果是这样,请将它们分成两半。
根据结果构造一个 MultiPolygon。
Alright, no answers. Here's what I've done.
Because GEOS doesn't like things crossing the 180th meridian:
First check if the polygon crosses the 180th meridian - If so, break it into 2 polygons along that line.
Because PostGIS assumes a polygon is as small as possible you can't make one cover more than half the world, so:
Check if the polygon or each of the split polygons covers half the world or more - If so, break them in half.
Construct a MultiPolygon from the results.