Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Page Properties
hiddentrue
idKB

Theme

Mapping

Type

Conversion

Available from

...

  1. If Python 3.9 is not already installed:

    1. download Python 3.9 from https://www.python.org/ftp/python/3.9.11/python-3.9.11-amd64.exe

    2. right-click on the downloaded .exe file and ‘Run as Admin’ to install

    3. Choose Custom Installation

    4. When prompted for an install location, install to C:/Python39

  2. Open the Windows command prompt and navigate to a suitable folder (normally D:/Astun/Tools)

  3. Run C:/Python39/python -m venv mapsource-ogc in that folder to create a Python virtual environment - this will keep the Python installation separate from other installations on the machine

  4. A mapsource-ogc folder will have been created in Astun/Tools, with a Scripts folder below it

  5. In the command prompt, cd to the mapsource-ogc folder, navigate to the Scripts folder, and run activate.bat to activate the environment

  6. The command prompt will now have a prefix (mapsource-ogc) to show that you are in the virtual environment

  7. Make sure you are running a recent (18+) version of pip by running pip install --upgrade pip . To check which version of pip you are running, run the command pip --version

  8. Download the latest version wheel file (currently 1.5.9 10 - mapsource_ogc-1.5.910-py2.py3-none-any.whl) from the Astun FTP site (https://download.astuntechnology.com/public/ ) and place it in the new folder that has been created for the virtual environment (e.g. D:/Astun/Tools/mapsource-ogc)

  9. Install the script in the virtual environment by running pip install mapsource_ogc-1.5.810-py2.py3-none-any.whl --force-reinstall, (using the correct file name for the current version)

...

  1. Symbol definitions must be held in the symbols (.sym) file, not inline in the .map file - this should be implemented before the script is run. In addition. if the map file directly references a symbol that has an external file reference, such as in the code below, the reference will fail.

    Code Block
    	SYMBOL
    		NAME "tree"
    		TYPE PIXMAP
    		IMAGE "D:/mapserver/shared/symbols/Legend/landuse_deciduous_green.png"
    	END  
    	 
  2. SYMBOL elements in the .map file must have their values quoted, otherwise, the conversion will fail:
    SYMBOL "circle"
    not
    SYMBOL circle

  3. A double backslash in the map file (for example IMAGEPATH "D:\mapserver\tmp\\" ) will cause the script to fail - this should be changed to a double slash before the script is run (IMAGEPATH "D:/mapserver/tmp//" )

  4. A style which retrieves colour values from query will cause the script to fail. For example:

    Code Block
    LAYER
            NAME "planning.mk_solid"
            STATUS OFF
            TYPE POLYGON
            INCLUDE "sdw.inc"
            DATA "wkb_geometry from (select *,replace (rgb_colour,',',' ') as mapservercolour from planning.mk_solid) as foo using unique ogc_fid using srid=27700"
            TOLERANCEUNITS PIXELS   
            VALIDATION  
                 qstring '.'  
            END
            OPACITY 50
            CLASS
                NAME ""
                STYLE
                    COLOR [mapservercolour]
                    WIDTH 0
                END
            END
        END

    In the above example, we can see that the COLOR parameter is taking its value from the [mapservercolour] attribute. This configuration will produce the following error:

    Code Block
      File "D:\Astun\Tools\mapsource-ogc\lib\site-packages\maputils\xml_to_sld.py", line 45, in <genexpr>
        return "#" + "".join("{:02X}".format(int(a)) for a in colors)
    ValueError: invalid literal for int() with base 10: '['

    The mapfile should be edited to amend this approach.

Known script issues

These issues are known, and will be fixed in a later version of the script.

  1. If SQL in the .map file contains an escaped quote character, for example
    where \"CaseFullRef\"
    the backslash escape character is not currently removed, and so the layer will fail - this will need to be manually fixed in the Map Source, either in the SQL editor in Studio, or in the Map Source XML itself, so that the text reads
    where "CaseFullRef"

  2. If the SQL in the .map file contains a test for not null values
    is not null
    the test is incorrectly translated to
    != null
    in the generated Map Source - this will need to be manually reverted in the Map Source, either in the SQL editor in Studio, or in the Map Source XML itself

Other issues

These issues may cause layers to fail or be incorrectly converted - they can be fixed manually in the Map Source post conversion.

  1. Queries containing an apostrophe in a text string (e.g. value='Children’s Centres') are correctly converted but iShare reports an error.

  2. Some pattern-matching regular expression rules are not being correctly converted,

  3. If Fields are specified in the Field List for a Layer but are not present in the database, the Layer will fail. Likewise, Fields used in expressions must be in a Field List.

  4. If in Field Settings, Add link to field is checked, but Link using is not set, when the layer is converted to a Standard Layer, it fails to display.

  5. If there is no ‘fallback’ class in the SLD, i.e. if only rules for specific values are set, MapServer creates a filter with incorrect syntax for any values with parentheses, so these values are omitted from the data returned. The fix is to add a fallback rule.

  6. Labels for Point styles may be incorrectly placed, and in some cases, the Point style is not showing. The fix is to delete the SLD from the Advanced tab and recreate the Style – the color settings are retained, normally only the Label attribute setting is needed.

  7. Having a select statement using double quotes for its query will cause MapServer to fail to draw the layers. For example:

    DATA "wkb_geometry from (select *, trim("path_type") as footpath_type from landscape.public_row) as foo using unique ogc_fid using srid=27700"

    the above will produce the following error in the MapServer logs:

    Code Block
    [Wed Jan 25 14:30:01 2023].739000 loadLayer(): Unknown identifier. Parsing error near (path_type):(line 2829)


    In that case, removing the double quotes from the DATA attribute and replacing them with single will resolve the issue:

    DATA 'wkb_geometry from (select *, trim("path_type") as footpath_type from landscape.public_row) as foo using unique ogc_fid using srid=27700'

  8. It is worth checking the rendering order of your layers after the conversion and rearranging it using Studio. Have in mind that for the Classic Layers, the rendering order is coming from the map file while for the OGC Layers, the order is coming from the Map Source.