コード例 #1
1
def main:
    map = mapscript.mapObj()
    map.name = 'Test Map'
    map.setSize(300, 300)
    map.setExtent(-180.0,-90.0,180.0,90.0)
    map.imagecolor.setRGB(80, 180, 80)
    map.units = mapscript.MS_DD

    layer = mapscript.layerObj(map)
    layer.name = "regioni"
    layer.type = mapscript.MS_LAYER_POLYGON
    layer.status = mapscript.MS_DEFAULT
    layer.data = os.getcwd() + '/../data/regioni'

    class1 = mapscript.classObj(layer)
    class1.name = "Regioni"
    style = mapscript.styleObj(class1)
    style.outlinecolor.setRGB(100, 100, 100)
    style.color.setRGB(200, 200, 200)
    extent = layer.getExtent()

    map.setExtent(extent.minx, extent.miny, extent.maxx, extent.maxy)
    mapimage = map.draw()

    mapimage.save(os.getcwd() + '/../images/mapscript_map.png')
コード例 #2
0
    def set_cartography(self, layer):
        """
        Sets the cartograhy for this layer

        TODO: This currently sets cartograpy to None, but should be a
        lookup to a set of cartographies or be a dynamically created one
        """

        # Select cartograpy or use default one
        carto_requested = self.request.GET.get('cartography', '')
        if carto_requested:
            self.cartograpy = None

        # Class and style settings
        if self.cartography:
            for cart in self.cartography:
                # Set categorization
                category = mapscript.classObj(layer)
                category.setExpression(cart['expression'])
                category.name = cart['name']
                # Set category style
                style = mapscript.styleObj(category)
                style.color.setHex(to_hex(cart['color']))
        else:
            category = mapscript.classObj(layer)
            category.name = layer.name
            style = mapscript.styleObj(category)
            style.color.setHex('#FF00FF')

        return layer
コード例 #3
0
ファイル: mapserver.py プロジェクト: pcecconi/mapground
def __agregar_simbologia_basica__(layer):
    class1 = mapscript.classObj(layer)
    class1.name = 'Default'
    style = mapscript.styleObj(class1)
    if layer.type == mapscript.MS_LAYER_POINT:
        style.symbolname = 'circle'
        style.size = 8
        style.minsize = 8
        style.maxsize = 10
        style.maxwidth = 2
        style.outlinecolor.setRGB(30, 30, 30)
        style.color.setRGB(31, 120, 180)
    elif layer.type == mapscript.MS_LAYER_POLYGON:
        style.outlinecolor.setRGB(126, 109, 83)
        style.color.setRGB(210, 182, 138)
    elif layer.type == mapscript.MS_LAYER_LINE:
        style.color.setRGB(76, 38, 0)
        style.width = 4
        style.minwidth = 4
        style.maxwidth = 6
        style2 = mapscript.styleObj(class1)
        style2.color.setRGB(255, 206, 128)
        style2.width = 2
        style2.minwidth = 2
        style2.maxwidth = 4
    elif layer.type == mapscript.MS_LAYER_RASTER:
        layer.offsite = mapscript.colorObj(0, 0, 0)
コード例 #4
0
    def serializeSimpleFillSymbolLayer(self, sl):
        """Serialize a QGis simple fill symbol layer into MapServer styles"""

        msStyleBg = mapscript.styleObj(self.msClass)
        msStyleBg.angle = sl.angle()
        msStyleBg.color = utils.serializeColor(sl.fillColor())
        msStyleBg.opacity = int((sl.fillColor().alpha() / 255.0) * 100)

        # Only serialize outline if we have one
        if sl.borderStyle() != Qt.NoPen:
            msStyleOutline = mapscript.styleObj(self.msClass)
            msStyleOutline.outlinecolor = utils.serializeColor(sl.borderColor())

            # QGis draws a default outline of .26mm (roughly 1px) even when the width is set to zero
            msStyleOutline.width = utils.sizeUnitToPx(sl.borderWidth(), sl.borderWidthUnit()) \
                    if sl.borderWidth() > 0 \
                    else utils.DEFAULT_OUTLINE_WIDTH

            # Assume that this is our only outline and set the layer's size units to map units
            # if we are using map units in QGis. This breaks every property with a size unit set to
            # anything other than the map unit.
            if (sl.borderWidth() > 0):
                utils.maybeSetLayerSizeUnitFromMap(sl.borderWidthUnit(), self.msLayer)

            # Emit line pattern only if we have a non-solid pen
            if sl.borderStyle() != Qt.SolidLine:
                utils.setPenStylePattern(msStyleOutline, utils.serializePenStylePattern(sl))
コード例 #5
0
ファイル: layers.py プロジェクト: cuulee/django-wms
    def set_cartography(self, layer):
        """
        Sets the cartograhy for this layer
        
        TODO: This currently sets cartograpy to None, but should be a
        lookup to a set of cartographies or be a dynamically created one
        """

        # Select cartograpy or use default one
        carto_requested = self.request.GET.get("cartography", "")
        if carto_requested:
            self.cartograpy = None

        # Class and style settings
        if self.cartography:
            for cart in self.cartography:
                # Set categorization
                category = mapscript.classObj(layer)
                category.setExpression(cart["expression"])
                category.name = cart["name"]
                # Set category style
                style = mapscript.styleObj(category)
                style.color.setHex(to_hex(cart["color"]))
        else:
            category = mapscript.classObj(layer)
            category.name = layer.name
            style = mapscript.styleObj(category)
            style.color.setHex("#FF00FF")

        return layer
