Skip to content

geometry.lengths method generates error "empty geometry" #2325

@FardoshtAmirpanahi

Description

@FardoshtAmirpanahi

Describe the bug
Trying to run geometry.lengths method but get "emty geometry" error message

To Reproduce

  1. Create a Polyline
  2. Execute Lengths methode
import arcgis
from arcgis.geometry import Polyline
from arcgis.geometry import lengths
simple_polyline = Polyline({
    "paths": [[[-95.5, 30.2], [-95.6, 30.3]]],
    "spatialReference": {"wkid": 4326}
})
print(type(simple_polyline))
print(simple_polyline)
usFeet_simple = lengths(
    spatial_ref={"wkid": 4326}, 
    polylines=[simple_polyline], 
    length_unit='esriUSFeet', 
    calculation_type='geodesic', 
    gis=gis
)
print("Length in US feet (simple):", usFeet_simple['lengths'][0])```
error:
```python
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[2], line 10
      8 print(type(simple_polyline))
      9 print(simple_polyline)
---> 10 usFeet_simple = lengths(
     11     spatial_ref={"wkid": 4326}, 
     12     polylines=[simple_polyline], 
     13     length_unit='esriUSFeet', 
     14     calculation_type='geodesic', 
     15     gis=gis
     16 )
     17 print("Length in US feet (simple):", usFeet_simple['lengths'][0])

File /opt/conda/lib/python3.11/site-packages/arcgis/geometry/functions.py:1217, in lengths(spatial_ref, polylines, length_unit, calculation_type, gis, future)
   1215     length_unit = length_unit.value
   1216 service = gis._tools.geometry
-> 1217 return service.lengths(
   1218     spatial_ref, polylines, length_unit, calculation_type, future=future
   1219 )

File /opt/conda/lib/python3.11/site-packages/arcgis/_impl/tools.py:22655, in _GeometryService.lengths(self, sr, polylines, lengthUnit, calculationType, future)
  22653     return job
  22654 else:
> 22655     results = job.result()
  22656     for result in results:
  22657         all_results.append(result)

File /opt/conda/lib/python3.11/site-packages/arcgis/_impl/_async/jobs.py:269, in GeometryJob.result(self)
    266 from arcgis.geometry import Geometry
    268 if self._task_name == "lengths":
--> 269     res = self._future.result()
    270     return res.get("lengths", [])
    271 elif self._wkid:  # set the output sr to that wkid integer

File /opt/conda/lib/python3.11/concurrent/futures/_base.py:456, in Future.result(self, timeout)
    454     raise CancelledError()
    455 elif self._state == FINISHED:
--> 456     return self.__get_result()
    457 else:
    458     raise TimeoutError()

File /opt/conda/lib/python3.11/concurrent/futures/_base.py:401, in Future.__get_result(self)
    399 if self._exception:
    400     try:
--> 401         raise self._exception
    402     finally:
    403         # Break a reference cycle with the exception in self._exception
    404         self = None

File /opt/conda/lib/python3.11/concurrent/futures/thread.py:58, in _WorkItem.run(self)
     55     return
     57 try:
---> 58     result = self.fn(*self.args, **self.kwargs)
     59 except BaseException as exc:
     60     self.future.set_exception(exc)

File /opt/conda/lib/python3.11/site-packages/arcgis/gis/_impl/_con/_connection.py:1529, in Connection.post(self, path, params, files, **kwargs)
   1527 if return_raw_response:
   1528     return resp
-> 1529 return self._handle_response(
   1530     resp=resp,
   1531     out_path=out_path,
   1532     file_name=file_name,
   1533     try_json=try_json,
   1534     force_bytes=kwargs.pop("force_bytes", False),
   1535 )

File /opt/conda/lib/python3.11/site-packages/arcgis/gis/_impl/_con/_connection.py:1004, in Connection._handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key)
   1002             return data
   1003         errorcode = data["error"]["code"] if "code" in data["error"] else 0
-> 1004         self._handle_json_error(data["error"], errorcode)
   1005     return data
   1006 else:

File /opt/conda/lib/python3.11/site-packages/arcgis/gis/_impl/_con/_connection.py:1027, in Connection._handle_json_error(self, error, errorcode)
   1024                 # _log.error(errordetail)
   1026 errormessage = errormessage + "\n(Error Code: " + str(errorcode) + ")"
-> 1027 raise Exception(errormessage)

Exception: Unable to complete operation.
The operation was attempted on an empty geometry.
(Error Code: 400)

Screenshots

Image

Expected behavior
A clear and concise description of what you expected to happen.

Platform (please complete the following information):
-Windows 11

  • Chrome
  • Python API Version 2.4.0.1 & 2.4.1

Additional context
I tried this in AGOL Notebook, ArfcGIS Pro, VS Note

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy