Created
September 3, 2013 23:29
-
-
Save bmoregeo/6430971 to your computer and use it in GitHub Desktop.
Query MYSQL based on extent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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