Exemplo n.º 1
0
def raster_shapes(layerObj, extent=None):
    if layerObj.tileindex is None:
        # no tileindex, use DATA
        filename = os.path.join(layerObj.map.shapepath, layerObj.data)
        layer = gdal.Open(filename, gdal.GA_ReadOnly)

        geotransform = layer.GetGeoTransform()
        minx = geotransform[0]
        maxy = geotransform[3]
        miny = maxy + layer.RasterYSize * geotransform[5]
        maxx = minx + layer.RasterXSize * geotransform[1]

        return [mapscript.rectObj(minx, miny, maxx, maxy).toPolygon()]
    else:
        filename = os.path.join(layerObj.map.shapepath, layerObj.tileindex + ".shp")
        ds = ogr.Open(filename)
        layer = ds.GetLayerByIndex(0)
        layer.ResetReading()

        if extent is not None:
            layer.SetSpatialFilterRect(*extent)

        tiles = []
        tile = layer.GetNextFeature()
        while tile:
            minx, maxx, miny, maxy = tile.GetGeometryRef().GetEnvelope() # WTF ?
            tiles.append(mapscript.rectObj(minx, miny, maxx, maxy).toPolygon())
            tile = layer.GetNextFeature()
        ds.Destroy()

        return tiles
Exemplo n.º 2
0
 def testZoomRectangle(self):
     """ZoomRectangleTestCase.testZoomRectangle: zooming to an extent returns proper map extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     r = mapscript.rectObj(1, 26, 26, 1, 1)
     extent = self.mapobj1.extent
     self.mapobj1.zoomRectangle(r, w, h, extent, None)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, mapscript.rectObj(-49, 24, -24, 49))
Exemplo n.º 3
0
 def testZoomRectangleConstrained(self):
     """ZoomRectangleTestCase.testZoomRectangleConstrained: zooming to a constrained extent returns proper extent"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     max = mapscript.rectObj(-100.0, -100.0, 100.0, 100.0)
     r = mapscript.rectObj(0, 200, 200, 0, 1)
     extent = self.mapobj1.extent
     self.mapobj1.zoomRectangle(r, w, h, extent, max)
     new_extent = self.mapobj1.extent
     self.assertRectsEqual(new_extent, max)
Exemplo n.º 4
0
 def testReBindingExtent(self):
     """test the rebinding of a map's extent"""
     test_map = mapscript.mapObj(TESTMAPFILE)
     rect1 = mapscript.rectObj(-10.0, -10.0, 10.0, 10.0)
     rect2 = mapscript.rectObj(-10.0, -10.0, 10.0, 10.0)
     test_map.extent = rect1
     assert repr(test_map.extent) != repr(rect1), (test_map.extent, rect1)
     del rect1
     self.assertRectsEqual(test_map.extent, rect2)
Exemplo n.º 5
0
 def testReBindingExtent(self):
     """test the rebinding of a map's extent"""
     test_map = mapscript.mapObj(TESTMAPFILE)
     rect1 = mapscript.rectObj(-10.0, -10.0, 10.0, 10.0)
     rect2 = mapscript.rectObj(-10.0, -10.0, 10.0, 10.0)
     test_map.extent = rect1
     assert repr(test_map.extent) != repr(rect1), (test_map.extent, rect1)
     del rect1
     self.assertRectsEqual(test_map.extent, rect2)
