【问题标题】:mapping geo points on picture map在图片地图上绘制地理点
【发布时间】:2020-06-30 04:57:34
【问题描述】:

有如下图:

我有一个点列表,我想将它们映射到这个 png 地图中 我知道图片的边界框: [52.00198088, 35.66569172, 52.08012633, 35.74706129]

我怎样才能把我的点放在下面的地图上?

我的意思是如何将纬度/经度转换为像素?

图片尺寸为600x600

我只是将 min 和 max 点的差除以 600 但结果图片不正确:

谁能帮帮我????

【问题讨论】:

    标签: python geometry mapbox geospatial geojson


    【解决方案1】:

    喂,

    这是程序...

    你知道图片的边界框...按照以下步骤操作

    1. 将左上角的纬度和经度转换为 UTM(东距和北距)。在 python 中,它很容易使用 UTM 库进行转换。现在以米为单位。
    2. 现在,如果您知道像素的分辨率,即图像每像素多少米,那么就知道您必须移动多少像素。
    3. 向右移动,您必须将东向的每像素米数添加到左上角,向下移动,您必须减去北向的每像素米数。
    4. 如果您在经纬度地图中有某个点,并且您想去那里,那么只需将该点也转换为 UTM(东、北),然后使用毕达哥拉斯定理找出您必须向左和向下移动多少像素方向。

    那个。如果您需要更多帮助,我可以解释更多...

    祝你好运

    【讨论】:

    • 如果我的图片在多个 utm 区域怎么办?
    • 图片这么小。您必须知道它在一个区域中。即使对于这么小的图片,它也会在两个区域中,也可以处理
    • 你能看看gitlab.com/pixozeus/geo/-/blob/master/utm吗,我也不知道你用毕达哥拉斯定理为我的观点找到合适的像素
    • 在您的gitlab.com/pixozeus/geo/-/blob/master/utm,您计算的 x_position 和 y_position 是 delata_x 和 delta_y。在这一步之后,您必须将其添加到 top_x 和 top_y 以获得最终位置。如果您喜欢答案,请接受答案并使其有用。
    • x_position 和 y_position 以像素为单位,但如果我将 top_x 和 top_y 添加到它们我会改变,我需要像素来找到图片上的正确位置
    【解决方案2】:

    你能添加你的代码吗?

    如果您的边界框是正确的,那么来自Mapbox 的以下代码将在 JS 中执行您喜欢的操作。只需将图片 URL 替换为您的 URL,并指定正确的边界框即可。

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8" />
    <title>Add an image</title>
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <script src="https://api.mapbox.com/mapbox-gl-js/v1.11.0/mapbox-gl.js"></script>
    <link href="https://api.mapbox.com/mapbox-gl-js/v1.11.0/mapbox-gl.css" rel="stylesheet" />
    <style>
        body { margin: 0; padding: 0; }
        #map { position: absolute; top: 0; bottom: 0; width: 100%; }
    </style>
    </head>
    <body>
    <div id="map"></div>
    <script>
        mapboxgl.accessToken = '<ACCESS_TOKEN>';
        var mapStyle = {
            'version': 8,
            'name': 'Dark',
            'sources': {
                'mapbox': {
                    'type': 'vector',
                    'url': 'mapbox://mapbox.mapbox-streets-v8'
                },
                'overlay': {
                    'type': 'image',
                    'url': 'https://docs.mapbox.com/mapbox-gl-js/assets/radar.gif',
                    'coordinates': [
                        [-80.425, 46.437],
                        [-71.516, 46.437],
                        [-71.516, 37.936],
                        [-80.425, 37.936]
                    ]
                }
            },
            'sprite': 'mapbox://sprites/mapbox/dark-v10',
            'glyphs': 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf',
            'layers': [
                {
                    'id': 'background',
                    'type': 'background',
                    'paint': { 'background-color': '#111' }
                },
                {
                    'id': 'water',
                    'source': 'mapbox',
                    'source-layer': 'water',
                    'type': 'fill',
                    'paint': { 'fill-color': '#2c2c2c' }
                },
                {
                    'id': 'boundaries',
                    'source': 'mapbox',
                    'source-layer': 'admin',
                    'type': 'line',
                    'paint': {
                        'line-color': '#797979',
                        'line-dasharray': [2, 2, 6, 2]
                    },
                    'filter': ['all', ['==', 'maritime', 0]]
                },
                {
                    'id': 'overlay',
                    'source': 'overlay',
                    'type': 'raster',
                    'paint': { 'raster-opacity': 0.85 }
                },
                {
                    'id': 'cities',
                    'source': 'mapbox',
                    'source-layer': 'place_label',
                    'type': 'symbol',
                    'layout': {
                        'text-field': '{name_en}',
                        'text-font': ['DIN Offc Pro Bold', 'Arial Unicode MS Bold'],
                        'text-size': [
                            'interpolate',
                            ['linear'],
                            ['zoom'],
                            4,
                            9,
                            6,
                            12
                        ]
                    },
                    'paint': {
                        'text-color': '#969696',
                        'text-halo-width': 2,
                        'text-halo-color': 'rgba(0, 0, 0, 0.85)'
                    }
                },
                {
                    'id': 'states',
                    'source': 'mapbox',
                    'source-layer': 'place_label',
                    'type': 'symbol',
                    'layout': {
                        'text-transform': 'uppercase',
                        'text-field': '{name_en}',
                        'text-font': ['DIN Offc Pro Bold', 'Arial Unicode MS Bold'],
                        'text-letter-spacing': 0.15,
                        'text-max-width': 7,
                        'text-size': [
                            'interpolate',
                            ['linear'],
                            ['zoom'],
                            4,
                            10,
                            6,
                            14
                        ]
                    },
                    'filter': ['==', ['get', 'class'], 'state'],
                    'paint': {
                        'text-color': '#969696',
                        'text-halo-width': 2,
                        'text-halo-color': 'rgba(0, 0, 0, 0.85)'
                    }
                }
            ]
        };
    
        var map = new mapboxgl.Map({
            container: 'map',
            maxZoom: 5.99,
            minZoom: 4,
            zoom: 5,
            center: [-75.789, 41.874],
            style: mapStyle
        });
    </script>
    
    </body>
    </html>

    【讨论】:

      【解决方案3】:

      对于 mapbox,您可以使用他们的静态图像 API

      https://docs.mapbox.com/help/how-mapbox-works/static-maps/

      使用 Playground 测试生成的 URL 的外观

      https://docs.mapbox.com/playground/static/

      作为示例,以下 kotlin 代码在地图上放置引脚和路线

      https://github.com/yschimke/okurl/blob/master/src/main/kotlin/com/baulsupp/okurl/services/mapbox/mapbox.kt

      https://github.com/yschimke/okurl/blob/master/src/test/kotlin/commands/uberprices.kts

      n.b.你需要一个合适的商业 Uber 访问令牌来运行代码。

      【讨论】:

      • 这对我没有帮助,因为我需要自定义标记图标,而且我应该能够用其他地图 api 替换 mapbox 地图,所以我需要找到一种通过代码手动完成的方法
      • 此回复未回答此问题。也许另一个..
      • 原始示例是使用 mapbox 图像。这是执行 OP 要求的官方方式。如果它不适合并且他们想手动完成所有操作,那么可以确定。但我已经完全按照 OP 的要求完成了使用上述 API 的操作,而且编写代码很简单。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-17
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-26
      • 2013-10-17
      相关资源
      最近更新 更多