09 csv to points

Converting CSV to points
Uncomment the following line to install leafmap if needed.
This notebook example requires the ipyleaflet plotting backend. Folium is not supported.
| import os
import leafmap.leafmap as leafmap
|
Read a CSV as a Pandas DataFrame.
| in_csv = "https://raw.githubusercontent.com/opengeos/data/main/world/world_cities.csv"
|
| df = leafmap.csv_to_df(in_csv)
df
|
Create a point layer from a CSV file containing lat/long information.
| Map = leafmap.Map()
Map.add_xy_data(in_csv, x="longitude", y="latitude", layer_name="World Cities")
Map
|
Set the output directory.
| out_dir = os.path.expanduser("~/Downloads")
if not os.path.exists(out_dir):
os.makedirs(out_dir)
out_shp = os.path.join(out_dir, "world_cities.shp")
|
Convert a CSV file containing lat/long information to a shapefile.
| leafmap.csv_to_shp(in_csv, out_shp)
|
| out_geojson = os.path.join(out_dir, "world_cities.geojson")
leafmap.csv_to_geojson(in_csv, out_geojson)
|
Convert a CSV file containing lat/long information to a GeoPandas GeoDataFrame.
| # gdf = leafmap.csv_to_gdf(in_csv)
# gdf
|