Exemplo n.º 6
0
 def testRectObjConstructorArgs(self):
     """a rect can be initialized with arguments"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0, 4.0)
     self.assertAlmostEqual(r.minx, -1.0)
     self.assertAlmostEqual(r.miny, -2.0)
     self.assertAlmostEqual(r.maxx, 3.0)
     self.assertAlmostEqual(r.maxy, 4.0)
Exemplo n.º 7
0
def vector_shapes(layerObj, extent=None):
    """ return all the shapes from 'layerObj' inside 'extent' """
    if extent is None:
        if valid_extent(layerObj.extent):
            extent = layerObj.extent
        else:
            extent = layerObj.map.extent
    else:
        extent = mapscript.rectObj(*extent)

    layerObj.open()
    status = layerObj.whichShapes(extent)
    if status == mapscript.MS_SUCCESS:
        shapes = []
        shape = layerObj.nextShape()
        while shape:
            shapes.append(shape)
            shape = layerObj.nextShape()
        layerObj.close()
        return shapes

    elif status == mapscript.MS_FAILURE:
        raise mapscript.MapServerError("error while querying layer: '%s'"%layerObj.name)

    elif status == mapscript.MS_DONE:
        # extent and shapefile don't overlap
        layerObj.close()
        return []
    
    else:
        raise mapscript.MapServerError("unknown status returned by whichShapes: '%s'"%status)
Exemplo n.º 8
0
def tiles(layersObj, tcLayer, bbox=None, levels=None, dataProjectionString=None, tilesProjectionString=None):
    dataProj = None
    if (dataProjectionString != None):
        print("Data projection: %s"%dataProjectionString)
        dataProj = mapscript.projectionObj(dataProjectionString)

    tilesProj = None
    if (tilesProjectionString != None):
        print("Tiles projection: %s"%tilesProjectionString)
        tilesProj = mapscript.projectionObj(tilesProjectionString)
    elif (tcLayer.srs != None and tcLayer.srs != ""):
        print("Tiles projection: %s"%tcLayer.srs)
        tilesProj = mapscript.projectionObj("+init=" + tcLayer.srs.lower())

    """ yield all non empty tiles indexes (x, y, z) """
    pad = pack('x')
    done = {}
    for layerObj in layersObj:
        if (dataProj == None and layerObj.map.getProjection() != ""):
            print("Data projection: %s"%layerObj.map.getProjection())
            dataProj = mapscript.projectionObj(layerObj.map.getProjection())

        for shapeObj in shapes(layerObj, projectArray(bbox, tilesProj, dataProj)): # reprojet bbox tiles -> data
            for x, y, z in tcLayer.range(projectRect(shapeObj.bounds, dataProj, tilesProj), levels):   # first filter using shapes bbox, reprojet bounds data -> tiles
                key = pack('3i', x, y, z)
                if key not in done:
                    tile = MetaTile(tcLayer, x, y, z)
                    # FIXME: handle metaSize
                    rect = mapscript.rectObj(*tile.bufferbounds())
                    if intersects(shapeObj, projectRect(rect, tilesProj, dataProj)):    # second filter using shapes geometry, reprojet bufferbounds tiles -> data
                        done[key] = pad
                        yield layerObj, shapeObj, x, y, z
Exemplo n.º 9
0
def projectRect(rect, source, dest):
    if (source != None and dest != None):
        reporjected = mapscript.rectObj(rect.minx, rect.miny, rect.maxx, rect.maxy)
        reporjected.project(source, dest)
        return reporjected
    else:
        return rect
Exemplo n.º 10
0
 def testRectObjConstructorNoArgs(self):
     """a rect can be initialized with no args"""
     r = mapscript.rectObj()
     self.assertAlmostEqual(r.minx, -1.0)
     self.assertAlmostEqual(r.miny, -1.0)
     self.assertAlmostEqual(r.maxx, -1.0)
     self.assertAlmostEqual(r.maxy, -1.0)
Exemplo n.º 11
0
 def testRectObjConstructorArgs(self):
     """a rect can be initialized with arguments"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0, 4.0)
     self.assertAlmostEqual(r.minx, -1.0)
     self.assertAlmostEqual(r.miny, -2.0)
     self.assertAlmostEqual(r.maxx, 3.0)
     self.assertAlmostEqual(r.maxy, 4.0)
Exemplo n.º 12
0
    def position_point_label(self,
                             shape,
                             node,
                             label_width,
                             label_height,
                             where_ud='center',
                             where_lr='right'):
        seed_point = shape.getCentroid()
        if (seed_point == None):
            return None

        x_scale = (node.max_x - node.min_x) / float(self.img_w)
        y_scale = (node.max_y - node.min_y) / float(self.img_h)

        #put the text to the right of the point
        label_geo_bbox = self.label_point_bbox(seed_point.x, seed_point.y,
                                               label_width, label_height,
                                               x_scale, y_scale, where_ud,
                                               where_lr)

        #make sure that this label doesnt intersect with any other labels
        label_shape = mapscript.rectObj(*label_geo_bbox).toPolygon()
        if (node.label_geoms != None):
            if (label_shape.intersects(node.label_geoms)):
                return None
            node.label_geoms = label_shape.Union(node.label_geoms)
        else:
            node.label_geoms = label_shape

        is_in_tile = False
        if (bbox_check(label_geo_bbox,
                       (node.min_x, node.min_y, node.max_x, node.max_y))):
            is_in_tile = True

        return (is_in_tile, label_geo_bbox)
Exemplo n.º 13
0
 def testZoomRectangleBadly(self):
     """zooming into an invalid extent raises proper error"""
     w, h = (self.mapobj1.width, self.mapobj1.height)
     r = mapscript.rectObj(0, 0, 200, 200)
     extent = self.mapobj1.extent
     self.assertRaises(mapscript.MapServerError, self.mapobj1.zoomRectangle,
                       r, w, h, extent, None)
Exemplo n.º 14
0
	def position_point_label(self, shape, node, label_width, label_height, where_ud='center', where_lr='right'):
		seed_point = shape.getCentroid()
		if(seed_point == None):
			return None

		x_scale = (node.max_x - node.min_x) / float(self.img_w)
		y_scale = (node.max_y - node.min_y) / float(self.img_h)

		#put the text to the right of the point
		label_geo_bbox = self.label_point_bbox(seed_point.x, seed_point.y, label_width, label_height,
				x_scale, y_scale, where_ud, where_lr)

		#make sure that this label doesnt intersect with any other labels
		label_shape = mapscript.rectObj(*label_geo_bbox).toPolygon()
		if(node.label_geoms != None):
			if(label_shape.intersects(node.label_geoms)):
				return None
			node.label_geoms =label_shape.Union(node.label_geoms)
		else:
			node.label_geoms = label_shape

		is_in_tile = False
		if(bbox_check(label_geo_bbox, (node.min_x, node.min_y, node.max_x, node.max_y))):
			is_in_tile = True

		return (is_in_tile, label_geo_bbox)
Exemplo n.º 15
0
    def testDrawMapWithSecondPolygon(self):
        """draw a blue polygon and a red polygon"""
        p = self.map.getLayerByName('POLYGON')
        ip = mapscript.layerObj(self.map)
        ip.type = mapscript.MS_LAYER_POLYGON
        ip.status = mapscript.MS_DEFAULT
        c0 = mapscript.classObj(ip)

        # turn off first polygon layer's color
        p.getClass(0).getStyle(0).color.setRGB(-1, -1, -1)

        # copy this style to inline polygon layer, then change outlinecolor
        c0.insertStyle(p.getClass(0).getStyle(0))
        st0 = c0.getStyle(0)
        st0.outlinecolor.setRGB(255, 0, 0)

        # pull out the first feature from polygon layer, shift it
        # and use this as an inline feature in new layer
        p.open()
        p.template = "FAKE"  # set a template so the layer can be queried
        p.queryByIndex(self.map, -1, 0, mapscript.MS_TRUE)
        res = p.getResult(0)
        s0 = p.getShape(res)
        p.close()
        r0 = s0.bounds
        r1 = mapscript.rectObj(r0.minx-0.1, r0.miny-0.1, r0.maxx-0.1, r0.maxy-0.1)
        s1 = r1.toPolygon()

        ip.addFeature(s1)
        img = self.map.draw()
        img.save('test_drawmapw2ndpolygon.png')
Exemplo n.º 16
0
 def testDirectExtentAccess(self):
     """direct access to a layer's extent works properly"""
     pt_layer = self.map.getLayerByName('POINT')
     rect = pt_layer.extent
     assert str(pt_layer.extent) == str(rect), (pt_layer.extent, rect)
     e = mapscript.rectObj(-0.5, 51.0, 0.5, 52.0)
     self.assertRectsEqual(e, rect)
Exemplo n.º 17
0
 def testRectObjConstructorArgs(self):
     """create a rect in image units"""
     r = mapscript.rectObj(-1.0, 2.0, 3.0, 0.0, mapscript.MS_TRUE)
     self.assertAlmostEqual(r.minx, -1.0)
     self.assertAlmostEqual(r.miny, 2.0)
     self.assertAlmostEqual(r.maxx, 3.0)
     self.assertAlmostEqual(r.maxy, 0.0)
Exemplo n.º 18
0
def projectArray(rect, source, dest):
    if (source != None and dest != None):
	reporjected = mapscript.rectObj(rect[0], rect[1], rect[2], rect[3])
        reporjected.project(source, dest)
        return [reporjected.minx, reporjected.miny, reporjected.maxx, reporjected.maxy]
    else:
        return rect
