Seeing that my issue on GitHub (areas_and_lengths Incorrect Default area_unit · Issue #106 · Esri/arcgis-python-api · GitHub) hasn't even been acknowledged in 6+ months, I am hoping that posting it here might get better traction since there are still issues with areas_and_lengths.
As an aside, I can't help but shake my head when reading Open Source | Esri's Open Vision:
Esri’s Open-Source Community on GitHubAt Esri we encourage our development staff to engage with the open-source community. We regularly work on and share open-source projects via GitHub. We welcome more interactions with the community of geospatial developers on this forum. |
I might be able to give them "sharing" but "regularly working" seems a stretch when issues can go unacknowledged, not even addressed, in 6+ months.
The areas_and_lengths - arcgis.geometry module — arcgis 1.3.0 documentation states (red color added by me):
length_unit - The length unit in which the perimeters of polygons will be calculated.
If calculation_type is planar, then length_unit can be any esriUnits constant. If lengthUnit is not specified, the units are derived from spatial_ref. If calculationType is not planar, then lengthUnit must be a linear esriUnits constant, such as esriSRUnit_Meter or esriSRUnit_SurveyMile. If length_unit is not specified, the units are meters. For a list of valid units, see esriSRUnitType Constants and esriSRUnit2Type Constant.
area_unit - The area unit in which areas of polygons will be calculated.
If calculation_type is planar, then area_unit can be any esriUnits constant. If area_unit is not specified, the units are derived from spatial_ref. If calculation_type is not planar, then area_unit must be a linear esriUnits constant such as esriSRUnit_Meter or esriSRUnit_SurveyMile. If area_unit is not specified, then the units are meters. For a list of valid units, see esriSRUnitType Constants and esriSRUnit2Type constant. The list of valid esriAreaUnits constants include, esriSquareInches | esriSquareFeet | esriSquareYards | esriAcres | esriSquareMiles | esriSquareMillimeters | esriSquareCentimeters | esriSquareDecimeters | esriSquareMeters | esriAres | esriHectares | esriSquareKilometers.
I can't speak for others, but "if area_unit is not specified" sure makes me think it is an optional argument, right? The problem is, the error message returned by ArcGIS API for Python says there are required:
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">from</SPAN> arcgis <SPAN class="keyword token">import</SPAN> gis<SPAN class="punctuation token">,</SPAN> geometry
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> gis <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>GIS<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> geom_json <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="string token">"rings"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="string token">"SpatialReference"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"wkid"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="number token">3857</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="punctuation token">}</SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> geom <SPAN class="operator token">=</SPAN> geometry<SPAN class="punctuation token">.</SPAN>Geometry<SPAN class="punctuation token">(</SPAN>geom_json<SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> geometry<SPAN class="punctuation token">.</SPAN>areas_and_lengths<SPAN class="punctuation token">(</SPAN>geom<SPAN class="punctuation token">,</SPAN> spatial_ref<SPAN class="operator token">=</SPAN><SPAN class="number token">3857</SPAN><SPAN class="punctuation token">)</SPAN>
TypeError Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token"><</SPAN>ipython<SPAN class="operator token">-</SPAN>input<SPAN class="number token">-12</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">3059784b616c</SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">1</SPAN> geometry<SPAN class="punctuation token">.</SPAN>areas_and_lengths<SPAN class="punctuation token">(</SPAN>geom<SPAN class="punctuation token">,</SPAN> spatial_ref<SPAN class="operator token">=</SPAN><SPAN class="number token">3857</SPAN><SPAN class="punctuation token">)</SPAN>
TypeError<SPAN class="punctuation token">:</SPAN> areas_and_lengths<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> missing <SPAN class="number token">3</SPAN> required positional arguments<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'length_unit'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'area_unit'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">and</SPAN> <SPAN class="string token">'calculation_type'</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>OK, so they are required by Python but don't need to be specified by ArcGIS. Let's try the old Esri standby of passing empty strings to use defaults:
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> geometry<SPAN class="punctuation token">.</SPAN>areas_and_lengths<SPAN class="punctuation token">(</SPAN>geom<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3857</SPAN><SPAN class="punctuation token">)</SPAN>
RuntimeError<SPAN class="punctuation token">:</SPAN> Error computing areas <SPAN class="operator token">and</SPAN> lengths
<SPAN class="punctuation token">(</SPAN>Error Code<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">500</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Well, it seems empty strings don't work either. To confuse the matter even more, specifying only the area units works while leaving the other two empty strings:
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> geometry<SPAN class="punctuation token">.</SPAN>areas_and_lengths<SPAN class="punctuation token">(</SPAN>geom<SPAN class="punctuation token">,</SPAN><SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"esriSquareMeters"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">3857</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN><SPAN class="string token">'areas'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">100</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'lengths'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">40</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>At this point, I am totally confused how exactly I am supposed to call areas_and_lengths because the documentation doesn't describe reality, and the method itself doesn't even behave consistently with unspecified parameters.