コード例 #6
0
 def testStyleConstructor(self):
     """styleObj Constructor"""
     self.initMap()
     style = mapscript.styleObj(self.map.getLayer(1).getClass(0))
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
コード例 #7
0
ファイル: refcount_test.py プロジェクト: umeier/mapserver
 def testStyleConstructor(self):
     """styleObj Constructor"""
     self.initMap()
     style = mapscript.styleObj(self.map.getLayer(1).getClass(0))
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
コード例 #8
0
ファイル: layers.py プロジェクト: geodesign/django-wms
    def get_vector_layer(self, field_name):
        """
        Connect this layer to a vector data model.
        """
        # Get base layer
        layer = self.get_base_layer()

        layer.type = self.layer_types[field_name]

        # Set connection to DB
        layer.setConnectionType(mapscript.MS_POSTGIS, '')
        connection_template = (
            'host={host} dbname={dbname} user={user} '
            'port={port} password={password}'
        )
        layer.connection = connection_template.format(
            host=settings.DATABASES['default']['HOST'],
            dbname=settings.DATABASES['default']['NAME'],
            user=settings.DATABASES['default']['USER'],
            port=settings.DATABASES['default']['PORT'],
            password=settings.DATABASES['default']['PASSWORD']
        )

        # Select data column
        layer.data = 'geom FROM {0}'.format(self.model._meta.db_table)

        # Set class item
        if self.classitem:
            layer.classitem = self.classitem

        # Cartography settings
        if self.cartography:
            for cart in self.cartography:
                # Set categorization and name
                category = mapscript.classObj(layer)
                category.setExpression(cart.get('expression', ''))
                category.name = cart.get('name', cart.get('expression', ''))
                # Set category style
                style = mapscript.styleObj(category)
                style.color.setHex(to_hex(cart.get('color', '#777777')))
                style.outlinecolor.setHex(to_hex(cart.get('outlinecolor',
                                                          '#000000')))
                style.width = cart.get('width', 1)
                # Set symbol name now, this will be linked to the map level
                # symbolset when registering layers in map.
                if cart.has_key('symbol'):
                    style.symbolname = cart.get('symbol')
        else:
            category = mapscript.classObj(layer)
            category.name = layer.name
            style = mapscript.styleObj(category)
            style.color.setHex('#777777')
            style.outlinecolor.setHex('#000000')
            style.width = 1

        return layer
コード例 #9
0
    def get_vector_layer(self, field_name):
        """
        Connect this layer to a vector data model.
        """
        # Get base layer
        layer = self.get_base_layer()

        layer.type = self.layer_types[field_name]

        # Set connection to DB
        layer.setConnectionType(mapscript.MS_POSTGIS, '')
        connection_template = ('host={host} dbname={dbname} user={user} '
                               'port={port} password={password}')
        layer.connection = connection_template.format(
            host=settings.DATABASES['default']['HOST'],
            dbname=settings.DATABASES['default']['NAME'],
            user=settings.DATABASES['default']['USER'],
            port=settings.DATABASES['default']['PORT'],
            password=settings.DATABASES['default']['PASSWORD'])

        # Select data column
        layer.data = 'geom FROM {0}'.format(self.model._meta.db_table)

        # Set class item
        if self.classitem:
            layer.classitem = self.classitem

        # Cartography settings
        if self.cartography:
            for cart in self.cartography:
                # Set categorization and name
                category = mapscript.classObj(layer)
                category.setExpression(cart.get('expression', ''))
                category.name = cart.get('name', cart.get('expression', ''))
                # Set category style
                style = mapscript.styleObj(category)
                style.color.setHex(to_hex(cart.get('color', '#777777')))
                style.outlinecolor.setHex(
                    to_hex(cart.get('outlinecolor', '#000000')))
                style.width = cart.get('width', 1)
                # Set symbol name now, this will be linked to the map level
                # symbolset when registering layers in map.
                if cart.has_key('symbol'):
                    style.symbolname = cart.get('symbol')
        else:
            category = mapscript.classObj(layer)
            category.name = layer.name
            style = mapscript.styleObj(category)
            style.color.setHex('#777777')
            style.outlinecolor.setHex('#000000')
            style.width = 1

        return layer
コード例 #10
0
ファイル: ms_renderer.py プロジェクト: adorsk-noaa/georefine
 def get_styleObj(self, classObj=None, **kwargs):
     if classObj:
         styleObj = ms.styleObj(classObj)
     else:
         styleObj = ms.styleObj(classObj)
     for attr, value in kwargs.items():
         if 'color' in attr:
             if isinstance(value, dict):
                 value = self.get_colorObj(**value)
             else:
                 value = self.get_colorObj(*value)
         setattr(styleObj, attr, value)
     return styleObj
コード例 #11
0
ファイル: layers.py プロジェクト: cuulee/django-wms
    def get_vector_layer(self, field_name):
        """
        Connect this layer to a vector data model.
        """
        # Get base layer
        layer = self.get_base_layer()

        layer.type = self.layer_types[field_name]

        # Set connection to DB
        layer.setConnectionType(mapscript.MS_POSTGIS, "")
        layer.connection = "host={host} dbname={dbname} user={user} " "port={port} password={password}".format(
            host=settings.DATABASES["default"]["HOST"],
            dbname=settings.DATABASES["default"]["NAME"],
            user=settings.DATABASES["default"]["USER"],
            port=settings.DATABASES["default"]["PORT"],
            password=settings.DATABASES["default"]["PASSWORD"],
        )

        # Select data column
        layer.data = "geom FROM {0}".format(self.model._meta.db_table)

        # Set class item
        if self.classitem:
            layer.classitem = self.classitem

        # Cartography settings
        if self.cartography:
            for cart in self.cartography:
                # Set categorization and name
                category = mapscript.classObj(layer)
                category.setExpression(cart.get("expression", ""))
                category.name = cart.get("name", cart.get("expression", ""))
                # Set category style
                style = mapscript.styleObj(category)
                style.color.setHex(to_hex(cart.get("color", "#777777")))
                style.outlinecolor.setHex(to_hex(cart.get("outlinecolor", "#000000")))
                style.width = cart.get("width", 1)
                # Set symbol name now, this will be linked to the map level
                # symbolset when registering layers in map.
                if cart.has_key("symbol"):
                    style.symbolname = cart.get("symbol")
        else:
            category = mapscript.classObj(layer)
            category.name = layer.name
            style = mapscript.styleObj(category)
            style.color.setHex("#777777")
            style.outlinecolor.setHex("#000000")
            style.width = 1

        return layer
コード例 #12
0
    def serializeSimpleLineSymbolLayer(self, sl, hatchProperties=None):
        """Serialize a QGis simple line symbol layer into a MapServer style"""

        msStyle = mapscript.styleObj(self.msClass);

        # Line cap and line join
        msStyle.linecap = utils.serializePenCapStyle(sl.penCapStyle())
        msStyle.linejoin = utils.serializePenJoinStyle(sl.penJoinStyle())

        # If `hatchProperties` is a dict, we are serializing a line symbol layer inside a line
        # pattern fill, so we act accordingly and emit the respective properties.
        if isinstance(hatchProperties, dict):
            msStyle.symbolname = utils.serializeHatchSymbol(self.msMap) 
            msStyle.size = hatchProperties['size']
            msStyle.angle = hatchProperties['angle']
            msStyle.color = utils.serializeColor(sl.color())
        else:
            msStyle.color = utils.serializeColor(sl.color())
       
        # Emit line pattern only if we have a non-solid pen
        if sl.penStyle() != Qt.NoPen and sl.penStyle() != Qt.SolidLine:
            utils.setPenStylePattern(msStyle, utils.serializePenStylePattern(sl))

        msStyle.width = 0 \
            if sl.penStyle() == Qt.NoPen \
            else utils.sizeUnitToPx(sl.width(), sl.widthUnit())

        # Assume that this is our only outline and set the layer's size units to map units
        # if we are using map units in QGis. This breaks every property with a size unit set to
        # anything other than the map unit.
        if (sl.width() > 0) and (hatchProperties == None):
            utils.maybeSetLayerSizeUnitFromMap(sl.widthUnit(), self.msLayer)
