File size: 4,225 Bytes
2cdce84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
{
 "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=<authority>:<code>' syntax is deprecated. '<authority>:<code>' 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
}