Exemplo n.º 19
0
 def get_latlon_extent(self):
     rect = mapscript.rectObj(*self.get_extent())
     rect.project(
         mapscript.projectionObj(self.get_proj4()),
         mapscript.projectionObj(
             "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))
     return Extent(rect.minx, rect.miny, rect.maxx, rect.maxy)
Exemplo n.º 20
0
 def testRectObjConstructorNoArgs(self):
     """a rect can be initialized with no args"""
     r = mapscript.rectObj()
     self.assertAlmostEqual(r.minx, -1.0)
     self.assertAlmostEqual(r.miny, -1.0)
     self.assertAlmostEqual(r.maxx, -1.0)
     self.assertAlmostEqual(r.maxy, -1.0)
Exemplo n.º 21
0
 def testRectObjConstructorArgs(self):
     """create a rect in image units"""
     r = mapscript.rectObj(-1.0, 2.0, 3.0, 0.0, mapscript.MS_TRUE)
     self.assertAlmostEqual(r.minx, -1.0)
     self.assertAlmostEqual(r.miny, 2.0)
     self.assertAlmostEqual(r.maxx, 3.0)
     self.assertAlmostEqual(r.maxy, 0.0)
Exemplo n.º 22
0
    def testDrawMapWithSecondPolygon(self):
        """draw a blue polygon and a red polygon"""
        p = self.map.getLayerByName('POLYGON')
        ip = mapscript.layerObj(self.map)
        ip.type = mapscript.MS_LAYER_POLYGON
        ip.status = mapscript.MS_DEFAULT
        c0 = mapscript.classObj(ip)

        # turn off first polygon layer's color
        p.getClass(0).getStyle(0).color.setRGB(-1, -1, -1)

        # copy this style to inline polygon layer, then change outlinecolor
        c0.insertStyle(p.getClass(0).getStyle(0))
        st0 = c0.getStyle(0)
        st0.outlinecolor.setRGB(255, 0, 0)

        # pull out the first feature from polygon layer, shift it
        # and use this as an inline feature in new layer
        p.open()
        p.template = "FAKE"  # set a template so the layer can be queried
        p.queryByIndex(self.map, -1, 0, mapscript.MS_TRUE)
        res = p.getResult(0)
        s0 = p.getShape(res)
        p.close()
        r0 = s0.bounds
        r1 = mapscript.rectObj(r0.minx - 0.1, r0.miny - 0.1, r0.maxx - 0.1,
                               r0.maxy - 0.1)
        s1 = r1.toPolygon()

        ip.addFeature(s1)
        img = self.map.draw()
        img.save('test_drawmapw2ndpolygon.png')
Exemplo n.º 23
0
 def setUp(self):
     self.mapobj1 = mapscript.mapObj(TESTMAPFILE)
     # Change the extent for purposes of zoom testing
     rect = mapscript.rectObj()
     rect.minx, rect.miny, rect.maxx, rect.maxy = (-50.0, -50.0, 50.0, 50.0)
     self.mapobj1.extent = rect
     # Change height/width as well
     self.mapobj1.width, self.mapobj1.height = (100, 100)
Exemplo n.º 24
0
 def testExceptionMessage(self):
     """test formatted error message"""
     try:
         r = mapscript.rectObj(1.0, -2.0, -3.0, 4.0)
         print(r)
     except mapscript.MapServerError as msg:
         assert str(msg) == "rectObj(): Invalid rectangle. { 'minx': 1.000000 , " \
                            "'miny': -2.000000 , 'maxx': -3.000000 , 'maxy': 4.000000 }", msg
Exemplo n.º 25
0
 def setUp(self):
     self.mapobj1 = mapscript.mapObj(TESTMAPFILE)
     # Change the extent for purposes of zoom testing
     rect = mapscript.rectObj()
     rect.minx, rect.miny, rect.maxx, rect.maxy = (-50.0, -50.0, 50.0, 50.0)
     self.mapobj1.extent = rect
     # Change height/width as well
     self.mapobj1.width, self.mapobj1.height = (100, 100)
Exemplo n.º 26
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))
Exemplo n.º 27
0
 def testExceptionMessage(self):
     """test formatted error message"""
     try:
         r = mapscript.rectObj(1.0, -2.0, -3.0, 4.0)
         print(r)
     except mapscript.MapServerError as msg:
         assert str(msg) == "rectObj(): Invalid rectangle. { 'minx': 1.000000 , " \
                            "'miny': -2.000000 , 'maxx': -3.000000 , 'maxy': 4.000000 }", msg
