Skip to content

Instantly share code, notes, and snippets.

@bmoregeo
Created September 3, 2013 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmoregeo/6430971 to your computer and use it in GitHub Desktop.
Save bmoregeo/6430971 to your computer and use it in GitHub Desktop.
Query MYSQL based on extent
//Get Coordinates From Javascript Call
$latMin = $_GET["c1"];
$lonMin = $_GET["c2"];
$latMax = $_GET["c3"];
$lonMax = $_GET["c4"];
//Gather Coordinates Into a MySQL Polygon Geometry Type
$bounds = "GeomFromText('POLYGON((".$lonMin." ".$latMin.",".$lonMin."," .$latMax.",".$lonMax." ".$latMax.",".$lonMax." ".$latMin.",".$lonMin." ".$latMin."))')";
//Database Fields
$fields = 'ASTEXT(`SHAPE`) AS SHAPE_TEXT, dnrname AS NAME, first_coun AS COUNTY, first_code AS CODE, first_mana AS MANAGER, first_base AS BASE, first_regi AS REGION, first_desi AS DESCRIPTION, first_webl AS WEB, first_dnrp AS PERCENT_DNR, sum_gisacr AS ACREAGE, sum_gismil as MILE';
//If None of the Coordinate Fields are Blank, Create a Selection
//I Should Probably Make Sure That the Variables are Numbers, But I Can Do That Later
if ($latMax != '' AND $lonMin != '' AND $lonMax != '' AND $latMin != ''){
$selection = 'WHERE Intersects(SHAPE, '.$bounds.')';
}
//Perform the Query
$query = 'SELECT '.$fields.' FROM park_points '.$selection;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment