在PostGIS中,将大于世界一半的多边形视为相反的多边形 [英] In PostGIS a polygon bigger than half the world is treated as it's opposite

查看:104
本文介绍了在PostGIS中,将大于世界一半的多边形视为相反的多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将GeoDjango与PostGIS结合使用,并尝试使用多边形从其内部的数据库中获取记录.

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.

我可以使用这个较小的错误区域来排除结果. Polygon.area似乎了解我的意图,因此我可以使用它来确定何时进行包含性或排他性的搜索.我觉得这个问题可能很常见,是否有更好的解决方法?

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?

更新:如果我的多边形内的经度为180度,则根本不起作用.这次似乎要怪GEOS.此图显示了我认为的原因.绿色是我定义的多边形,红色是它的解释方式.同样,这看起来像这个问题经常会出现,并且像GEOS这样的图书馆也要处理这个问题.有办法吗?

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?

推荐答案

好的,没有答案.这就是我所做的.

Alright, no answers. Here's what I've done.

因为GEOS不喜欢穿越180号子午线的事物:
首先检查多边形是否与第180个子午线相交-如果是,则将其沿该线分成2个多边形.

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.

因为PostGIS假定多边形尽可能小,所以您制作的封面不能超过世界的一半,因此:
检查多边形或每个拆分的多边形是否覆盖了一半或更多的世界-如果是这样,请将其切成两半.

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.

从结果中构造一个MultiPolygon.

Construct a MultiPolygon from the results.

这篇关于在PostGIS中,将大于世界一半的多边形视为相反的多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