小言_互联网的博客

ChatGPT 为我制作了一张地图

514人阅读  评论(0)

  

有人说:一个人从1岁活到80岁很平凡,但如果从80岁倒着活,那么一半以上的人都可能不凡。

生活没有捷径,我们踩过的坑都成为了生活的经验,这些经验越早知道,你要走的弯路就会越少。 


今天在刷视频的时候看到了我订阅的Youtube博主更新了,感觉内容蛮有用的,就分享给大家

原视频链接如下,打开需要魔法

https://www.youtube.com/watch?v=iNHQgLw7qZc

数据说明

本数据采用的是中国的机场数据,数据来源ourairports,该数据详细介绍可参考下列内容

https://mp.weixin.qq.com/s/YFEEphaNWHhFXhjzGe89qw

这是该网站上内嵌的web机场地图,正在本期教程中,我们将让ChatGPT来制作这样一份地图

 

数据比较杂乱,注意记住这三列就可以

代码编写

交互式地图绘制

作为一个对话型AI,当然需要告诉他我使用什么数据,什么平台,什么编程语言完成地图,让我们见识一下ChatGPT的能力吧

 

修改一下文件路径,然后运行程序


  
  1. import pandas  as pd
  2. import geopandas  as gpd
  3. from folium import Map, Marker
  4. Read the CSV  file  into a DataFrame
  5. df  = pd. read_csv(r "C:\Users\zheyu\Desktop\cn-airports.csv")
  6. # Convert the DataFrame  to a GeoDataFrame
  7. gdf  = gpd.GeoDataFrame(
  8.     df, 
  9.     geometry =gpd.points_ from_xy(df.longitude_deg, df.latitude_deg)
  10. )
  11. # Create an instance  of the Folium Map  class
  12. m  = Map( location =[df.latitude_deg.mean(), df.longitude_deg.mean()])
  13. # Iterate over the rows  of the GeoDataFrame
  14. for i, row  in gdf.iterrows():
  15.     Marker( location =[row.latitude_deg, row.longitude_deg], popup =row.name). add_ to(m)
  16. # Save the map  to an HTML  file
  17. m.save( "map.html")

然后在桌面就会生成一个map.html,你可以使用任何网络浏览器打开

显示的数据多是因为包含了直升机机场

 

筛选需要的数据

在数据中type列是机场属性,接下来就让ChatGPT教我如何显示筛选出的大型机场吧

 

这是ChatGPT修改后的代码


  
  1. import pandas  as pd
  2. import geopandas  as gpd
  3. from folium import Map, Marker
  4. Read the CSV  file  into a DataFrame
  5. df  = pd. read_csv(r "C:\Users\zheyu\Desktop\cn-airports.csv")
  6. # Filter the DataFrame  to only include rows  with  "type"  value  "large_airport"
  7. df  = df[df. type  = =  "large_airport"]
  8. # Convert the DataFrame  to a GeoDataFrame
  9. gdf  = gpd.GeoDataFrame(
  10.     df, 
  11.     geometry =gpd.points_ from_xy(df.longitude_deg, df.latitude_deg)
  12. )
  13. # Create an instance  of the Folium Map  class
  14. m  = Map( location =[gdf.latitude_deg.mean(), gdf.longitude_deg.mean()])
  15. # Iterate over the rows  of the filtered GeoDataFrame
  16. for i, row  in gdf.iterrows():
  17.     Marker( location =[row.latitude_deg, row.longitude_deg], popup =row.name). add_ to(m)
  18. # Save the map  to an HTML  file
  19. m.save( "map.html")

默认使用的是osm作为背景

 

修改web地图图层

ChatGPT切换成卫星影像

ChatGPT具有上下文多轮会话能力,这太神奇了

 

生成的代码如下


  
  1. import pandas  as pd
  2. import geopandas  as gpd
  3. from folium import Map, Marker
  4. Read the CSV  file  into a DataFrame
  5. df  = pd. read_csv(r "C:\Users\zheyu\Desktop\cn-airports.csv")
  6. # Filter the DataFrame  to only include rows  with  "type"  value  "large_airport"
  7. df  = df[df. type  = =  "large_airport"]
  8. # Convert the DataFrame  to a GeoDataFrame
  9. gdf  = gpd.GeoDataFrame(
  10.     df, 
  11.     geometry =gpd.points_ from_xy(df.longitude_deg, df.latitude_deg)
  12. )
  13. # Create an instance  of the Folium Map  class
  14. m  = Map( location =[gdf.latitude_deg.mean(), gdf.longitude_deg.mean()], tiles = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', attr = 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community')
  15. # Iterate over the rows  of the filtered GeoDataFrame
  16. for i, row  in gdf.iterrows():
  17.     Marker( location =[row.latitude_deg, row.longitude_deg], popup =row.name). add_ to(m)
  18. # Save the map  to an HTML  file
  19. m.save( "map.html")

结语

 

ChatGPT的功能不仅仅是制作这种简单的交互式地图,他在很多领域有着非常大的应用,我们行业内就有大佬用它写标书,写规划大纲,他很大程度上减轻了我们的重复劳动。

在遥感和GIS领域,我看到他巨大的潜力,特别是作为编写代码修改BUG的工具方面,他会给我们提供非常有用的指导,在未来 的地理空间分析学习工程中,我将尝试把ChatGPT带给你们,展现出在AI帮助下我们的工作将会变得更加轻松

 这些程序员职场“潜规则”,让你少走5年弯路_【官方推荐】唐城的博客-CSDN博客


   一边赶路,一边寻找出路,希望大家在每个幸福的日子里,都能快乐前行。



转载:https://blog.csdn.net/qq_41570658/article/details/128905957
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场