list_of_points2json

tomni.transformers.list_of_points2json.main.list_of_points2json(list_of_points: Union[list, numpy.array]) dict[source]

Convert a list of points into a JSON object representing a polygon.

Parameters

list_of_points (Union[list, np.ndarray]) – The list of points describing a polygon in the form of a list or NumPy array, where each point is represented as [x, y].

Returns

A JSON object representing a polygon.

Return type

dict

Example:

# Define a list of points representing a polygon
polygon_points = [[1, 1], [2, 1], [2, 2], [1, 2]]

# Convert the list of points to a JSON object
polygon_json = list_of_points_to_json(polygon_points)

# Print the resulting JSON object
polygon_json = {
    'type': 'polygon',
    'points': [{'x': 1, 'y': 1}, {'x': 2, 'y': 1}, {'x': 2, 'y': 2}, {'x': 1, 'y': 2}]
}

Note

  • The input list_of_points should be a list or NumPy array where each element is a point represented as [x, y].

  • The resulting JSON object represents a polygon with type ‘polygon’ and a list of points.