[postgis-users] (no subject)

Stephen Woodbridge woodbri at swoodbridge.com
Wed Feb 16 17:43:55 PST 2011


Brent,

You solution is probably faster than mine and probably works even if the 
polygons are not valid.

Colin,

Sorry, best answer we could give without a full description of the problem.

So how does this case work?

*-------------------* *----*
|       A           | | D  |
*-------------------* *----*
*------------*   *---------*
|     B      |   |    C    |
*------------*   *---------*
           *---------------------------------*
           |                E                |
           *---------------------------------*

So is A a neightbor of E? ie: narrow gap bewteen B and C
Is D a neighbor of E?

If these ar true, then you need to look into ray-tracing techniques to 
solve the problem, and there are no canned solution in postGIS that I 
can think of. If you search the archives I think there was a discussion 
of viewsheds 6+ months ago that might have yielded some stored 
procedures that you could try.

The problem here is that you need to evaluate every point along the 
boundary of say E and run a fan of rays outbound from each evaluation 
point and see what polygons they hit. Obviously there are an infinite 
number of evaluation points and an infinite number of rays from each 
point, so you have to decide on some sample size for both these items 
based on your tolerance for compute time and missed neighbors.

-Steve W

On 2/16/2011 6:44 AM, Colin wrote:
> Hi Steve / Brent
>
> Thanks for replies
>
> Steve: Yes I did look at buffer but I discounted it because a small
> number of the polys are at distances well outside the mean and I didnt
> see any easy way of including them.
> Brents solution with st_distance and a tolerance factor might suffer
> from the same problem
>
> And in fact the definition of adjacent doesnt include distance - its
> simply that no other polygon crosses some path between any 2
>
> I also have the centroids calced and stored so in my spatial innocence i
> devised a solution which almost works and uses ST_Crosses(ST_MakeLine
> something like this:
>
> select a.id, b.id, ST_Crosses(ST_MakeLine(a.centroid, b.centroid),
> b.geom) as stcrosses
> from a, b where a.id = nnn and a.id!=b.id order by stcrosses
>
> I run this per id from program code. I then filter the return to give
> adjacents
>
> I'm not at my dev machine right now and I suspect thats not exacty
> right(at all!) but what I have isnt affected by distance and almost
> works - except occasionally for the very complex and where there are
> larger gaps between polys.
>
> so maybe a combination of these methods?
>
> Or since the data wont change often, maybe I just plot them in qgis and
> do it manually! ;-)
>
> Colin
>
>
> On 02/16/2011 05:12 AM, Stephen Woodbridge wrote:
>> Colin,
>>
>> Did you look at buffer?
>>
>> Not tested but something like this might work where b.id are the
>> adjacent id's to a.id with the distance of<tolerance>.
>>
>> select a.id, b.id from mypolys a, mypolys b
>> where a.id != b.id
>> and buffer(a.geom,<tolerance>)&&  b.geom
>> and intersects(buffer(a.geom,<tolerance>), b.geom)
>>
>> -Steve
>>
>> On 2/15/2011 5:38 PM, Colin wrote:
>>> Hi
>>>
>>> I'm quite new to postgis and spatial databases.
>>> competent with sql and db's
>>>
>>> My problem: How to locate adjacent polygons.
>>>
>>> I have around around 2k irregular polygons.
>>> They've have been calculated as alpha / concave hulls from point sets.
>>> They're saved into pg as multipolygons
>>>
>>> id | description | geom
>>>
>>> The polygons dont have any regularity with regard to location and
>>> interaction
>>> the majority are close to a neighbour, but not touching. Typically
>>> within +/- 1 - 5% of polygon max dim
>>> a small number slightly overlap 1 or more neighbours, usually to quite a
>>> small extent
>>> their irregular shape can include 'undercuts'
>>>
>>>
>>> I need to identify the adjacent neighbours for each polygon
>>>
>>> I looked at various methods that might allow me to do this but I cant
>>> get a 100% solution
>>>
>>> Can anyone suggest methods that might work
>>>
>>> thanks
>>>
>>>
>>> Colin
>




More information about the postgis-users mailing list