Move grease pencil origin to average of selection in edit mode.
_Note have not converted to operator or added shortcut, have simply pasted scripts into text editor and run via "Run Script" (play button).

I'm assuming by 2D shape you are referring to a grease pencil object. The equivalent of method shown in https://blender.stackexchange.com/a/134460/15543 using GP is
import bpy
from mathutils import Vector
from bpy import context
ob = context.object
mw = ob.matrix_world
gp = ob.data
active_layer = gp.layers.active
active_frame = active_layer.active_frame
selected_points = [
p for layer in gp.layers
for frame in layer.frames
for stroke in frame.strokes
for p in stroke.points
if p.select
]
if selected_points:
cl = sum([p.co for p in selected_points], Vector()) / len(selected_points)
for layer in gp.layers:
for frame in layer.frames:
for stroke in frame.strokes:
for p in stroke.points:
p.co -= cl
ob.matrix_world.translation = mw @ cl
Move grease pencil origin to 3D cursor loc in edit mode.
import bpy
from mathutils import Vector
from bpy import context
ob = context.object
mw = ob.matrix_world
scene = context.scene
cl = mw.inverted() @ scene.cursor.location
gp = ob.data
active_layer = gp.layers.active
active_frame = active_layer.active_frame
for layer in gp.layers:
for frame in layer.frames:
for stroke in frame.strokes:
for p in stroke.points:
p.co -= cl
ob.matrix_world.translation = scene.cursor.location