Aspose.GIS Shapes are saving incorrectly in File GeoDatabase.
GetFileReport(), below, is run passing a Dataset populated with a simple SQL query that returns a column named ‘Shape’. Several shapes are drastically distorted when viewing the gdb in QGIS. However, if saving as a shapefile, using the same PolygonFromDbGeometry() function, shapefile works perfectly.
public Polygon PolygonFromDbGeometry(DbGeometry shape) {
LinearRing ext = LinearRingFromDbGeometry(shape.ExteriorRing);
List<LinearRing> interior = new List<LinearRing>();
Polygon p;
if(interior.Count > 0) {
p = new Polygon(ext, interior);
} else {
p = new Polygon(ext);
}
if(!p.IsValid) {
return null;
}
return p;
}
public LinearRing LinearRingFromDbGeometry(DbGeometry shape) {
List<Point> pts = new List<Point>();
DbGeometry pt;
for(int i = 1; i <= shape.PointCount; ++i) {
pt = shape.PointAt(i);
pts.Add(new Point(pt.XCoordinate.Value, pt.YCoordinate.Value));
}
LinearRing ext = new LinearRing(pts);
return ext;
}
public void GetFileReport(DataSet layers, string path) {
using(Dataset ds = Dataset.Create(path, Drivers.Shapefile)) {
foreach(DataTable l in layers.Tables) {
using(var layer = ds.CreateLayer(l.TableName, SpatialReferenceSystem.Wgs84)) {
foreach(DataRow r in l.Rows) {
Feature ft = layer.ConstructFeature();
foreach(DataColumn c in l.Columns) {
if(c.ColumnName == "Shape") {
var sqlgeom = ((SqlGeometry)r[c]);
sqlgeom = sqlgeom.MakeValid();
var g = (DbGeometry)DbGeometry.FromBinary(sqlgeom.AsBinaryZM().Value);
if(g.IsValid) {
if(g.SpatialTypeName.ToLower() == "multipolygon") {
} else if(g.SpatialTypeName.ToLower() == "polygon") {
var geom = PolygonFromDbGeometry(g);
if(geom != null) {
ft.Geometry = geom;
}
}
}
}
}
layer.Add(ft);
}
}
}
}
}