From d84efe246a3b53edfccf0423b12355bb6fc2ec07 Mon Sep 17 00:00:00 2001 From: Nate Hilker <nhilker2@unl.edu> Date: Tue, 19 Mar 2019 15:12:07 -0500 Subject: [PATCH] WIP: ArcGisQuery --- src/SpatialTools/ArcGisQuery.php | 95 ++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/SpatialTools/ArcGisQuery.php diff --git a/src/SpatialTools/ArcGisQuery.php b/src/SpatialTools/ArcGisQuery.php new file mode 100644 index 0000000..550de3c --- /dev/null +++ b/src/SpatialTools/ArcGisQuery.php @@ -0,0 +1,95 @@ +<?php + +namespace IANR\SpatialTools; + +use InvalidArgumentException; + +class ArcGisQuery { + /* + * spatialRel: [esriSpatialRelContains, esriSpatialRelCrosses, esriSpatialRelEnvelopeIntersects, esriSpatialRelIndexIntersects, esriSpatialRelIntersects, esriSpatialRelOverlaps, esriSpatialRelRelation, esriSpatialRelTouches, esriSpatialRelWithin] + * esriGeometryType: [] + esriGeometryNull = Unknown type of geometry + esriGeometryPoint = Point + esriGeometryMultipoint = Multipoint (Collection of Points) + esriGeometryLine = Line (Segment) + esriGeometryCircularArc = CircularArc (Segment) + esriGeometryEllipticArc = EllipticArc (Segment) + esriGeometryBezier3Curve = BezierCurve (Segment) + esriGeometryPath = Path + esriGeometryPolyline = Polyline (Collection of Paths) + esriGeometryRing = Ring (Ring / SurfacePatch) + esriGeometryPolygon = Polygon (Collection of Rings) + esriGeometryEnvelope = Envelope + esriGeometryAny = Any valid geometry + esriGeometryBag = GeometryBag (Collection of Geometries) + esriGeometryMultiPatch = MultiPatch (Collection of SurfacePatches) + esriGeometryTriangleStrip = TriangleStrip (SurfacePatch) + esriGeometryTriangeFan = TriangleFan (SurfacePatch) + esriGeometryRay = Ray + esriGeometrySphere = Sphere + esriGeometryTriangles = Triangles (SurfacePatch) + * + * + * + * + * + * + */ + + private $mapServer = ''; + private $params = [ + // 'inSR' => '{"wkid" : 4326}', + 'outFields' => '*', + 'returnCountOnly' => 'false', + 'returnIdsOnly' => 'false', + 'returnGeometry' => 'true', + 'outSR' => '{"wkid" : 4326}', + 'returnGeometry' => 'true', + 'f' => 'pjson' + ]; + + public $complete = false; + public $response = null; + public $responseCode = null; + + public function __construct($url){ + if(filter_var($url, FILTER_VALIDATE_URL)){ + $this->mapServer = $url; + } else { + throw new InvalidArgumentException('Must use valid URL'); + } + } + + public function setParam($key, $value){ + $this->params[$key] = $value; + } + + public function setGeometry($geometry, $spatialRelationship = 'esriSpatialRelEnvelopeIntersects'){ + $this->params['geometry'] = $geometry->out('arcgis'); + // TODO: actual geometryType + $this->params['geometryType'] = 'esriGeometryNull'; + $this->params['spatialRel'] = $spatialRelationship; + } + + public function execute(){ + // make curl request + $handle = curl_init($this->mapServer); + $params = http_build_query($this->params); + + curl_setopt($handle, CURLOPT_POST, true); + curl_setopt($handle, CURLOPT_POSTFIELDS, $params); + curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); + + curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($handle, CURLOPT_VERBOSE, false); + + $response = curl_exec($handle); + $responseCode = curl_getinfo($handle, CURLINFO_RESPONSE_CODE); + + $this->response = json_decode($response, true); + $this->responseCode = $responseCode; + } + + + +} -- GitLab