@@ -26,19 +26,37 @@ public function getType(string $table): string
2626 return $ this ->reflection ->getType ($ table );
2727 }
2828
29- private function getGeometryColumnName (string $ tableName , string $ geometryParam ): string
29+ private function getGeometryColumnName (string $ tableName , array & $ params ): string
3030 {
31+ $ geometryParam = isset ($ params ['geometry ' ]) ? $ params ['geometry ' ][0 ] : '' ;
3132 $ table = $ this ->reflection ->getTable ($ tableName );
33+ $ geometryColumnName = '' ;
3234 foreach ($ table ->getColumnNames () as $ columnName ) {
3335 if ($ geometryParam && $ geometryParam != $ columnName ) {
3436 continue ;
3537 }
3638 $ column = $ table ->getColumn ($ columnName );
3739 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 ();
3957 }
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 ])) " ;
4059 }
41- return "" ;
4260 }
4361
4462 private function convertRecordToFeature ( /*object*/ $ record , string $ geometryColumnName )
@@ -53,11 +71,9 @@ private function convertRecordToFeature( /*object*/$record, string $geometryColu
5371
5472 public function _list (string $ tableName , array $ params ): FeatureCollection
5573 {
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 );
5976 $ records = $ this ->records ->_list ($ tableName , $ params );
60-
6177 $ features = array ();
6278 foreach ($ records ->getRecords () as $ record ) {
6379 $ features [] = $ this ->convertRecordToFeature ($ record , $ geometryColumnName );
@@ -67,9 +83,8 @@ public function _list(string $tableName, array $params): FeatureCollection
6783
6884 public function read (string $ tableName , string $ id , array $ params ): Feature
6985 {
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 );
7388 $ record = $ this ->records ->read ($ tableName , $ id , $ params );
7489 return $ this ->convertRecordToFeature ($ record , $ geometryColumnName );
7590 }
0 commit comments