{"id":654,"date":"2010-01-27T12:15:13","date_gmt":"2010-01-27T11:15:13","guid":{"rendered":"http:\/\/sickel.net\/blogg\/?p=654"},"modified":"2010-01-30T12:24:28","modified_gmt":"2010-01-30T11:24:28","slug":"selection-from-a-mysqlogr-layer-in-php-mapscript","status":"publish","type":"post","link":"https:\/\/sickel.net\/blogg\/?p=654","title":{"rendered":"Selection from a mysql\/ogr layer in php mapscript"},"content":{"rendered":"<p>A little phpsnippet for filtering out items from a layer. I have a layer &#8220;mobil&#8221; which may be on or off. This layer consists of a number of dataset collected at various times. There is one field &#8216;visible&#8217; that is used to indicate if the dataset is of general interest (eg testing and calibration datasets are set with visible to false) The datasets do also belong to a project, indicated with a projectid in the table. There are also going to be some more items to filter on. Since I don&#8217;t know a priori how many items there will be filtered on, I am putting the filter expressions in an array and combining them with &#8216;and&#8217; before I set the filter on the layer.<\/p>\n<pre>\r\nif($_GET['mobil']=='ON'){ \/\/ no reason to do this if the layer is not visible\r\n\tif(!($_GET['invisible']=='ON')){$filters[]=\"visible = 1\";}\r\n\tif($_GET['project']*1){$filters[]=\"projectid = \".$_GET['project']*1;}\r\n\tif(count($filters)){ \/\/ if there are any items to filter on\r\n\t\t$qLayer = $map->getlayerbyname('mobil');\r\n\t\t$filter=\"where \".implode(\" and \",$filters);\r\n\t\t$qLayer->setfilter($filter);\r\n\t}\r\n}\r\n<\/pre>\n<p>This works for sql-based layers and maybe some others, for some types of layers, one needs to set filter and filteritem.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A little phpsnippet for filtering out items from a layer. I have a layer &#8220;mobil&#8221; which may be on or off. This layer consists of a number of dataset collected at various times. There is one field &#8216;visible&#8217; that is &hellip; <a href=\"https:\/\/sickel.net\/blogg\/?p=654\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[20],"tags":[],"class_list":["post-654","post","type-post","status-publish","format-standard","hentry","category-mapserver"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pnVtD-ay","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=654"}],"version-history":[{"count":8,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/654\/revisions"}],"predecessor-version":[{"id":675,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/654\/revisions\/675"}],"wp:attachment":[{"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}