Subscribe to this thread
Home - General / All posts - Delete branches
rotten_apple21 post(s)
#17-Nov-14 01:36

Is there a faster way to delete all branches of an area/polygon?

Graeme

990 post(s)
#17-Nov-14 04:48

Faster than what?

Tell us what you've tried and the issues you're having. Consider posting a sample of your data.

rotten_apple21 post(s)
#17-Nov-14 05:12

I've written a script in VB. What i'm trying to achieve is remove all branches/holes inside a selected area using the script below.

Sub Main

Set window = Application.ActiveWindow

Set component = window.ActiveComponent

if component.Type = ComponentDrawing then

for each obj in component.ObjectSet

if obj.isSelected() then

Remove the branches here

end if

next

else

Application.MessageBox "Component is not Drawing"

end if

End Sub

tjhb
10,094 post(s)
#17-Nov-14 09:03

(That's not VB but vbscript, though it doesn't matter here.)

Yes, the faster way is to use SQL.

rotten_apple21 post(s)
#18-Nov-14 03:09

:)

how do you know that a branch is a "hole" in an area?

tjhb
10,094 post(s)
#18-Nov-14 04:08

Good question. After you run Normalize() on an area in SQL, branch 0 is always the outermost branch (the perimeter). So you retain only that branch. All holes are filled.

If you wanted to find all holes, rather than simply get rid of them, then you woukd need something only slightly more complicated. The branch that describes a hole, when considered as an area, is one not contained by the original area.

rotten_apple21 post(s)
#18-Nov-14 07:24

what is normalize() in SQL? is it different from normalize topology / normalize metric in the transform toolbar?

rotten_apple21 post(s)
#25-Nov-14 05:07
tjhb
10,094 post(s)
#25-Nov-14 06:18

Is that an empty bump? Hard to tell--bumps of any kind don't normally exist here.

No doubt by now you have answered your last question by standard RTFM. Right?

What else do you need? And do you have example data?

rotten_apple21 post(s)
#25-Nov-14 06:58

i'm sorry about that. i was about about to ask you if you could give me a sample query using/involving "normalize" in sql. but i already found one in the previous posts so i tried to delete my reply.

:) next time i will follow the Standard RTFM. Thx

tjhb
10,094 post(s)
#25-Nov-14 07:52

For a drawing named [Drawing], with one or more areas selected, where each area has a single island, you can replace those areas with filled areas (no holes) by running a query like this.

UPDATE [Drawing]

SET [Geom (I)] = Branch(Normalize([Geom (I)]), 0)

WHERE IsArea([ID]AND [Selection (I)];

Where areas might have more than one island, it's more complicated, though not much.

tjhb
10,094 post(s)
#25-Nov-14 08:01

Where areas can have more than one island, you'd do something like this. (There's quite a bit more to explain here.)

UPDATE

    (SELECT

        [D].[Geom (I)],

        [T].[Perimeters]

    FROM

        [Drawing] AS [D]

        INNER JOIN

        (SELECT

            [ID],

            UnionAll(Branch(Normalize([Island]), 0)) AS [Perimeters]

        FROM [Drawing]

        WHERE IsArea([ID]AND [Selection (I)]

        SPLIT BY Islands([Geom (I)]AS [Island]

        GROUP BY [ID]

        ) AS [T]

        ON [D].[ID] = [T].[ID]

    )

SET [Geom (I)] = [Perimeters];

[Edit: I misspoke. AllBranches() corrected to UnionAll() at line 10.]

tjhb
10,094 post(s)
#25-Nov-14 08:15

Example attached. There's only one area in the example drawing. It has three islands, two having holes, some holes containing islands with further holes in them. Select everything--i.e. the only area--before running the query. The result is an area having three islands with no holes. Questions welcome.

Attachments:
20141125 Fill holes in areas.map

rotten_apple21 post(s)
#25-Nov-14 08:37

Wow. I can't thank you enough.

tjhb
10,094 post(s)
#25-Nov-14 09:02

Don't be shy with searching questions because while it is often hard at first it is hugely worthwhile learning spatial SQL, and many of us who have learnt here are keen to "pay forward" that debt. [Or just enjoy it.]

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