|
Thanks. Actually it's not necessary to know that. There's a better way. Name the first query [Islands]. This returns the islands (contiguous patches) in [Drawing]. -- Islands SELECT [Island] FROM (SELECT UnionAll([Geom (I)]) AS [Union] FROM [Drawing] ) SPLIT BY Islands([Union]) AS [Island]; Name the second query [Islands with index]. This calls [Islands] twice, and gives each island an index. The index, for each metric, is the number of metrics less than it. (We don't need to know exactly what "less than" means, provided that metrics in different locations necessarily evaluate to different values, which I believe to be true.) -- Islands with index SELECT COUNT([T2].[Island]) AS [N], [T1].[Island] FROM [Islands] AS [T1] LEFT JOIN [Islands] AS [T2] ON CentroidInner([T1].[Island]) > CentroidInner([T2].[Island]) GROUP BY [T1].[Island]; The third query, [Areas by island], returns each original area, along with the index of the island it belongs to. -- Areas by island SELECT [D].[Geom (I)], [T].[N] AS [Island number] FROM [Drawing] AS [D] LEFT JOIN [Islands with index] AS [T] ON Touches([D].[Geom (I)], [T].[Island]) AND ClipSubtract([D].[Geom (I)], [T].[Island]) IS NULL; If you want to put the island index (i.e. patch number) into a column in the original drawing, then the third query can be made into an UPDATE version. -- Areas by island (UPDATE) UPDATE (SELECT [D].[Island], [T].[N] FROM [Drawing] AS [D] LEFT JOIN [Islands with index] AS [T] ON Touches([D].[Geom (I)], [T].[Island]) AND ClipSubtract([D].[Geom (I)], [T].[Island]) IS NULL ) SET [D].[Island] = [N]; If you want to know where the island with each index is, link a drawing from the second query.
|