In the code snippet below, I am trying to create 3d geometries (cuboids) and save them in a shapefile. Each cuboid is defined by 6 polygons, each with 4 coordinates. When I create a Feature from the Shape, it has 3 additional coordinates. I have also given the coordinate lists for each below the code snippet.
FeatureSet fs = new FeatureSet() { CoordinateType = CoordinateType.Z };
foreach (var item in ItemList) // items are 3d cuboid objects
{
DotSpatial.Data.Shape elementShape = new DotSpatial.Data.Shape(FeatureType.Polygon);
// for each polygon in item geometry
foreach (var face in item.Faces)
try
{
List<Coordinate> coordList = new List<Coordinate>();
// for each point in face polygon
foreach (Point point in face)
{
coordList.Add(new Coordinate(point.Longitude, point.Latitude, point.Altitude));
}
elementShape.AddPart(coordList.AsEnumerable(), CoordinateType.Z);
}
catch (Exception ex)
{
// handle exception
}
__ Feature feature = new Feature(elementShape); __ // this feature has 27 coordinates and the shape has only 24
var feat = fs.AddFeature(feature);
}
SaveFeature(fs, FileName);
I numbered the coordinates on the left. Numbers 5, 14 and 22 look like they may be extra, but 15-21 are definitely different.
Feature Coordinates Shape Coordinates
1 {(-105.131665500059, 39.7526329557437, 0)} -105.131665500059 39.7526329557437 0
2 {(-105.131665500059, 39.7526329557437, 10)} -105.131665500059 39.7526329557437 10
3 {(-105.131665500059, 39.7527317962905, 10)} -105.131665500059 39.7527317962905 10
4 {(-105.131665500059, 39.7527317962905, 0)} -105.131665500059 39.7527317962905 0
5 {(-105.131665500059, 39.7526329557437, 0)}
6 {(-105.131663125821, 39.7527317962905, 10)} -105.131663125821 39.7527317962905 10
7 {(-105.131663125821, 39.7526329557437, 10)} -105.131663125821 39.7526329557437 10
8 {(-105.131663125821, 39.7526329557437, 0)} -105.131663125821 39.7526329557437 0
9 {(-105.131663125821, 39.7527317962905, 0)} -105.131663125821 39.7527317962905 0
10 {(-105.131665500059, 39.7527317962905, 0)} -105.131665500059 39.7527317962905 0
11 {(-105.131663125821, 39.7527317962905, 0)} -105.131663125821 39.7527317962905 0
12 {(-105.131663125821, 39.7526329557437, 0)} -105.131663125821 39.7526329557437 0
13 {(-105.131665500059, 39.7526329557437, 0)} -105.131665500059 39.7526329557437 0
14 {(-105.131665500059, 39.7527317962905, 0)}
15 {(-105.131665500059, 39.7526329557437, 10)} -105.131665500059 39.7526329557437 0
16 {(-105.131663125821, 39.7526329557437, 10)} -105.131663125821 39.7526329557437 0
17 {(-105.131663125821, 39.7527317962905, 10)} -105.131663125821 39.7526329557437 10
18 {(-105.131665500059, 39.7527317962905, 10)} -105.131665500059 39.7526329557437 10
19 {(-105.131665500059, 39.7526329557437, 10)} -105.131665500059 39.7526329557437 10
20 {(-105.131665500059, 39.7526329557437, 0)} -105.131663125821 39.7526329557437 10
21 {(-105.131663125821, 39.7526329557437, 0)} -105.131663125821 39.7527317962905 10
22 {(-105.131663125821, 39.7526329557437, 10)}
23 {(-105.131665500059, 39.7526329557437, 10)} -105.131665500059 39.7527317962905 10
24 {(-105.131665500059, 39.7527317962905, 10)} -105.131665500059 39.7527317962905 10
25 {(-105.131663125821, 39.7527317962905, 10)} -105.131663125821 39.7527317962905 10
26 {(-105.131663125821, 39.7527317962905, 0)} -105.131663125821 39.7527317962905 0
27 {(-105.131665500059, 39.7527317962905, 0)} -105.131665500059 39.7527317962905 0
Comments: Part 1 {(-105.131665500059, 39.7526329557437, 0)} {(-105.131665500059, 39.7526329557437, 10)} {(-105.131665500059, 39.7527317962905, 10)} {(-105.131665500059, 39.7527317962905, 0)} Part 2 {(-105.131663125821, 39.7527317962905, 10)} {(-105.131663125821, 39.7526329557437, 10)} {(-105.131663125821, 39.7526329557437, 0)} {(-105.131663125821, 39.7527317962905, 0)} Part 3 {(-105.131665500059, 39.7527317962905, 0)} {(-105.131663125821, 39.7527317962905, 0)} {(-105.131663125821, 39.7526329557437, 0)} {(-105.131665500059, 39.7526329557437, 0)} Part 4 {(-105.131665500059, 39.7526329557437, 0)} {(-105.131663125821, 39.7526329557437, 0)} {(-105.131663125821, 39.7526329557437, 10)} {(-105.131665500059, 39.7526329557437, 10)} Part 5 {(-105.131665500059, 39.7526329557437, 10)} {(-105.131663125821, 39.7526329557437, 10)} {(-105.131663125821, 39.7527317962905, 10)} {(-105.131665500059, 39.7527317962905, 10)} Part 6 {(-105.131665500059, 39.7527317962905, 10)} {(-105.131663125821, 39.7527317962905, 10)} {(-105.131663125821, 39.7527317962905, 0)} {(-105.131665500059, 39.7527317962905, 0)}
FeatureSet fs = new FeatureSet() { CoordinateType = CoordinateType.Z };
foreach (var item in ItemList) // items are 3d cuboid objects
{
DotSpatial.Data.Shape elementShape = new DotSpatial.Data.Shape(FeatureType.Polygon);
// for each polygon in item geometry
foreach (var face in item.Faces)
try
{
List<Coordinate> coordList = new List<Coordinate>();
// for each point in face polygon
foreach (Point point in face)
{
coordList.Add(new Coordinate(point.Longitude, point.Latitude, point.Altitude));
}
elementShape.AddPart(coordList.AsEnumerable(), CoordinateType.Z);
}
catch (Exception ex)
{
// handle exception
}
__ Feature feature = new Feature(elementShape); __ // this feature has 27 coordinates and the shape has only 24
var feat = fs.AddFeature(feature);
}
SaveFeature(fs, FileName);
I numbered the coordinates on the left. Numbers 5, 14 and 22 look like they may be extra, but 15-21 are definitely different.
Feature Coordinates Shape Coordinates
1 {(-105.131665500059, 39.7526329557437, 0)} -105.131665500059 39.7526329557437 0
2 {(-105.131665500059, 39.7526329557437, 10)} -105.131665500059 39.7526329557437 10
3 {(-105.131665500059, 39.7527317962905, 10)} -105.131665500059 39.7527317962905 10
4 {(-105.131665500059, 39.7527317962905, 0)} -105.131665500059 39.7527317962905 0
5 {(-105.131665500059, 39.7526329557437, 0)}
6 {(-105.131663125821, 39.7527317962905, 10)} -105.131663125821 39.7527317962905 10
7 {(-105.131663125821, 39.7526329557437, 10)} -105.131663125821 39.7526329557437 10
8 {(-105.131663125821, 39.7526329557437, 0)} -105.131663125821 39.7526329557437 0
9 {(-105.131663125821, 39.7527317962905, 0)} -105.131663125821 39.7527317962905 0
10 {(-105.131665500059, 39.7527317962905, 0)} -105.131665500059 39.7527317962905 0
11 {(-105.131663125821, 39.7527317962905, 0)} -105.131663125821 39.7527317962905 0
12 {(-105.131663125821, 39.7526329557437, 0)} -105.131663125821 39.7526329557437 0
13 {(-105.131665500059, 39.7526329557437, 0)} -105.131665500059 39.7526329557437 0
14 {(-105.131665500059, 39.7527317962905, 0)}
15 {(-105.131665500059, 39.7526329557437, 10)} -105.131665500059 39.7526329557437 0
16 {(-105.131663125821, 39.7526329557437, 10)} -105.131663125821 39.7526329557437 0
17 {(-105.131663125821, 39.7527317962905, 10)} -105.131663125821 39.7526329557437 10
18 {(-105.131665500059, 39.7527317962905, 10)} -105.131665500059 39.7526329557437 10
19 {(-105.131665500059, 39.7526329557437, 10)} -105.131665500059 39.7526329557437 10
20 {(-105.131665500059, 39.7526329557437, 0)} -105.131663125821 39.7526329557437 10
21 {(-105.131663125821, 39.7526329557437, 0)} -105.131663125821 39.7527317962905 10
22 {(-105.131663125821, 39.7526329557437, 10)}
23 {(-105.131665500059, 39.7526329557437, 10)} -105.131665500059 39.7527317962905 10
24 {(-105.131665500059, 39.7527317962905, 10)} -105.131665500059 39.7527317962905 10
25 {(-105.131663125821, 39.7527317962905, 10)} -105.131663125821 39.7527317962905 10
26 {(-105.131663125821, 39.7527317962905, 0)} -105.131663125821 39.7527317962905 0
27 {(-105.131665500059, 39.7527317962905, 0)} -105.131665500059 39.7527317962905 0
Comments: Part 1 {(-105.131665500059, 39.7526329557437, 0)} {(-105.131665500059, 39.7526329557437, 10)} {(-105.131665500059, 39.7527317962905, 10)} {(-105.131665500059, 39.7527317962905, 0)} Part 2 {(-105.131663125821, 39.7527317962905, 10)} {(-105.131663125821, 39.7526329557437, 10)} {(-105.131663125821, 39.7526329557437, 0)} {(-105.131663125821, 39.7527317962905, 0)} Part 3 {(-105.131665500059, 39.7527317962905, 0)} {(-105.131663125821, 39.7527317962905, 0)} {(-105.131663125821, 39.7526329557437, 0)} {(-105.131665500059, 39.7526329557437, 0)} Part 4 {(-105.131665500059, 39.7526329557437, 0)} {(-105.131663125821, 39.7526329557437, 0)} {(-105.131663125821, 39.7526329557437, 10)} {(-105.131665500059, 39.7526329557437, 10)} Part 5 {(-105.131665500059, 39.7526329557437, 10)} {(-105.131663125821, 39.7526329557437, 10)} {(-105.131663125821, 39.7527317962905, 10)} {(-105.131665500059, 39.7527317962905, 10)} Part 6 {(-105.131665500059, 39.7527317962905, 10)} {(-105.131663125821, 39.7527317962905, 10)} {(-105.131663125821, 39.7527317962905, 0)} {(-105.131665500059, 39.7527317962905, 0)}