Skip to main content
1 of 4
jdoe
  • 132
  • 1
  • 1
  • 7

How can i set the CRS of a point with shapely

Im working on a tool, which transfers data, including geometries, from different legacy databases to postgis.

Currently this means i have a MS-access Database, which contains point geometries, but since access does not have a geometry type, the points consist of two columns, containing numbers, like so:

lat lon
371744,668 5700069,115

During the flow of my tool, i take these coordinates with pyodbc, and use shapely to create a point. This point does not have crs since it is newly created. Now im trying to set it to EPSG:25832, since the postgis DB expects geometry data to be in 25832. The code below shows what is going on. In the docs i found an example, and even when i'm directly pasting the example to my code it does not work. What am i missing here?

def getGeomAsWKB(self, table, ids):
    tmp = self.getCoordinates(table) # tmp = list of tuples with coordinate pairs [(X,Y),(X2,Y2)...]
    geoms = []
    for coords in tmp:
        pt = Point(coords) no crs at this point, as to be expected
        srid = pyproj.CRS('EPSG:25832')
        old_srid = pyproj.CRS('EPSG:25832')
        project = pyproj.Transformer.from_crs(old_srid, srid, always_xy=True).transform
        t_pt = transform(project, pt) nothing changes
        #pt._crs = 'EPSG:25832'# i tried to set it this way, becausei did not know what else to try
        tmp_binary = wkb.dumps(t_pt)
        geoms.append(tmp_binary)
    return geoms

Just to be clear, pt and t_pt are correctly build, its just that t_pt does not contain the crs information after the transformation.

Thank you for your advice.

jdoe
  • 132
  • 1
  • 1
  • 7