Subscribe to this thread
Home - General / All posts - Count neighbours
dumbledown62 post(s)
#07-Dec-17 17:01

I'm struggling with a query relating to a drawing with lots of touching polygons.

I would simply like to return the number of neighbours touching each individual polygon.

I've got this query, but that selects polygons that touch others, but can't work out how to return a count column.

SELECT A.[ID] INTO test FROM [Drawing] AS [A], [Drawing] AS [B]

WHERE Touches( A.[ID], B.[ID]) AND A.[ID] <> B.[ID]

GROUP BY A.[ID]

Thanks

artlembo


2,916 post(s)
online
#07-Dec-17 17:25

try this (I'm using states):

SELECT a.[NAME], count(*) numneighbors

FROM states AS A, states AS B

WHERE touches(a.[geom (i)], b.[geom (i)])

GROUP BY a.name

dumbledown62 post(s)
#07-Dec-17 18:54

awesome art - works perfectly, you guys are great

adamw


7,307 post(s)
#08-Dec-17 06:52

The WHERE section should perhaps include ... AND a.name <> b.name (or, better, ... AND a.id <> b.id like in the first post) to avoid counting self-touches.

Manifold User Community Use Agreement Copyright (C) 2007-2017 Manifold Software Limited. All rights reserved.