0

我刚开始使用 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)
    {

    }
}

}

4

1 回答 1

0

X 和 Y 应该相反:

geomColl.Add(gf.CreatePoint(new GeoAPI.Geometries.Coordinate(-3.6690416, 40.4177623)));
于 2016-01-18T21:06:46.120 回答