如何将DataSet转换为FeatureDataSet

时间:2014-02-27 14:26:03

标签: sharpmap

我正在尝试将数据集中的几何数据转换为特色数据集:

private void QueryCustomer(DataSet ds)
        {

            SharpMap.Data.FeatureDataSet ds_feature = new SharpMap.Data.FeatureDataSet();

            ds_feature = (SharpMap.Data.FeatureDataSet)ds;  // ERROR HERE
..

我得到了:

无法将'System.Data.DataSet'类型的对象强制转换为'SharpMap.Data.FeatureDataSet'

任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:1)

无需创建DataSet。只需使用FeatureDataSet直接从SqLite获取表格:

double x, y;
FeatureDataSet fds = new FeatureDataSet();
Envelope env = new Envelope(double.MinValue, double.MaxValue, double.MinValue, double.MaxValue); 

SharpMap.Data.Providers.ManagedSpatiaLite p = new ManagedSpatiaLite(ConnectionString, Table, GeometryColumn.ToUpper(), KeyColumn.ToUpper()); 
p.Open();
p.ExecuteIntersectionQuery(env, fds);
foreach (FeatureDataRow fdr in ((FeatureDataTable)fds.Tables[0]).Rows)
{
x = fdr.Geometry.Centroid.X;
y = fdr.Geometry.Centroid.Y;
//...process x and y here...
}
p.Close();
p.Dispose();