Example #1
0
def bug_673():

    if string.find(mapscript.msGetVersion(), 'SUPPORTS=PROJ') == -1:
        return 'skip'

    map = mapscript.mapObj('../misc/ogr_direct.map')

    map.setProjection('+proj=utm +zone=11 +datum=WGS84')

    layer = map.getLayer(0)

    # Draw map without reprojection.

    layer.setProjection('+proj=utm +zone=11 +datum=WGS84')
    img1 = map.draw()

    # Draw map with reprojection

    map.setProjection('+proj=latlong +datum=WGS84')
    map.setExtent(-117.25, 43.02, -117.21, 43.05)

    img2 = map.draw()
    try:
        os.mkdir('result')
    except:
        pass
    img2.save('result/bug673.png')

    # Verify we got the image we expected ... at least hopefully we didn't
    # get all white which would indicate the bug is back.

    return pmstestlib.compare_and_report('bug673.png')
Example #2
0
def bug_673():

    
    if string.find(mapscript.msGetVersion(),'SUPPORTS=PROJ') == -1:
        return 'skip'

    map = mapscript.mapObj('../misc/ogr_direct.map')

    map.setProjection('+proj=utm +zone=11 +datum=WGS84')

    layer = map.getLayer(0)

    # Draw map without reprojection.

    layer.setProjection('+proj=utm +zone=11 +datum=WGS84')
    img1 = map.draw()

    # Draw map with reprojection

    map.setProjection('+proj=latlong +datum=WGS84')
    map.setExtent(-117.25,43.02,-117.21,43.05)

    img2 = map.draw()
    try:
        os.mkdir('result')
    except:
        pass
    img2.save( 'result/bug673.png' )

    # Verify we got the image we expected ... at least hopefully we didn't
    # get all white which would indicate the bug is back.

    return pmstestlib.compare_and_report( 'bug673.png' )
Example #3
0
def wkt_test_2():

    if ('SUPPORTS=GEOS' in mapscript.msGetVersion()
            or 'INPUT=OGR' not in mapscript.msGetVersion()):
        return 'skip'

    orig_wkt = 'MULTIPOLYGON(((50 50, 350 50, 350 250, 50 250, 50 50)),((250 150, 550 150, 550 350, 250 350, 250 150)))'
    expected_wkt = 'POLYGON ((50 50, 350 50, 350 250, 50 250, 50 50), (250 150, 550 150, 550 350, 250 350, 250 150))'

    shp = mapscript.shapeObj.fromWKT(orig_wkt)
    new_wkt = shp.toWKT().replace('.0000000000000000', '')

    if new_wkt != expected_wkt:
        pmstestlib.post_reason( 'WKT "%s" converted to "%s".' \
                                % (expected_wkt, new_wkt) )
        return 'fail'

    return 'success'
Example #4
0
def wkt_test_2():

    if string.find(mapscript.msGetVersion(),'SUPPORTS=GEOS') != -1 \
       or string.find(mapscript.msGetVersion(),'INPUT=OGR') == -1:
        return 'skip'

    orig_wkt = 'MULTIPOLYGON(((50 50, 350 50, 350 250, 50 250, 50 50)),((250 150, 550 150, 550 350, 250 350, 250 150)))'
    expected_wkt = 'POLYGON ((50 50,350 50,350 250,50 250,50 50),(250 150,550 150,550 350,250 350,250 150))'

    shp = mapscript.shapeObj.fromWKT(orig_wkt)
    new_wkt = shp.toWKT()

    if new_wkt != expected_wkt:
        pmstestlib.post_reason( 'WKT "%s" converted to "%s".' \
                                % (expected_wkt, new_wkt) )
        return 'fail'

    return 'success'
Example #5
0
def wkt_test_2():

    if string.find(mapscript.msGetVersion(),'SUPPORTS=GEOS') != -1 \
       or string.find(mapscript.msGetVersion(),'INPUT=OGR') == -1:
        return 'skip'

    orig_wkt = 'MULTIPOLYGON(((50 50, 350 50, 350 250, 50 250, 50 50)),((250 150, 550 150, 550 350, 250 350, 250 150)))'
    expected_wkt = 'POLYGON ((50 50,350 50,350 250,50 250,50 50),(250 150,550 150,550 350,250 350,250 150))'
    
    shp = mapscript.shapeObj.fromWKT( orig_wkt )
    new_wkt = shp.toWKT()

    if new_wkt != expected_wkt:
        pmstestlib.post_reason( 'WKT "%s" converted to "%s".' \
                                % (expected_wkt, new_wkt) )
        return 'fail'
    
    return 'success'
