Create a dynamic polygon

Topics: General Topics
Feb 1, 2007 at 11:14 AM

What I want to do is create a polygon given the following information: the rectangular extents of the map data, and the outline of a polygon contained within the map.

For example, say I have a map of the UK and I have a polygon representing a specific county; what I want to do is dynamically create a rectangle that encompasses the whole of the mapping data, but specifically excludes the chosen county. That is a polygon the height and width of the whole of the UK, with a hole in the middle of it representing the polygon of the chosen county.

Best way I can think to show it is with the below ASCII art :)

|                         |
|       .------.          |
|       |      |          |
|       |  a   |    b     |
|       |      |          |
|       '------'          |
|                         |

In the above example, I would have specified the polygon labelled "a" as my known data, and the full dataset would encompass the whole area shown as the big rectangle. Now the polygon I want to generate (labelled "b") is basically the larger rectangle excluding the smaller one. Does that clear things up? :s

Does anyone have any idea how I can do this on the fly?
Feb 7, 2007 at 1:52 PM
You can dynamically create a polygon by creating a polygon object and set its exteriorring property to a linearring object.

Feb 7, 2007 at 3:51 PM
Ok, I can see what you are telling me I need to do, but the big problem that hits me straight away is that I can't figure out how to get a linear ring object from an existing layer/dataset.

Say I want to get a linear ring object for the box shown as "a" in the diagram above, how would I do that? :s

Feb 21, 2007 at 5:23 PM

You already have the data in a layer? If so, you can compose a new Polygon geometry by adding the ExteriorRing of the "a" polygon to the InteriorRings collection of the "b" polygon. Interior rings in a polygon are defined as holes in the polygon.
Feb 21, 2007 at 9:40 PM
Thanks. That's what I ended up doing, but with some loops to handle multi-polygon layers. It was pretty simple once I got my mind going :)