Polygon within Polygon

1,388 views
Skip to first unread message

Buster

unread,
Jun 24, 2012, 2:18:33 PM6/24/12
to google-map...@googlegroups.com
I have 2 polygons
Polygon2 is inside Polygon.  Map type is terrain

Is it possible Polygon2 fill can be made transparent, i.e., polygon1 fill color within Polygon2 is removed.  You can see the boundaries of Polygon2, but no color --> map (terrain) is now visible within Polygon2 with no fill color.

Thanks in advance for any assistance.


Andrew Leach

unread,
Jun 24, 2012, 2:39:16 PM6/24/12
to google-map...@googlegroups.com
On 24 June 2012 19:18, Buster <bust...@gmapsapi.net> wrote:
> I have 2 polygons
> Polygon2 is inside Polygon.  Map type is terrain
>
> Is it possible Polygon2 fill can be made transparent, i.e., polygon1 fill
> color within Polygon2 is removed.  You can see the boundaries of Polygon2,
> but no color --> map (terrain) is now visible within Polygon2 with no fill
> color.

I *think* you are describing a "doughnut" polygon, one with a hole in
the middle. This is achieved by changing the "winding" direction -- if
the outer line has its points listed in a clockwise direction, the
inner line must be specified anticlockwise. Both lines need to be
separate paths in the one polygon.

geoco...@gmail.com

unread,
Jun 24, 2012, 2:51:51 PM6/24/12
to Google Maps JavaScript API v3
On Jun 24, 11:18 am, Buster <buste...@gmapsapi.net> wrote:
> I have 2 polygons
> Polygon2 is inside Polygon.  Map type is terrain
>
> Is it possible Polygon2 fill can be made transparent, i.e., polygon1 fill
> color within Polygon2 is removed.  You can see the boundaries of Polygon2,
> but no color --> map (terrain) is now visible within Polygon2 with no fill
> color.

If you mean something like these:
http://www.geocodezip.com/v3_polygon_example_donut.html
http://www.geocodezip.com/v3_polygon_example_donutA.html

It is done by (as Andrew said) reversing the winding direction on the
interior polygons. If your polygons are in kml, I implemented a
"winding calculator" that will determine the winding direction of
somewhat complex polygons (probably doesn't handle all the cases):
http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_winding_linkto.html?filename=http://www.geocodezip.com/geoxml3_test/Polygon_with_holesA.xml

-- Larry

Buster

unread,
Jun 24, 2012, 3:01:04 PM6/24/12
to google-map...@googlegroups.com
not a doughnut polygon.  I saw larry's examples. 
These are irregular polygons.

Andrew Leach

unread,
Jun 24, 2012, 3:07:15 PM6/24/12
to google-map...@googlegroups.com
On 24 June 2012 20:01, Buster <bust...@gmapsapi.net> wrote:
> not a doughnut polygon.  I saw larry's examples.
> These are irregular polygons.

We'll need to see an example then.

Buster

unread,
Jun 24, 2012, 3:13:16 PM6/24/12
to google-map...@googlegroups.com
haven't created the map yet pending if I what I asked is possible.
irregular polygons are not circles and have many vertices.
Polygon1 may have 50 vertices = irregular shape polygon.
Polygon2 has 20 vertices = irregular polygon.
Hope this is not confusing.




On Sunday, June 24, 2012 12:18:33 PM UTC-6, Buster wrote:

geoco...@gmail.com

unread,
Jun 24, 2012, 3:20:15 PM6/24/12
to Google Maps JavaScript API v3
On Jun 24, 12:13 pm, Buster <buste...@gmapsapi.net> wrote:
> haven't created the map yet pending if I what I asked is possible.
> irregular polygons are not circles and have many vertices.
> Polygon1 may have 50 vertices = irregular shape polygon.
> Polygon2 has 20 vertices = irregular polygon.
> Hope this is not confusing.

The circles are just easy examples of polygons with many vertices.
Here is another example (with "irregular polygons" from kml), if it
helps:
http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_linktoB.html?filename=http://www.geocodezip.com/geoxml3_test/crues_450_windingFix_kml.xml

The problem you will have is if the outer polygon doesn't completely
contain the inner polygon(s) (if they intersect).

You can probably adapt the winding calculator for native v3 polygons
if you want.

-- Larry

-- Larry

Buster

unread,
Jun 24, 2012, 3:40:21 PM6/24/12
to google-map...@googlegroups.com
example at www.gmapsapi.net

Thanks again for any assistance.




On Sunday, June 24, 2012 12:18:33 PM UTC-6, Buster wrote:

Buster

unread,
Jun 24, 2012, 4:10:36 PM6/24/12
to google-map...@googlegroups.com
Found the solution at http://gmaps-samples-v3.googlecode.com/svn/trunk/poly/pentagon.html
that's might be good for starters to experiment further.
Any additional comments are welcome
Regards,
Buster



On Sunday, June 24, 2012 12:18:33 PM UTC-6, Buster wrote:

geoco...@gmail.com

unread,
Jun 24, 2012, 4:13:14 PM6/24/12
to Google Maps JavaScript API v3
On Jun 24, 12:40 pm, Buster <buste...@gmapsapi.net> wrote:
> example at
http://www.gmapsapi.net

To make a "hole" in a polygon, both paths have to be part of the same
polygon. The example you provided draws two independent polygons.
You need to add the interior "hole" polygon as a second path in the
first polygon:

http://www.geocodezip.com/v3_polygons_gmapsapi_netA.html

(luckily the winding directions worked out)

-- Larry

Andrew Leach

unread,
Jun 24, 2012, 4:26:12 PM6/24/12
to google-map...@googlegroups.com
On 24 June 2012 21:13, geoco...@gmail.com <geoco...@gmail.com> wrote:
>
> To make a "hole" in a polygon, both paths have to be part of the same
> polygon.  The example you provided draws two independent polygons.
> You need to add the interior "hole" polygon as a second path in the
> first polygon:

And if you want different coloured lines, you need to add each line
separately to the fill.

http://acleach.me.uk/gmaps/v3/gmapsapi.htm

Buster

unread,
Jun 24, 2012, 4:32:33 PM6/24/12
to google-map...@googlegroups.com
Thanks Larry and Andrew.

For some reason, probably not paying attention, I found my solution before seeing Larry's example.

But we are both on the same page and the good part is, I understand about the "hole" within the Polygon now.

Thanks again,




On Sunday, June 24, 2012 12:18:33 PM UTC-6, Buster wrote:
Reply all
Reply to author
Forward
0 new messages