def test_xmp():

    if 'INPUT=GDAL' not in mapscript.msGetVersion():
        return 'skip'
    if 'SUPPORTS=XMP' not in mapscript.msGetVersion():
        return 'skip'

    map = mapscript.mapObj('test_xmp.map')
    layer = map.getLayer(0)
    img = map.draw()
    try:
        os.mkdir('result')
    except:
        pass
    img.save('result/test_xmp.png', map)

    f = open('result/test_xmp.png', 'rb')
    data = f.read()
    f.close()

    if data.find('dc:Title="Super Map"') == -1 or \
       data.find('xmpRights:Marked="true"') == -1 or \
       data.find('cc:License="http://creativecommons.org/licenses/by-sa/2.0/"') == -1 or \
       data.find('xmlns:lightroom="http://ns.adobe.com/lightroom/1.0/"') == -1 or \
       data.find('lightroom:PrivateRTKInfo="My Information Here"') == -1  or \
       data.find('exif:ExifVersion="dummy"') == -1  or \
       data.find('xmp:CreatorTool="MapServer"') == -1  or \
       data.find('photoshop:Source="MapServer"') == -1  or \
       data.find('crs:Converter="MapServer"') == -1 or \
       data.find('x:Author="John Doe"') == -1 :
        try:
            from osgeo import gdal
            ds = gdal.Open('result/test_xmp.png')
            print(ds.GetMetadata('xml:XMP'))
            ds = None
        except:
            pass
        return 'fail'

    return 'success'
Example #7
0
def test_xmp():

    if string.find(mapscript.msGetVersion(),'INPUT=GDAL') == -1:
        return 'skip'
    if string.find(mapscript.msGetVersion(),'SUPPORTS=XMP') == -1:
        return 'skip'

    map = mapscript.mapObj('test_xmp.map')
    layer = map.getLayer(0)
    img = map.draw()
    try:
        os.mkdir('result')
    except:
        pass
    img.save( 'result/test_xmp.png', map )

    f = open('result/test_xmp.png', 'rb')
    data = f.read()
    f.close()

    if data.find('dc:Title="Super Map"') == -1 or \
       data.find('xmpRights:Marked="true"') == -1 or \
       data.find('cc:License="http://creativecommons.org/licenses/by-sa/2.0/"') == -1 or \
       data.find('xmlns:lightroom="http://ns.adobe.com/lightroom/1.0/"') == -1 or \
       data.find('lightroom:PrivateRTKInfo="My Information Here"') == -1  or \
       data.find('exif:ExifVersion="dummy"') == -1  or \
       data.find('xmp:CreatorTool="MapServer"') == -1  or \
       data.find('photoshop:Source="MapServer"') == -1  or \
       data.find('crs:Converter="MapServer"') == -1 or \
       data.find('x:Author="John Doe"') == -1 :
        try:
            from osgeo import gdal
            ds = gdal.Open('result/test_xmp.png')
            print(ds.GetMetadata('xml:XMP'))
            ds = None
        except:
            pass
        return 'fail'

    return 'success'
Example #8
0
def wkt_test_1():

    if string.find(mapscript.msGetVersion(),'SUPPORTS=GEOS') != -1 \
       or string.find(mapscript.msGetVersion(),'INPUT=OGR') == -1:
        return 'skip'

    wkt_list = [ 'POINT (5 7)',
                 'LINESTRING (5 7,7 9,9 -1)',
                 'POLYGON ((500 500,3500 500,3500 2500,500 2500,500 500),(1000 1000,1000 1500,1500 1500,1500 1000,1000 1000))',
                 'MULTIPOINT (2000 2000,2000 1900)',
                 'MULTILINESTRING ((600 1500,1600 2500),(700 1500,1700 2500))']

    for orig_wkt in wkt_list:
        shp = mapscript.shapeObj.fromWKT( orig_wkt )
        new_wkt = shp.toWKT()

        if new_wkt != orig_wkt:
            pmstestlib.post_reason( 'WKT "%s" converted to "%s".' \
                                    % (orig_wkt, new_wkt) )
            return 'fail'
    
    return 'success'
Example #9
0
def wkt_test_1():

    if string.find(mapscript.msGetVersion(),'SUPPORTS=GEOS') != -1 \
       or string.find(mapscript.msGetVersion(),'INPUT=OGR') == -1:
        return 'skip'

    wkt_list = [ 'POINT (5 7)',
                 'LINESTRING (5 7,7 9,9 -1)',
                 'POLYGON ((500 500,3500 500,3500 2500,500 2500,500 500),(1000 1000,1000 1500,1500 1500,1500 1000,1000 1000))',
                 'MULTIPOINT (2000 2000,2000 1900)',
                 'MULTILINESTRING ((600 1500,1600 2500),(700 1500,1700 2500))']

    for orig_wkt in wkt_list:
        shp = mapscript.shapeObj.fromWKT( orig_wkt )
        new_wkt = shp.toWKT()

        if new_wkt != orig_wkt:
            pmstestlib.post_reason( 'WKT "%s" converted to "%s".' \
                                    % (orig_wkt, new_wkt) )
            return 'fail'
    
    return 'success'