コード例 #13
0
def update_classobj_from_dict(classobj, c, mapobj):
    if 'expression' in c:
        classobj.setExpression(c['expression'].encode('utf8'))

    if 'label' in c:
        update_labelobj_from_dict(classobj.label, c['label'], mapobj)

    if 'maxscaledenom' in c:
        classobj.maxscaledenom = c['maxscaledenom']

    if 'minscaledenom' in c:
        classobj.minscaledenom = c['minscaledenom']

    if 'name' in c:
        classobj.name = c['name'].encode('utf8')

    if 'text' in c:
        classobj.setText(c['text'])

    if 'title' in c:
        classobj.title = c['title']

    if 'styles' in c:
        for style in c['styles']:
            styleobj = mapscript.styleObj()
            update_styleobj_from_dict(styleobj, style, mapobj)
            classobj.insertStyle(styleobj)

    return classobj
コード例 #14
0
def get_vector_layer(data, name, group, crs=None):
    """
    Mapscript Layer для векторных данных.
    """
    layer = mapscript.layerObj()
    layer.type = mapscript.MS_LAYER_POLYGON
    layer.status = mapscript.MS_ON  # mapscript.MS_DEFAULT
    layer.name = name
    layer.group = group
    layer.setProjection('EPSG:4326')
    layer.metadata.set('wms_srs', 'EPSG:4326')
    layer.metadata.set('wms_title', name)
    for polygon in data:
        shape = mapscript.shapeObj_fromWKT(polygon.wkt)
        layer.addFeature(shape)
    # layer.setExtent({'minx': 3, 'miny': 3, 'maxx': 3, 'maxy': 3})
    # layer.setExtent(1, 2, 3, 4)
    # layer.setProjection('EPSG:4326')
    # layer.setProcessing("SCALE=0,255")
    # layer.setProcessing("DITHER=YES")
    # layer.setProcessing("RESAMPLE=BILINEAR")   # BILINEAR, AVERAGE, NEAREST
    # layer.setProcessing("EXTENT_PRIORITY=WORLD")
    # layer.setProcessing("LOAD_FULL_RES_IMAGE=NO")
    # layer.setProcessing("LOAD_WHOLE_IMAGE=NO")
    c = mapscript.classObj(layer)
    style = mapscript.styleObj(c)
    fill_color = mapscript.colorObj(0, 255, 0)
    out_color = mapscript.colorObj(0, 0, 255)
    style.color = fill_color
    style.outlinecolor = out_color
    style.opacity = 50
    layer.opacity = 50
    return layer
コード例 #15
0
ファイル: style_test.py プロジェクト: umeier/mapserver
 def testStyleBinding(self):
     """attribute binding can be set and get"""
     new_style = mapscript.styleObj()
     assert (not new_style.getBinding(mapscript.MS_STYLE_BINDING_COLOR))
     new_style.setBinding(mapscript.MS_STYLE_BINDING_COLOR, "NEW_BINDING")
     assert (new_style.getBinding(
         mapscript.MS_STYLE_BINDING_COLOR) == "NEW_BINDING")
コード例 #16
0
ファイル: style_test.py プロジェクト: dmorissette/mapserver
 def testCloneStyle(self):
     """check attributes of a cloned style"""
     new_style = mapscript.styleObj()
     new_style.color.setHex('#808080')
     clone = new_style.clone()
     assert clone.thisown == 1
     assert clone.color.toHex() == '#808080'
コード例 #17
0
ファイル: style_test.py プロジェクト: dmorissette/mapserver
 def testInsertStylePastEnd(self):
     """NewStylesTestCase.testInsertStylePastEnd: inserting a style past the end of
     the list raises the proper error"""
     p_layer = self.map.getLayerByName('POINT')
     class0 = p_layer.getClass(0)
     new_style = mapscript.styleObj()
     self.assertRaises(mapscript.MapServerChildError, class0.insertStyle, new_style, 6)
コード例 #18
0
ファイル: style_test.py プロジェクト: umeier/mapserver
 def testStyleColorSettable(self):
     """a style can be set with a color tuple"""
     new_style = mapscript.styleObj()
     new_style.color.setRGB(1, 2, 3)
     assert new_style.color.red == 1
     assert new_style.color.green == 2
     assert new_style.color.blue == 3
コード例 #19
0
ファイル: mapserializer.py プロジェクト: camptocamp/Studio
def update_classobj_from_dict(classobj,c,mapobj):
    if 'expression' in c:
        classobj.setExpression(c['expression'].encode('utf8'))   
    
    if 'label' in c:
        update_labelobj_from_dict(classobj.label,c['label'],mapobj)

    if 'maxscaledenom' in c:
        classobj.maxscaledenom = c['maxscaledenom']

    if 'minscaledenom' in c:
        classobj.minscaledenom = c['minscaledenom'] 

    if 'name' in c:
        classobj.name = c['name'].encode('utf8')

    if 'text' in c:
        classobj.setText(c['text'])

    if 'title' in c:
        classobj.title = c['title']

    if 'styles' in c:
        for style in c['styles']:
            styleobj = mapscript.styleObj()
            update_styleobj_from_dict(styleobj,style,mapobj)
            classobj.insertStyle(styleobj)
    
    return classobj
コード例 #20
0
ファイル: style_test.py プロジェクト: dmorissette/mapserver
 def testStyleColorSettable(self):
     """a style can be set with a color tuple"""
     new_style = mapscript.styleObj()
     new_style.color.setRGB(1, 2, 3)
     assert new_style.color.red == 1
     assert new_style.color.green == 2
     assert new_style.color.blue == 3
