Quantcast
Channel: DotSpatial
Viewing all articles
Browse latest Browse all 3973

Commented Unassigned: Polygon with hole [63600]

$
0
0
Hello
I am sorry for my English
I have short fragment of code

```
static void Main(string[] args)
{
FeatureSet fs = new FeatureSet(FeatureType.Polygon);
fs.Projection = KnownCoordinateSystems.Geographic.World.WGS1984;
List<Coordinate> coorBig = new List<Coordinate> { new Coordinate(0, 0), new Coordinate(0, 100), new Coordinate(100, 100), new Coordinate(100, 0) };
List<Coordinate> coordCenter = new List<Coordinate> { new Coordinate(25, 25), new Coordinate(25, 75), new Coordinate(75, 75), new Coordinate(75, 25) };

LinearRing lr1 = new LinearRing(coorBig);
LinearRing[] lr2 = { new LinearRing(coordCenter) };
Polygon pgHole = new Polygon(lr1, lr2);

fs.AddFeature(pgHole);
fs.SaveAs("C:\\Temp\\testD.shp", true);
}
```

When I open this shape file, I see multipolygon instead polygon this hole. Could somebody help me, what I did wrong? Thanks for your help.
Comments: You have to make sure, that the points of your shell (lr1) are ordered clockwise and the points of your holes (lr2) are ordered counter clockwise. Have a look at the example below on how to make sure that your holes are counter clockwise. ``` using DotSpatial.Topology; using System.Collections.Generic; using DotSpatial.Topology.Algorithm; LinearRing[] lr2 = { new LinearRing(coordCenter) }; //make sure the holes are oriented counterclockwise for (int i = 0; i < lr2.Length; i++) { if (!CgAlgorithms.IsCounterClockwise(lr2[i].Coordinates)) { lr2[i] = new LinearRing(lr2[i].Reverse()); } } Polygon pgHole = new Polygon(lr1, lr2); ```

Viewing all articles
Browse latest Browse all 3973

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>