Fix two bugs

fix wrong sql and regular expression occasionally causing wrong
coordinates conversion.