manuelbieh / geolib

Zero dependency library to provide some basic geo functions
MIT License
4.23k stars 342 forks source link

Compare performance vs MySQL spatial funcs? #265

Open kalnode opened 3 years ago

kalnode commented 3 years ago

In my app I use MySQL spatial functions directly in db queries, to filter results based on distance from location (e.g. restaurants near a user). When researching this in the past, there were performance benefits to doing this directly in MySQL as opposed to in my server code (e.g. PHP, Go, etc). e.g. Link

Fast-forward a bit, my app is fully Node.js (for lots of other reasons). I still use raw queries with the MySQL spatial func, however it's difficult juggling raw queries against the high-level stuff my CMS/ORM wants to do. In this case, your library may be much more practical. Aside from the query filtering, I think this lib would be useful since there's lots of mapping of data involved in the app and all the UX/UI that comes with that.

Anyhow, I'm wondering if there are any performance worries ie this library vs MySQL spatial funcs?

MySQL distance calc example:

                .join('locations', 'restaurants.Location', 'locations.id')               
                .where(connection.raw(                
                    `round(st_distance_sphere(
                        st_geomfromtext(CONCAT('  POINT(',locations.Longitude, ' ', locations.Latitude,')'  )),
                        st_geomfromtext(CONCAT('  POINT(` + ctx.query.Longitude + ` ` + ctx.query.Latitude + `) '))
                    )) <= 5000`
                ))