コード例 #21
0
ファイル: style_test.py プロジェクト: umeier/mapserver
 def testCloneStyle(self):
     """check attributes of a cloned style"""
     new_style = mapscript.styleObj()
     new_style.color.setHex('#808080')
     clone = new_style.clone()
     assert clone.thisown == 1
     assert clone.color.toHex() == '#808080'
コード例 #22
0
ファイル: style_test.py プロジェクト: umeier/mapserver
 def testInsertStylePastEnd(self):
     """NewStylesTestCase.testInsertStylePastEnd: inserting a style past the end of
     the list raises the proper error"""
     p_layer = self.map.getLayerByName('POINT')
     class0 = p_layer.getClass(0)
     new_style = mapscript.styleObj()
     self.assertRaises(mapscript.MapServerChildError, class0.insertStyle,
                       new_style, 6)
コード例 #23
0
def draw_map_wfs(name, save=0):

    # print("making map in thread %s" % (name))
    mo = mapscript.mapObj(TESTMAPFILE)

    # WFS layer
    lo = mapscript.layerObj()
    lo.name = 'cheapo_wfs'
    lo.setProjection('+init=epsg:4326')
    lo.connectiontype = mapscript.MS_WFS
    lo.connection = 'http://zcologia.com:9001/mapserver/members/features.rpy?'
    lo.metadata.set('wfs_service', 'WFS')
    lo.metadata.set('wfs_typename', 'users')
    lo.metadata.set('wfs_version', '1.0.0')
    lo.type = mapscript.MS_LAYER_POINT
    lo.status = mapscript.MS_DEFAULT
    lo.labelitem = 'zco:mid'

    so1 = mapscript.styleObj()
    so1.color.setHex('#FFFFFF')
    so1.size = 9
    so1.symbol = 1  # mo.symbolset.index('circle')

    so2 = mapscript.styleObj()
    so2.color.setHex('#333333')
    so2.size = 7
    so2.symbol = 1  # mo.symbolset.index('circle')

    co = mapscript.classObj()
    co.label.type = mapscript.MS_BITMAP
    co.label.size = mapscript.MS_SMALL
    co.label.color.setHex('#000000')
    co.label.outlinecolor.setHex('#FFFFFF')
    co.label.position = mapscript.MS_AUTO

    co.insertStyle(so1)
    co.insertStyle(so2)
    lo.insertClass(co)
    mo.insertLayer(lo)

    if not mo.web.imagepath:
        mo.web.imagepath = os.environ.get('TEMP', None) or INCOMING
    mo.debug = mapscript.MS_ON
    im = mo.draw()
    if save:
        im.save('threadtest_wfs_%s.png' % (name))
コード例 #24
0
ファイル: refcount_test.py プロジェクト: umeier/mapserver
 def testInsertStyle(self):
     """styleObj Insert"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     self.map.getLayer(1).getClass(0).insertStyle(style)
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
コード例 #25
0
def create_default_style():
    style = mapscript.styleObj()
    style.backgroundcolor.setHex('#00ff00')
    style.color.setHex('#ff0000')
    style.outlinecolor.setHex('#aa00aa')
    style.size = 12
    style.symbol = 3
    style.width = 4
    return style
コード例 #26
0
 def testInsertStyle(self):
     """styleObj Insert"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     self.map.getLayer(1).getClass(0).insertStyle(style)
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
コード例 #27
0
ファイル: style_test.py プロジェクト: umeier/mapserver
 def testPattern5(self):
     """pattern length is read-only"""
     si = mapscript.styleObj()
     exception = None
     try:
         si.patternlength = 0
     except Exception:
         exception = True
     assert exception is True
コード例 #28
0
def create_default_style():
    style = mapscript.styleObj()
    style.backgroundcolor.setHex('#00ff00')
    style.color.setHex('#ff0000')
    style.outlinecolor.setHex('#aa00aa')
    style.size = 12
    style.symbol = 3
    style.width = 4
    return style
コード例 #29
0
ファイル: style_test.py プロジェクト: umeier/mapserver
    def testPattern3(self):
        """a pattern must have at least 2 elements"""

        si = mapscript.styleObj()
        exception = None
        try:
            si.pattern = [1.0]
        except Exception:
            exception = True
        assert exception is True
コード例 #30
0
    def serializeSimpleMarkerSymbolLayer(self, sl, fillProperties=None):
        """Serialize a QGis simple marker symbol layer into MapServer styles"""

        # Emit fill only if it's visible and the marker is polygonal
        markerName = unicode(sl.name()).encode('utf-8')
        if (sl.fillColor().alpha() != 0) and utils.isWellKnownMarkerPolygonal(markerName):
            msFillSymbol = utils.serializeWellKnownMarker(markerName, True)
            self.msMap.symbolset.appendSymbol(msFillSymbol) 

            msStyleBg = mapscript.styleObj(self.msClass)
            msStyleBg.symbolname = msFillSymbol.name
            msStyleBg.color = utils.serializeColor(sl.fillColor())
            msStyleBg.size = utils.sizeUnitToPx(sl.size(), sl.sizeUnit())

            # If `fillProperties` is a dict, we are serializing a marker symbol layer inside a point
            # pattern fill, so we act accordingly and emit the respective properties.
            if isinstance(fillProperties, dict):
                msStyleBg.gap = (fillProperties['distanceX'] + fillProperties['distanceY']) / 2
                msStyleBg.angle = fillProperties['angle']

        # Emit outline only if the marker has one
        if sl.outlineStyle() != Qt.NoPen:
            msOutlineSymbol = utils.serializeWellKnownMarker(markerName, False)
            self.msMap.symbolset.appendSymbol(msOutlineSymbol)

            msStyleOutline = mapscript.styleObj(self.msClass)
            msStyleOutline.symbolname = msOutlineSymbol.name
            msStyleOutline.color = utils.serializeColor(sl.borderColor())

            # QGis draws a default outline of .26mm even when the width is set to zero
            msStyleOutline.width = utils.sizeUnitToPx(sl.outlineWidth(), sl.outlineWidthUnit()) \
                    if sl.outlineWidth() > 0 \
                    else utils.DEFAULT_OUTLINE_WIDTH
            msStyleOutline.size = utils.sizeUnitToPx(sl.size(), sl.sizeUnit())

            # If `fillProperties` is a dict, we are serializing a marker symbol layer inside a point
            # pattern fill, so we act accordingly and emit the respective properties.
            if isinstance(fillProperties, dict):
                msStyleOutline.gap = (fillProperties['distanceX'] + fillProperties['distanceY']) / 2
                msStyleOutline.angle = fillProperties['angle']

            if sl.outlineStyle() != Qt.SolidLine:
                utils.setPenStylePattern(msStyleOutline, utils.serializePenStylePattern(sl))
