Skip to content

Commit

Permalink
Added chart by feature property #339
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Mar 11, 2021
1 parent 5a96b6e commit dddb5dd
Show file tree
Hide file tree
Showing 10 changed files with 363 additions and 38 deletions.
117 changes: 111 additions & 6 deletions docs/notebooks/63_charts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"outputs": [],
"source": [
"import ee\n",
"import geemap"
"import geemap\n",
"import geemap.chart as chart"
]
},
{
Expand All @@ -35,6 +36,15 @@
"# geemap.update_package()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a chart from ee.FeatureCollection by feature\n",
"\n",
"Reference: https://developers.google.com/earth-engine/guides/charts_feature#uichartfeaturebyfeature"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -47,7 +57,6 @@
" .select('[0-9][0-9]_tmean|label')\n",
"\n",
"Map.addLayer(features, {}, \"Ecoregions\")\n",
"\n",
"Map"
]
},
Expand All @@ -57,7 +66,8 @@
"metadata": {},
"outputs": [],
"source": [
"import geemap.chart as chart"
"df = geemap.ee_to_pandas(features)\n",
"df"
]
},
{
Expand All @@ -68,6 +78,7 @@
"source": [
"xProperty = \"label\"\n",
"yProperties = [str(x).zfill(2) + \"_tmean\" for x in range(1, 13)]\n",
"\n",
"labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']\n",
"colors = ['#604791', '#1d6b99', '#39a8a7', '#0f8755', '#76b349', '#f0af07',\n",
" '#e37d05', '#cf513e', '#96356f', '#724173', '#9c4f97', '#696969']\n",
Expand All @@ -82,17 +93,111 @@
"metadata": {},
"outputs": [],
"source": [
"options = {\"labels\": labels, \"colors\": colors, \"title\": title, \"xlabel\": xlabel, \"ylabel\": ylabel}"
"options = {\"labels\": labels, \n",
" \"colors\": colors, \n",
" \"title\": title, \n",
" \"xlabel\": xlabel, \n",
" \"ylabel\": ylabel, \n",
" \"legend_location\": \"top-left\",\n",
" \"height\": \"500px\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"chart.feature_byFeature(features, xProperty, yProperties, **options)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a chart from ee.FeatureCollection by property\n",
"\n",
"Reference: https://developers.google.com/earth-engine/guides/charts_feature#uichartfeaturebyproperty"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map = geemap.Map()\n",
"\n",
"features = ee.FeatureCollection('projects/google/charts_feature_example') \\\n",
" .select('[0-9][0-9]_ppt|label')\n",
"\n",
"Map.addLayer(features, {}, 'Features')\n",
"Map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = geemap.ee_to_pandas(features)\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"keys = [str(x).zfill(2) + \"_ppt\" for x in range(1, 13)]\n",
"values = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"xProperties = dict(zip(keys, values))\n",
"seriesProperty = \"label\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"options = {\n",
" 'title': \"Average Ecoregion Precipitation by Month\",\n",
" 'colors': ['#f0af07', '#0f8755', '#76b349'],\n",
" 'xlabel': \"Month\",\n",
" 'ylabel': \"Precipitation (mm)\",\n",
" 'legend_location': \"top-left\",\n",
" \"height\": \"500px\"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"chart.feature_byProperty(features, xProperties, seriesProperty, **options)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down Expand Up @@ -125,7 +230,7 @@
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
"toc_window_display": true
},
"varInspector": {
"cols": {
Expand Down
Binary file added examples/data/charts_feature_example.dbf
Binary file not shown.
Binary file added examples/data/charts_feature_example.fix
Binary file not shown.
1 change: 1 addition & 0 deletions examples/data/charts_feature_example.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["WGS 84", DATUM["World Geodetic System 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4326"]]
Binary file added examples/data/charts_feature_example.shp
Binary file not shown.
1 change: 1 addition & 0 deletions examples/data/charts_feature_example.shp.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file added examples/data/charts_feature_example.shx
Binary file not shown.
117 changes: 111 additions & 6 deletions examples/notebooks/63_charts.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"outputs": [],
"source": [
"import ee\n",
"import geemap"
"import geemap\n",
"import geemap.chart as chart"
]
},
{
Expand All @@ -35,6 +36,15 @@
"# geemap.update_package()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a chart from ee.FeatureCollection by feature\n",
"\n",
"Reference: https://developers.google.com/earth-engine/guides/charts_feature#uichartfeaturebyfeature"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -47,7 +57,6 @@
" .select('[0-9][0-9]_tmean|label')\n",
"\n",
"Map.addLayer(features, {}, \"Ecoregions\")\n",
"\n",
"Map"
]
},
Expand All @@ -57,7 +66,8 @@
"metadata": {},
"outputs": [],
"source": [
"import geemap.chart as chart"
"df = geemap.ee_to_pandas(features)\n",
"df"
]
},
{
Expand All @@ -68,6 +78,7 @@
"source": [
"xProperty = \"label\"\n",
"yProperties = [str(x).zfill(2) + \"_tmean\" for x in range(1, 13)]\n",
"\n",
"labels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']\n",
"colors = ['#604791', '#1d6b99', '#39a8a7', '#0f8755', '#76b349', '#f0af07',\n",
" '#e37d05', '#cf513e', '#96356f', '#724173', '#9c4f97', '#696969']\n",
Expand All @@ -82,17 +93,111 @@
"metadata": {},
"outputs": [],
"source": [
"options = {\"labels\": labels, \"colors\": colors, \"title\": title, \"xlabel\": xlabel, \"ylabel\": ylabel}"
"options = {\"labels\": labels, \n",
" \"colors\": colors, \n",
" \"title\": title, \n",
" \"xlabel\": xlabel, \n",
" \"ylabel\": ylabel, \n",
" \"legend_location\": \"top-left\",\n",
" \"height\": \"500px\"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"chart.feature_byFeature(features, xProperty, yProperties, **options)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating a chart from ee.FeatureCollection by property\n",
"\n",
"Reference: https://developers.google.com/earth-engine/guides/charts_feature#uichartfeaturebyproperty"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"Map = geemap.Map()\n",
"\n",
"features = ee.FeatureCollection('projects/google/charts_feature_example') \\\n",
" .select('[0-9][0-9]_ppt|label')\n",
"\n",
"Map.addLayer(features, {}, 'Features')\n",
"Map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = geemap.ee_to_pandas(features)\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"keys = [str(x).zfill(2) + \"_ppt\" for x in range(1, 13)]\n",
"values = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"xProperties = dict(zip(keys, values))\n",
"seriesProperty = \"label\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"options = {\n",
" 'title': \"Average Ecoregion Precipitation by Month\",\n",
" 'colors': ['#f0af07', '#0f8755', '#76b349'],\n",
" 'xlabel': \"Month\",\n",
" 'ylabel': \"Precipitation (mm)\",\n",
" 'legend_location': \"top-left\",\n",
" \"height\": \"500px\"\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"chart.feature_byProperty(features, xProperties, seriesProperty, **options)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down Expand Up @@ -125,7 +230,7 @@
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
"toc_window_display": true
},
"varInspector": {
"cols": {
Expand Down

0 comments on commit dddb5dd

Please sign in to comment.