Quantcast
Channel: DotSpatial Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 1128

Commented Unassigned: After creating shapefile from db the geometry coordinate becomes reverse order. [63622]

$
0
0
I have a database table named 'hitbgt'. There is a column name 'the_geom' contains the geometry value. Get the data from db table as datatable and create a shapefile based on it. The codes are given below..........

DataTable dt = new DataTable();

DbHandeler dbHandelerObj = new DbHandeler();
string query = "Select st_asBinary(the_geom) as geom, * from hitbgt";

try
{
dt = dbHandelerObj.GetDataTable(query);

IFeature feature = new Feature();
FeatureSet fs = new FeatureSet(FeatureType.Polygon);

foreach (DataColumn dc in dt.Columns)
{
if (dc.ColumnName != "the_geom" && dc.ColumnName != "geom")
{
fs.DataTable.Columns.Add(dc.ColumnName, dc.DataType);
}
}

foreach (DataRow dr in dt.Rows)
{

Byte[] data = (Byte[])dr["geom"];

WkbReader wkbReader = new WkbReader();
IGeometry geometry = wkbReader.Read(data);

feature = fs.AddFeature(geometry);

feature.DataRow.BeginEdit();
foreach (DataColumn dc in fs.DataTable.Columns)
{
feature.DataRow[dc.ColumnName] = dr[dc.ColumnName];
}
feature.DataRow.EndEdit();
}

fs.SaveAs("F:\\Test_value\\hitbgt_test.shp", true);
fs.Close();

MessageBox.Show("Done");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

Everything work fine. But when I retrieve the geom data from shapefile, the polygon coordinate values show reverse clockwise as in database.
IList<Coordinate> shapeCorList = null;
IFeatureSet fb = FeatureSet.Open("F:\\Test_value\\hitbgt_test.shp");
foreach (IFeature ff in fb.Features)
{
if (ff.DataRow["cadid"].ToString() == "12345")
{
shapeGeometry = ff.BasicGeometry as IGeometry;
shapeCorList = shapeGeometry.Coordinates;
}
}
Example:
Db geometry:
"POLYGON((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))"
Shape Geometry:
"MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10),(20 30,30 20,35 35,20 30)))"

Anyone please help.........

Comments: I drew the coordinates and came up with a quadrangle with a hole in form of a triangle. Based on this I can say that the order of the multipolygon's coordinates looks alright. The shapefiles definition says that polygon shells (the quadrangle) are orientated clockwise and holes (the tirangle) are orientated counterclockwise. And your multipolygon conforms to that definition. It is possible that the definition your database uses to store polygons differs from the definition that is used to store polygons in shapefiles. That could explain why the coordinates of your databases polygon are in reverse order. The problem that I see is that you got a multipolygon instead of a polygon with a hole. So could you please post the content of the Byte[] data object you gave to wkbReader for me to have a look why wkbReader creates a MultiPolygon from this.

Viewing all articles
Browse latest Browse all 1128

Trending Articles



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