{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\"Open\n", "\n", "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import geemap\n", "import pandas as pd\n", "import geopandas as gpd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# geemap.update_package()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create an interactive map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Convert ee.FeatureCollection to Pandas DataFrame" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "countries_shp = '../data/countries.shp'\n", "countries = geemap.shp_to_ee(countries_shp)\n", "Map.addLayer(countries, {}, 'Countries')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = geemap.ee_to_df(countries, selectors=['id', 'name'])\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Convert ee.FeatureCollection to GeoPandas GeoDataFrame" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gdf = geemap.ee_to_gdf(countries, selectors=['id', 'name'])\n", "gdf.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Convert Pandas DataFrame to ee.FeatureCollection" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "in_csv = 'https://raw.githubusercontent.com/giswqs/data/main/world/world_cities.csv'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(in_csv)\n", "df.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc = geemap.pandas_to_ee(df, latitude=\"latitude\", longitude=\"longitude\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(fc, {}, \"pandas to ee\")\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Convert GeoPandas GeoDataFrame to ee.FeatureCollection" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gdf = gpd.read_file(\n", " \"https://raw.githubusercontent.com/giswqs/data/main/us/us_states.geojson\"\n", ")\n", "gdf.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fc = geemap.geopandas_to_ee(gdf)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map.addLayer(fc, {}, \"geopandas to ee\")\n", "Map" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }