Assumes a string "pos" of latitude longitude(lat lon). Split the string and cast it to float, use strip to remove any unwanted whitespaces.
tmp = pos.split()
lat = float(tmp[0].strip())
lon = float(tmp[1].strip())
You could then do something like:
latlonString = 'POINT(%f %f)' % (lat,lon)
Using the variable in a query:
ST_GeomFromText(latlonString,4326)
For example:
SELECT id
FROM features
WHERE pos = ST_GeomFromText(latlonString,4326)
For a string of multiple coordinate pairs; xyString = "x1 y1 x2 y2" NOTE! not separated by comma:
xyString = '3.584731 60.739211 3.590472 60.738030 3.592740 60.736220'
xy = xyString.split()
tuples = [i+' '+j for i,j in zip(xy[::2],xy[1::2])]
multiPointString = ','.join(map(str,tuples))
polygonString = 'POLYGON((%s))' % (multiPointString)
print polygonString
print:
POLYGON((3.584731 60.739211,3.590472 60.738030,3.592740 60.736220))
If you have a polygon string like this: "x1 y1, x2 y2, ....", just edit the line:
xy = xyString.replace(",", " ").split()
This should be sufficient if you use psycopg2 as postgresql adapter.
Maybe it doesn't answer all your questions, but hope this helps.
regexp_split_...functions.