Exemple #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])
Exemple #2
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])
Exemple #3
0
 def WGSbounds(self):
     x = self.bounds.minx
     y = self.bounds.miny
     p = ms.pointObj(x,y)
     assert p.project(GMERC,ms.projectionObj(WGS84)) == 0
     X = self.bounds.maxx
     Y = self.bounds.maxy
     P = ms.pointObj(X,Y)
     assert P.project(GMERC,ms.projectionObj(WGS84)) == 0
     
     return {'minx':p.x,'miny':p.y,'maxx':P.x,'maxy':P.y}
Exemple #4
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))
Exemple #5
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'
Exemple #6
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"
Exemple #7
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'
Exemple #8
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'
Exemple #9
0
 def setUp(self):
     MapLayerTestCase.setUp(self)
     self.layer.minscaledenom = 1000
     self.layer.maxscaledenom = 2000
     self.layer.status = mapscript.MS_ON
     self.map.zoomScale(1500, mapscript.pointObj(100, 100), 200, 200,
                        self.map.extent, None)
Exemple #10
0
def main(input_file, x_field_idx, y_field_idx, input_proj, output_proj):

    # set input and output projections
    proj_in = mapscript.projectionObj(input_proj)
    proj_out = mapscript.projectionObj(output_proj)

    # open file
    with open(input_file, encoding='utf-8') as f:
        # read csv
        csv_in = csv.reader(f)
        headers = next(csv_in)

        # setup output
        csv_out = csv.writer(sys.stdout)
        csv_out.writerow(headers)

        for row in csv_in:
            # set pointObj
            point = mapscript.pointObj(float(row[x_field_idx]), float(row[y_field_idx]))
            # project
            point.project(proj_in, proj_out)

            # update with reprojected coordinates
            row[x_field_idx] = point.x
            row[y_field_idx] = point.y

            csv_out.writerow(row)
Exemple #11
0
 def testPointGeoInterface(self):
     """return point using the  __geo_interface__ protocol"""
     p = mapscript.pointObj(1.0, 1.0, 0.002, 15.0)
     if hasattr(p, 'z'):
         assert p.__geo_interface__ == {"type": "Point", "coordinates": (1.0, 1.0, 0.002)}
     else:
         assert p.__geo_interface__ == {"type": "Point", "coordinates": (1.0, 1.0)}
Exemple #12
0
def query_raster_MS(mapfile_path, rasters):
    #import mapscript #dopo aggiornamento python se carico mapscript dopo le gdal via web ritorna un errore
    mapfile2 = mapfile_path
    m2 = mapscript.mapObj(mapfile2)
    p2 = mapscript.pointObj(x, y)
    #raster = rasters[0]
    for raster in rasters:
        layer2 = m2.getLayerByName(raster)
        print layer2.name
        layer2.queryByPoint(
            m2, p2, mapscript.MS_MULTIPLE, 500.0
        )  ##tolleranza in unita mappa. Se <=0 si usa la tolleranza (in pixel) definita nel file MAP
        results2 = layer2.getResults()
        if results2:
            for i in range(results2.numresults):
                result2 = results2.getResult(i)
        layer2.open()
        s2 = layer2.getShape(result2)
        if results2:
            for i in range(results2.numresults):
                result2 = results2.getResult(i)
                s2 = layer2.getShape(result2)
                for j in range(layer2.numitems):
                    print '%s: %s<br/>' % (layer2.getItem(j), s2.getValue(j))

        layer2.close()
Exemple #13
0
def main(input_file, x_field_idx, y_field_idx, input_proj, output_proj):

    # set input and output projections
    proj_in = mapscript.projectionObj(input_proj)
    proj_out = mapscript.projectionObj(output_proj)

    # open file
    with open(input_file, encoding='utf-8') as f:
        # read csv
        csv_in = csv.reader(f)
        headers = next(csv_in)

        # setup output
        csv_out = csv.writer(sys.stdout)
        csv_out.writerow(headers)

        for row in csv_in:
            # set pointObj
            point = mapscript.pointObj(float(row[x_field_idx]),
                                       float(row[y_field_idx]))
            # project
            point.project(proj_in, proj_out)

            # update with reprojected coordinates
            row[x_field_idx] = point.x
            row[y_field_idx] = point.y

            csv_out.writerow(row)
Exemple #14
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 setPoints(ps):
        """Set the points of the marker"""

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

        msSymbol.setPoints(msLine)
Exemple #16
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])
Exemple #17
0
 def testPoint__str__(self):
     """return properly formatted string"""
     p = mapscript.pointObj(1.0, 1.0)
     if hasattr(p, 'z'):
         p_str = "{ 'x': %.16g, 'y': %.16g, 'z': %.16g }" % (p.x, p.y, p.z)
     else:
         p_str = "{ 'x': %.16g, 'y': %.16g }" % (p.x, p.y)
     assert str(p) == p_str, str(p)
Exemple #18
0
 def testSetXYM(self):
     """point can have its x and y reset (with m value)"""
     p = mapscript.pointObj()
     p.setXY(1.0, 1.0, 1.0)
     self.assertAlmostEqual(p.x, 1.0)
     self.assertAlmostEqual(p.y, 1.0)
     if hasattr(p, 'm'):
         self.assertAlmostEqual(p.m, 1.0)
Exemple #19
0
 def testSetXYM(self):
     """point can have its x and y reset (with m value)"""
     p = mapscript.pointObj()
     p.setXY(1.0, 1.0, 1.0)
     self.assertAlmostEqual(p.x, 1.0)
     self.assertAlmostEqual(p.y, 1.0)
     if hasattr(p, 'm'):
         self.assertAlmostEqual(p.m, 1.0)
Exemple #20
0
 def testZoomInPoint(self):
     """ZoomPointTestCase.testZoomInPoint: zooming in by a power of 2 returns the proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj(50.0, 50.0)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(2, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-25, -25, 25, 25))
Exemple #21
0
 def xtestGetPoints(self):
     """get symbol points as line and test coords"""
     symbol = self.map.symbolset.getSymbol(1)
     assert symbol.name == 'circle'
     line = symbol.getPoints()
     assert line.numpoints == 1, line.numpoints
     pt = self.getPointFromLine(line, 0)
     self.assertPointsEqual(pt, mapscript.pointObj(1.0, 1.0))
Exemple #22
0
 def testRecenter(self):
     """ZoomPointTestCase.testRecenter: recentering the map with a point returns the same extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj(50.0, 50.0)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(1, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-50, -50, 50, 50))
Exemple #23
0
 def testPoint__str__(self):
     """return properly formatted string"""
     p = mapscript.pointObj(1.0, 1.0)
     if hasattr(p, 'z'):
         p_str = "{ 'x': %.16g, 'y': %.16g, 'z': %.16g }" % (p.x, p.y, p.z)
     else:
         p_str = "{ 'x': %.16g, 'y': %.16g }" % (p.x, p.y)
     assert str(p) == p_str, str(p)
    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)
Exemple #25
0
def rqtest_6():

    pnt = mapscript.pointObj()
    pnt.x = 35.2
    pnt.y = 25.3

    pmstestlib.map.queryByPoint(pnt, mapscript.MS_SINGLE, 10.0)

    return 'success'
Exemple #26
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)
Exemple #27
0
 def testZoomBadSize(self):
     """ZoomPointTestCase.testZoomBadSize: zooming to a bad size raises proper error"""
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     extent = self.mapobj1.extent
     w = 0
     h = -1
     self.assertRaises(mapscript.MapServerError, self.mapobj1.zoomPoint, -2,
                       p, w, h, extent, None)
Exemple #28
0
def rqtest_6():

    pnt = mapscript.pointObj()
    pnt.x = 35.2
    pnt.y = 25.3
    
    pmstestlib.map.queryByPoint( pnt, mapscript.MS_SINGLE, 10.0 )

    return 'success'
Exemple #29
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)
Exemple #30
0
 def testSetXYZ(self):
     """point can have its x, y, z reset (with m value)"""
     p = mapscript.pointObj()
     p.setXYZ(1.0, 2.0, 3.0, 4.0)
     self.assertAlmostEqual(p.x, 1.0)
     self.assertAlmostEqual(p.y, 2.0)
     if hasattr(p, 'z') and hasattr(p, 'm'):
         self.assertAlmostEqual(p.z, 3.0)
         self.assertAlmostEqual(p.m, 4.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)
Exemple #32
0
 def testSetXYZ(self):
     """point can have its x, y, z reset (with m value)"""
     p = mapscript.pointObj()
     p.setXYZ(1.0, 2.0, 3.0, 4.0)
     self.assertAlmostEqual(p.x, 1.0)
     self.assertAlmostEqual(p.y, 2.0)
     if hasattr(p, 'z') and hasattr(p, 'm'):
         self.assertAlmostEqual(p.z, 3.0)
         self.assertAlmostEqual(p.m, 4.0)
