[postgis-users] How to locate adjacent polygons?
Colin
colinflack at fastmail.co.uk
Thu Feb 17 01:45:11 PST 2011
thanks all for replies
my apologies for confused replies and stringing the thread out
Nick
No that wasnt me at stackexchange. altho the graphic shows a
similar scenario, except mine are a little bit more evenly sized and
distributed.
Brett
yea thats pretty much where I'm at... except I hadnt considered
dropping to foreach vertex.
Altho even then I can see that there might well be cases where count
would be >2 for all vertexes in 'adjacent' polygons.
Steven
Re your diagram: Only A would be considered a neighbour of E
And I agree only a raytracing type solution will give a complete solution. But its not justified.
I think extending my current solution with Brents suggestion of foreach(vertex) is the best compromise.
I feel there are sufficient vertices to identify a high percentage of neighbours.
And since 99% is prob OK for this project, I guess thats the way to go.
thanks all
--
Colin
On Wed, 16 Feb 2011 10:13 -0800, pcreso at pcreso.com wrote:
Hi Colin,
Given your definition of adjacent, you are probably better off
with a script using sqls to retrieve data/write result & the
script to implement the logic, iterating through the polygons:
foreach polygon (a)
foreach different polygon (b)
foreach a.vertex
foreach b.vertex
get count of polygons intersected by a line between
a.vertex and b.vertex
if count > 2 then (a) and (b) are not adjacent
next b.vertex
next (a) vertex
write result
next (b) polygon
next (a) polygon
This would define adjacency as having no intervening polygons
between any two polygons, partial adjacency (where parts of two
polygons are & other parts are separated) would require a slight
change in the logic, so if any a.vertex & b.vertex have no
intervening polygons, then (a) and (b) are adjacent. How you
define & implement adjacency is up to you. As is the choice of
scripting language :-)
HTH,
Brent Wood
Subject: Re: [postgis-users] How to locate adjacent polygons?
To: postgis-users at postgis.refractions.net
Date: Thursday, February 17, 2011, 2:09 AM
sorry for double post - working from dodgy pda
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
--
[1]http://www.fastmail.fm - IMAP accessible web-mail
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
[2]http://postgis.refractions.net/mailman/listinfo/postgis-users
References
Visible links
1. http://www.fastmail.fm/
2. http://postgis.refractions.net/mailman/listinfo/postgis-users
Hidden links:
3. mailto:colinflack at fastmail.co.uk
--
http://www.fastmail.fm - IMAP accessible web-mail
--
Colin
colinflack at fastmail.co.uk
--
http://www.fastmail.fm - A fast, anti-spam email service.
More information about the postgis-users
mailing list