コード例 #31
0
def ShapefileLayer(mapObj, imageryShp, filters, rgb):
    layerObj = mapscript.layerObj(mapObj)
    layerObj.name = "Sentinel2Shapefile"
    layerObj.status = mapscript.MS_ON
    layerObj.type = mapscript.MS_LAYER_POLYGON
    layerObj.setProjection("AUTO")
    layerObj.data = imageryShp
    layerObj.setFilter(filters)
    classObj = mapscript.classObj(layerObj)
    styleObj = mapscript.styleObj(classObj)
    styleObj.outlinecolor = mapscript.colorObj(rgb[0], rgb[1], rgb[2])
コード例 #32
0
ファイル: gdalogr_catalogue.py プロジェクト: gijs/NME
    def __init__(self,datasource,extent,layername,layerftype):
        #from mapscript import *
	import mapscript
        from time import time
        tmap = mapscript.mapObj()
	print "checkpoint 1"
        map.setSize(400,400)
        #ext = rectObj(-180,-90,180,90)
        ext = mapscript.rectObj(extent[0],extent[2],extent[1],extent[3]) # some trouble with some bad extents in my test data
        map.extent = ext
        map.units = mapscript.MS_DD # should be programmatically set
        lay = mapscript.layerObj(map)
        lay.name = "Autolayer"
        lay.units = mapscript.MS_DD
        if (layerftype == 'RASTER'):
		lay.data = datasource.GetDescription()
	else:
		lay.data = datasource.GetName()
        print lay.data
        lay.status = mapscript.MS_DEFAULT
        cls = mapscript.classObj(lay)
        sty = mapscript.styleObj()
        col = mapscript.colorObj(0,0,0)
#        symPoint = mapscript.symbolObj
        map.setSymbolSet("symbols/symbols_basic.sym")
        if (layerftype == 'POINT'): 
            lay.type = mapscript.MS_LAYER_POINT
            sty.setSymbolByName = "achteck"
            sty.width = 100
            sty.color = col
        elif (layerftype == 'LINE'): 
            lay.type = mapscript.MS_LAYER_LINE
            sty.setSymbolByName = "punkt"
            sty.width = 5
            sty.color = col
        elif (layerftype == 'POLYGON'): 
            lay.type = mapscript.MS_LAYER_POLYGON
            sty.setSymbolByName = "circle"
            sty.width = 10
            sty.outlinecolor = col
        elif (layerftype == 'RASTER'): 
            lay.type = mapscript.MS_LAYER_RASTER
            sty.setSymbolByName = "squares"
            sty.size = 10
            sty.color = col
        #sty.setSymbolByName(map,symname)
        #sty.size = symsize
        cls.insertStyle(sty)
        try:
            img = map.draw()
            img.save(str(time()) + "auto.gif")
            map.save(str(time()) + "auto.map")
        except MapServerError:
            return None
コード例 #33
0
ファイル: style_test.py プロジェクト: umeier/mapserver
    def testPattern4(self):
        """a pattern can have a max of 10 elements
        This is set in mapsymbol.h with #define MS_MAXPATTERNLENGTH 10"""

        si = mapscript.styleObj()
        exception = None
        try:
            si.pattern = [i for i in range(11)]
        except Exception:
            exception = True
        assert exception is True
コード例 #34
0
def get_map_image_from_wms(wms_parameters=None, habitat_dao=None, filters=None):

	# Initialize mapscript map object from the habitat mapfile template.
	mapfile = "%s/habitat.map" % os.path.abspath(os.path.dirname(__file__))
	ms_map = mapscript.mapObj(mapfile)

	layer = mapscript.layerObj()
	layer.name = "habitat" 

	layer.setProjection('init=epsg:4326')
	layer.status = mapscript.MS_DEFAULT
	layer.setConnectionType(mapscript.MS_POSTGIS, '')
	connection_str = habitat_dao.get_mapserver_connection_string()
	layer.connection = connection_str
	layer.data = habitat_dao.get_mapserver_data_string(filters=filters)

	layer.type = mapscript.MS_LAYER_POLYGON

	# Create classes for types of substrates.

	substrate_styles= [
			{'name': 'S1', 'color': '8DD3C7'},
			{'name': 'S2', 'color': 'FFFFB3'},
			{'name': 'S3', 'color': 'BEBADA'},
			{'name': 'S4', 'color': 'FB8072'},
			{'name': 'S5', 'color': '80B1D3'},
			]

	for ss in substrate_styles:
		clz = mapscript.classObj()
		clz.name = ss['name']
		expression = "('[substrate_id]' eq '%s')" % ss['name']
		clz.setExpression(expression)
		style = mapscript.styleObj()
		rgb_color = hex_to_rgb(ss['color'])
		style.color= mapscript.colorObj(*rgb_color)
		clz.insertStyle(style)
		layer.insertClass(clz)

	ms_map.insertLayer(layer)

	# Build WMS request from parameters.
	wms_request = mapscript.OWSRequest()
	for k, v in wms_parameters:
		wms_request.setParameter(k,v)

	# Load the parameters into the map.
	ms_map.loadOWSParameters(wms_request)
	
	# Draw the map.
	ms_image = ms_map.draw()

	# Return the raw image.
	return ms_image.getBytes()
コード例 #35
0
 def _get_default_style(self):
     styleobj = mapscript.styleObj()
     if self.type == 'POINT':
         styleobj.size = 5
         styleobj.color.setHex('#ff0000')
     elif self.type == 'POLYGON':
         styleobj.color.setHex('#ffff00')
     else:
         styleobj.color.setHex('#0000ff')
         styleobj.width = 3
     return styleobj
コード例 #36
0
 def _get_default_style(self):
     styleobj = mapscript.styleObj()
     if self.type == 'POINT':
         styleobj.size = 5
         styleobj.color.setHex('#ff0000')
     elif self.type == 'POLYGON':
         styleobj.color.setHex('#ffff00')
     else:
         styleobj.color.setHex('#0000ff')
         styleobj.width=3
     return styleobj