Exemplo n.º 28
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))
Exemplo n.º 29
0
 def testGetPresetExtent(self):
     """test layer.setExtent() and layer.getExtent() to return preset instead of calculating extents"""
     r = mapscript.rectObj(1.0, 1.0, 3.0, 3.0)
     self.layer.setExtent(r.minx, r.miny, r.maxx, r.maxy)
     rect = self.layer.extent
     assert r.minx == rect.minx, rect
     assert r.miny == rect.miny, rect.miny
     assert r.maxx == rect.maxx, rect.maxx
     assert r.maxy == rect.maxy, rect.maxy
Exemplo n.º 30
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))
Exemplo n.º 31
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))
Exemplo n.º 32
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))
Exemplo n.º 33
0
 def testRectObjToPolygon(self):
     """a rect can be converted into a MS_POLYGON shape"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0, 4.0)
     s = r.toPolygon()
     assert s.numlines == 1, s.numlines
     line = self.getLineFromShape(s, 0)
     assert line.numpoints == 5, line.numpoints
     point = self.getPointFromLine(line, 0)
     self.assertAlmostEqual(point.x, -1.0)
     self.assertAlmostEqual(point.y, -2.0)
Exemplo n.º 34
0
 def testRect__str__(self):
     """__str__ returns properly formatted string"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0001, 4.0)
     r_str = str(r)
     assert r_str == "{ 'minx': -1 , 'miny': -2 , 'maxx': 3.0001 , 'maxy': 4 }", r_str
     r2 = eval(r_str)
     self.assertAlmostEqual(r2['minx'], r.minx)
     self.assertAlmostEqual(r2['miny'], r.miny)
     self.assertAlmostEqual(r2['maxx'], r.maxx)
     self.assertAlmostEqual(r2['maxy'], r.maxy)
Exemplo n.º 35
0
 def calcExtent(self,x,y,zoom):
     """ 'Calculate the ground extents of the tile request.' - src/mapserv5/maptile.c"""
     box = ms.rectObj()
     zoomfactor = 2**zoom
     tilesize = SPHEREMERC_GROUND_SIZE / zoomfactor
     box.minx = (x * tilesize) - (SPHEREMERC_GROUND_SIZE / 2.0)
     box.maxx = ((x + 1) * tilesize) - (SPHEREMERC_GROUND_SIZE / 2.0)
     box.miny = (SPHEREMERC_GROUND_SIZE / 2.0) - ((y + 1) * tilesize)
     box.maxy = (SPHEREMERC_GROUND_SIZE / 2.0) - (y * tilesize)
     return box
