Browse Source

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

master
Skylar Ittner 3 years ago
parent
commit
633ee1bf41

+ 7
- 5
composer.json View File

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

+ 47
- 2
composer.lock View File

@@ -4,9 +4,54 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "14739f64042726cd1da2fc3588dd655d",
"content-hash": "a04c7422846ed42285920bcc09babfd3",
"hash": "3263d618bf8cadc450b356bb7e55fc47",
"content-hash": "4d7fd8e97f1d509497db70232de37ec8",
"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",
"version": "v1.1.3",

+ 79
- 0
places.php View File

@@ -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);

+ 17
- 11
terrain.php View File

@@ -2,6 +2,8 @@

require 'required.php';

use AnthonyMartin\GeoLocation\GeoLocation as GeoLocation;

// Validate input
if (is_empty($VARS['lat']) || is_empty($VARS['long'])) {
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);
}

$userlocation = GeoLocation::fromDegrees($lat, $long);
$searchbounds = $userlocation->boundingCoordinates(1.2, 'km');

$finallat = $lat;
$finallong = $long;

$failtowater = false;

if ($database->has('terrain', ["AND" => ["latitude" => $lat, "longitude" => $long]])) {
// We're good
} else if ($database->has('terrain', ["AND" => ["latitude" => $lat + .01, "longitude" => $long]])) {
$finallat = $lat + 0.01;
} else if ($database->has('terrain', ["AND" => ["latitude" => $lat, "longitude" => $long + .01]])) {
$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 {
if (!$database->has('terrain', ['AND' => [
'latitude[>]' => $searchbounds[0]->getLatitudeInDegrees(),
'latitude[<]' => $searchbounds[1]->getLatitudeInDegrees(),
'longitude[>]' => $searchbounds[0]->getLongitudeInDegrees(),
'longitude[<]' => $searchbounds[1]->getLongitudeInDegrees()]
])) {
$failtowater = true;
}

@@ -59,7 +60,12 @@ $terrainstrings = [
if ($failtowater) {
$terrainid = 0;
} 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) {
$terrainid = 13;
}

+ 7
- 5
vendor/composer/ClassLoader.php View File

@@ -53,8 +53,8 @@ class ClassLoader

private $useIncludePath = false;
private $classMap = array();

private $classMapAuthoritative = false;
private $missingClasses = array();

public function getPrefixes()
{
@@ -322,20 +322,20 @@ class ClassLoader
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative) {
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}

$file = $this->findFileWithExtension($class, '.php');

// 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');
}

if ($file === null) {
if (false === $file) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
$this->missingClasses[$class] = true;
}

return $file;
@@ -399,6 +399,8 @@ class ClassLoader
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}

return false;
}
}


+ 1
- 0
vendor/composer/autoload_namespaces.php View File

@@ -6,4 +6,5 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
'AnthonyMartin' => array($vendorDir . '/anthonymartin/geo-location/src'),
);

+ 11
- 0
vendor/composer/autoload_static.php View File

@@ -10,9 +10,20 @@ class ComposerStaticInitced6a9042f97dd8b342a978ca0b1aac0
'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)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixesPsr0 = ComposerStaticInitced6a9042f97dd8b342a978ca0b1aac0::$prefixesPsr0;

}, null, ClassLoader::class);
}

+ 47
- 0
vendor/composer/installed.json View File

@@ -55,5 +55,52 @@
"sql",
"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