Changes and corrections to allow it to work on 3.x

Also making it usable in rasterstats