如何获得几何点使用地理API (Sharpmap)
本文关键字:API Sharpmap 何获得 何点使 | 更新日期: 2023-09-27 18:05:58
我有一个EPSG:4326 WGS 84 Shapefile,我已经将其转换为Sql空间数据,我能够使用sharpmap 1.1(以前使用sharpmap 0.9)渲染地图。
我想要实现的是,当我点击一个生成的多边形,点击多边形必须填充颜色(为了识别的目的),所以我能够得到我点击的点,但如何使用那个点,并查询多边形内的所有点,以便我可以为所有的点上色,这可能导致所有的多边形上色。
问题是我不知道如何在sharpmap 1.1版本中做到这一点。
以前当我使用Sharpmap 0.9时,我使用下面的线来获取所有的点来为整个多边形上色。
pointArray.Collection.Add (SharpMap.Geometries.LinearRing.GeomFromWKB ((byte[])行[" the_geom "]));
我的数据来自Sql空间数据库,因此行["the_geom"]。
到目前为止,我已经这样做了。(只突出点,需要将点添加到Geo API集合中) Collection<GeoAPI.Geometries.IGeometry> geomColl = new Collection<GeoAPI.Geometries.IGeometry>();
GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();
GeoAPI.Geometries.IGeometryFactory gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();
SharpMap.Layers.VectorLayer mySuggestedLayer = new SharpMap.Layers.VectorLayer("Higlight");
fillcolor = shapeFillColor;
var factory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(_SRID);
var pointArraySubject = factory.CreateGeometryCollection(null);
var mySubjectLayer = new SharpMap.Layers.VectorLayer("SubjectIcon");
DataRow Row = accounts.NewRow();
for (int i = 0; i < accounts.Rows.Count; i++)
{
Row = accounts.Rows[i];
GeoAPI.Geometries.Coordinate PinPnt = new GeoAPI.Geometries.Coordinate();
double x = Double.Parse(Row["Xcoord_geo"].ToString());
double y = Double.Parse(Row["Ycoord_geo"].ToString());
PinPnt.X = x;
PinPnt.Y = y;
//pointArray.Collection.Add(SharpMap.Geometries.LinearRing.GeomFromWKB((byte[])Row["the_geom"]));
geomColl.Add(gf.CreatePoint(PinPnt));
mySuggestedLayer.DataSource = new SharpMap.Data.Providers.GeometryFeatureProvider(geomColl);
mySuggestedLayer.Style.Fill = new System.Drawing.SolidBrush(fillcolor);
mySuggestedLayer.Style.EnableOutline = true;
mySuggestedLayer.SRID = _SRID;
_map.Layers.Add(mySuggestedLayer);
return _map;
任何主意/帮助都会使我很高兴。
在Sharpmap的FObermaier的帮助下,我自己解决了这个问题,我把它贴出来,也许能帮到别人。
问题在于层的几何变换
似乎转换格式错误
GeoAPI.Geometries.Coordinate PinPnt = new GeoAPI.Geometries.Coordinate();
NetTopologySuite.IO.WKBReader reader = new NetTopologySuite.IO.WKBReader();
var wkb = (byte[])Row["the_geom"];
Geometry geom = (Geometry)reader.Read(wkb);
var p = new GeometryFeatureProvider(geom);
myLayer.DataSource = p;
myLayer.Style.Fill = new System.Drawing.SolidBrush(fillcolor);
ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
myLayer.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
myLayer.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84);
_map.Layers.Add(myLayer);
在上面
行("the_geom")
有需要高亮显示的图层。使用ProjNet,我已经将几何体转换为web墨卡托,它工作了。