Skip to content

get_geom_type is case sensitive but query response case can differ. #2490

@domdfcoding

Description

@domdfcoding

Describe the bug
A clear and concise description of what the bug is.

When querying the Historic England dataset an exception is raised because the query response has the geometry type as "esriGeometryMultipoint" but the check in get_geom_type() (arcgis.features.feature.FeatureSet.to_geojson.esri_to_geo.get_geom_type) is looking for "esriGeometryMultiPoint" (capital P on Point). get_geom_type() therefore falls through to returning "Point", for which the expected keys cannot be found

To Reproduce
Steps to reproduce the behavior:

from arcgis.gis import GIS

gis = GIS()
data_item_id = "767f279327a24845bf47dfe5eae9862b"
data_item = gis.content.get(data_item_id)

for layer in data_item.layers:
	print("  ", layer.properties.name)
	print("  ", str(layer.properties.geometryType))
	query = layer.query()
	
	print(repr(query))

	if query.features:  # If no features (e.g. no preservation notices at this time) don't proceed
		query.to_geojson

error:

   Listed Building points
   esriGeometryMultipoint
<FeatureSet> 379664 features
Traceback (most recent call last):
  File "nhle-map/t.py", line 15, in <module>
    query.to_geojson
  File "nhle-map/venv/lib/python3.10/site-packages/arcgis/features/feature.py", line 827, in to_geojson
    return json.dumps(esri_to_geo(self.value), default=_date_handler)
  File "nhle-map/venv/lib/python3.10/site-packages/arcgis/features/feature.py", line 821, in esri_to_geo
    feats.append(extract(feat, esri_geom_type))
  File "nhle-map/venv/lib/python3.10/site-packages/arcgis/features/feature.py", line 776, in extract
    geometry["coordinates"] = get_coordinates(geom, geometry["type"])
  File "nhle-map/venv/lib/python3.10/site-packages/arcgis/features/feature.py", line 811, in get_coordinates
    return [geom["x"], geom["y"]]
KeyError: 'x'

Expected behavior
GeoJSON data is successfully produced for the query.

Platform (please complete the following information):

  • OS: Ubuntu 20.04 (Python 3.10)
  • Browser: Firefox
  • Python API Version: 2.4.2

Additional context
The esriGeometryMultipoint (lowercase P) form is used three times in feature.py and esriGeometryMultiPoint (capital P) twice (in to_geojson and from_geojson). I tried setting the uppercase form manually with query.geometry_type = "esriGeometryMultiPoint" but there is a check that the geometry type is valid, and the capital P form isn't.

Bypassing the check with query._geometry_type = "esriGeometryMultiPoint" does work and I can convert to GeoJSON, but accessing the private attribute isn't ideal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions