I'm trying to figure out a way to use the GeoSeriesAccessor snap_to_line function so that I can return a geometry where a point snaps to the nearest line. I have the geometry for both an example point and polyline contained within separate Spatial Enabled DataFrames (created from FeatureSets).
snap = point_sdf.SHAPE.geom.snap_to_line((polyline_sdf.SHAPE.geom))But when I try to apply snap_to_line on the point SeDF, I get an error:
TypeError: Type not known: <class 'numpy.ndarray'> vs <class 'arcgis.features.geo._accessor.GeoSeriesAccessor'>
When I check the type of both point_sdf.SHAPE.geom and polyline_sdf.SHAPE.geom, they are both
<class 'arcgis.features.geo._accessor.GeoSeriesAccessor'>.
I then tried using a Polyline object as the parameter:
polyline = Polyline({'paths': [[[1241715.1635674685, 460269.8582556397], [1241717.2567391396, 460272.0662564784], [1241724.025098309, 460279.2214258909], [1241739.3006583005, 460295.40643289685], [1241768.2212041318, 460326.0494162291], [1241796.472459972, 460355.9843957275], [1241818.4445288926, 460380.5283098966]]], 'spatialReference': SpatialReference({'wkid': 2248})})
point_sdf.SHAPE.geom.snap_to_line(polyline)
But got this as an error:
TypeError: <geoprocessing describe geometry object object at 0x00000198CAA74A80>
The documentation for this tool says that the parameter for the tool should be a Geometry object.
I can't find any examples of this tool being used in the docs, tutorials, or boards to help me figure out the right way to apply this tool.
Does anyone know what might be wrong with what I'm doing? Or are there any examples of how to use this tool that I can use?
Solved! Go to Solution.
I can reproduce this issue when calling snap_to_line on the point with the line as the second geometry. The reverse is successful. Try snapping the point to the line.
point_geom(line_geom) = GP error
line_geom(point_geom) = Success (point geometry is returned)
It looks like this is expected although the Python API documentation is somewhat confusing. The snapToLine method doc states that a point feature should be argument passed.
"""Geometry.snapToLine(in_point)
Returns a new point based on in_point snapped to this geometry.
in_point(PointGeometry):
A point ( PointGeometry or Point ) to be snapped to the line."""
I can reproduce this issue when calling snap_to_line on the point with the line as the second geometry. The reverse is successful. Try snapping the point to the line.
point_geom(line_geom) = GP error
line_geom(point_geom) = Success (point geometry is returned)
It looks like this is expected although the Python API documentation is somewhat confusing. The snapToLine method doc states that a point feature should be argument passed.
"""Geometry.snapToLine(in_point)
Returns a new point based on in_point snapped to this geometry.
in_point(PointGeometry):
A point ( PointGeometry or Point ) to be snapped to the line."""