Beispiel #1
0
 def setUp(self):
     """The test fixture is a line with two points"""
     self.points = (mapscript.pointObj(0.0,
                                       1.0), mapscript.pointObj(2.0, 3.0))
     self.line = mapscript.lineObj()
     self.addPointToLine(self.line, self.points[0])
     self.addPointToLine(self.line, self.points[1])
Beispiel #2
0
 def setUp(self):
     """The test fixture is a shape of one point"""
     self.points = (mapscript.pointObj(0.0, 1.0), )
     self.lines = (mapscript.lineObj(), )
     self.addPointToLine(self.lines[0], self.points[0])
     self.shape = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
     self.addLineToShape(self.shape, self.lines[0])
Beispiel #3
0
 def setUp(self):
     """The test fixture is a shape of one point"""
     self.points = (mapscript.pointObj(0.0, 1.0), )
     self.lines = (mapscript.lineObj(), )
     self.addPointToLine(self.lines[0], self.points[0])
     self.shape = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
     self.addLineToShape(self.shape, self.lines[0])
def serializeWellKnownMarker(marker, filled):
    """Serialize a well known marker into a mapscript.symbolObj()"""

    msSymbol = mapscript.symbolObj('%s' % (makeSymbolUUID(marker)))
    msSymbol.type = mapscript.MS_SYMBOL_VECTOR
    msSymbol.inmapfile = True
    msLine = mapscript.lineObj()

    def setPoints(ps):
        """Set the points of the marker"""

        for p in ps:
            msLine.add(mapscript.pointObj(p[0], p[1]))

        msSymbol.setPoints(msLine)

    if isWellKnownMarker(marker):
        setPoints(WELL_KNOWN_MARKER_MAP[marker])
        mayHaveFill = isWellKnownMarkerPolygonal(marker)
    else:
        # We use a simple circle if the marker is not among our currently known markers
        msSymbol.type = mapscript.MS_SYMBOL_ELLIPSE
        setPoints([[1, 1]])
        mayHaveFill = True

    msSymbol.filled = mayHaveFill and filled

    return msSymbol
Beispiel #5
0
 def setUp(self):
     """The test fixture is a line with two points"""
     self.points = (mapscript.pointObj(0.0, 1.0),
                    mapscript.pointObj(2.0, 3.0))
     self.line = mapscript.lineObj()
     self.addPointToLine(self.line, self.points[0])
     self.addPointToLine(self.line, self.points[1])
 def _update_symbol_set(self, map):
     circle = map.symbolset.getSymbolByName('circle')
     # circle = mapscript.symbolObj("circle")
     circle.type = mapscript.MS_SYMBOL_ELLIPSE
     circle.filled = mapscript.MS_ON
     l1 = mapscript.lineObj()
     l1.add(mapscript.pointObj(1, 1))
     circle.setPoints(l1)
     map.symbolset.appendSymbol(circle)
Beispiel #7
0
 def _update_symbol_set(self, map):
     circle = map.symbolset.getSymbolByName('circle')
     # circle = mapscript.symbolObj("circle")
     circle.type = mapscript.MS_SYMBOL_ELLIPSE
     circle.filled = mapscript.MS_ON
     l1 = mapscript.lineObj()
     l1.add(mapscript.pointObj(1, 1))
     circle.setPoints(l1)
     map.symbolset.appendSymbol(circle)
Beispiel #8
0
    def testGetPointWKT(self):
        # Create new instance from class data
        po = mapscript.pointObj(self.point_xy[0], self.point_xy[1])
        lo = mapscript.lineObj()
        lo.add(po)
        so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
        so.add(lo)

        # test output WKT
        wkt = so.toWKT()
        self.assertTrue(wkt == self.point_wkt, wkt)