コード例 #37
0
ファイル: refcount_test.py プロジェクト: umeier/mapserver
 def testRemoveStyleAtBeginning(self):
     """styleObj remove first one"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     self.map.getLayer(1).getClass(0).insertStyle(style)
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
     style = self.map.getLayer(1).getClass(0).removeStyle(0)
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
コード例 #38
0
 def testRemoveStyleAtBeginning(self):
     """styleObj remove first one"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     self.map.getLayer(1).getClass(0).insertStyle(style)
     assert style.refcount == 2, style.refcount
     assert style.thisown == 1, style.thisown
     style = self.map.getLayer(1).getClass(0).removeStyle(0)
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
コード例 #39
0
    def _get_default_mapserver_style(self, map, new_layer):
        ''' Returns an array of styles based on the geomerty
        type of the created layer'''
        mapscript = self.mapscript

        styleobj_array = []

        # Line Geometry default styling
        if new_layer.type == mapscript.MS_LAYER_LINE:
            styleobj = mapscript.styleObj()
            styleobj.color.setHex("#0000FF")
            styleobj.size = 1
            styleobj_array.append(styleobj)

        # Polygon Geometry default styling
        elif new_layer.type == mapscript.MS_LAYER_POLYGON:
            styleobj = mapscript.styleObj()
            styleobj.color.setHex("#AAAAAA")
            styleobj.outlinecolor.setHex("#000000")
            styleobj.size = 1
            styleobj_array.append(styleobj)

        # Point Geometry default styling
        elif new_layer.type == mapscript.MS_LAYER_POINT:

            styleobj = mapscript.styleObj()
            styleobj.color.setHex("#FF0000")
            styleobj.setSymbolByName(map, 'square')
            styleobj.size = 6
            styleobj_array.append(styleobj)

        else:
            styleobj = mapscript.styleObj()
            styleobj.color.setHex('#0000ff')
            styleobj.width = 3
            styleobj_array.append(styleobj)

        return styleobj_array
コード例 #40
0
    def _get_default_mapserver_style(self, map, new_layer):
        ''' Returns an array of styles based on the geomerty
        type of the created layer'''
        mapscript = self.mapscript

        styleobj_array = []

        # Line Geometry default styling
        if new_layer.type == mapscript.MS_LAYER_LINE:
            styleobj = mapscript.styleObj()
            styleobj.color.setHex("#0000FF")
            styleobj.size = 1
            styleobj_array.append(styleobj)

        # Polygon Geometry default styling
        elif new_layer.type == mapscript.MS_LAYER_POLYGON:
            styleobj = mapscript.styleObj()
            styleobj.color.setHex("#AAAAAA")
            styleobj.outlinecolor.setHex("#000000")
            styleobj.size = 1
            styleobj_array.append(styleobj)

        # Point Geometry default styling
        elif new_layer.type == mapscript.MS_LAYER_POINT:

            styleobj = mapscript.styleObj()
            styleobj.color.setHex("#FF0000")
            styleobj.setSymbolByName(map, 'square')
            styleobj.size = 6
            styleobj_array.append(styleobj)

        else:
            styleobj = mapscript.styleObj()
            styleobj.color.setHex('#0000ff')
            styleobj.width=3
            styleobj_array.append(styleobj)

        return styleobj_array
コード例 #41
0
ファイル: wms_api.py プロジェクト: BCCVL/BCCVL_Visualiser
 def default_class_style(self, col_name):
     # return a default class for styling based on the value of a specified
     # column
     styleobj = mapscript.styleObj()
     styleobj.mincolor = mapscript.colorObj(255, 255, 255)
     styleobj.maxcolor = mapscript.colorObj(0, 128, 255)
     if 'min' in self._data and 'max' in self._data:
         styleobj.minvalue = self._data['min']
         styleobj.maxvalue = self._data['max']
     styleobj.rangeitem = col_name
     clsobj = mapscript.classObj()
     clsobj.name = "-"
     clsobj.insertStyle(styleobj)
     return clsobj
コード例 #42
0
 def default_class_style(self, col_name):
     # return a default class for styling based on the value of a specified
     # column
     styleobj = mapscript.styleObj()
     styleobj.mincolor = mapscript.colorObj(255, 255, 255)
     styleobj.maxcolor = mapscript.colorObj(0, 128, 255)
     if 'min' in self._data and 'max' in self._data:
         styleobj.minvalue = self._data['min']
         styleobj.maxvalue = self._data['max']
     styleobj.rangeitem = col_name
     clsobj = mapscript.classObj()
     clsobj.name = "-"
     clsobj.insertStyle(styleobj)
     return clsobj
コード例 #43
0
	def addPlaneSymbol(self,position):
		"""Adds the plane symbol at the indicated position"""
		pt = mapscript.pointObj()
		pt.x = position[0] #lat
		pt.y = position[1] #lon
		
		# project our point into the mapObj's projection 
		#ddproj = mapscript.projectionObj('proj=latlong,ellps=WGS84')
		#http://www.mass.gov/mgis/dd-over.htm
		ddproj = mapscript.projectionObj('proj=lcc,ellps=GRS80')
		
		origproj = mapscript.projectionObj(self.map.getProjection())
		pt.project(ddproj,origproj)
		
		# create the symbol using the image 
		planeSymbol = mapscript.symbolObj('from_img') 
		planeSymbol.type = mapscript.MS_SYMBOL_PIXMAP 
		planeImg = mapscript.imageObj('images/map-plane-small.png','GD/PNG')
		#TODO: need to rotate plane to current heading
		planeSymbol.setImage(planeImg) 
		symbol_index = self.map.symbolset.appendSymbol(planeSymbol) 

		# create a shapeObj out of our location point so we can 
		# add it to the map. 
		self.routeLine = mapscript.lineObj()
		self.routeLine.add(pt)
		routeShape=mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
		routeShape.add(self.routeLine) 
		routeShape.setBounds() 

		# create our inline layer that holds our location point 
		self.planeLayer = mapscript.layerObj(None)
		self.planeLayer.addFeature(routeShape) 
		self.planeLayer.setProjection(self.map.getProjection()) 
		self.planeLayer.name = "plane" 
		self.planeLayer.type = mapscript.MS_LAYER_POINT 
		self.planeLayer.connectiontype=mapscript.MS_INLINE 
		self.planeLayer.status = mapscript.MS_ON 
		self.planeLayer.transparency = mapscript.MS_GD_ALPHA 
		
		# add the image symbol we defined above to the inline layer. 
		planeClass = mapscript.classObj(None)
		planeClass.name='plane' 
		style = mapscript.styleObj(None)
		style.symbol = self.map.symbolset.index('from_img') 
		planeClass.insertStyle(style) 
		self.planeLayer.insertClass(planeClass)
		self.map.insertLayer(self.planeLayer)
		if debug: print "added plane layer, layerorder=",self.map.getLayerOrder()
