Coder Social home page Coder Social logo

the907 / gridlatlong Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jamiembrown/gridlatlong

0.0 1.0 0.0 128 KB

Converts any latitude and longitude to a unique numerical global grid reference. Useful for quick lookups and indexing in a database like MySQL.

License: MIT License

PHP 100.00%

gridlatlong's Introduction

GridLatLong

Converts any latitude and longitude to a unique numerical global grid reference. Useful for quick lookups and indexing in a database like MySQL using standard equals or IN syntax.

Used by http://www.chicmi.com/ to provide a quick and dirty geospatial index for geographical entities.

Usage

Firstly import the file:

require_once('GridLatLong.php');

To get the grid reference for any point:

$gridlatlong = new JamieMBrown\GridLatLong\GridLatLong();
var_dump($gridlatlong->getGridReferences(51.5155800, -0.1763000));
# returns [ 826754 ]

Store this next to any latlong values you put into your database. It fits nicely into an INT in MySQL

To get all grid references in an area with a 30 kilometers radius around a point:

$gridlatlong = new JamieMBrown\GridLatLong\GridLatLong();
var_dump($gridlatlong->getGridReferences(51.5155800, -0.1763000, 30)); 
# returns [ 824184, 825469, 826755, 825468, 826754, 828041, 826753, 828040, 829328 ]

Feed this into an IN statement in SQL to narrow down your query results efficiently, then apply your own bounding box / great circle query to get the absolute results.

By default GridLatLong splits the world into a 1000 x 1000 grid. To make the grid more or less granular, configure the size of the grid on initialisation:

$gridlatlong = new JamieMBrown\GridLatLong\GridLatLong(10000);
var_dump($gridlatlong->getGridReferences(51.5155800, -0.1763000)); 
# returns [ 82649791 ]

By default GridLatLong takes distances in KM. Configure different units in initialisation, with 'M' being miles and 'N' being nautical miles:

$gridlatlong = new JamieMBrown\GridLatLong\GridLatLong(1000, 'M');
var_dump($gridlatlong->getGridReferences(51.5155800, -0.1763000, 5)); 
# returns [ 825469, 826754 ]

The World is Not Flat

GridLatLong splits the world into a 1000 x 1000 grid based on the latitude and longitude co-ordinates. This works well enough for most purposes but does mean that there are more grid references per KM at the poles, and fewer at the equator.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.