1

我有一个名为“hitbgt”的数据库表。有一列名称“the_geom”包含几何值。从 db 表中获取数据作为数据表并基于它创建一个 shapefile。代码如下......

        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);
        }

一切正常。但是当我从 shapefile 检索几何数据时,多边形坐标值显示为逆时针,如数据库中一样。

        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;     
            }
        }

示例:Db 几何:“POLYGON((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))” 形状几何:“MULTIPOLYGON(((35 10) ,10 20,15 40,45 45,35 10),(20 30,30 20,35 35,20 30)))"

任何人请帮助......

我对此感到困扰,因为它需要比较......

        foreach (DataRow dr in dt.Rows)
        {
            if (dr["cadid"].ToString() == "12345")
            {
                dbGeometry = reader.Read((Byte[])dr["geom"]);
                dbCorList = dbGeometry.Coordinates;                    
            }
        }          
        foreach (IFeature ff in fb.Features)
        {
            if (ff.DataRow["cadid"].ToString() == "12345")
            {
                shapeGeometry = ff.BasicGeometry as IGeometry;
                shapeCorList = shapeGeometry.Coordinates;
            }
        }

        bool equal = dbCorList.SequenceEqual(shapeCorList);
4

1 回答 1

2

不是比较 WKT 字符串,而是将每个多边形加载到一个对象中并比较对象。 IGeometry.Equals不应该关心排序。

于 2016-03-15T14:12:29.643 回答