Exemplo n.º 36
0
 def testRectObjToPolygon(self):
     """a rect can be converted into a MS_POLYGON shape"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0, 4.0)
     s = r.toPolygon()
     assert s.numlines == 1, s.numlines
     line = self.getLineFromShape(s, 0)
     assert line.numpoints == 5, line.numpoints
     point = self.getPointFromLine(line, 0)
     self.assertAlmostEqual(point.x, -1.0)
     self.assertAlmostEqual(point.y, -2.0)
Exemplo n.º 37
0
 def testRect__str__(self):
     """__str__ returns properly formatted string"""
     r = mapscript.rectObj(-1.0, -2.0, 3.0001, 4.0)
     r_str = str(r)
     assert r_str == "{ 'minx': -1 , 'miny': -2 , 'maxx': 3.0001 , 'maxy': 4 }", r_str
     r2 = eval(r_str)
     self.assertAlmostEqual(r2['minx'], r.minx)
     self.assertAlmostEqual(r2['miny'], r.miny)
     self.assertAlmostEqual(r2['maxx'], r.maxx)
     self.assertAlmostEqual(r2['maxy'], r.maxy)
Exemplo n.º 38
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)
Exemplo n.º 39
0
    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
Exemplo n.º 40
0
def rqtest_8():

    rect = mapscript.rectObj()
    rect.minx = 35
    rect.maxx = 45
    rect.miny = 25
    rect.maxy = 35

    pmstestlib.layer.queryByRect(pmstestlib.map, rect)

    return 'success'
Exemplo n.º 41
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))
Exemplo n.º 42
0
def rqtest_8():

    rect = mapscript.rectObj()
    rect.minx = 35
    rect.maxx = 45
    rect.miny = 25
    rect.maxy = 35
    
    pmstestlib.layer.queryByRect( pmstestlib.map, rect )

    return 'success'
Exemplo n.º 43
0
def ogr_query_4():

    rect = mapscript.rectObj()
    rect.minx = 479000
    rect.maxx = 480000
    rect.miny = 4763000
    rect.maxy = 4764000

    pmstestlib.layer.queryByRect(pmstestlib.map, rect)

    return 'success'
Exemplo n.º 44
0
def ogr_query_4():

    rect = mapscript.rectObj()
    rect.minx = 479000
    rect.maxx = 480000
    rect.miny = 4763000
    rect.maxy = 4764000

    pmstestlib.layer.queryByRect(pmstestlib.map, rect)

    return "success"
Exemplo n.º 45
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))
Exemplo n.º 46
0
 def generate_map(self, in_t, minx, miny, maxx, maxy,lay):
     map = mapscript.mapObj()
     map.name = "Map"
     map.setSize(self.sizex,self.sizey)
     map.setImageType(self.outtype)
     map.imagecolor = mapscript.colorObj(0,0,0)
     map.units = mapscript.MS_METERS
     map.extent = mapscript.rectObj(minx,miny,maxx,maxy)
     map.web = mapscript.webObj()
     map.web.template = self.templatepath
     map.web.imagepath = self.imagespath
     map.web.imageurl = "/tmp"
     map.shapepath = DIRECTORIO_BASE+"maps/"
     map.insertLayer(lay)
     return map
Exemplo n.º 47
0
	def setDist(self,dist):
		"""Create an extent for our mapObj by buffering our
		projected point by the buffer distance. Then set the mapObj's extent."""
		extent = mapscript.rectObj() 
		topleft = self.getPointFromDist(self.parent.currentLocation,dist,360-45)
		bottomright = self.getPointFromDist(self.parent.currentLocation,dist,135) #returns (lat,lon)
		
		extent.minx = min(topleft[1],bottomright[1])
		extent.miny = min(topleft[0],bottomright[0])
		extent.maxx = max(topleft[1],bottomright[1]) 
		extent.maxy = max(topleft[0],bottomright[0])
		#so it works for any quadrant
		
		self.map.setExtent(extent.minx, extent.miny, 
		               extent.maxx, extent.maxy)
		if debug: print "map extent:",self.map.extent
Exemplo n.º 48
0
	def fast_position_poly_label(self, shape, node, ghost_x, ghost_y, x_scale, y_scale, min_label_x, max_label_x, label_geo_w, label_geo_h):
		x_buffer = self.label_buffer * x_scale
		y_buffer = self.label_buffer * y_scale

		label_geo_bbox = (ghost_x - label_geo_w, ghost_y - label_geo_h,
				ghost_x + label_geo_w + x_buffer, ghost_y + label_geo_h + y_buffer) 

		label_shape = mapscript.rectObj(*label_geo_bbox).toPolygon()
		if(not shape.contains(label_shape)):
			return None

		if(node.label_geoms != None):
			if(label_shape.intersects(node.label_geoms)):
				return None

		return label_geo_bbox, label_shape
Exemplo n.º 49
0
    def _get_map(self):
        """
        Generate a mapserver mapObj.
        """
        # create a mapscript map from scratch
        map = mapscript.mapObj()
        # Configure the map
        # NAME
        map.name = "BCCVLMap"
        # EXTENT ... in projection units (we use epsg:4326) WGS84
        map.extent = mapscript.rectObj(-180.0, -90.0, 180.0, 90.0)

        # UNITS ... in projection units
        map.units = mapscript.MS_DD
        # SIZE
        map.setSize(256, 256)
        # PROJECTION ... WGS84
        map.setProjection("init=epsg:4326")

        # TRANSPARENT ON
        map.transparent = mapscript.MS_ON

        # metadata: wfs_feature_info_mime_type text/htm/ application/json
        # WEB
        # TODO: check return value of setMetaData MS_SUCCESS/MS_FAILURE
        map.setMetaData("wfs_enable_request", "*")
        map.setMetaData("wfs_title", "BCCVL WFS Server")
        map.setMetaData(
            "wfs_srs",
            "EPSG:4326 EPSG:3857")  # allow reprojection to Web Mercator
        map.setMetaData("ows_enable_request",
                        "*")  # wfs_enable_request enough?
        onlineresource = urlparse.urlunsplit(
            (self.request.scheme, "{}:{}".format(self.request.host,
                                                 self.request.host_port),
             self.request.path,
             urllib.urlencode(
                 (('DATA_URL', self.request.params.get('DATA_URL')), )), ""))
        map.setMetaData("wfs_onlineresource", onlineresource)
        # TODO: metadata
        #       title, author, xmp_dc_title
        #       wfs_onlineresource ... help to generate GetCapabilities request
        #       ows_http_max_age ... WFS client caching hints http://www.mnot.net/cache_docs/#CACHE-CONTROL
        #       ows_lsd_enabled ... if false ignore SLD and SLD_BODY
        #       wfs_attribution_xxx ... do we want attribution metadata?

        return map