Exemple #33
0
	def position_boundary_label(self, shape, node, label_width, label_height, node_extent_shape):
		x_scale = (node.max_x - node.min_x) / float(self.img_w)
		y_scale = (node.max_y - node.min_y) / float(self.img_h)
		label_geo_w = label_width * x_scale * .5
		label_geo_h = label_height * y_scale * .5
		#TODO: this will be weird if the extent isn't square
		label_geo_spacing = self.label_spacing * x_scale

		ret_results = []

		if(not shape):
			return None

		distance_since_last_label = 0
		line = shape.get(0)
		for line_iter in range(shape.numlines):
			line = shape.get(line_iter)

			if(line.numpoints == 0):
				continue

			last_point = line.get(0)
			last_x, last_y = tiletree.geo_coord_to_img(last_point.x, last_point.y,
					self.img_w, self.img_h, node.min_x, node.min_y, node.max_x, node.max_y)
			point_iter = 1
			while point_iter < line.numpoints:
				point = line.get(point_iter)
				this_x, this_y = tiletree.geo_coord_to_img(point.x, point.y,
					self.img_w, self.img_h, node.min_x, node.min_y, node.max_x, node.max_y)
				this_distance = calc_distance(this_x, this_y, last_x, last_y)

				if((distance_since_last_label + this_distance) > self.label_spacing ):
					point = pro_rate_point(last_point.x, last_point.y, point.x, point.y,
							label_geo_spacing - distance_since_last_label*x_scale)
					point = mapscript.pointObj(*point)
					this_x, this_y = tiletree.geo_coord_to_img(point.x, point.y,
						self.img_w, self.img_h, node.min_x, node.min_y, node.max_x, node.max_y)
					point_iter -= 1

					if(node_extent_shape.contains(point)):
						min_label_x = point.x - (x_scale * self.label_adjustment_max)
						max_label_x = point.x + (x_scale * self.label_adjustment_max)
						pos_results = self.slow_position_poly_label(shape, node, point.x, point.y, x_scale,
							y_scale, min_label_x, max_label_x, label_geo_w, label_geo_h)
						ret_results.append(self.return_pos_results(node, pos_results))

					distance_since_last_label = 0
				else:
					distance_since_last_label += this_distance

				last_x = this_x
				last_y = this_y
				last_point = point
				point_iter +=1 

		return ret_results
Exemple #34
0
 def xtestZoomInScale(self):
     """ZoomScaleTestCase.testZoomInScale: zooming in to a specified scale returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     scale = 1417.3236
     extent = self.mapobj1.extent
     self.mapobj1.zoomScale(scale, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-25, -25, 25, 25))
Exemple #35
0
 def xtestRecenter(self):
     """ZoomScaleTestCase.testRecenter: recentering map returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     scale = 2834.6472
     extent = self.mapobj1.extent
     self.mapobj1.zoomScale(scale, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-50, -50, 50, 50))
Exemple #36
0
    def testPointToString(self):
        """return properly formatted string in toString()"""
        p = mapscript.pointObj(1.0, 1.0, 0.002, 15.0)
        if hasattr(p, 'z') and hasattr(p, 'm'):
            p_str = "{ 'x': %.16g, 'y': %.16g, 'z': %.16g, 'm': %.16g }" \
                  % (p.x, p.y, p.z, p.m)
        else:
            p_str = "{ 'x': %.16g, 'y': %.16g }" % (p.x, p.y)

        assert p.toString() == p_str, p.toString()
Exemple #37
0
def rqtest_12():

    pnt = mapscript.pointObj()
    pnt.x = 13.5
    pnt.y = 36.5

    pmstestlib.layer.queryByPoint(pmstestlib.map, pnt, mapscript.MS_SINGLE,
                                  10.0)

    return 'success'
