class TestLayerBasic(myTestCase): def setUp(self): self.m = Map() self.m.scale = 1e-3 self.m.bbox = ((-3.0, -4.0), (2.0, 1.0)) def tearDown(self): self.m.close() def testcalc_cell_extents(self): layer = Layer(self.m, name="The Layer", filename="layer", layertype=LayerTypePoint, nlevels = 1) lbb = layer._bbox.todiscrete(layer.refpoint, layer.scale) self.assertEqual(lbb, Rec((-3000,-1000), (2000,4000))) self.assertEqual(layer.calc_cell_extents(1), lbb) self.assertEqual(layer.calc_cell_extents(2), Rec((-3000, -1000),(-500, 1500)))
def testLayerStyle(self): """Test layer style consistency""" try: for mapfile in self.mapimages: img = Image(os.path.join('.','images',mapfile)) m = Map(img) m.open('r') for layername in m.getLayerNames(): style = m.getLayerStyleByName(layername) style.verify(layername, m) m.close() finally: img.__del__()
def testSimple(self): refmap = Map(MapDirectory('./layerdata8')) refmap.open('r') reflayer = refmap.getLayerByName('00_Trails_4WD') reflayer.open('r') map = Map(MapDirectory(self.testdatadir.dir), maptype=MapTypeImage) map.open("w") map.bbox = ((-18.04, 28.4), (-17.7, 28.89)) map.bbox = refmap.bbox ## Add trails layer trails = Layer(map, name="00_Trails", filename="00trails", layertype=LayerTypePolyline) trails.open(mode='w') trailstyle = DetailMapLayerStyle() trailstyle.style = 'TRAIL_LINE' map.addLayer(trails, layerstyle = trailstyle) trailwkt = 'LINESTRING (-17.768953959275908 28.775591075650038,-17.768678531255482 28.7757692937809,-17.768346397466143 28.775890806142854,-17.767981860380281 28.775923209439377,-17.767779339777025 28.775923209439377,-17.767212282087907 28.775874604494597,-17.766669526871183 28.775777394605033,-17.766151074126846 28.775647781418947,-17.765438201603384 28.775388555046781,-17.764879244738399 28.775145530322874,-17.764514707652538 28.774943009719617,-17.764239279632111 28.77467568252332,-17.763040357660834 28.774238238020288,-17.762813534585188 28.774189633075505,-17.762513804092368 28.774222036372027,-17.762513804092368 28.774222036372027)' trail = CellElementPolyline(trails, wkt=trailwkt, objtype=11) cellelementrefs = trails.addCellElement(trail) print "cellelementrefs", cellelementrefs ## Add group roadsgroup = map.getGroupByName('00_Roads') roadsgroup.addLayer(trails) feature = FeatureNormal(name="Apstigen", layerindex=map.getLayerIndex(trails), objtype=29, cellelementreflist=cellelementrefs) roadsgroup.addFeature(feature) ## Add topo map.addTopo('layerdata8/00t0.blx') # map.mapdir.copyfile('layerdata8/topo3d.ini') map.close() map.writeImage('trails.imi') self.assertTrue('00map.ini' in os.listdir(self.testdatadir.dir)) files = os.listdir(self.testdatadir.dir) expectedfiles = Set(('bmp2bit.ics', 'bmp4bit.ics', '00map.ini', 'add_maps.cfg', 'db00.dbd' , '00trails.lay', '00trails.clt', 'gr0.ext', 'gr0.clp', 'gr0.aux', 'gr1.ext', 'gr1.clp', 'gr1.aux', 'gr2.ext', 'gr2.clp', 'gr2.aux', 'gr3.ext', 'gr3.clp', 'gr3.aux', '00z.dat', '00cn.dat', '00t0.blx', 'topo3d.ini')) self.assertEqual(expectedfiles, Set(files)) expectedinitfile = "" inifile = open(os.path.join(self.testdatadir.dir, '00map.ini')) print inifile.read() map = Map(MapDirectory(self.testdatadir.dir)) map.open("r") roadsgroup = map.getGroupByName('00_Roads') roadsgroup.open('r') print "features: ", list(roadsgroup.getFeatures()) trails = map.getLayerByName('00_Trails') trails.open('r') trails.check() print trails.cellnumbers
def setUp(self): self.m = Map() self.m.scale = 1e-3 self.m.bbox = ((-3.0, -4.0), (2.0, 1.0))
def createMapFromBLX(mapdir, blxfile): north, south, east, west = getBBox(blxfile) m = Map(mapdir) m.open('w') m.bbox = ((west, south), (east,north)) ## Add dummy layer trails = Layer(m, name="00_dummy", filename="00dummy", layertype=LayerTypePolyline) trails.open(mode='w') trailstyle = DetailMapLayerStyle() m.addLayer(trails, layerstyle = trailstyle) roadsgroup = m.getGroupByName('00_Roads') roadsgroup.addLayer(trails) m.addTopo(blxfile) m.close() mapdir.write()
#!/usr/bin/env python import sys from glob import glob import osgeo.ogr as ogr import os from sets import Set from magellan.Map import Map import magellan.OGRInterface as OGRInterface import magellan.mapdir as mapdir outpath = sys.argv[2] if os.path.isfile(sys.argv[1]): map = Map(mapdir.Image(sys.argv[1])) elif os.path.isdir(sys.argv[1]): map = Map(mapdir.MapDirectory(sys.argv[1])) else: raise Exception("Cannot open " + sys.argv[1]) map.debug=False map.open() driver=ogr.GetDriverByName('ESRI Shapefile') ds=driver.CreateDataSource(outpath) pge = OGRInterface.OGRExporter(map) layers = list(map.layers) for group in map.groups: group.open('r')