Exemplo n.º 50
0
    def _get_map(self):
        """
        Generate a mapserver mapObj.
        """
        # create a mapscript map from scratch
        map = mapscript.mapObj()
        # Configure the map
        # NAME
        map.name = "BCCVLMap"
        # EXTENT ... in projection units (we use epsg:4326) WGS84
        map.extent = mapscript.rectObj(-180.0, -90.0, 180.0, 90.0)

        # UNITS ... in projection units
        map.units = mapscript.MS_DD
        # SIZE
        map.setSize(256, 256)
        # PROJECTION ... WGS84
        map.setProjection("init=epsg:4326")

        # TRANSPARENT ON
        map.transparent = mapscript.MS_ON

        # metadata: wfs_feature_info_mime_type text/htm/ application/json
        # WEB
        # TODO: check return value of setMetaData MS_SUCCESS/MS_FAILURE
        map.setMetaData("wfs_enable_request", "*")
        map.setMetaData("wfs_title", "BCCVL WFS Server")
        map.setMetaData("wfs_srs", "EPSG:4326 EPSG:3857")  # allow reprojection to Web Mercator
        map.setMetaData("ows_enable_request", "*")  # wfs_enable_request enough?
        onlineresource = urlparse.urlunsplit(
            (
                self.request.scheme,
                "{}:{}".format(self.request.host, self.request.host_port),
                self.request.path,
                urllib.urlencode((("DATA_URL", self.request.params.get("DATA_URL")),)),
                "",
            )
        )
        map.setMetaData("wfs_onlineresource", onlineresource)
        # TODO: metadata
        #       title, author, xmp_dc_title
        #       wfs_onlineresource ... help to generate GetCapabilities request
        #       ows_http_max_age ... WFS client caching hints http://www.mnot.net/cache_docs/#CACHE-CONTROL
        #       ows_lsd_enabled ... if false ignore SLD and SLD_BODY
        #       wfs_attribution_xxx ... do we want attribution metadata?

        return map
Exemplo n.º 51
0
    def fast_position_poly_label(self, shape, node, ghost_x, ghost_y, x_scale,
                                 y_scale, min_label_x, max_label_x,
                                 label_geo_w, label_geo_h):
        x_buffer = self.label_buffer * x_scale
        y_buffer = self.label_buffer * y_scale

        label_geo_bbox = (ghost_x - label_geo_w, ghost_y - label_geo_h,
                          ghost_x + label_geo_w + x_buffer,
                          ghost_y + label_geo_h + y_buffer)

        label_shape = mapscript.rectObj(*label_geo_bbox).toPolygon()
        if (not shape.contains(label_shape)):
            return None

        if (node.label_geoms != None):
            if (label_shape.intersects(node.label_geoms)):
                return None

        return label_geo_bbox, label_shape
Exemplo n.º 52
0
    def get_layer_points_layer(self, layer, bbox_str, max_features):
        # print("Content-type: text/plain\n\n")

        points = []

        status = layer.open()
        bbox_arr = [float(x) for x in bbox_str.split(",")]
        rect = mapscript.rectObj(bbox_arr[0], bbox_arr[1], bbox_arr[2], bbox_arr[3])
        if layer.queryByRect(self.map, rect) == mapscript.MS_FAILURE:
            # print('queryByRect failed')
            return points

        # Query success and points found: create Points array from result
        results = layer.getResults()
        n_res = layer.getNumResults()

        # Return at most max_features by skipping points in the array
        skip_count = (n_res / max_features) + 1

        # print('QUERY OK: results=' + str(n_res) + ' skip_count=' + str(skip_count))
        for j in range(n_res):
            # Skip when remainder not 0
            if j % skip_count:
                # print('skip j=' + str(j))
                continue

            # print('do j=' + str(j))
            res = results.getResult(j)
            # print('res=' + str(res))

            # later version may use  resultsGetShape() ??
            # see: http://www.mail-archive.com/[email protected]/msg11286.html
            # shp = mapscript.shapeObj(mapscript.MS_SHAPE_NULL)
            # shp = layer.resultsGetShape(shp, res.shapeindex)
            shp = layer.getFeature(res.shapeindex, res.tileindex)

            shp_point = shp.get(0).get(0)
            point = Point((shp_point.y, shp_point.x))
            points.append(point)

        layer.close()
        return points
