Using Shapely to convert 2 columns to WKB

607 Views Asked by At

I have 2 columns in a CSV called Longitude and Latitude which are being parsed using my Python AWS Lambda Code.

I am using the shapely module with the following code to convert the long/lats into geometry format

g = wkt.loads('POINT(-2.5378432182396935 55.20394960316738)')
                    new = wkb.dumps(g, hex=True, srid=4326)
                    print (new)

Is there a way to call the two columns so that each entry is individually given their wkb, rather than put each point in individually?

e.g.

g = wkt.loads('POINT('longitude' 'latitude')')
                    new = wkb.dumps(g, hex=True, srid=4326)
                    print (new)
1

There are 1 best solutions below

0
mikewatt On

You could instantiate a MultiPoint object (instead of going through wkt) using lat/lon pairs:

from shapely.geometry import MultiPoint
from shapely import wkb

mp = MultiPoint(tuple(zip(latitude, longitude)))
mp_wkb = wkb.dumps(mp, hex=True, srid=4326)
print(mp_wkb)