Example #10
0
def test_msIO_getAndStripStdoutBufferMimeHeaders():

    if 'INPUT=GDAL' not in mapscript.msGetVersion():
        return 'skip'
    if 'SUPPORTS=WMS' not in mapscript.msGetVersion():
        return 'skip'

    map = mapscript.mapObj('test_mapio.map')
    request = mapscript.OWSRequest()
    mapscript.msIO_installStdoutToBuffer()
    request.loadParamsFromURL(
        'service=WMS&version=1.1.1&request=GetMap&layers=grey&srs=EPSG:4326&bbox=-180,-90,180,90&format=image/png&width=80&height=40'
    )
    status = map.OWSDispatch(request)
    if status != 0:
        pmstestlib.post_reason('wrong OWSDispatch status')
        return 'fail'
    headers = mapscript.msIO_getAndStripStdoutBufferMimeHeaders()
    if headers is None:
        pmstestlib.post_reason('headers is None')
        return 'fail'
    if 'Content-Type' not in headers or headers['Content-Type'] != 'image/png':
        pmstestlib.post_reason('wrong Content-Type')
        print(headers)
        return 'fail'
    if 'Cache-Control' not in headers or headers[
            'Cache-Control'] != 'max-age=86400':
        pmstestlib.post_reason('wrong Cache-Control')
        print(headers)
        return 'fail'

    result = mapscript.msIO_getStdoutBufferBytes()
    if result is None or result[1:4] != b'PNG':
        pmstestlib.post_reason('wrong data')
        return 'fail'

    return 'success'
Example #11
0
def wkt_test_3():

    if 'SUPPORTS=GEOS' not in mapscript.msGetVersion():
        return 'skip'

    wkt_list = [
        'POINT (5.0000000000000000 7.0000000000000000)',
        'LINESTRING (5.0000000000000000 7.0000000000000000, 7.0000000000000000 9.0000000000000000, 9.0000000000000000 -1.0000000000000000)',
        'POLYGON ((500.0000000000000000 500.0000000000000000, 3500.0000000000000000 500.0000000000000000, 3500.0000000000000000 2500.0000000000000000, 500.0000000000000000 2500.0000000000000000, 500.0000000000000000 500.0000000000000000), (1000.0000000000000000 1000.0000000000000000, 1000.0000000000000000 1500.0000000000000000, 1500.0000000000000000 1500.0000000000000000, 1500.0000000000000000 1000.0000000000000000, 1000.0000000000000000 1000.0000000000000000))',
        'MULTIPOINT (2000.0000000000000000 2000.0000000000000000, 2000.0000000000000000 1900.0000000000000000)',
        'MULTILINESTRING ((600.0000000000000000 1500.0000000000000000, 1600.0000000000000000 2500.0000000000000000), (700.0000000000000000 1500.0000000000000000, 1700.0000000000000000 2500.0000000000000000))'
    ]

    for orig_wkt in wkt_list:
        shp = mapscript.shapeObj.fromWKT(orig_wkt)
        new_wkt = shp.toWKT()

        if new_wkt != orig_wkt:
            pmstestlib.post_reason( 'WKT "%s" converted to "%s".' \
                                    % (orig_wkt, new_wkt) )
            return 'fail'

    return 'success'
Example #12
0
from config import es_constants
import mapscript

MapserverVersion = mapscript.msGetVersion()
#print MapserverVersion


def getmap():
    productfile = '/data/processing/vgt_ndvi/WGS84_Africa_1km/tif/ndv/20130701_vgt_ndvi_ndv_WGS84_Africa_1km.tif'

    #####   create MAP OBJECT   #####

    # create a new mapfile from scratch
    productmap = mapscript.mapObj(es_constants.template_mapfile)
    #productmap.save('temp.map')
    productmap.setSize(736, 782)
    productmap.setExtent(-4863270.2540311385, -7205400.673576976, 9538688.86734863, 8096680.892889029)
    productmap.units = mapscript.MS_DD
    #productmap.imagecolor.setRGB(255, 255, 255)

    # create a layer for the raster
    layer = mapscript.layerObj(productmap)
    layer.name = 'testlayer'
    layer.type = mapscript.MS_RASTER
    layer.status = mapscript.MS_ON
    layer.data = productfile
    return productmap

Example #13
0
 def debug(self, msg=None):
     print("Content-type: text/plain\n\n")
     print(mapscript.msGetVersion())
     print("version int=" + str(mapscript.msGetVersionInt()))
     if msg:
         print(msg)
Example #14
0
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from future import standard_library

from config import es_constants
import mapscript

standard_library.install_aliases()

MapserverVersion = mapscript.msGetVersion()


def getmap():
    productfile = '/data/processing/vgt_ndvi/WGS84_Africa_1km/tif/ndv/20130701_vgt_ndvi_ndv_WGS84_Africa_1km.tif'

    #####   create MAP OBJECT   #####

    # create a new mapfile from scratch
    productmap = mapscript.mapObj(es_constants.template_mapfile)
    # productmap.save('temp.map')
    productmap.setSize(736, 782)
    productmap.setExtent(-4863270.2540311385, -7205400.673576976,
                         9538688.86734863, 8096680.892889029)
    productmap.units = mapscript.MS_DD
    # productmap.imagecolor.setRGB(255, 255, 255)

    # create a layer for the raster
    layer = mapscript.layerObj(productmap)
    layer.name = 'testlayer'
Example #15
0
try:
    #MS_VERSION_MAJOR was defined in 5.2
    VERSION_MAJOR = mapscript.MS_VERSION_MAJOR
    VERSION_MINOR = mapscript.MS_VERSION_MINOR
    VERSION_REV = mapscript.MS_VERSION_REV
except AttributeError:
    version = mapscript.MS_VERSION.split('.')
    VERSION_MAJOR = int(version[0])
    if len(version) > 2:
        VERSION_MINOR = int(version[1])
        VERSION_REV = int(version[2])
    else:
        VERSION_MINOR = int(version[1][0])
        VERSION_REV = 'dev'

SUPPORTS_AGG = "SUPPORTS=AGG " in mapscript.msGetVersion()

status = msConstants({
    mapscript.MS_ON: "on",
    mapscript.MS_OFF: "off",
    mapscript.MS_DEFAULT: "default",
})

fonttypes = msConstants({
    mapscript.MS_TRUETYPE: "truetype",
    mapscript.MS_BITMAP: "bitmap"
})

imagemodes = msConstants({
    mapscript.MS_IMAGEMODE_RGB: "rgb",
    mapscript.MS_IMAGEMODE_RGBA: "rgba",
Example #16
0
try:
    #MS_VERSION_MAJOR was defined in 5.2
    VERSION_MAJOR = mapscript.MS_VERSION_MAJOR
    VERSION_MINOR = mapscript.MS_VERSION_MINOR
    VERSION_REV = mapscript.MS_VERSION_REV
except AttributeError:
    version = mapscript.MS_VERSION.split('.')
    VERSION_MAJOR = int(version[0])
    if len(version)>2:
        VERSION_MINOR = int(version[1])
        VERSION_REV = int(version[2])
    else:
        VERSION_MINOR = int(version[1][0])
        VERSION_REV='dev'
    
SUPPORTS_AGG = "SUPPORTS=AGG " in mapscript.msGetVersion()


status = msConstants({
        mapscript.MS_ON:"on",
        mapscript.MS_OFF:"off",
        mapscript.MS_DEFAULT:"default",
    })

fonttypes = msConstants({
        mapscript.MS_TRUETYPE:"truetype",
        mapscript.MS_BITMAP:"bitmap"
    })

imagemodes = msConstants({
        mapscript.MS_IMAGEMODE_RGB:"rgb",
Example #17
0
### System imports, Standard Libraries
import os
import sys
import zlib
import math
import struct
import base64

### Custom Imports, these need to be installed.
import mapscript as ms
assert ms.msGetVersionInt() >= 50200 #require 5.2.0 or above
assert 'OUTPUT=PNG' in ms.msGetVersion() #require PNG support
assert 'INPUT=SHAPEFILE' in ms.msGetVersion() #require PNG support
### Local imports. included
from common import SPHEREMERC_GROUND_SIZE,MAPFILE


WGS = ms.projectionObj('init=epsg:4326')
#GMERC = ms.projectionObj('init=epsg:900913')
GMERC = ms.projectionObj('init=epsg:3857')
ID_OFFSET = 2 # 0==background,1==borders

class Tiler:
    def __init__(self,mapobj):
        if issubclass(type(mapobj),basestring):
            mapobj = ms.mapObj(mapobj)
        self.map = mapobj
    def getScales(self):
        #print "Zoom: "
        scales = []
        for i in range(20):