Beispiel #9
0
    def testGetPointWKT(self):
        # Create new instance from class data
        po = mapscript.pointObj(self.point_xy[0], self.point_xy[1])
        lo = mapscript.lineObj()
        lo.add(po)
        so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
        so.add(lo)

        # test output WKT
        wkt = so.toWKT()
        self.assertTrue(wkt == self.point_wkt, wkt)
Beispiel #10
0
 def testSetPoints(self):
     """add lines of points to an existing symbol"""
     symbol = self.map.symbolset.getSymbol(1)
     assert symbol.name == 'circle'
     line = mapscript.lineObj()
     self.addPointToLine(line, mapscript.pointObj(2.0, 2.0))
     self.addPointToLine(line, mapscript.pointObj(3.0, 3.0))
     assert symbol.setPoints(line) == 2
     assert symbol.numpoints == 2
     line = symbol.getPoints()
     assert line.numpoints == 2, line.numpoints
     pt = self.getPointFromLine(line, 1)
     self.assertPointsEqual(pt, mapscript.pointObj(3.0, 3.0))
Beispiel #11
0
 def testAddPointFeature(self):
     """adding a point to an inline feature works correctly"""
     inline_layer = self.map.getLayerByName('INLINE')
     assert inline_layer.connectiontype == mapscript.MS_INLINE
     p = mapscript.pointObj(0.2, 51.5)
     lyr = mapscript.lineObj()
     self.addPointToLine(lyr, p)
     shape = mapscript.shapeObj(inline_layer.type)
     shape.classindex = 0
     self.addLineToShape(shape, lyr)
     inline_layer.addFeature(shape)
     msimg = self.map.draw()
     filename = 'testAddPointFeature.png'
     msimg.save(filename)
Beispiel #12
0
def rqtest_2():

    line = mapscript.lineObj()
    line.add(mapscript.pointObj(35, 25))
    line.add(mapscript.pointObj(45, 25))
    line.add(mapscript.pointObj(45, 35))
    line.add(mapscript.pointObj(35, 25))

    poly = mapscript.shapeObj(mapscript.MS_SHAPE_POLYGON)
    poly.add(line)

    pmstestlib.layer.queryByShape(pmstestlib.map, poly)

    return 'success'
Beispiel #13
0
 def testAddPointFeature(self):
     """adding a point to an inline feature works correctly"""
     inline_layer = self.map.getLayerByName('INLINE')
     assert inline_layer.connectiontype == mapscript.MS_INLINE
     p = mapscript.pointObj(0.2, 51.5)
     lyr = mapscript.lineObj()
     self.addPointToLine(lyr, p)
     shape = mapscript.shapeObj(inline_layer.type)
     shape.classindex = 0
     self.addLineToShape(shape, lyr)
     inline_layer.addFeature(shape)
     msimg = self.map.draw()
     filename = 'testAddPointFeature.png'
     msimg.save(filename)
Beispiel #14
0
def rqtest_2():

    line = mapscript.lineObj()
    line.add( mapscript.pointObj( 35, 25 ) )
    line.add( mapscript.pointObj( 45, 25 ) )
    line.add( mapscript.pointObj( 45, 35 ) )
    line.add( mapscript.pointObj( 35, 25 ) )

    poly = mapscript.shapeObj( mapscript.MS_SHAPE_POLYGON )
    poly.add( line )

    pmstestlib.layer.queryByShape( pmstestlib.map, poly )

    return 'success'
Beispiel #15
0
def ogr_query_2():

    line = mapscript.lineObj()
    line.add(mapscript.pointObj(479000, 4763000))
    line.add(mapscript.pointObj(480000, 4763000))
    line.add(mapscript.pointObj(480000, 4764000))
    line.add(mapscript.pointObj(479000, 4764000))

    poly = mapscript.shapeObj(mapscript.MS_SHAPE_POLYGON)
    poly.add(line)

    pmstestlib.layer.queryByShape(pmstestlib.map, poly)

    return "success"
