wiki:FaqConfiguration

TOC?

FAQ: Configuration and settings

Switch on a layer and set extents via Url

I would like to choose via URL wich layer to switch on.

In p.mapper 2 you can add to the url

&dg=layer1,layer2

(in fact, if a layer belongs to a group you have to use the group name,as this a general rule in pmapper when using groups/layers).
Or - more statically - you can use a setting with different config XML files and different 'defGroups' entries that you can specify via the URL, &config=...'

For extents use this way

&dg=countries,cities,rivers&me=4300982,2134585,4721175,3092410

See details of the starting parameters in the p.mapper manual

PostGIS tables

The correct functioning of select and attribute search of PostGIS layers in p.mapper requires a unique field for the PostGIS table. This was typically the OID field that was added by default in Postgres versions including 8.0. Since version 8.1 Postgres creates this OID field only if explicitely specified during creation WITH OID. The import of shapefiles via the shp2pgsql tool does not set this flag, so these layers typically do not have an OID field. But they usually have a unique field called gid. So this field can be used as the required unique field, it has to be specified in the map file like

DATA "the_geom from (select the_geom, gid, xyz from mylayer) AS new_tab USING UNIQUE gid"

And do not forget to add an index on that field in order to speed up queries.

See also the PostGIS documentation

PostGIS layers as database views

The MapServer-PostGIS connector needs to know which projection (SRID) the PostGIS layer has. It tries to find this information in the table geometry_columns. If the layer is not referenced there - which is typically the case for database views - then the connector returns an error. In this case it is necessary to add this projection information in the connection string, like

DATA "the_geom from ... USING SRID=3035"

Joins of PostGIS layers with Postgres tables

DATA "the_geom FROM (SELECT a.the_geom as the_geom, a.gid as gid, a.field1 as field1, 
                            b.field1 as field_b1, b.field4 as field4 
                      FROM table_1 a, table_2 b  
                      WHERE a.joinfield = b.joinfield) AS new_tab USING UNIQUE gid USING SRID=3035"

Joins to external database tables

(added by Toni)

  • First of all, ensure yourself that PEAR library is installed. If you don't know how to check it, read the p.mapper documentation at section Installation/PHP settings/PHP.ini/Optional
  • Read section Configuration/Joining? Database tables to layers of pmapper documentation
  • Keep in mind that one2many joins are not working correctly
  • Additional notes for the connection string syntax:
    • in the DB parameters use @0@ to join numeric fields, use @1@ to join text fields
  • If you want to connect a MS Access database with ODBC follow this instructions:
    • your odbc_connection_dsn must be a SYSTEM DSN; to make a SYSTEM DSN just enter control panel > admin tools > ODBC > System dsn; then have a new one with the MS Access database driver, name it and link it to your mdb database
    • If you have to retrieve information from a MEMO field (very long string) find section Module settings in the php.ini file and modify item odbc.defaultlrl to a bigger value
    • remember that host has to be replaced with localhost (in the string syntax) if the web server is running on your machine
  • Add the joined field names in the "RESULT_HEADERS" tag
  • If you are in troubles try these hints:
    • check the error log file to see if your connection is refused
    • [only tested on p.mapper 1.2.0]: open file \incphp\query\squery.php and try what you get if you remove the comments to the instruction $data with print_r() around line 220
    • check if PEAR connection works running this .phtml file (result page must be white, otherwise some connection error message appears):

    <?php require_once('DB.php');
    $dsn = "odbc://'':''/localhost@name_of_system_dsn";
    $dbh = DB::connect($dsn);
    if (DB::isError($dbh)) {
        die ($dbh->getDebugInfo());
        }
    ?>

A working example for mapfile

I suggest to use for testing a numeric field for joining on due to trick for char coding, space and some characters

  LAYER
    NAME "mysqltest"
    STATUS ON
    DATA "/var/www/map/dati/mysqljointest"
    TYPE POLYGON
    MINSCALE 400
    TRANSPARENCY 70
    TEMPLATE void
    METADATA
      "DESCRIPTION"  "mysqljointtest"
      "RESULT_FIELDS" "ED,DESCRIZIONE"
      "RESULT_HEADERS" "Descrizione,MySQL"
      "RESULT_JOIN" "mysql://<user>:<password>@localhost/<database>||<table>@ED@0@DESCRIZIONE||ED||1"
    END
    CLASS
      NAME "mysqltest"
      STYLE
        COLOR 255 0 0
        OUTLINECOLOR 0 0 0
      END
    END
  END

Cookies for session handling: yes or no?

As laid down in the Quick install instructions, in most cases it is recommended to disable the usage of cookies for session handling. You achieve this by the following setting in php.ini under the [Session] section:

session.use_cookies = 0

If you need cookies for session management in other applications, it is possible to disable cookies for just the p.mapper application under the <Location> or <Directory> tag of your Apache config. This requires to run PHP as an Apache module.

<Location /pmapper>
   php_flag session.use_cookies off
   ...
</Location>

If cookies are enabled and still existing in the Web browser for a specific p.mapper application, the application will start always with the settings from the last session. This means typically with the last map extent, the last enabled layers, etc. Though this might be a desired behaviour, sometimes it is not and might conflict with other settings, e.g. from plugins. It is possible to reset the session by adding a 'resetsession' key to the URL.

For p.mapper 3.2 this would be

  http://myhost/pmapper?resetsession=Y

For p.mapper 3.3dev one can decide which session parameters to reset:

To reset ALL parameters use

  http://myhost/pmapper?resetsession=ALL

To reset just some paramaters use a comma-sepatated list, like

  http://myhost/pmapper?resetsession=GEOEXT,groups

This would reset the map extent and the layers/groups turned on at start.

Security settings

PHP settings

see also >>> here for some description with regard to php.ini.

Apache configuration

Access to files that potentially can store sensitive information (passwords, etc.), like map files or p.mapper XML configuration files, can be denied using Apache settings. Globally denying access to certain files based on the file extension is achieved through the setting in the httpd.conf or apache.conf by adding the lines

<Files ~ "^\.ht|\.map$|\.ini$|\.db$|\.log$|\.xml$">
    Order allow,deny
    Deny from all
</Files>

In most cases this entry is already existing for *.ht files and just needs to be extended for all other file extensions where access shall be denied.

p.mapper since version 4.x contains by default a file .htaccess that contains this setting. In order to enable the definitions in .htaccess files it it necessary to allow this inside your <direcory> or <location> configuration, like

<directory /var/www/pmapper>
   AllowOverride All
   ...
</directory>
Last modified 6 years ago Last modified on Jul 22, 2011, 3:25:02 PM