Exemple #38
0
 def testZoomOutPoint(self):
     """ZoomPointTestCase.testZoomOutPoint: zooming out by a power of 2 returns the proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(-2, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent,
                           mapscript.rectObj(-100, -100, 100, 100))
Exemple #39
0
def rqtest_12():

    pnt = mapscript.pointObj()
    pnt.x = 13.5
    pnt.y = 36.5
    
    pmstestlib.layer.queryByPoint( pmstestlib.map, pnt, mapscript.MS_SINGLE,
                                   10.0 )

    return 'success'
Exemple #40
0
    def testPointToString(self):
        """return properly formatted string in toString()"""
        p = mapscript.pointObj(1.0, 1.0, 0.002, 15.0)
        if hasattr(p, 'z') and hasattr(p, 'm'):
            p_str = "{ 'x': %.16g, 'y': %.16g, 'z': %.16g, 'm': %.16g }" \
                  % (p.x, p.y, p.z, p.m)
        else:
            p_str = "{ 'x': %.16g, 'y': %.16g }" % (p.x, p.y)

        assert p.toString() == p_str, p.toString()
Exemple #41
0
def rqtest_4():

    pnt = mapscript.pointObj()
    pnt.x = 35.5
    pnt.y = 25.5
    
    pmstestlib.layer.queryByPoint( pmstestlib.map, pnt, mapscript.MS_MULTIPLE,
                                   1.25 )

    return 'success'
Exemple #42
0
 def testDrawPoints(self):
     """DrawProgrammedStylesTestCase.testDrawPoints: point drawing with styles works as advertised"""
     points = [mapscript.pointObj(-0.2, 51.6),
               mapscript.pointObj(0.0, 51.2),
               mapscript.pointObj(0.2, 51.6)]
     colors = [mapscript.colorObj(255, 0, 0),
               mapscript.colorObj(0, 255, 0),
               mapscript.colorObj(0, 0, 255)]
     img = self.map.prepareImage()
     layer = self.map.getLayerByName('POINT')
     # layer.draw(self.map, img)
     class0 = layer.getClass(0)
     for i in range(len(points)):
         style0 = class0.getStyle(0)
         style0.color = colors[i]
         # style0.color.pen = -4
         assert style0.color.toHex() == colors[i].toHex()
         points[i].draw(self.map, layer, img, 0, "foo")
     img.save('test_draw_points.png')
Exemple #43
0
def rqtest_4():

    pnt = mapscript.pointObj()
    pnt.x = 35.5
    pnt.y = 25.5

    pmstestlib.layer.queryByPoint(pmstestlib.map, pnt, mapscript.MS_MULTIPLE,
                                  1.25)

    return 'success'
Exemple #44
0
 def testZoomBadExtent(self):
     """ZoomPointTestCase.testZoomBadExtent: zooming to a bad extent raises proper error"""
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     extent = self.mapobj1.extent
     extent.maxx = extent.maxx - 1000000
     w = 100
     h = 100
     self.assertRaises(mapscript.MapServerError, self.mapobj1.zoomPoint, -2,
                       p, w, h, extent, None)
Exemple #45
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)
Exemple #46
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)
Exemple #47
0
 def xtestZoomOutScale(self):
     """ZoomScaleTestCase.testZoomOutScale: zooming out to a specified scale returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     scale = 5669.2944
     extent = self.mapobj1.extent
     self.mapobj1.zoomScale(scale, p, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent,
                           mapscript.rectObj(-100, -100, 100, 100))
Exemple #48
0
 def testZoomOutPointConstrained(self):
     """ZoomPointTestCase.testZoomOutPointConstrained: zooming out to a constrained extent returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     max = mapscript.rectObj()
     max.minx, max.miny, max.maxx, max.maxy = (-100.0, -100.0, 100.0, 100.0)
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     extent = self.mapobj1.extent
     self.mapobj1.zoomPoint(-4, p, w, h, extent, max)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, max)
Exemple #49
0
 def testRecenter(self):
     """ZoomScaleTestCase.testRecenter: recentering map returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)  # 100 by 100
     p = mapscript.pointObj()
     p.x, p.y = (50, 50)
     scale = 2834.6472
     extent = self.mapobj1.extent
     self.mapobj1.zoomScale(scale, p, w, h, extent, None)
     assert self.mapobj1.scaledenom == scale
     new_extent = self.mapobj1.extent
     # self.assertRectsEqual(new_extent, mapscript.rectObj(-50, -50, 50, 50))  # old values
     self.assertRectsEqual(new_extent,
                           mapscript.rectObj(-49.5, -49.5, 49.5, 49.5))
Exemple #50
0
 def testPointGeoInterface(self):
     """return point using the  __geo_interface__ protocol"""
     p = mapscript.pointObj(1.0, 1.0, 0.002, 15.0)
     if hasattr(p, 'z'):
         assert p.__geo_interface__ == {
             "type": "Point",
             "coordinates": (1.0, 1.0, 0.002)
         }
     else:
         assert p.__geo_interface__ == {
             "type": "Point",
             "coordinates": (1.0, 1.0)
         }
Exemple #51
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)
	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()
Exemple #53
0
def rqtest_16():

    pmstestlib.map = mapscript.mapObj('../gdal/tileindex_mi.map')
    pmstestlib.layer = pmstestlib.map.getLayer(0)

    pmstestlib.map.setProjection("+proj=utm +zone=30 +datum=WGS84")

    pnt = mapscript.pointObj()
    pnt.x =  889690
    pnt.y =   55369
    
    pmstestlib.layer.queryByPoint( pmstestlib.map, pnt, mapscript.MS_MULTIPLE,
                                   200000.0 )

    return 'success'