Beispiel #16
0
def ogr_query_2():

    line = mapscript.lineObj()
    line.add(mapscript.pointObj(479000, 4763000))
    line.add(mapscript.pointObj(480000, 4763000))
    line.add(mapscript.pointObj(480000, 4764000))
    line.add(mapscript.pointObj(479000, 4764000))

    poly = mapscript.shapeObj(mapscript.MS_SHAPE_POLYGON)
    poly.add(line)

    pmstestlib.layer.queryByShape(pmstestlib.map, poly)

    return 'success'
	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()
Beispiel #18
0
    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')
    def _create_symbolset(self, symbolset_path):
        '''Creates a symbolset (containing the square symbol)
        and saves it as symbols.sym'''
        mapscript = self.mapscript
        
        symbolset = mapscript.symbolSetObj()
        new_symbol = mapscript.symbolObj('square')
        line = mapscript.lineObj()
        line.add(mapscript.pointObj(0.0, 4.0))
        line.add(mapscript.pointObj(4.0, 4.0))
        line.add(mapscript.pointObj(4.0, 0.0))
        line.add(mapscript.pointObj(0.0, 0.0))
        line.add(mapscript.pointObj(0.0, 4.0))

        new_symbol.setPoints(line)
        new_symbol.filled = True
        symbolset.appendSymbol(new_symbol)
        symbolset.save(symbolset_path)
Beispiel #20
0
    def _create_symbolset(self, symbolset_path):
        '''Creates a symbolset (containing the square symbol)
        and saves it as symbols.sym'''
        mapscript = self.mapscript

        symbolset = mapscript.symbolSetObj()
        new_symbol = mapscript.symbolObj('square')
        line = mapscript.lineObj()
        line.add(mapscript.pointObj(0.0, 4.0))
        line.add(mapscript.pointObj(4.0, 4.0))
        line.add(mapscript.pointObj(4.0, 0.0))
        line.add(mapscript.pointObj(0.0, 0.0))
        line.add(mapscript.pointObj(0.0, 4.0))

        new_symbol.setPoints(line)
        new_symbol.filled = True
        symbolset.appendSymbol(new_symbol)
        symbolset.save(symbolset_path)