Exemplo n.º 53
0
 def _draw_extents_as_rectangle(self, msmap):
     #generate a new temporary layer and draw a polygon on it:
     new_layer = mapscript.layerObj()
     new_layer.name = 'temp'
     new_layer.type = mapscript.MS_LAYER_POLYGON
     new_layer.status = 1
     new_class = mapscript.classObj()
     
     #generate a new style object:
     new_style = mapscript.styleObj()
     c = mapscript.colorObj()
     c.red = 50 #218
     c.green = 50 #124
     c.blue = 50 #12
     new_style.outlinecolor = c
     new_style.width = 2
     li = msmap.insertLayer(new_layer)
     ci = msmap.getLayer(li).insertClass(new_class)
     si = msmap.getLayer(li).getClass(ci).insertStyle(new_style)
     box = mapscript.rectObj(self.west, self.south, self.east, self.north)
     new_layer.addFeature(box.toPolygon())
Exemplo n.º 54
0
 def _draw_extents_as_rectangle(self, msmap):
     #generate a new temporary layer and draw a polygon on it:
     new_layer = mapscript.layerObj()
     new_layer.name = 'temp'
     new_layer.type = mapscript.MS_LAYER_POLYGON
     new_layer.status = 1
     new_class = mapscript.classObj()
     
     #generate a new style object:
     new_style = mapscript.styleObj()
     c = mapscript.colorObj()
     c.red = 50 #218
     c.green = 50 #124
     c.blue = 50 #12
     new_style.outlinecolor = c
     new_style.width = 2
     li = msmap.insertLayer(new_layer)
     ci = msmap.getLayer(li).insertClass(new_class)
     si = msmap.getLayer(li).getClass(ci).insertStyle(new_style)
     box = mapscript.rectObj(self.west, self.south, self.east, self.north)
     new_layer.addFeature(box.toPolygon())
Exemplo n.º 55
0
    def setUp(self):
        # Inline feature layer
        self.ilayer = mapscript.layerObj()
        self.ilayer.type = mapscript.MS_LAYER_POLYGON
        self.ilayer.status = mapscript.MS_DEFAULT
        self.ilayer.connectiontype = mapscript.MS_INLINE

        cs = 'f7fcfd, e5f5f9, ccece6, 99d8c9, 66c2a4, 41ae76, 238b45, 006d2c, 00441b'
        colors = ['#' + h for h in cs.split(', ')]

        for i in range(9):
            # Make a class for feature
            ci = self.ilayer.insertClass(mapscript.classObj())
            co = self.ilayer.getClass(ci)
            si = co.insertStyle(mapscript.styleObj())
            so = co.getStyle(si)
            so.color.setHex(colors[i])
            li = co.addLabel(mapscript.labelObj())
            lbl = co.getLabel(li)
            lbl.color.setHex('#000000')
            lbl.outlinecolor.setHex('#FFFFFF')
            lbl.type = mapscript.MS_BITMAP
            lbl.size = mapscript.MS_SMALL

            # The shape to add is randomly generated
            xc = 4.0*(random() - 0.5)
            yc = 4.0*(random() - 0.5)
            r = mapscript.rectObj(xc-0.25, yc-0.25, xc+0.25, yc+0.25)
            s = r.toPolygon()

            # Classify
            s.classindex = i
            s.text = "F%d" % (i)

            # Add to inline feature layer
            self.ilayer.addFeature(s)
Exemplo n.º 56
0
    def get_latlon_extent(self):
        rect = mapscript.rectObj(*self.get_extent())
        res = rect.project(mapscript.projectionObj(self.get_proj4()),
                           mapscript.projectionObj('+init=epsg:4326'))

        return Extent(rect.minx, rect.miny, rect.maxx, rect.maxy)
Exemplo n.º 57
0
 def testShapeQueryNoResults(self):
     qrect = mapscript.rectObj(-101.0, 0.0, -100.0, 1.0)
     qshape = qrect.toPolygon()
     self.layer.queryByShape(self.map, qshape)
     assert self.layer.getNumResults() == 0