Browse Source

Some GeoJSON fixes

Maurits van der Schee 5 years ago
parent
commit
5bd37a0a16
1 changed files with 25 additions and 10 deletions
  1. 25
    10
      api.php

+ 25
- 10
api.php View File

4554
         return $this->reflection->getType($table);
4554
         return $this->reflection->getType($table);
4555
     }
4555
     }
4556
 
4556
 
4557
-    private function getGeometryColumnName(string $tableName, string $geometryParam): string
4557
+    private function getGeometryColumnName(string $tableName, array &$params): string
4558
     {
4558
     {
4559
+        $geometryParam = isset($params['geometry']) ? $params['geometry'][0] : '';
4559
         $table = $this->reflection->getTable($tableName);
4560
         $table = $this->reflection->getTable($tableName);
4561
+        $geometryColumnName = '';
4560
         foreach ($table->getColumnNames() as $columnName) {
4562
         foreach ($table->getColumnNames() as $columnName) {
4561
             if ($geometryParam && $geometryParam != $columnName) {
4563
             if ($geometryParam && $geometryParam != $columnName) {
4562
                 continue;
4564
                 continue;
4563
             }
4565
             }
4564
             $column = $table->getColumn($columnName);
4566
             $column = $table->getColumn($columnName);
4565
             if ($column->isGeometry()) {
4567
             if ($column->isGeometry()) {
4566
-                return $columnName;
4568
+                $geometryColumnName = $columnName;
4569
+                break;
4567
             }
4570
             }
4568
         }
4571
         }
4569
-        return "";
4572
+        if ($geometryColumnName) {
4573
+            $params['mandatory'][] = $tableName . "." . $geometryColumnName;
4574
+        }
4575
+        return $geometryColumnName;
4576
+    }
4577
+
4578
+    private function setBoudingBoxFilter(string $geometryColumnName, array &$params)
4579
+    {
4580
+        $boundingBox = isset($params['bbox']) ? $params['bbox'][0] : '';
4581
+        if ($boundingBox) {
4582
+            $c = explode(',', $boundingBox);
4583
+            if (!isset($params['filter'])) {
4584
+                $params['filter'] = array();
4585
+            }
4586
+            $params['filter'][] = "$geometryColumnName,sin,POLYGON(($c[0] $c[1],$c[2] $c[1],$c[2] $c[3],$c[0] $c[3],$c[0] $c[1]))";
4587
+        }
4570
     }
4588
     }
4571
 
4589
 
4572
     private function convertRecordToFeature( /*object*/$record, string $geometryColumnName)
4590
     private function convertRecordToFeature( /*object*/$record, string $geometryColumnName)
4581
 
4599
 
4582
     public function _list(string $tableName, array $params): FeatureCollection
4600
     public function _list(string $tableName, array $params): FeatureCollection
4583
     {
4601
     {
4584
-        $geometryParam = isset($params['geometry']) ? $params['geometry'][0] : '';
4585
-        $geometryColumnName = $this->getGeometryColumnName($tableName, $geometryParam);
4586
-        $params['mandatory'][] = $tableName . "." . $geometryColumnName;
4602
+        $geometryColumnName = $this->getGeometryColumnName($tableName, $params);
4603
+        $this->setBoudingBoxFilter($geometryColumnName, $params);
4587
         $records = $this->records->_list($tableName, $params);
4604
         $records = $this->records->_list($tableName, $params);
4588
-
4589
         $features = array();
4605
         $features = array();
4590
         foreach ($records->getRecords() as $record) {
4606
         foreach ($records->getRecords() as $record) {
4591
             $features[] = $this->convertRecordToFeature($record, $geometryColumnName);
4607
             $features[] = $this->convertRecordToFeature($record, $geometryColumnName);
4595
 
4611
 
4596
     public function read(string $tableName, string $id, array $params): Feature
4612
     public function read(string $tableName, string $id, array $params): Feature
4597
     {
4613
     {
4598
-        $geometryParam = isset($params['geometry']) ? $params['geometry'][0] : '';
4599
-        $geometryColumnName = $this->getGeometryColumnName($tableName, $geometryParam);
4600
-        $params['mandatory'][] = $tableName . "." . $geometryColumnName;
4614
+        $geometryColumnName = $this->getGeometryColumnName($tableName, $params);
4615
+        $this->setBoudingBoxFilter($geometryColumnName, $params);
4601
         $record = $this->records->read($tableName, $id, $params);
4616
         $record = $this->records->read($tableName, $id, $params);
4602
         return $this->convertRecordToFeature($record, $geometryColumnName);
4617
         return $this->convertRecordToFeature($record, $geometryColumnName);
4603
     }
4618
     }

Loading…
Cancel
Save