如何在地图上绘制一个矩形网格?

huangapple go评论125阅读模式
英文:

How to plot a rectangular grid on word map?

问题

I've the coordinates(Latitude, Longitude) of the 4 corners of all the 300 grids that I want to plot on the world map. How do I do it in python?

这些网格的坐标(Latitude, Longitude)存储在Excel/CSV文件中,具有以下标题:"Box Number","Top left coordinate","Top right coordinate","Bottom left coordinate" 和 "Bottom right coordinate"。

如何在Python中绘制它?

如何在地图上绘制一个矩形网格?

英文:

I've the coordinates(Latitude, Longitude) of the 4 corners of all the 300 grids that I want to plot on the world map. How do I do it in python?

The grids' coordinates are stored in excel/Csv file with the headers : "Box Number", "Top left coordinate", "Top right coordinate", "Bottom left coordinate" and "Bottom right coordinate".

How do I plot it in python?

如何在地图上绘制一个矩形网格?

答案1

得分: 0

我开发了一种相对灵活的方法来在地图上添加有界的网格线,使用了EOmaps

查看文档以获取更多信息:EOmaps - gridlines

from eomaps import Maps

m = Maps()
m.add_feature.preset.ocean()

for i in range(-180, 180, 20):
    for j in range(-90, 90, 20):
        bounds = [i + 5, i + 15, j + 5, j + 15]
        
        m.add_gridlines(d=2.5, bounds=bounds, c=f"C{i%9}")

如何在地图上绘制一个矩形网格?

英文:

Not sure if this is what you're searching for, but I've developed a rather flexible way to add bounded gridlines to a map with EOmaps:

Check the docs for more info: EOmaps - gridlines

from eomaps import Maps

m = Maps()
m.add_feature.preset.ocean()

for i in range(-180, 180, 20):
    for j in range(-90, 90, 20):
        bounds = [i + 5, i + 15, j + 5, j + 15]
        
        m.add_gridlines(d=2.5, bounds=bounds, c=f"C{i%9}")

如何在地图上绘制一个矩形网格?

答案2

得分: 0

Sure, here is the translated code snippet:

top_left_coordinates = (float(values[2]), float(values[1]))
bottom_right_coordinates = (float(values[2]) - difference, float(values[3]))
folium.Rectangle([top_left_coordinates, bottom_right_coordinates]).add_child(folium.Popup(values[0])).add_to(mapobj)

mapobj.save('map.html')

If you have any more code that needs translation, feel free to ask.

英文:
top_left_coordinates = (float(values[2]),float(values[1]))
bottom_right_coordinates = (float(values[2])- difference,float(values[3]))     
 folium.Rectangle([top_left_coordinates,bottom_right_coordinates]).add_child(folium.Popup(values[0])).add_to(mapobj)

mapobj.save('map.html')

huangapple
  • 本文由 发表于 2023年5月24日 17:53:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322232.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定