关于sharpmap 的属性查询

梁健禧 发布于 2012/06/17 19:16
阅读 1K+
收藏 0

我的查询代码如下:

private void QueryFeatureByAttri(string sLayerName, string sFieldName, string sFieldValue)

    {
        SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();
        SharpMap.Layers.VectorLayer objVLyr = myMap.Layers[sLayerName] as SharpMap.Layers.VectorLayer;

        if (objVLyr != null)
        {
           
            long count = objVLyr.DataSource.GetFeatureCount();
            if (!objVLyr.DataSource.IsOpen) objVLyr.DataSource.Open();

            SharpMap.Data.FeatureDataRow tempFeat;
            for (uint i = 0; i < count; i++)
            {
               
                tempFeat = objVLyr.DataSource.GetFeature(i);


               

                lblProperty.Text = tempFeat[sFieldName].ToString();//就是这里出现问题,这里得到的是一些奇怪的文字

                if (tempFeat[sFieldName].ToString() == sFieldValue)
                {
                  
                    //高亮度显示该要素
                    SharpMap.Data.FeatureDataTable tempTable = new SharpMap.Data.FeatureDataTable();
                    tempTable = (tempFeat.Table as SharpMap.Data.FeatureDataTable).Clone();
                    tempTable.LoadDataRow(tempFeat.ItemArray, false);
                    FeatureDataRow tempRow;
                    tempRow = tempTable.Rows[tempTable.Rows.Count - 1] as FeatureDataRow;
                    tempRow.Geometry = tempFeat.Geometry;


                    SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("Selection");
                    laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(tempTable);
                    laySelected.Style.Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow);
                    myMap.Layers.Add(laySelected);
                    //显示该要素的其他属性
                    lblProperty.Text = "<table width='95%' border='0' cellpadding='0' cellspacing='0' align='center'>";

                    lblProperty.Text += "<tr><td colspan='2' heigth='25'><b>属性:</b></td></tr>";
                    for (int j = 0; j < tempFeat.Table.Columns.Count; j++)
                    {
                        // lblProperty.Text += tempFeat.Table.Columns[i].ColumnName+ " " +tempFeat[i].ToString()+" "
                        lblProperty.Text += "<tr><td>" + tempFeat.Table.Columns[j].ColumnName;
                        lblProperty.Text += "</td><td>" + tempFeat[j].ToString() + "</td></tr>";
                    }
                    lblProperty.Visible = true;
                    break;

                }
            }

        }

    }

 

 

就因为tempFeat[sFieldName].ToString()得到的是一些奇怪的文字,最后导致查询不了,我想知道是因为我的软件问题吗?我用的是vs2010

加载中
0
q
qiulei_21
你是不是用的shapefile文件做的数据源,如果是的话,你这里就要转换一下,转换成你之前的数据,也就是读shapefile的过程,然后就能显示成功了
返回顶部
顶部