【问题标题】:Google map as background to my sharpmap map not aligning correctly谷歌地图作为我的sharpmap地图的背景没有正确对齐
【发布时间】:2016-08-22 12:31:41
【问题描述】:

我在这方面已经有一段时间了。 我在这里想要实现的是将谷歌地图作为背景图层添加到我的 Sharpmap 中,我能够做到这一点,但我现在面临的问题是我的地图总是以谷歌地图中格陵兰海附近的一个点为中心,就好像它不会占用我的中心点坐标。

我正在使用 Sharpmap 1.1 和 BruTile 0.7.4.4

到目前为止,我已经完成了以下操作。

SharpMap.Map _map = new SharpMap.Map();
SharpMap.Layers.VectorLayer layer = new SharpMap.Layers.VectorLayer("parcel");
SharpMap.Data.Providers.MsSqlSpatial DBlayer = new SharpMap.Data.Providers.MsSqlSpatial(_connectionString, "XXXXXX", "XXXX", "XXX");
layer.Style.Fill = new SolidBrush(Color.Transparent);
layer.Style.Outline = new Pen(Color.Black);
layer.Style.EnableOutline = true;
layer.MaxVisible = 13000;

layer.DataSource = DBlayer;

ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
layer.CoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator);
layer.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator, ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84);

//SharpMap.Layers.TileLayer layerBackground = new TileLayer(new BingTileSource(BingRequest.UrlBing, "", BingMapType.Aerial), "TileLayer");
SharpMap.Layers.TileLayer layerBackground = new TileLayer(new GoogleTileSource(GoogleMapType.GoogleMap), "googlemaps");   

_map.Layers.Add(layerBackground);

_map.Layers.Add(layer);

_map.BackColor = Color.White;

//-98.526890,29.411539  
_map.Center = new GeoAPI.Geometries.Coordinate(0,0);

return _map;

即使我手动提供地理坐标,它也只是指向海中的同一地点。

请查看下面的谷歌地图地理点,这是我的地图显示为中心的点。每次我生成时,无论我做什么,它都会以这个点为中心。

71.946088,-3.956171

非常感谢任何帮助。谢谢和干杯!

【问题讨论】:

  • 您确定 DBLayer 提供程序在 WGS84 中吗?如果删除该层会发生什么? DBLayer 覆盖哪个区域?使用 bing 层的 OSM 背景是否也有同样的效果?
  • 是的,图层在 WGS84 中,我使用 QGIS 对其进行了转换。我没有尝试过使用 OSM,但使用 bing 也会发生同样的情况。同一个地方居中。
  • 如果你删除这一行会发生什么?:_map.Layers.Add(layer);
  • 如果我删除它,我只会得到没有我的 shapefile 的谷歌地图,并再次固定到同一位置。我怀疑问题出在坐标变换上,但不知道出了什么问题。
  • 这让我很吃惊。转换仅在图层上。如果您不将图层添加到地图,则图层及其所有属性(转换、数据库提供程序)可能根本不起作用。似乎问题的原因不在您粘贴的代码中。您是否在其他地方设置了 CRS?如果您从一个全新的项目开始,添加一个 google 图层并以 (0,0) 为中心怎么办?当然它必须正确居中。然后添加你在上面代码中配置的层。

标签: google-maps gis sharpmap


【解决方案1】:

我发现 Google 地图图层未居中的问题。 原因是我使用 QGIS 将我的 ESRI shapefile 从 WGS84(EPSG:4326) 格式转换为 Spherical Mercator(EPSG:900913) 并且它改变了坐标格式但是

谷歌地图使用谷歌地图全球墨卡托(Spherical Mercator)。

当我使用在线转换器进行测试时,您可以找到here。当我给出结果坐标时,结果很好。现在我要做的就是找到一种方法来转换谷歌地图全球墨卡托(Spherical Mercator)。 感谢@pauldendulk 的帮助。

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,他们在Examples 中提供了LatLongToGoogle 转换函数

    public static ICoordinateTransformation LatLonToGoogle()
        {
            CoordinateSystemFactory csFac = new CoordinateSystemFactory();
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
            IGeographicCoordinateSystem sourceCs = csFac.CreateGeographicCoordinateSystem(
                "WGS 84",
                AngularUnit.Degrees,
                HorizontalDatum.WGS84,
                PrimeMeridian.Greenwich,
                new AxisInfo("north", AxisOrientationEnum.North),
                new AxisInfo("east", AxisOrientationEnum.East));
    
            List<ProjectionParameter> parameters = new List<ProjectionParameter>
            {
                new ProjectionParameter("semi_major", 6378137.0),
                new ProjectionParameter("semi_minor", 6378137.0),
                new ProjectionParameter("latitude_of_origin", 0.0),
                new ProjectionParameter("central_meridian", 0.0),
                new ProjectionParameter("scale_factor", 1.0),
                new ProjectionParameter("false_easting", 0.0),
                new ProjectionParameter("false_northing", 0.0)
            };
            IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters);
            IProjectedCoordinateSystem targetCs = csFac.CreateProjectedCoordinateSystem(
                "Google Mercator",
                sourceCs,
                projection,
                LinearUnit.Metre,
                new AxisInfo("East", AxisOrientationEnum.East),
                new AxisInfo("North", AxisOrientationEnum.North));
            ICoordinateTransformation transformation = ctFac.CreateFromCoordinateSystems(sourceCs, targetCs);
            return transformation;
    

    【讨论】:

      猜你喜欢
      • 2012-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-06
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2012-06-27
      相关资源
      最近更新 更多