74 csv to points
Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
In [2]:
Copied!
import os
import geemap
import os
import geemap
In [3]:
Copied!
# geemap.update_package()
# geemap.update_package()
In [4]:
Copied!
Map = geemap.Map()
Map
Map = geemap.Map()
Map
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [5]:
Copied!
in_csv = 'https://raw.githubusercontent.com/giswqs/data/main/world/world_cities.csv'
in_csv = 'https://raw.githubusercontent.com/giswqs/data/main/world/world_cities.csv'
In [6]:
Copied!
df = geemap.csv_to_pandas(in_csv)
df
df = geemap.csv_to_pandas(in_csv)
df
Out[6]:
id | name | country | latitude | longitude | population | |
---|---|---|---|---|---|---|
0 | 1 | Bombo | UGA | 0.58330 | 32.53330 | 75000 |
1 | 2 | Fort Portal | UGA | 0.67100 | 30.27500 | 42670 |
2 | 3 | Potenza | ITA | 40.64200 | 15.79900 | 69060 |
3 | 4 | Campobasso | ITA | 41.56300 | 14.65600 | 50762 |
4 | 5 | Aosta | ITA | 45.73700 | 7.31500 | 34062 |
... | ... | ... | ... | ... | ... | ... |
1244 | 1245 | Rio de Janeiro | BRA | -22.92502 | -43.22502 | 11748000 |
1245 | 1246 | Sao Paulo | BRA | -23.55868 | -46.62502 | 18845000 |
1246 | 1247 | Sydney | AUS | -33.92001 | 151.18518 | 4630000 |
1247 | 1248 | Singapore | SGP | 1.29303 | 103.85582 | 5183700 |
1248 | 1249 | Hong Kong | CHN | 22.30498 | 114.18501 | 7206000 |
1249 rows × 6 columns
In [7]:
Copied!
Map.add_xy_data(in_csv, x="longitude", y="latitude", layer_name="csv to ee", to_ee=True)
Map.add_xy_data(in_csv, x="longitude", y="latitude", layer_name="csv to ee", to_ee=True)
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [7], in <cell line: 1>() ----> 1 Map.add_xy_data(in_csv, x="longitude", y="latitude", layer_name="csv to ee", to_ee=True) AttributeError: 'Map' object has no attribute 'add_xy_data'
In [8]:
Copied!
fc = geemap.csv_to_ee(in_csv)
fc = geemap.csv_to_ee(in_csv)
In [9]:
Copied!
Map.addLayer(fc, {}, 'csv to ee 2')
Map.addLayer(fc, {}, 'csv to ee 2')
In [10]:
Copied!
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')
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')
In [11]:
Copied!
geemap.csv_to_shp(in_csv, out_shp)
geemap.csv_to_shp(in_csv, out_shp)
In [12]:
Copied!
out_geojson = os.path.join(out_dir, 'world_cities.geojson')
geemap.csv_to_geojson(in_csv, out_geojson)
out_geojson = os.path.join(out_dir, 'world_cities.geojson')
geemap.csv_to_geojson(in_csv, out_geojson)
In [13]:
Copied!
gdf = geemap.csv_to_geopandas(in_csv)
gdf
gdf = geemap.csv_to_geopandas(in_csv)
gdf
Out[13]:
id | name | country | latitude | longitude | population | geometry | |
---|---|---|---|---|---|---|---|
0 | 1 | Bombo | UGA | 0.58330 | 32.53330 | 75000 | POINT (32.53330 0.58330) |
1 | 2 | Fort Portal | UGA | 0.67100 | 30.27500 | 42670 | POINT (30.27500 0.67100) |
2 | 3 | Potenza | ITA | 40.64200 | 15.79900 | 69060 | POINT (15.79900 40.64200) |
3 | 4 | Campobasso | ITA | 41.56300 | 14.65600 | 50762 | POINT (14.65600 41.56300) |
4 | 5 | Aosta | ITA | 45.73700 | 7.31500 | 34062 | POINT (7.31500 45.73700) |
... | ... | ... | ... | ... | ... | ... | ... |
1244 | 1245 | Rio de Janeiro | BRA | -22.92502 | -43.22502 | 11748000 | POINT (-43.22502 -22.92502) |
1245 | 1246 | Sao Paulo | BRA | -23.55868 | -46.62502 | 18845000 | POINT (-46.62502 -23.55868) |
1246 | 1247 | Sydney | AUS | -33.92001 | 151.18518 | 4630000 | POINT (151.18518 -33.92001) |
1247 | 1248 | Singapore | SGP | 1.29303 | 103.85582 | 5183700 | POINT (103.85582 1.29303) |
1248 | 1249 | Hong Kong | CHN | 22.30498 | 114.18501 | 7206000 | POINT (114.18501 22.30498) |
1249 rows × 7 columns
In [14]:
Copied!
Map.add_xy_data(in_csv, x="longitude", y="latitude", layer_name="Marker cluster")
Map
Map.add_xy_data(in_csv, x="longitude", y="latitude", layer_name="Marker cluster")
Map
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Input In [14], in <cell line: 1>() ----> 1 Map.add_xy_data(in_csv, x="longitude", y="latitude", layer_name="Marker cluster") 2 Map AttributeError: 'Map' object has no attribute 'add_xy_data'
Last update:
2022-03-14