首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何解决mplleaflet.show的问题?

如何解决mplleaflet.show的问题?
EN

Stack Overflow用户
提问于 2022-10-15 21:42:48
回答 1查看 58关注 0票数 0

我想学习用python绘制地图&网格。我找到了https://smarte-mobilitaet-blog.ftm.mw.tum.de/index.php/2019/09/17/coordinate-systems-projections-grids-and-visualization-in-python-practical-guide/第5步。

代码语言:javascript
复制
import geopandas as gpd
import mplleaflet
from math import ceil
from shapely.geometry import box
__author__ = "Lennart Adenaw"
__copyright__ = "Copyright 2019, Lennart Adenaw"
__credits__ = ["Lennart Adenaw"]
__license__ = "GNU Lesser General Public License v3.0 "
__version__ = "0.0.1"
__maintainer__ = "Lennart Adenaw"
__email__ = "adenaw@ftm.mw.tum.de"
###############################
#### OPTIONS                ####
###############################
# Define coordinate reference systems to use
METRIC_EPSG = {'init': 'epsg:31468'} # Gauss-Krueger Zone 4
WGS84_EPSG = {'init': 'epsg:4326'} # WGS 84 (GPS)
# Define bounding box in WGS84 (GPS) coordinates
MINX_MUC = 11.38
MAXX_MUC = 11.80
MINY_MUC = 48.00
MAXY_MUC = 48.25
# Define the number of rows and colums in the grid
N_ROWS = 25
N_COLS = 25
###############################
#### FUNCTIONS             ####
###############################
# Defines a function to create a grid inside a bounding box given by (minx, miny, maxx, maxy). Only Metric coordinates are allowed!

def createGrid(minx_grid, miny_grid, maxx_grid, maxy_grid, N_rows, N_cols):
    
    # Grid size
    grid_width = maxx_grid-minx_grid
    grid_height = maxy_grid-miny_grid
    
    # Cell size
    cell_width = grid_width/N_cols
    cell_height = grid_height/N_rows
    
    # Define grid origin as upper left grid corner
    origin_y = maxy_grid
    origin_x = minx_grid
    
    # Create grid cells
    grid_cells = []
    for i in range(N_rows): # For each row
        
        cell_origin_y = origin_y - i * cell_height # Calculate the current y coordinate
        
        for j in range(N_cols): # Create all cells in row
        
            cell_origin_x = origin_x + j * cell_width # Calculate the current x coordinate
            
            minx_cell = cell_origin_x
            miny_cell = cell_origin_y - cell_height
            maxx_cell = cell_origin_x + cell_width
            maxy_cell = cell_origin_y
            
            grid_cells.append(box(minx_cell, miny_cell, maxx_cell, maxy_cell)) # Store the new cell
            
    # Create a GeoDataFrame containing the grid
    grid = gpd.GeoDataFrame(geometry=grid_cells)
    
    return grid, cell_width,  cell_height
    
###############################
#### SCRIPT                ####
###############################
    
# Bounding box as geopandas dataframe
muc = gpd.GeoDataFrame(geometry=[box(MINX_MUC, MINY_MUC, MAXX_MUC, MAXY_MUC)])
muc.crs = WGS84_EPSG
# Transformation to a metric crs
muc = muc.to_crs(METRIC_EPSG)
# Retrieving the transformed coordinates
muc_bounds = muc.total_bounds
# Create the grid using the munich bounding box
grid, cell_width_m, cell_height_m = createGrid(muc_bounds[0], muc_bounds[1], muc_bounds[2], muc_bounds[3], N_ROWS, N_COLS)
grid.crs = METRIC_EPSG
# Transform the grid back to the WGS84 system
grid = grid.to_crs(WGS84_EPSG)
# Plot the result using mplleaflet
ax = grid.plot(edgecolor='k')
mplleaflet.show(fig=ax.figure, crs=grid.crs, path='grid_map.html')
# Print the resulting sizes of the grid cells
print("Grid Statistics\nCell Width [m]: {}\nCell Height [m]: {}".format(cell_width_m, cell_height_m))

不幸的是,我遇到了一个错误:“在**后面输入对象参数必须是映射,而不是CRS”。我尝试了与mplleaflet.show()进行不同的组合,但没有成功。

你能帮我吗?你能推荐另一套来绘制地图吗?

下面我添加了回溯:

代码语言:javascript
复制
Traceback (most recent call last):

  Input In [1] in <cell line: 84>
    mplleaflet.show(fig=ax.figure, crs=grid.crs, path='grid_map.html')

  File C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\_display.py:180 in show
    save_html(fig, fileobj=f, **kwargs)

  File C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\_display.py:131 in save_html
    html = fig_to_html(fig, **kwargs)

  File C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\_display.py:82 in fig_to_html
    renderer = LeafletRenderer(crs=crs, epsg=epsg)

  File C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\leaflet_renderer.py:26 in __init__
    proj_in = pyproj.Proj(preserve_units=True, **crs)

TypeError: type object argument after ** must be a mapping, not CRS
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-17 04:59:06

薄荷叶是一个非常古老和没有维护的项目。上一次承诺发生在2018年3月。坦白说,我很惊讶你能安装它。

您应该能够在带有geopandas.GeoDataFrame.explore的传单地图上绘制地理数据图,例如在您的例子中:

代码语言:javascript
复制
grid.explore()

有关更多信息和示例,请参阅地质公园中的交互式映射指南。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74083245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档