Update terrain.php to use bounding boxes, add places.php from earth.apis.netsyms.com

master
Skylar Ittner 8 years ago
parent 1b3a85b72b
commit 633ee1bf41

@ -1,13 +1,15 @@
{ {
"name": "vendor/g-i-s-a-p-i", "name": "netsyms/gis-api",
"description": "Description of project GIS API.", "description": "Simple PHP API for accessing earth data.",
"authors": [ "authors": [
{ {
"name": "skylar", "name": "Skylar Ittner",
"email": "your@email.here" "email": "admin@netsyms.com",
"homepage": "https://netsyms.com"
} }
], ],
"require": { "require": {
"catfan/medoo": "^1.1" "catfan/medoo": "^1.1",
"anthonymartin/geo-location": "^1.0"
} }
} }

49
composer.lock generated

@ -4,9 +4,54 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "14739f64042726cd1da2fc3588dd655d", "hash": "3263d618bf8cadc450b356bb7e55fc47",
"content-hash": "a04c7422846ed42285920bcc09babfd3", "content-hash": "4d7fd8e97f1d509497db70232de37ec8",
"packages": [ "packages": [
{
"name": "anthonymartin/geo-location",
"version": "v1.0.1",
"source": {
"type": "git",
"url": "https://github.com/anthonymartin/GeoLocation.php.git",
"reference": "50bf026f069296dfae11aa195d987854b2e75855"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/anthonymartin/GeoLocation.php/zipball/50bf026f069296dfae11aa195d987854b2e75855",
"reference": "50bf026f069296dfae11aa195d987854b2e75855",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "class",
"autoload": {
"psr-0": {
"AnthonyMartin": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"CC 3.0"
],
"authors": [
{
"name": "Anthony Martin",
"email": "anthony@replaycreative.com",
"homepage": "http://replaycreative.com",
"role": "Developer"
}
],
"description": "Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php",
"homepage": "https://github.com/anthonymartin/GeoLocation.php",
"keywords": [
"bounding coordinates",
"distances",
"geocoding",
"geolocation"
],
"time": "2016-09-17 18:05:14"
},
{ {
"name": "catfan/medoo", "name": "catfan/medoo",
"version": "v1.1.3", "version": "v1.1.3",

@ -0,0 +1,79 @@
<?php
/**
* Takes the latitude and longitude and gets nearby places from OSM.
*
* Uses WGS84 in the DD.DD format, because I say so.
*/
require 'required.php';
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
if (is_empty($VARS['lat'])) {
sendError("Missing required latitude (lat) variable.", true);
}
if (is_empty($VARS['long'])) {
sendError("Missing required longitude (long) variable.", true);
}
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{1,}/', $VARS['lat'])) {
sendError("Latitude (lat) is in the wrong format, or does not have enough precision (DD.DD, at least 2 decimal places.", true);
}
if (!preg_match('/-?[0-9]{1,3}\.[0-9]{1,}/', $VARS['long'])) {
sendError("Longitude (long) is in the wrong format, or does not have enough precision (DD.DD, at least 2 decimal places.", true);
}
$lat = number_format((float) $VARS['lat'], 5, '.', '');
$long = number_format((float) $VARS['long'], 5, '.', '');
$radius = 5;
if (!is_empty($VARS['radius']) && is_numeric($VARS['radius'])) {
$radius = floatval($VARS['radius']);
}
$userlocation = GeoLocation::fromDegrees($VARS['lat'], $VARS['long']);
$searchbounds = $userlocation->boundingCoordinates($radius, 'miles');
if (is_empty($VARS['names'])) {
$places = $database->select('places', '*', ['AND' => [
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()],
"LIMIT" => 100
]);
} else {
$places = $database->select('places', '*', ['AND' => [
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees(),
'name[!]' => ''],
"LIMIT" => 100
]);
}
$geo['name'] = "Places";
$geo['type'] = 'FeatureCollection';
$geo['features'] = [];
foreach ($places as $place) {
$geo['features'][] = array("type" => "Feature",
"geometry" => [
"type" => "Point",
"coordinates" => [
floatval($place['longitude']),
floatval($place['latitude'])
]
],
"properties" => [
"osm_id" => intval($place['osmid']),
"name" => ($place['name'] == '' ? null : $place['name']),
"name:en" => ($place['name'] == '' ? null : $place['name'])
]
);
}
echo json_encode($geo);

@ -2,6 +2,8 @@
require 'required.php'; require 'required.php';
use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;
// Validate input // Validate input
if (is_empty($VARS['lat']) || is_empty($VARS['long'])) { if (is_empty($VARS['lat']) || is_empty($VARS['long'])) {
sendError("Missing information.", true); sendError("Missing information.", true);
@ -21,21 +23,20 @@ if (abs($lat) > 90.00 || abs($long) > 180.00) {
sendError("Coordinates out-of-bounds. Are you sure you're on Earth?", true); sendError("Coordinates out-of-bounds. Are you sure you're on Earth?", true);
} }
$userlocation = GeoLocation::fromDegrees($lat, $long);
$searchbounds = $userlocation->boundingCoordinates(1.2, 'km');
$finallat = $lat; $finallat = $lat;
$finallong = $long; $finallong = $long;
$failtowater = false; $failtowater = false;
if ($database->has('terrain', ["AND" => ["latitude" => $lat, "longitude" => $long]])) { if (!$database->has('terrain', ['AND' => [
// We're good 'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
} else if ($database->has('terrain', ["AND" => ["latitude" => $lat + .01, "longitude" => $long]])) { 'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
$finallat = $lat + 0.01; 'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
} else if ($database->has('terrain', ["AND" => ["latitude" => $lat, "longitude" => $long + .01]])) { 'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()]
$finallong = $long + 0.01; ])) {
/*} else if ($database->has('terrain', ["AND" => ["latitude" => $lat + .01, "longitude" => $long + .01]])) {
$finallat = $finallat + 0.01;
$finallong = $finallong + 0.01;*/
} else {
$failtowater = true; $failtowater = true;
} }
@ -59,7 +60,12 @@ $terrainstrings = [
if ($failtowater) { if ($failtowater) {
$terrainid = 0; $terrainid = 0;
} else { } else {
$terrainid = (int) $database->select('terrain', 'type', ["AND" => ["latitude" => $finallat, "longitude" => $finallong]])[0]; $terrainid = (int) $database->select('terrain', 'type', ['AND' => [
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()]
])[0];
if ($terrainid == 14) { if ($terrainid == 14) {
$terrainid = 13; $terrainid = 13;
} }

@ -53,8 +53,8 @@ class ClassLoader
private $useIncludePath = false; private $useIncludePath = false;
private $classMap = array(); private $classMap = array();
private $classMapAuthoritative = false; private $classMapAuthoritative = false;
private $missingClasses = array();
public function getPrefixes() public function getPrefixes()
{ {
@ -322,20 +322,20 @@ class ClassLoader
if (isset($this->classMap[$class])) { if (isset($this->classMap[$class])) {
return $this->classMap[$class]; return $this->classMap[$class];
} }
if ($this->classMapAuthoritative) { if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false; return false;
} }
$file = $this->findFileWithExtension($class, '.php'); $file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM // Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) { if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh'); $file = $this->findFileWithExtension($class, '.hh');
} }
if ($file === null) { if (false === $file) {
// Remember that this class does not exist. // Remember that this class does not exist.
return $this->classMap[$class] = false; $this->missingClasses[$class] = true;
} }
return $file; return $file;
@ -399,6 +399,8 @@ class ClassLoader
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file; return $file;
} }
return false;
} }
} }

@ -6,4 +6,5 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir); $baseDir = dirname($vendorDir);
return array( return array(
'AnthonyMartin' => array($vendorDir . '/anthonymartin/geo-location/src'),
); );

@ -10,9 +10,20 @@ class ComposerStaticInitced6a9042f97dd8b342a978ca0b1aac0
'c7359326b6707d98bdc176bf9ddeaebf' => __DIR__ . '/..' . '/catfan/medoo/medoo.php', 'c7359326b6707d98bdc176bf9ddeaebf' => __DIR__ . '/..' . '/catfan/medoo/medoo.php',
); );
public static $prefixesPsr0 = array (
'A' =>
array (
'AnthonyMartin' =>
array (
0 => __DIR__ . '/..' . '/anthonymartin/geo-location/src',
),
),
);
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixesPsr0 = ComposerStaticInitced6a9042f97dd8b342a978ca0b1aac0::$prefixesPsr0;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }

@ -55,5 +55,52 @@
"sql", "sql",
"sqlite" "sqlite"
] ]
},
{
"name": "anthonymartin/geo-location",
"version": "v1.0.1",
"version_normalized": "1.0.1.0",
"source": {
"type": "git",
"url": "https://github.com/anthonymartin/GeoLocation.php.git",
"reference": "50bf026f069296dfae11aa195d987854b2e75855"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/anthonymartin/GeoLocation.php/zipball/50bf026f069296dfae11aa195d987854b2e75855",
"reference": "50bf026f069296dfae11aa195d987854b2e75855",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2016-09-17 18:05:14",
"type": "class",
"installation-source": "dist",
"autoload": {
"psr-0": {
"AnthonyMartin": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"CC 3.0"
],
"authors": [
{
"name": "Anthony Martin",
"email": "anthony@replaycreative.com",
"homepage": "http://replaycreative.com",
"role": "Developer"
}
],
"description": "Retrieve bounding coordinates, distances, longitude and latitude with GeoLocation.class.php",
"homepage": "https://github.com/anthonymartin/GeoLocation.php",
"keywords": [
"bounding coordinates",
"distances",
"geocoding",
"geolocation"
]
} }
] ]

Loading…
Cancel
Save