@@ -26,19 +26,37 @@ public function getType(string $table): string
26
26
return $ this ->reflection ->getType ($ table );
27
27
}
28
28
29
- private function getGeometryColumnName (string $ tableName , string $ geometryParam ): string
29
+ private function getGeometryColumnName (string $ tableName , array & $ params ): string
30
30
{
31
+ $ geometryParam = isset ($ params ['geometry ' ]) ? $ params ['geometry ' ][0 ] : '' ;
31
32
$ table = $ this ->reflection ->getTable ($ tableName );
33
+ $ geometryColumnName = '' ;
32
34
foreach ($ table ->getColumnNames () as $ columnName ) {
33
35
if ($ geometryParam && $ geometryParam != $ columnName ) {
34
36
continue ;
35
37
}
36
38
$ column = $ table ->getColumn ($ columnName );
37
39
if ($ column ->isGeometry ()) {
38
- return $ columnName ;
40
+ $ geometryColumnName = $ columnName ;
41
+ break ;
42
+ }
43
+ }
44
+ if ($ geometryColumnName ) {
45
+ $ params ['mandatory ' ][] = $ tableName . ". " . $ geometryColumnName ;
46
+ }
47
+ return $ geometryColumnName ;
48
+ }
49
+
50
+ private function setBoudingBoxFilter (array &$ params )
51
+ {
52
+ $ boundingBox = isset ($ params ['bbox ' ]) ? $ params ['bbox ' ][0 ] : '' ;
53
+ if ($ boundingBox ) {
54
+ $ c = explode (', ' , $ boundingBox );
55
+ if (!isset ($ params ['filter ' ])) {
56
+ $ params ['filter ' ] = array ();
39
57
}
58
+ $ params ['filter ' ][] = "$ geometryColumnName,swi,POLYGON(( $ c [0 ] $ c [1 ], $ c [2 ] $ c [1 ], $ c [2 ] $ c [3 ], $ c [0 ] $ c [3 ], $ c [0 ] $ c [1 ])) " ;
40
59
}
41
- return "" ;
42
60
}
43
61
44
62
private function convertRecordToFeature ( /*object*/ $ record , string $ geometryColumnName )
@@ -53,11 +71,9 @@ private function convertRecordToFeature( /*object*/$record, string $geometryColu
53
71
54
72
public function _list (string $ tableName , array $ params ): FeatureCollection
55
73
{
56
- $ geometryParam = isset ($ params ['geometry ' ]) ? $ params ['geometry ' ][0 ] : '' ;
57
- $ geometryColumnName = $ this ->getGeometryColumnName ($ tableName , $ geometryParam );
58
- $ params ['mandatory ' ][] = $ tableName . ". " . $ geometryColumnName ;
74
+ $ geometryColumnName = $ this ->getGeometryColumnName ($ tableName , $ params );
75
+ $ this ->setBoudingBoxFilter ($ params );
59
76
$ records = $ this ->records ->_list ($ tableName , $ params );
60
-
61
77
$ features = array ();
62
78
foreach ($ records ->getRecords () as $ record ) {
63
79
$ features [] = $ this ->convertRecordToFeature ($ record , $ geometryColumnName );
@@ -67,9 +83,8 @@ public function _list(string $tableName, array $params): FeatureCollection
67
83
68
84
public function read (string $ tableName , string $ id , array $ params ): Feature
69
85
{
70
- $ geometryParam = isset ($ params ['geometry ' ]) ? $ params ['geometry ' ][0 ] : '' ;
71
- $ geometryColumnName = $ this ->getGeometryColumnName ($ tableName , $ geometryParam );
72
- $ params ['mandatory ' ][] = $ tableName . ". " . $ geometryColumnName ;
86
+ $ geometryColumnName = $ this ->getGeometryColumnName ($ tableName , $ params );
87
+ $ this ->setBoudingBoxFilter ($ params );
73
88
$ record = $ this ->records ->read ($ tableName , $ id , $ params );
74
89
return $ this ->convertRecordToFeature ($ record , $ geometryColumnName );
75
90
}
0 commit comments