{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "\"Open\n", "\n", "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "# !pip install geemap" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "import os\n", "import geemap\n", "import pandas as pd\n", "import geopandas as gpd" ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "# geemap.update_package()" ] }, { "cell_type": "markdown", "id": "4", "metadata": {}, "source": [ "## Create an interactive map" ] }, { "cell_type": "code", "execution_count": null, "id": "5", "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "markdown", "id": "6", "metadata": {}, "source": [ "## Convert ee.FeatureCollection to Pandas DataFrame" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "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, "id": "8", "metadata": {}, "outputs": [], "source": [ "df = geemap.ee_to_df(countries, selectors=[\"id\", \"name\"])\n", "df.head()" ] }, { "cell_type": "markdown", "id": "9", "metadata": {}, "source": [ "## Convert ee.FeatureCollection to GeoPandas GeoDataFrame" ] }, { "cell_type": "code", "execution_count": null, "id": "10", "metadata": {}, "outputs": [], "source": [ "gdf = geemap.ee_to_gdf(countries, selectors=[\"id\", \"name\"])\n", "gdf.head()" ] }, { "cell_type": "markdown", "id": "11", "metadata": {}, "source": [ "## Convert Pandas DataFrame to ee.FeatureCollection" ] }, { "cell_type": "code", "execution_count": null, "id": "12", "metadata": {}, "outputs": [], "source": [ "in_csv = \"https://raw.githubusercontent.com/giswqs/data/main/world/world_cities.csv\"" ] }, { "cell_type": "code", "execution_count": null, "id": "13", "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv(in_csv)\n", "df.head()" ] }, { "cell_type": "code", "execution_count": null, "id": "14", "metadata": {}, "outputs": [], "source": [ "fc = geemap.pandas_to_ee(df, latitude=\"latitude\", longitude=\"longitude\")" ] }, { "cell_type": "code", "execution_count": null, "id": "15", "metadata": {}, "outputs": [], "source": [ "Map.addLayer(fc, {}, \"pandas to ee\")\n", "Map" ] }, { "cell_type": "markdown", "id": "16", "metadata": {}, "source": [ "## Convert GeoPandas GeoDataFrame to ee.FeatureCollection" ] }, { "cell_type": "code", "execution_count": null, "id": "17", "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, "id": "18", "metadata": {}, "outputs": [], "source": [ "fc = geemap.geopandas_to_ee(gdf)" ] }, { "cell_type": "code", "execution_count": null, "id": "19", "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 }