Create polygon with hole

280 views
Skip to first unread message

Nguyễn Văn Mỹ

unread,
Apr 30, 2013, 2:56:47 AM4/30/13
to nettopol...@googlegroups.com
I create polygons by Polygonizer class, but it can not create polygon with a polygon inside, it only create a polygon outside,
Sorry for my English
Thanks,

Diego Guidi

unread,
May 13, 2013, 2:53:31 AM5/13/13
to nettopol...@googlegroups.com
can you post an example of the code are you using?

shawty

unread,
Jul 30, 2013, 3:39:05 PM7/30/13
to nettopol...@googlegroups.com
What you need to do is create a MULTIPOLYGON not just a POLYGON

You can do it easily using the wktReader classes in NTS....

Create a string containing your polygon definition as shown here:


Then once you have this string use a wktReader to convert it to an NTS geometry.

Shawty

Nguyễn Văn Mỹ

unread,
Nov 6, 2013, 10:21:18 PM11/6/13
to nettopol...@googlegroups.com
I am programing MicroStation Addmin, i load all line in a dgn file to List<LineString> and using code:

Polygonizer polygonizer = new Polygonizer();
                polygonizer.Add(listLines);
                var polys = polygonizer.GetPolygons();

It's ok, but can not get Polygon inside a polygon.
My solution: after get polygon, i scan line inside this polygon, then add to a List<LineString> listHoleLines, it's ok, using polygonizer again

Polygonizer holePolygonizer = new Polygonizer();
                        holePolygonizer.Add(listHoleLines);                        
                        var holePolys = holePolygonizer.GetPolygons();
but it allways return no polygon in holePolys.

thanks.
Vào 13:53:31 UTC+7 Thứ hai, ngày 13 tháng năm năm 2013, Diego Guidi đã viết:

FObermaier

unread,
Nov 7, 2013, 9:56:18 AM11/7/13
to nettopol...@googlegroups.com

You are getting polygon with holes and you want the hole-polygons as extra polygons?

 Why don’t you iterate over the resulting polygons, see if they have holes

   ((IPolygon)geom).NumInteriorRings > 0

and then build new polygons for the interior rings

   //…
  var f = geom.Factory;
  var p = (IPolygon) geom;
  var polys = new List<IGeometry>();
  foreach (var i = 0; i < p.NumInteriorRings; i++)
  {
      polys.Add(f.CreatePolyogn((ILinearRing)p.GetInteriorRingN(i), null));

Nguyễn Văn Mỹ

unread,
Nov 8, 2013, 4:08:54 AM11/8/13
to nettopol...@googlegroups.com
Hi FObermaier,
Thanks for your reply.
 I want to getting 2 polygons in this case. 
I iterate over the resulting polygons, but  ((IPolygon)geom).NumInteriorRings always return 0 for all polygons, seem like Polygonizer can not get InterriorRings. 
Thanks again, specially Sharpmap project, it's very usefull with me.

Vào 21:56:18 UTC+7 Thứ năm, ngày 07 tháng mười một năm 2013, FObermaier đã viết:
Untitled.jpg

FObermaier

unread,
Nov 8, 2013, 5:26:03 AM11/8/13
to nettopol...@googlegroups.com
Could you provide the WKT of the polygonizer input geometries and result?

Nguyễn Văn Mỹ

unread,
Nov 8, 2013, 8:52:33 PM11/8/13
to nettopol...@googlegroups.com
Hi FObermaier,
I attach 2 files, Line.txt contain set of LineString from a dgn file, and Polygons.txt contain a set of Polygon after polygonizer.
My solution: I iterate over the resulting polygons, then get all linestrings inside this polygon (example 4 linestring) and polygonizer its (4 linestrings) again, 
i think GetPolygons() method will return 1 polygon but it return 0 polygon.
What wrong in my solution?
Thanks,

Vào 17:26:03 UTC+7 Thứ sáu, ngày 08 tháng mười một năm 2013, FObermaier đã viết:
Line.txt
Polygons.txt

Nguyễn Văn Mỹ

unread,
Nov 9, 2013, 8:56:39 PM11/9/13
to nettopol...@googlegroups.com
Hi FObermaier,
I am tested on different dgn files, method ((IPolygon)geom).NumInteriorRings do not return 0 if have a LinearRing inside polygon, but i only have a list of LineString. 

Vào 17:26:03 UTC+7 Thứ sáu, ngày 08 tháng mười một năm 2013, FObermaier đã viết:

FObermaier

unread,
Nov 10, 2013, 6:20:11 AM11/10/13
to nettopol...@googlegroups.com
You are -probably- not getting the desired result because the input linestrings are not all well connected.
For example the x-ordinate of the 2nd Point of the 2ndlast linestring and the x-ordinate of the 1st point of the last linestring are off by a tiny fraction.

Not knowing how you build your NTS geometries, you might want to use a scaled precision to avoid that.

Nguyễn Văn Mỹ

unread,
Nov 14, 2013, 3:08:31 AM11/14/13
to nettopol...@googlegroups.com
thanks for your reply.
Best regards, FObermaie

Vào 18:20:11 UTC+7 Chủ nhật, ngày 10 tháng mười một năm 2013, FObermaier đã viết:
Reply all
Reply to author
Forward
0 new messages