Thank you for the replies! I adapted the code and it's running. The only problem is that the shape seems to have a different coordinate system, or projection, because it's displaced (see attached figure). I checked the values of the markers' coordinates, and they're correct. I also checked that both shape and project have the same local coordinate system ('LOCAL_CS["Local Coordinates (m)",LOCAL_DATUM["Local Datum",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]'), and it's also correct. What could be the problem? Thank you again for your help.
Clemente