{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import folium\n", "from folium.plugins import Draw\n", "\n", "center_start = [15.572363674301132, 32.69167103104079]\n", "zoom_start = 13\n", "\n", "\n", "\n", "m = folium.Map(location=center_start, zoom_start=zoom_start)\n", "\n", "\n", "draw_options = {'polyline': False, 'polygon': True, 'rectangle': True, 'circle': True, 'marker': False, 'circlemarker': False}\n", "Draw(export=True, draw_options=draw_options).add_to(m)\n", "#\n", "m" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "28579648969.878418\n", "28579.648969878417\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\Edin\\anaconda3\\envs\\amazon\\lib\\site-packages\\pyproj\\crs\\crs.py:141: FutureWarning: '+init=:' syntax is deprecated. ':' is the preferred initialization method. When making the change, be mindful of axis order changes: https://pyproj4.github.io/pyproj/stable/gotchas.html#axis-order-changes-in-proj-6\n", " in_crs_string = _prepare_from_proj_string(in_crs_string)\n", "c:\\Users\\Edin\\anaconda3\\envs\\amazon\\lib\\site-packages\\shapely\\ops.py:276: FutureWarning: This function is deprecated. See: https://pyproj4.github.io/pyproj/stable/gotchas.html#upgrading-to-pyproj-2-from-pyproj-1\n", " shell = type(geom.exterior)(zip(*func(*zip(*geom.exterior.coords))))\n" ] } ], "source": [ "from shapely.geometry import Polygon\n", "import shapely.ops as ops\n", "from functools import partial\n", "import pyproj\n", "edges = [\n", " [32.584179, 15.217575],\n", " [32.726973, 13.546143],\n", " [33.957199, 13.973163],\n", " [34.286724, 14.739791],\n", " [33.69358, 15.620197],\n", " [32.584179, 15.217575]\n", " ]\n", "geom = Polygon(edges)\n", "\n", "geom_area = ops.transform(\n", " partial(\n", " pyproj.transform,\n", " pyproj.Proj(init='EPSG:4326'),\n", " pyproj.Proj(\n", " proj='aea',\n", " lat_1=geom.bounds[1],\n", " lat_2=geom.bounds[3]\n", " )\n", " ),\n", " geom)\n", "\n", "# Print the area in m^2\n", "print(geom_area.area)\n", "#print the area in km^2\n", "print(geom_area.area/1000000)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geom" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pyproj \n", "import shapely\n", "import shapely.ops as ops\n", "from shapely.geometry.polygon import Polygon\n", "from functools import partial\n", "\n", "\n", "\n", "\n", "geom = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])\n", "geom_area = ops.transform(\n", " partial(\n", " pyproj.transform,\n", " pyproj.Proj(init='EPSG:4326'),\n", " pyproj.Proj(\n", " proj='aea',\n", " lat_1=geom.bounds[1],\n", " lat_2=geom.bounds[3]\n", " )\n", " ),\n", " geom)\n", "\n", "# Print the area in m^2\n", "print(geom_area.area)" ] } ], "metadata": { "kernelspec": { "display_name": "amazon", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" } }, "nbformat": 4, "nbformat_minor": 2 }