Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save easherma/1e116e2e02128411c54833b023a5154d to your computer and use it in GitHub Desktop.
Save easherma/1e116e2e02128411c54833b023a5154d to your computer and use it in GitHub Desktop.
inital bounds
http://jsfiddle.net/nathansnider/ts4oyyn0/ <--similar concept
Just using turf:
array of routepoints
* http://turfjs.org/docs/#point <--should be an unessary step, including for refrence
* either http://turfjs.org/docs/#buffer or http://turfjs.org/docs/#circle
routepointCircle = make a buffer/circle for each routepoint
* http://turfjs.org/docs/#bbox for each routepoint circle individually (NOT all of them together)
var circleBbox = turf.bbox(routepointCircle);
circleBbox is bbox as an array of points ( (west, south, east, north) )
bboxArea= http://turfjs.org/docs/#area (this will be square meters, fyi)
var area = turf.area(circleBbox); calcs the area of the bbox. (you MAY need to turn the bbox into a polygon first http://turfjs.org/docs/#bboxpolygon)
Write a function that feeds these into the factual api bbox call and return the total count of that area
function bboxAPICall; (either with a parameter for get count, or we write two functions, one that uses factual facets to get just the counts, the other that actually calls the places api)
for i in squareGrid:
getCount
if total_count > splitLimit:
splitTheShit
else
callDatShit
function recursivethingidunnowtfimdoing(params)
{
if (if total_count <= splitLimit) {
callDatShit;
}
else if (if total_count > splitLimit) {
splitTheShit;
}
}
getCount
if total_count > splitLimit:
//use this baby: http://turfjs.org/docs/#squaregrid
function splitTheShit:
var extent = same as our bbox made from EACH individual circle;
var cellWidth = ((square root of bboxarea (cause its square meters))/2)/1000 (to convert to kilometrs)
var units = 'kilometers'; (yes turf only takes degrees, radians, miles, or kilometers for this unit)
var squareGrid = turf.squareGrid(extent, cellWidth, units);
returns squareGrid
else total_count <= splitLimit:
runAPI Call (not just count but get the resuts of the bbox apicall
bboxAPICall maybe inside this function is where we should test the count?
This returns a geoJSON feature collection. We'll have to verify the best way to parse through this, but im assuming a loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment