Skip to content

Commit 5bd37a0

Browse files
committed
Some GeoJSON fixes
1 parent 92babce commit 5bd37a0

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

api.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4554,19 +4554,37 @@ public function getType(string $table): string
45544554
return $this->reflection->getType($table);
45554555
}
45564556

4557-
private function getGeometryColumnName(string $tableName, string $geometryParam): string
4557+
private function getGeometryColumnName(string $tableName, array &$params): string
45584558
{
4559+
$geometryParam = isset($params['geometry']) ? $params['geometry'][0] : '';
45594560
$table = $this->reflection->getTable($tableName);
4561+
$geometryColumnName = '';
45604562
foreach ($table->getColumnNames() as $columnName) {
45614563
if ($geometryParam && $geometryParam != $columnName) {
45624564
continue;
45634565
}
45644566
$column = $table->getColumn($columnName);
45654567
if ($column->isGeometry()) {
4566-
return $columnName;
4568+
$geometryColumnName = $columnName;
4569+
break;
45674570
}
45684571
}
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+
}
45704588
}
45714589

45724590
private function convertRecordToFeature( /*object*/$record, string $geometryColumnName)
@@ -4581,11 +4599,9 @@ private function convertRecordToFeature( /*object*/$record, string $geometryColu
45814599

45824600
public function _list(string $tableName, array $params): FeatureCollection
45834601
{
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);
45874604
$records = $this->records->_list($tableName, $params);
4588-
45894605
$features = array();
45904606
foreach ($records->getRecords() as $record) {
45914607
$features[] = $this->convertRecordToFeature($record, $geometryColumnName);
@@ -4595,9 +4611,8 @@ public function _list(string $tableName, array $params): FeatureCollection
45954611

45964612
public function read(string $tableName, string $id, array $params): Feature
45974613
{
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);
46014616
$record = $this->records->read($tableName, $id, $params);
46024617
return $this->convertRecordToFeature($record, $geometryColumnName);
46034618
}

0 commit comments

Comments
 (0)