コード例 #44
0
 def testCloneStyle(self):
     """styleObj Clone"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     clone = style.clone()
     assert clone.refcount == 1, clone.refcount
     assert clone.thisown == 1, clone.thisown
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     style = self.map.getLayer(1).getClass(0).getStyle(0)
     clone = style.clone()
     assert clone.refcount == 1, clone.refcount
     assert clone.thisown == 1, clone.thisown
コード例 #45
0
ファイル: style_test.py プロジェクト: sdlime/mapserver
 def testAppendNewStyleOldWay(self):
     """NewStylesTestCase.testAppendNewStyleOldWay: a new style can be appended properly using old method"""
     p_layer = self.map.getLayerByName('POINT')
     class0 = p_layer.getClass(0)
     assert class0.numstyles == 2, class0.numstyles
     new_style = mapscript.styleObj(class0)
     assert new_style.thisown == 1, new_style.thisown
     new_style.color.setRGB(0, 0, 0)
     new_style.symbol = 1
     new_style.size = 3
     msimg = self.map.draw()
     filename = 'testAppendNewStyleOldWay.png'
     fh = open(filename, 'wb')
     msimg.write(fh)
     fh.close()
コード例 #46
0
ファイル: refcount_test.py プロジェクト: umeier/mapserver
 def testCloneStyle(self):
     """styleObj Clone"""
     self.initMap()
     style = mapscript.styleObj()
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     clone = style.clone()
     assert clone.refcount == 1, clone.refcount
     assert clone.thisown == 1, clone.thisown
     assert style.refcount == 1, style.refcount
     assert style.thisown == 1, style.thisown
     style = self.map.getLayer(1).getClass(0).getStyle(0)
     clone = style.clone()
     assert clone.refcount == 1, clone.refcount
     assert clone.thisown == 1, clone.thisown
コード例 #47
0
ファイル: main.py プロジェクト: djskl/pgmap
def getStyle():
    style_obj = styleObj()

    style_obj.rangeitem = "pixel"

    style_obj.maxcolor = colorObj(175, 240, 233)
    style_obj.mincolor = colorObj(255, 255, 179)

    style_obj.maxvalue = 1
    style_obj.minvalue = -47

    clz_obj = classObj()
    clz_obj.setExpression("([pixel] >= -47 AND [pixel] <= 1)")
    clz_obj.insertStyle(style_obj)

    return clz_obj
コード例 #48
0
ファイル: style_test.py プロジェクト: dmorissette/mapserver
 def testAppendNewStyleOldWay(self):
     """NewStylesTestCase.testAppendNewStyleOldWay: a new style can be appended properly using old method"""
     p_layer = self.map.getLayerByName('POINT')
     class0 = p_layer.getClass(0)
     assert class0.numstyles == 2, class0.numstyles
     new_style = mapscript.styleObj(class0)
     assert new_style.thisown == 1, new_style.thisown
     new_style.color.setRGB(0, 0, 0)
     new_style.symbol = 1
     new_style.size = 3
     msimg = self.map.draw()
     data = msimg.saveToString()
     filename = 'testAppendNewStyleOldWay.png'
     fh = open(filename, 'wb')
     fh.write(data)
     fh.close()
コード例 #49
0
ファイル: font_test.py プロジェクト: glennneiger/mapserver-1
    def testSettingFonts(self):
        mo = mapscript.mapObj()
        assert mo.fontset.numfonts == 0
        mo.fontset.fonts.set('Vera', os.path.join(TESTS_PATH, 'vera',
                                                  'Vera.ttf'))
        # NB: this does *not* increment the fonset.numfonts -- new bug

        mo.setSize(300, 300)
        mo.setExtent(-1.0, -1.0, 1.0, 1.0)

        lo = mapscript.layerObj()
        lo.type = mapscript.MS_LAYER_POINT
        lo.connectiontype = mapscript.MS_INLINE
        lo.status = mapscript.MS_DEFAULT

        co = mapscript.classObj()
        lbl = mapscript.labelObj()
        lbl.type = mapscript.MS_TRUETYPE
        lbl.font = 'Vera'
        lbl.size = 10
        lbl.color.setHex('#000000')
        co.addLabel(lbl)

        so = mapscript.styleObj()
        so.symbol = 0
        so.color.setHex('#000000')

        co.insertStyle(so)
        lo.insertClass(co)
        li = mo.insertLayer(lo)
        lo = mo.getLayer(li)

        point = mapscript.pointObj(0, 0)
        line = mapscript.lineObj()
        line.add(point)
        shape = mapscript.shapeObj(lo.type)
        shape.add(line)
        shape.setBounds()
        shape.text = 'Foo'
        shape.classindex = 0

        lo.addFeature(shape)
        im = mo.draw()

        # im = mo.prepareImage()
        # shape.draw(mo, lo, im)
        im.save('testSettingFonts.png')
コード例 #50
0
ファイル: style_test.py プロジェクト: sdlime/mapserver
 def testInsertNewStyleAtIndex0(self):
     """NewStylesTestCase.testInsertNewStyleAtIndex0: a new style can be inserted ahead of all others"""
     l_layer = self.map.getLayerByName('LINE')
     class0 = l_layer.getClass(0)
     new_style = mapscript.styleObj()
     new_style.color.setRGB(255, 255, 0)
     new_style.symbol = 1
     new_style.size = 7
     index = class0.insertStyle(new_style, 0)
     assert index == 0, index
     assert class0.numstyles == 2, class0.numstyles
     msimg = self.map.draw()
     assert msimg.thisown == 1
     filename = 'testInsertNewStyleAtIndex0.png'
     fh = open(filename, 'wb')
     msimg.write(fh)
     fh.close()
コード例 #51
0
def get_pg_layer(data,
                 name,
                 group,
                 connection,
                 query_filter=None,
                 crs=None,
                 fill_color=None,
                 out_color=None,
                 opacity=None):
    """
    Mapscript Layer для векторных данных, хранящихся в Postgres.
    """
    layer = mapscript.layerObj()
    layer.type = mapscript.MS_LAYER_POLYGON
    layer.status = mapscript.MS_ON  # mapscript.MS_DEFAULT
    layer.name = name
    layer.group = group
    layer.setProjection('EPSG:4326')
    layer.metadata.set('wms_srs', 'EPSG:4326')
    layer.metadata.set('wms_title', name)
    layer.connectiontype = mapscript.MS_POSTGIS
    layer.connection = connection
    layer.data = data  # "geom from data"
    # status = layer.setFilter(query_filter)  # "id = 123"
    # layer.setExtent({'minx': 3, 'miny': 3, 'maxx': 3, 'maxy': 3})
    # layer.setExtent(1, 2, 3, 4)
    # layer.setProjection('EPSG:4326')
    # layer.setProcessing("SCALE=0,255")
    # layer.setProcessing("DITHER=YES")
    # layer.setProcessing("RESAMPLE=BILINEAR")   # BILINEAR, AVERAGE, NEAREST
    # layer.setProcessing("EXTENT_PRIORITY=WORLD")
    # layer.setProcessing("LOAD_FULL_RES_IMAGE=NO")
    # layer.setProcessing("LOAD_WHOLE_IMAGE=NO")
    c = mapscript.classObj(layer)
    style = mapscript.styleObj(c)
    if fill_color:
        fill_color = mapscript.colorObj(*fill_color)
        style.color = fill_color
    if out_color:
        out_color = mapscript.colorObj(*out_color)
        style.outlinecolor = out_color
    if opacity:
        # style.opacity = opacity
        layer.opacity = opacity
    return layer
コード例 #52
0
    def testPointDraw(self):
        """Can create a point, add to a layer, and draw it directly"""

        map_string = """
        MAP
            EXTENT 0 0 90 90
            SIZE 500 500

            SYMBOL
            NAME "circle"
            TYPE ELLIPSE
            POINTS 1 1 END
            FILLED true
            END

            LAYER
            NAME "punkt"
            STATUS ON
            TYPE POINT
            END

        END"""

        test_map = mapscript.fromstring(map_string)
        layer = test_map.getLayerByName('punkt')
        cls = mapscript.classObj()
        style = mapscript.styleObj()
        style.outlinecolor.setHex('#00aa00ff')
        style.size = 10
        style.setSymbolByName(test_map, 'circle')

        cls.insertStyle(style)
        class_idx = layer.insertClass(cls)
        point = mapscript.pointObj(45, 45)

        img = test_map.prepareImage()
        point.draw(test_map, layer, img, class_idx, "test")

        filename = 'testDrawPoint.png'
        with open(filename, 'wb') as fh:
            img.write(fh)

        if have_image:
            pyimg = Image.open(filename)
            assert pyimg.size == (500, 500)
コード例 #53
0
    def serializeSvgMarkerSymbolLayer(self, sl):
        """Serialize a QGis SVG marker symbol layer into a MapServer style
        
        """
        try:
            msSymbol = utils.serializeSvgSymbol(unicode(sl.path()).encode('utf-8'))
        except Exception as e:
            QgsMessageLog.logMessage(
                u'Cannot serialize SVG symbol: %s' % unicode(e),
                'RT MapServer Exporter'
            )
            return

        self.msMap.symbolset.appendSymbol(msSymbol)

        msStyle = mapscript.styleObj(self.msClass)
        msStyle.symbolname = msSymbol.name
        msStyle.size = utils.sizeUnitToPx(sl.size(), sl.sizeUnit())
コード例 #54
0
ファイル: style_test.py プロジェクト: sdlime/mapserver
 def testAppendNewStyle(self):
     """a new style can be appended properly"""
     p_layer = self.map.getLayerByName('POINT')
     class0 = p_layer.getClass(0)
     assert class0.numstyles == 2, class0.numstyles
     new_style = mapscript.styleObj()
     new_style.color.setRGB(0, 0, 0)
     new_style.setSymbolByName(self.map, 'circle')
     new_style.size = 3
     index = class0.insertStyle(new_style)
     assert index == 2, index
     assert class0.numstyles == 3, class0.numstyles
     msimg = self.map.draw()
     assert msimg.thisown == 1
     filename = 'testAppendNewStyle.png'
     fh = open(filename, 'wb')
     msimg.write(fh)
     fh.close()
コード例 #55
0
ファイル: style_test.py プロジェクト: dmorissette/mapserver
 def testInsertNewStyleAtIndex0(self):
     """NewStylesTestCase.testInsertNewStyleAtIndex0: a new style can be inserted ahead of all others"""
     l_layer = self.map.getLayerByName('LINE')
     class0 = l_layer.getClass(0)
     new_style = mapscript.styleObj()
     new_style.color.setRGB(255, 255, 0)
     new_style.symbol = 1
     new_style.size = 7
     index = class0.insertStyle(new_style, 0)
     assert index == 0, index
     assert class0.numstyles == 2, class0.numstyles
     msimg = self.map.draw()
     assert msimg.thisown == 1
     data = msimg.saveToString()
     filename = 'testInsertNewStyleAtIndex0.png'
     fh = open(filename, 'wb')
     fh.write(data)
     fh.close()
コード例 #56
0
def get_color_class(attr=None, cmin=None, cmax=None, hsv=None):

	clz = mapscript.classObj()
	clz.name = "{} to {}".format(cmin, cmax)
	style = mapscript.styleObj()
	rgb = [int(c) for c in colorsys.hsv_to_rgb(*hsv)]
	style.color= mapscript.colorObj(*rgb)
	clz.insertStyle(style)

	criteria = []
	if cmin != None: criteria.append("[{}] >= {}".format(attr, cmin))
	if cmax != None: criteria.append("[{}] < {}".format(attr, cmax))

	if criteria:
		expression = "({})".format(' AND '.join(criteria))
		clz.setExpression(expression)

	return clz
コード例 #57
0
ファイル: static_maps.py プロジェクト: munners17/localground
    def _add_north_arrow(self, msmap, map_height):
        north_arrow_layer = mapscript.layerObj()
        north_arrow_layer.transform = False
        north_arrow_layer.name = 'north_arrow'
        north_arrow_layer.type = mapscript.MS_LAYER_POINT
        north_arrow_layer.status = 1
        new_class = mapscript.classObj()
        new_style = mapscript.styleObj()
        new_style.setSymbolByName(msmap, 'northarrow1')

        li = msmap.insertLayer(north_arrow_layer)
        ci = msmap.getLayer(li).insertClass(new_class)
        si = msmap.getLayer(li).getClass(ci).insertStyle(new_style)
        point = mapscript.pointObj()
        
        #place north arrow at the bottom of the image:
        point.x = 30
        point.y = map_height-30
        north_arrow_layer.addFeature(point.toShape())