Exemple #54
0
def rqtest_10():

    pmstestlib.layer = None
    pmstestlib.map = None

    pmstestlib.map = mapscript.mapObj('../gdal/classtest1.map')
    pmstestlib.layer = pmstestlib.map.getLayer(0)
    
    pnt = mapscript.pointObj()
    pnt.x = 88.5
    pnt.y = 7.5
    
    pmstestlib.layer.queryByPoint( pmstestlib.map, pnt, mapscript.MS_SINGLE,
                                   10.0 )

    return 'success'
Exemple #55
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')
Exemple #56
0
	def position_poly_label(self, shape, node, label_width, label_height):
		x_scale = (node.max_x - node.min_x) / float(self.img_w)
		y_scale = (node.max_y - node.min_y) / float(self.img_h)
		label_geo_w = label_width * x_scale * .5
		label_geo_h = label_height * y_scale * .5
		x_repeat_interval = self.label_spacing * x_scale
		y_repeat_interval = self.label_spacing * y_scale

		#this crashes :(
		#shape = shape.simplify(min(x_scale, y_scale))

		seed_point = shape.getCentroid()
		if(seed_point == None):
			return None
		ghost_x, ghost_y = self.find_poly_label_ghost(seed_point.x, seed_point.y,
				node, x_repeat_interval,  y_repeat_interval)

		#make sure the ghost point is in the polygon
		if(not shape.contains(mapscript.pointObj(ghost_x, ghost_y))):
				return None

		min_label_x = ghost_x - (x_scale * self.label_adjustment_max)
		max_label_x = ghost_x + (x_scale * self.label_adjustment_max)
		min_label_y = ghost_y - (y_scale * self.label_adjustment_max)
		max_label_y = ghost_y + (y_scale * self.label_adjustment_max)

		#if this label couldn't possibly intersect this tile + tile_buffer
		#then skip it!
		if(not bbox_check((min_label_x - label_geo_w, min_label_y - label_geo_h, 
				max_label_x + label_geo_w, max_label_y + label_geo_h),
				(self.mapfile.extent.minx, self.mapfile.extent.miny,
				self.mapfile.extent.maxx, self.mapfile.extent.maxy))):
			host_y = seed_y + y_spaces * y_repeat_interval
			return None

		pos_results = self.fast_position_poly_label(shape, node,
				ghost_x, ghost_y, x_scale, y_scale, min_label_x, max_label_x,
				label_geo_w, label_geo_h)
		#if the shape's area is less than 1/10 of a tile then don't bother 
		#trying to label it
		if(not pos_results and (shape.getArea() < (self.img_w * x_scale**2 * .1)) ):
			pos_results = self.slow_position_poly_label(shape, node,
					ghost_x, ghost_y, x_scale, y_scale, min_label_x, max_label_x,
					label_geo_w, label_geo_h)

		return self.return_pos_results(node, pos_results)
Exemple #57
0
    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())
Exemple #58
0
def rqtest_17():
    
    layer = pmstestlib.layer
    
    pnt = mapscript.pointObj()
    pnt.x =  889690
    pnt.y =   55369
    
    #########################################################################
    # Check result count.
    layer.open()
    count = 0
    for i in range(1000):
        result = layer.getResult( i )
        if result is None:
            break

        count = count + 1

        s = layer.getShape( result )
        x = float(pmstestlib.get_item_value( layer, s, 'x' ))
        y = float(pmstestlib.get_item_value( layer, s, 'y' ))
        dist_sq = (x-pnt.x) * (x-pnt.x) + (y-pnt.y) * (y-pnt.y)
        dist = math.pow(dist_sq,0.5)
        if dist > 200000.0:
            pmstestlib.post_reason(
                'Got point %f from target, but tolerance was 200000.0.' % dst )
            return 'fail'
                
    
    if count != 4:
        pmstestlib.post_reason( 'got %d results instead of expected %d.' \
                             % (count, 10) )
        return 'fail'

    layer.close() 
    layer.close() # discard resultset.

    return 'success'
Exemple #59
0
 def testZoomOutVisibility(self):
     """expect false visibility after zooming out beyond maximum"""
     self.map.zoomScale(2500, mapscript.pointObj(100, 100), 200, 200, self.map.extent, None)
     assert self.layer.isVisible() == mapscript.MS_FALSE
Exemple #60
0
 def setUp(self):
     MapLayerTestCase.setUp(self)
     self.layer.minscaledenom = 1000
     self.layer.maxscaledenom = 2000
     self.layer.status = mapscript.MS_ON
     self.map.zoomScale(1500, mapscript.pointObj(100, 100), 200, 200, self.map.extent, None)