Skip to content

Commit 4dbfade

Browse files
author
Atma Mani
authored
Merge pull request #1074 from Esri/chun7642/add_use_case_areas_and_lengths
add b10 use cases for areas_and_lengths enhancement
2 parents e69e69a + 6aca13f commit 4dbfade

File tree

1 file changed

+130
-4
lines changed

1 file changed

+130
-4
lines changed

guide/15-working-with-geometries/part3_spatial_operations_on_geometries.ipynb

Lines changed: 130 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"source": [
2323
"<h1>Table of Contents<span class=\"tocSkip\"></span></h1>\n",
24-
"<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Spatial-Operations\" data-toc-modified-id=\"Spatial-Operations-1\">Spatial Operations</a></span><ul class=\"toc-item\"><li><span><a href=\"#Two-patterns-of-applying-spatial-operations\" data-toc-modified-id=\"Two-patterns-of-applying-spatial-operations-1.1\">Two patterns of applying spatial operations</a></span></li><li><span><a href=\"#a.-OOP-Pattern---Uses-local-geometry-engine\" data-toc-modified-id=\"a.-OOP-Pattern---Uses-local-geometry-engine-1.2\">a. OOP Pattern - Uses local geometry engine</a></span><ul class=\"toc-item\"><li><span><a href=\"#a1.-Union\" data-toc-modified-id=\"a1.-Union-1.2.1\">a1. Union</a></span></li><li><span><a href=\"#a2.-Difference\" data-toc-modified-id=\"a2.-Difference-1.2.2\">a2. Difference</a></span></li><li><span><a href=\"#a3.-Symmetric-difference\" data-toc-modified-id=\"a3.-Symmetric-difference-1.2.3\">a3. Symmetric difference</a></span></li><li><span><a href=\"#a4.-intersect()-V.S.-overlaps()\" data-toc-modified-id=\"a4.-intersect()-V.S.-overlaps()-1.2.4\">a4. intersect() V.S. overlaps()</a></span></li><li><span><a href=\"#a5.-Equals\" data-toc-modified-id=\"a5.-Equals-1.2.5\">a5. Equals</a></span></li><li><span><a href=\"#a6.-generalize()-V.S.-buffer()\" data-toc-modified-id=\"a6.-generalize()-V.S.-buffer()-1.2.6\">a6. generalize() V.S. buffer()</a></span></li><li><span><a href=\"#a7.-Find-the-nearest-point\" data-toc-modified-id=\"a7.-Find-the-nearest-point-1.2.7\">a7. Find the nearest point</a></span></li><li><span><a href=\"#a8.-contains()\" data-toc-modified-id=\"a8.-contains()-1.2.8\">a8. contains()</a></span></li><li><span><a href=\"#a9.-Clip-a-geometry-object\" data-toc-modified-id=\"a9.-Clip-a-geometry-object-1.2.9\">a9. Clip a geometry object</a></span></li></ul></li><li><span><a href=\"#b.-Pattern-using-arcgis.geometry.functions:-uses-server-side-geometry-engine\" data-toc-modified-id=\"b.-Pattern-using-arcgis.geometry.functions:-uses-server-side-geometry-engine-1.3\">b. Pattern using <code>arcgis.geometry.functions</code>: uses server-side geometry engine</a></span><ul class=\"toc-item\"><li><span><a href=\"#b1.-Union\" data-toc-modified-id=\"b1.-Union-1.3.1\">b1. Union</a></span></li><li><span><a href=\"#b2.-intersect()-V.S.-overlaps()\" data-toc-modified-id=\"b2.-intersect()-V.S.-overlaps()-1.3.2\">b2. intersect() V.S. overlaps()</a></span></li><li><span><a href=\"#b3.-Difference\" data-toc-modified-id=\"b3.-Difference-1.3.3\">b3. Difference</a></span></li><li><span><a href=\"#b4.-Symmetric-difference\" data-toc-modified-id=\"b4.-Symmetric-difference-1.3.4\">b4. Symmetric difference</a></span></li><li><span><a href=\"#b5.-Equals\" data-toc-modified-id=\"b5.-Equals-1.3.5\">b5. Equals</a></span></li><li><span><a href=\"#b6.-generalize()-V.S.-buffer()\" data-toc-modified-id=\"b6.-generalize()-V.S.-buffer()-1.3.6\">b6. generalize() V.S. buffer()</a></span></li><li><span><a href=\"#b7.-Distance\" data-toc-modified-id=\"b7.-Distance-1.3.7\">b7. Distance</a></span></li><li><span><a href=\"#b8.-Determine-the-spatial-relation-between-two-geometries\" data-toc-modified-id=\"b8.-Determine-the-spatial-relation-between-two-geometries-1.3.8\">b8. Determine the spatial relation between two geometries</a></span></li><li><span><a href=\"#b9.-Clip-a-geometry-object\" data-toc-modified-id=\"b9.-Clip-a-geometry-object-1.3.9\">b9. Clip a geometry object</a></span></li></ul></li></ul></li><li><span><a href=\"#Conclusion\" data-toc-modified-id=\"Conclusion-2\">Conclusion</a></span></li></ul></div>"
24+
"<div class=\"toc\"><ul class=\"toc-item\"><li><span><a href=\"#Spatial-Operations\" data-toc-modified-id=\"Spatial-Operations-1\">Spatial Operations</a></span><ul class=\"toc-item\"><li><span><a href=\"#Two-patterns-of-applying-spatial-operations\" data-toc-modified-id=\"Two-patterns-of-applying-spatial-operations-1.1\">Two patterns of applying spatial operations</a></span></li><li><span><a href=\"#a.-OOP-Pattern---Uses-local-geometry-engine\" data-toc-modified-id=\"a.-OOP-Pattern---Uses-local-geometry-engine-1.2\">a. OOP Pattern - Uses local geometry engine</a></span><ul class=\"toc-item\"><li><span><a href=\"#a1.-Union\" data-toc-modified-id=\"a1.-Union-1.2.1\">a1. Union</a></span></li><li><span><a href=\"#a2.-Difference\" data-toc-modified-id=\"a2.-Difference-1.2.2\">a2. Difference</a></span></li><li><span><a href=\"#a3.-Symmetric-difference\" data-toc-modified-id=\"a3.-Symmetric-difference-1.2.3\">a3. Symmetric difference</a></span></li><li><span><a href=\"#a4.-intersect()-V.S.-overlaps()\" data-toc-modified-id=\"a4.-intersect()-V.S.-overlaps()-1.2.4\">a4. intersect() V.S. overlaps()</a></span></li><li><span><a href=\"#a5.-Equals\" data-toc-modified-id=\"a5.-Equals-1.2.5\">a5. Equals</a></span></li><li><span><a href=\"#a6.-generalize()-V.S.-buffer()\" data-toc-modified-id=\"a6.-generalize()-V.S.-buffer()-1.2.6\">a6. generalize() V.S. buffer()</a></span></li><li><span><a href=\"#a7.-Find-the-nearest-point\" data-toc-modified-id=\"a7.-Find-the-nearest-point-1.2.7\">a7. Find the nearest point</a></span></li><li><span><a href=\"#a8.-contains()\" data-toc-modified-id=\"a8.-contains()-1.2.8\">a8. contains()</a></span></li><li><span><a href=\"#a9.-Clip-a-geometry-object\" data-toc-modified-id=\"a9.-Clip-a-geometry-object-1.2.9\">a9. Clip a geometry object</a></span></li></ul></li><li><span><a href=\"#b.-Pattern-using-arcgis.geometry.functions:-uses-server-side-geometry-engine\" data-toc-modified-id=\"b.-Pattern-using-arcgis.geometry.functions:-uses-server-side-geometry-engine-1.3\">b. Pattern using <code>arcgis.geometry.functions</code>: uses server-side geometry engine</a></span><ul class=\"toc-item\"><li><span><a href=\"#b1.-Union\" data-toc-modified-id=\"b1.-Union-1.3.1\">b1. Union</a></span></li><li><span><a href=\"#b2.-intersect()-V.S.-overlaps()\" data-toc-modified-id=\"b2.-intersect()-V.S.-overlaps()-1.3.2\">b2. intersect() V.S. overlaps()</a></span></li><li><span><a href=\"#b3.-Difference\" data-toc-modified-id=\"b3.-Difference-1.3.3\">b3. Difference</a></span></li><li><span><a href=\"#b4.-Symmetric-difference\" data-toc-modified-id=\"b4.-Symmetric-difference-1.3.4\">b4. Symmetric difference</a></span></li><li><span><a href=\"#b5.-Equals\" data-toc-modified-id=\"b5.-Equals-1.3.5\">b5. Equals</a></span></li><li><span><a href=\"#b6.-generalize()-V.S.-buffer()\" data-toc-modified-id=\"b6.-generalize()-V.S.-buffer()-1.3.6\">b6. generalize() V.S. buffer()</a></span></li><li><span><a href=\"#b7.-Distance\" data-toc-modified-id=\"b7.-Distance-1.3.7\">b7. Distance</a></span></li><li><span><a href=\"#b8.-Determine-the-spatial-relation-between-two-geometries\" data-toc-modified-id=\"b8.-Determine-the-spatial-relation-between-two-geometries-1.3.8\">b8. Determine the spatial relation between two geometries</a></span></li><li><span><a href=\"#b9.-Clip-a-geometry-object\" data-toc-modified-id=\"b9.-Clip-a-geometry-object-1.3.9\">b9. Clip a geometry object</a></span></li><li><span><a href=\"#b10.-Areas-and-Lengths\" data-toc-modified-id=\"b10.-Areas-and-Lengths-1.3.10\">b10. Areas and Lengths</a></span></li></ul></li></ul></li><li><span><a href=\"#Conclusion\" data-toc-modified-id=\"Conclusion-2\">Conclusion</a></span></li></ul></div>"
2525
]
2626
},
2727
{
@@ -1048,7 +1048,7 @@
10481048
},
10491049
{
10501050
"cell_type": "code",
1051-
"execution_count": 131,
1051+
"execution_count": 4,
10521052
"metadata": {},
10531053
"outputs": [
10541054
{
@@ -1070,7 +1070,7 @@
10701070
" [-8234935.963979837, 4978263.2306637755]]]}"
10711071
]
10721072
},
1073-
"execution_count": 131,
1073+
"execution_count": 4,
10741074
"metadata": {},
10751075
"output_type": "execute_result"
10761076
}
@@ -3084,6 +3084,132 @@
30843084
" })"
30853085
]
30863086
},
3087+
{
3088+
"cell_type": "markdown",
3089+
"metadata": {},
3090+
"source": [
3091+
"#### b10. Areas and Lengths\n",
3092+
"\n",
3093+
"The `areas_and_lengths` function calculates areas and perimeter lengths for each `Polygon` object specified in the input array. The input parameters include:\n",
3094+
" - `polygons` - The array of polygons whose areas and lengths are to be computed.\n",
3095+
" - `length_unit` - The length unit in which the perimeters of polygons will be calculated. \n",
3096+
" - If `calculation_type` is `planar`, then length_unit can be any `esriUnits` constant. \n",
3097+
" - If `calculation_type` is not `planar`, then `length_unit` must be a linear `esriUnits` constant, such as `esriSRUnit_Meter`(i.e. `9001`|`LengthUnits.METER`) or `esriSRUnit_SurveyMile`(i.e. `9035`|`LengthUnits.SURVEYMILE`). \n",
3098+
" - If `length_unit` is not specified, the units are derived from `spatial_ref` parameter. If ``spatial_ref`` is not specified, the units are in meters. \n",
3099+
" - For a list of valid units, see <a href=\"https://developers.arcgis.com/enterprise-sdk/api-reference/net/esriGeometry/esriSRUnitType/\">`esriSRUnitType Constants`</a> and <a href=\"https://developers.arcgis.com/enterprise-sdk/api-reference/net/esriGeometry/esriSRUnitType/\">`esriSRUnit2Type Constants`</a>.\n",
3100+
" - `area_unit` - The area unit in which areas of polygons will be calculated. \n",
3101+
" - If `calculation_type` is `planar`, then `area_unit` can be any `esriAreaUnits` constant. \n",
3102+
" - If `calculation_type` is not `planar`, then `area_unit` must be a linear esriUnits constant such as `AreaUnits.SQUAREMETERS` (i.e. `{\"areaUnit\": \"esriSquareMeters\"}`) or `AreaUnits.SQUAREMILES` (i.e. `{\"areaUnit\": \"esriSquareMiles\"}`).\n",
3103+
" - If `area_unit` is not specified, the units are derived from `spatial_ref`. If `spatial_ref` is not specified, then the units are meters.\n",
3104+
" - For a list of valid units, see <a href=\"https://developers.arcgis.com/enterprise-sdk/api-reference/net/esriSystem/esriAreaUnits/\">`esriAreaUnits Constants`</a>. The list of valid `esriAreaUnits constants` include, esriSquareInches | esriSquareFeet | esriSquareYards | esriAcres | esriSquareMiles | esriSquareMillimeters | esriSquareCentimeters | esriSquareDecimeters | esriSquareMeters | esriAres | esriHectares | esriSquareKilometers.\n",
3105+
" - `calculation_type` - The type defined for the area and length calculation of the input geometries. The type can be one of the following values:\n",
3106+
" - `planar` - Planar measurements use 2D Euclidean distance to calculate area and length. This should only be used if the area or length needs to be calculated in the given `SpatialReference`. Otherwise, use ``preserveShape``.\n",
3107+
" - `geodesic` - Use this type if you want to calculate an area or length using only the vertices of the `Polygon` and define the lines between the points as geodesic segments independent of the actual shape of the `Polygon`. A geodesic segment is the shortest path between two points on an ellipsoid.\n",
3108+
" - `preserveShape` - This type calculates the area or length of the geometry on the surface of the Earth ellipsoid. The shape of the geometry in its coordinate system is preserved.\n",
3109+
" \n",
3110+
"There are other optional parameters to be specify in the input arguments. For more information, check out the <a href=\"https://developers.arcgis.com/python/api-reference/arcgis.geometry.functions.html?highlight=areas_and_lengths#arcgis.geometry.functions.areas_and_lengths\">API ref</a>. Now let's look at two use cases below:"
3111+
]
3112+
},
3113+
{
3114+
"cell_type": "markdown",
3115+
"metadata": {},
3116+
"source": [
3117+
"##### The traditional use case\n",
3118+
"\n",
3119+
"For API version <= 1.9.0, `length_unit` shall be input as constant integer value (as found in <a href=\"https://developers.arcgis.com/enterprise-sdk/api-reference/net/esriSystem/esriAreaUnits/\">esriSRUnitType Constants</a> or <a href=\"https://developers.arcgis.com/enterprise-sdk/api-reference/net/esriGeometry/esriSRUnitType/\">`esriSRUnit2Type Constants`</a>) while `area_unit` only accepts a `dict` object where the a list of valid units can be found in <a href=\"https://developers.arcgis.com/enterprise-sdk/api-reference/net/esriSystem/esriAreaUnits/\">`esriAreaUnits Constants`</a>."
3120+
]
3121+
},
3122+
{
3123+
"cell_type": "code",
3124+
"execution_count": 26,
3125+
"metadata": {},
3126+
"outputs": [
3127+
{
3128+
"data": {
3129+
"text/plain": [
3130+
"{'areas': [266.67415681137567], 'lengths': [720.7725858813257]}"
3131+
]
3132+
},
3133+
"execution_count": 26,
3134+
"metadata": {},
3135+
"output_type": "execute_result"
3136+
}
3137+
],
3138+
"source": [
3139+
"from arcgis.geometry.functions import areas_and_lengths\n",
3140+
"\n",
3141+
"areas_and_lengths(polygons =[access_polygon],\n",
3142+
" length_unit = 9001,\n",
3143+
" spatial_ref=3857,\n",
3144+
" area_unit = {\"areaUnit\": \"esriSquareMeters\"},\n",
3145+
" calculation_type = \"planar\")"
3146+
]
3147+
},
3148+
{
3149+
"cell_type": "markdown",
3150+
"metadata": {},
3151+
"source": [
3152+
"##### The enhanced use case\n",
3153+
"\n",
3154+
"After 1.9.0, there is an easier way to represent `length_unit` and `area_unit`. Users can use `enum` declared in the `arcgis.geometry.functions.AreaUnits` and `arcgis.geometry.functions.LengthUnits` as input, e.g. \n",
3155+
" - the `length_unit` parameter can be represented by `LengthUnits.BRITISH1936FOOT | LengthUnits.GOLDCOASTFOOT | LengthUnits.INTERNATIONALCHAIN | LengthUnits.INTERNATIONALLINK | LengthUnits.INTERNATIONALYARD | LengthUnits.METER | LengthUnits.FOOT | LengthUnits.SURVEYFOOT | LengthUnits.CLARKEFOOT | LengthUnits.FATHOM | etc.`\n",
3156+
" - while the `area_unit` parameter can be represented by `AreaUnits.SQUAREINCHES | AreaUnits.SQUAREFEET | AreaUnits.SQUAREYARDS | AreaUnits.ACRES | AreaUnits.SQUAREMILES | AreaUnits.SQUAREMILLIMETERS | AreaUnits.SQUARECENTIMETERS | AreaUnits.SQUAREDECIMETERS | AreaUnits.SQUAREMETERS | AreaUnits.ARES | AreaUnits.HECTARES | AreaUnits.SQUAREKILOMETERS | etc.`"
3157+
]
3158+
},
3159+
{
3160+
"cell_type": "code",
3161+
"execution_count": 27,
3162+
"metadata": {},
3163+
"outputs": [
3164+
{
3165+
"data": {
3166+
"text/plain": [
3167+
"<areas_and_lengths job c9721c39d3bf4da98eb37423f8486608>"
3168+
]
3169+
},
3170+
"execution_count": 27,
3171+
"metadata": {},
3172+
"output_type": "execute_result"
3173+
}
3174+
],
3175+
"source": [
3176+
"from arcgis.geometry.functions import LengthUnits, AreaUnits\n",
3177+
"\n",
3178+
"res = areas_and_lengths(polygons =[access_polygon],\n",
3179+
" length_unit = LengthUnits.METER,\n",
3180+
" area_unit = AreaUnits.SQUAREMETERS,\n",
3181+
" calculation_type = \"planar\",\n",
3182+
" future = True)\n",
3183+
"res"
3184+
]
3185+
},
3186+
{
3187+
"cell_type": "markdown",
3188+
"metadata": {},
3189+
"source": [
3190+
"Also note that, when `future` is set to True, the `areas_and_lengths` function will return a `GeometryJob` object which indicates the job is processed asynchronously. When the job is done, querying its result will bring out a `dict` object of `areas`, and `lengths` for the list of polygons."
3191+
]
3192+
},
3193+
{
3194+
"cell_type": "code",
3195+
"execution_count": 29,
3196+
"metadata": {},
3197+
"outputs": [
3198+
{
3199+
"data": {
3200+
"text/plain": [
3201+
"{'areas': [266.67415681137567], 'lengths': [720.7725858813257]}"
3202+
]
3203+
},
3204+
"execution_count": 29,
3205+
"metadata": {},
3206+
"output_type": "execute_result"
3207+
}
3208+
],
3209+
"source": [
3210+
"res.result()"
3211+
]
3212+
},
30873213
{
30883214
"cell_type": "markdown",
30893215
"metadata": {},
@@ -3117,7 +3243,7 @@
31173243
"name": "python",
31183244
"nbconvert_exporter": "python",
31193245
"pygments_lexer": "ipython3",
3120-
"version": "3.6.10"
3246+
"version": "3.7.10"
31213247
},
31223248
"toc": {
31233249
"base_numbering": 1,

0 commit comments

Comments
 (0)