SharpMap使用GeoAPI.Geometries选择几何

时间:2012-12-30 15:34:28

标签: c# spatial sharpmap geoapi

在那里,我正在尝试创建一个函数,它将选择图层几何体并更改其颜色或突出显示它。

我找到了FindGeoNearPoint函数,但是它处理的旧版SharpMap.Geometries已不再存在,并且已被GeoAPI.Geometries取代。

如何更改FindGeoNearPoint功能以使用GeoAPI

这是我的尝试

     public SharpMap.Data.FeatureDataRow FindGeoNearPoint(GeoAPI.Geometries.IPoint pos, SharpMap.Layers.VectorLayer layer, double amountGrow)
    {

        GeoAPI.Geometries.Envelope bbox = new GeoAPI.Geometries.Envelope();
        SharpMap.Data.FeatureDataSet ds = new SharpMap.Data.FeatureDataSet();

        layer.DataSource.ExecuteIntersectionQuery(bbox, ds);

        DataTable tbl = ds.Tables[0] as SharpMap.Data.FeatureDataTable;

        NetTopologySuite.IO.WKTReader reader = new NetTopologySuite.IO.WKTReader();

        GeoAPI.Geometries.IGeometry point = reader.Read(pos.ToString());

        if (tbl.Rows.Count == 0)

            return null;



        double distance = point.Distance(reader.Read((tbl.Rows[0] as SharpMap.Data.FeatureDataRow).Geometry.ToString()));

        SharpMap.Data.FeatureDataRow selectedFeature = tbl.Rows[0] as SharpMap.Data.FeatureDataRow;



        if (tbl.Rows.Count > 1)

            for (int i = 1; i < tbl.Rows.Count; i++)
            {

                GeoAPI.Geometries.IGeometry line = reader.Read((tbl.Rows[i] as SharpMap.Data.FeatureDataRow).Geometry.ToString());

                if (point.Distance(line) < distance)
                {

                    distance = point.Distance(line);

                    selectedFeature = tbl.Rows[i] as SharpMap.Data.FeatureDataRow;

                }

            }

        return selectedFeature;

    }

0 个答案:

没有答案