Beispiel #21
0
    def warp(self):
        """Warp given URL and SRS

        Returns:
        mapscript.ImageObj
        """
        if not self.url or not self.sourceSRS:
            return
        self.map = mapscript.mapObj()
        self.map.setSize(int(self.url.getArgument("width")),int(self.url.getArgument("height")))
        (minx,miny,maxx,maxy) = map(lambda x: float(x), self.url.getArgument("bbox").split(","))
        self.map.extent = mapscript.rectObj(minx,miny,maxx,maxy)
        self.map.web.imagepath=tempfile.mkdtemp()
        self.map.setProjection(self.targetSRS.__str__())
        self.layer = mapscript.layerObj(self.map)
        self.layer.type = mapscript.MS_LAYER_RASTER
        self.layer.connection = self.url.getConnection()
        self.layer.status = mapscript.MS_DEFAULT
        self.layer.setConnectionType(mapscript.MS_WMS,None)
        self.layer.setMetaData("wms_srs",self.sourceSRS.__str__())
        self.layer.setMetaData("wms_name", self.url.getArgument("layers"))
        self.layer.setMetaData("wms_server_version",self.url.getArgument("version"))

        # WMS 1.3.0 is not supported by MapServer < 6.0 
        #  http://trac.osgeo.org/mapserver/ticket/3039
        if self.url.getArgument("version") == "1.3.0":
            self.layer.setMetaData("wms_server_version","1.1.1")
            
            if self.sourceSRS.authority == "CRS" and self.sourceSRS.code == "84":
                self.layer.setMetaData("wms_srs","EPSG:4326")
                

        self.layer.setMetaData("wms_exceptions_format",self.url.getArgument("exceptions"))
        self.layer.setMetaData("wms_formatlist",self.url.getArgument("format"))
        self.layer.setMetaData("wms_style",self.url.getArgument("style"))
        self.layer.setMetaData("wms_transparent",self.url.getArgument("transparent"))
        self.layer.setProjection(self.sourceSRS.__str__())
        self.layer.debug = 5

        if self.url.getArgument("format") == "image/png":
            self.map.outputformat.imagemode = mapscript.MS_IMAGEMODE_RGBA
        if self.url.getArgument("format") == "image/jpg":
            self.layer.setMetaData("wms_formatlist","image/jpeg")
            self.map.selectOutputFormat("image/jpeg")
        else:
            self.map.selectOutputFormat(self.url.getArgument("format"))
        self.map.outputformat.transparent= 1

        try:
            # draw the map
            #self.map.save("/tmp/pokus2.map")
            image = self.map.draw()
            if image:
                return image
        except :

            # something failed during the layer drawing. try to print the
            # error to stderr as well as generate new image with the error
            # message
            exc_type, exc_value, exc_traceback = sys.exc_info()
            traceback.print_exc(file=sys.stderr)
            traceback.print_tb(exc_traceback, limit=1, file=sys.stderr)

            self.map.removeLayer(0)
            self.map.setFontSet(os.path.join(os.path.abspath(os.path.dirname(__file__)),"fonts.txt"))
            self.map.outputformat.transparent= 0

            self.layer = mapscript.layerObj(self.map)
            self.layer.type = mapscript.MS_LAYER_ANNOTATION
            #self.layer.transform = mapscript.MS_OFF

            line = mapscript.lineObj()
            line.add(mapscript.pointObj(minx+(maxx-minx)/2.,miny+(maxy-miny)/2.))
            feature = mapscript.shapeObj()
            feature.add(line)
            self.layer.addFeature(feature)
            self.layer.labelcache = mapscript.MS_TRUE
            

            classobj = mapscript.classObj(self.layer)
            text = ""
            
            ## try to guess, where the problem is
            for i in textwrap.wrap(str(exc_value),70):
                text += i+"\n"
            classobj.setText(text)

            classobj.label.font = "sans"
            classobj.label.type = mapscript.MS_TRUETYPE
            classobj.label.antialias = mapscript.MS_FALSE
            classobj.label.size = 12
            classobj.label.position = mapscript.MS_CC
            #classobj.label.partials = mapscript.MS_FALSE
            classobj.label.force = mapscript.MS_TRUE


            self.layer.status = mapscript.MS_ON
            #self.map.save("/tmp/pokus3.map")
            image =  self.map.draw()
            return image
Beispiel #22
0
    def _create_preset_point_symbols(self):
        """
        Initiates preset point symbols.
        """
        # Circle symbol
        symb = mapscript.symbolObj('circle')
        symb.type = mapscript.MS_SYMBOL_ELLIPSE
        symb.filled = mapscript.MS_TRUE
        line = mapscript.lineObj()
        line.add(mapscript.pointObj())
        symb.setPoints(line)
        symb.sizex = self.symbol_size
        symb.sizey = self.symbol_size
        self.preset_symbols.append(symb)

        # Square symbol
        symb = mapscript.symbolObj('square')
        symb.type = mapscript.MS_SYMBOL_VECTOR
        symb.filled = mapscript.MS_TRUE
        line = mapscript.lineObj()
        for pnt in [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]:
            line.add(mapscript.pointObj(pnt[0], pnt[1]))
        symb.setPoints(line)
        symb.sizex = self.symbol_size
        symb.sizey = self.symbol_size
        self.preset_symbols.append(symb)

        # Triangle symbol
        symb = mapscript.symbolObj('triangle')
        symb.type = mapscript.MS_SYMBOL_VECTOR
        symb.filled = mapscript.MS_TRUE
        line = mapscript.lineObj()
        for pnt in [(0, 0), (14, 0), (7, 7), (0, 0)]:
            line.add(mapscript.pointObj(pnt[0], pnt[1]))
        symb.setPoints(line)
        symb.sizex = self.symbol_size
        symb.sizey = self.symbol_size
        self.preset_symbols.append(symb)

        # Cross symbol
        symb = mapscript.symbolObj('cross')
        symb.type = mapscript.MS_SYMBOL_VECTOR
        symb.filled = mapscript.MS_FALSE
        line = mapscript.lineObj()
        for pnt in [(0, 0), (10, 10), (-99, -99), (0, 10), (10, 0)]:
            line.add(mapscript.pointObj(pnt[0], pnt[1]))
        symb.setPoints(line)
        symb.sizex = self.symbol_size
        symb.sizey = self.symbol_size
        self.preset_symbols.append(symb)

        # Diagonal symbol
        symb = mapscript.symbolObj('diagonal')
        symb.type = mapscript.MS_SYMBOL_VECTOR
        symb.filled = mapscript.MS_FALSE
        line = mapscript.lineObj()
        for pnt in [(0, 0), (10, 10)]:
            line.add(mapscript.pointObj(pnt[0], pnt[1]))
        symb.setPoints(line)
        symb.sizex = self.symbol_size
        symb.sizey = self.symbol_size
        self.preset_symbols.append(symb)
