我刚刚开始使用Sharpmap,但我遇到了问题。我无法使用此库在地图上打印点(甚至不能打印一个点)。
我没有找到一个很好的例子,我的代码无效。它距离应该的位置太远(西班牙马德里)。
如果有人知道如何使用它,我将不胜感激。
这是我的代码:
namespace TestsSharpmapForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
VectorLayer vlay = new VectorLayer("Spain");
vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(@"ESP_adm_shp\ESP_adm2.shp", true);
VectorLayer vlay2 = new VectorLayer("Points");
Collection<GeoAPI.Geometries.IGeometry> geomColl = new Collection<GeoAPI.Geometries.IGeometry>();
//Get the default geometry factory
GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();
GeoAPI.Geometries.IGeometryFactory gf =
GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();
geomColl.Add(gf.CreatePoint(new GeoAPI.Geometries.Coordinate(40.4177623, -3.6690416)));
vlay2.DataSource = new SharpMap.Data.Providers.GeometryProvider(geomColl);
mapBox1.Map.Layers.Add(vlay);
mapBox1.Map.Layers.Add(vlay2);
//ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
//vlay.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
//vlay.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84);
mapBox1.Map.ZoomToExtents();
mapBox1.Refresh();
mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
Image imgMap = mapBox1.Map.GetMap();
}
private void mapBox1_Click(object sender, EventArgs e)
{
}
}
}
答案 0 :(得分:0)
X和Y应该相反:
geomColl.Add(gf.CreatePoint(new GeoAPI.Geometries.Coordinate(-3.6690416, 40.4177623)));