Beispiel #23
0
    def _create_preset_point_symbols(self):
        """Initiates preset point symbols"""

        # Circle symbol
        symb = mapscript.symbolObj('circle')
        symb.type = mapscript.MS_SYMBOL_ELLIPSE
        symb.filled = mapscript.MS_TRUE
        line = mapscript.lineObj()
        line.add(mapscript.pointObj())
        symb.setPoints(line)
        symb.sizex = self.symbol_size
        symb.sizey = self.symbol_size
        self.preset_symbols.append(symb)

        # Square symbol
        symb = mapscript.symbolObj('square')
        symb.type = mapscript.MS_SYMBOL_VECTOR
        symb.filled = mapscript.MS_TRUE
        line = mapscript.lineObj()
        for pnt in [(0,0), (0, 10), (10, 10), (10, 0), (0, 0)]:
            line.add(mapscript.pointObj(pnt[0], pnt[1]))
        symb.setPoints(line)
        symb.sizex = self.symbol_size
        symb.sizey = self.symbol_size
        self.preset_symbols.append(symb)

        # Triangle symbol
        symb = mapscript.symbolObj('triangle')
        symb.type = mapscript.MS_SYMBOL_VECTOR
        symb.filled = mapscript.MS_TRUE
        line = mapscript.lineObj()
        for pnt in [(0,0), (14, 0), (7, 7), (0, 0)]:
            line.add(mapscript.pointObj(pnt[0], pnt[1]))
        symb.setPoints(line)
        symb.sizex = self.symbol_size
        symb.sizey = self.symbol_size
        self.preset_symbols.append(symb)

        # Cross symbol
        symb = mapscript.symbolObj('cross')
        symb.type = mapscript.MS_SYMBOL_VECTOR
        symb.filled = mapscript.MS_FALSE
        line = mapscript.lineObj()
        for pnt in [(0,0), (10, 10), (-99, -99), (0, 10), (10, 0)]:
            line.add(mapscript.pointObj(pnt[0], pnt[1]))
        symb.setPoints(line)
        symb.sizex = self.symbol_size
        symb.sizey = self.symbol_size
        self.preset_symbols.append(symb)

        # Diagonal symbol
        symb = mapscript.symbolObj('diagonal')
        symb.type = mapscript.MS_SYMBOL_VECTOR
        symb.filled = mapscript.MS_FALSE
        line = mapscript.lineObj()
        for pnt in [(0,0), (10, 10)]:
            line.add(mapscript.pointObj(pnt[0], pnt[1]))
        symb.setPoints(line)
        symb.sizex = self.symbol_size
        symb.sizey = self.symbol_size
        self.preset_symbols.append(symb)