示例#1
0
    def testOpenForAppend(self):
        ## Open for read-only and read features
        map = createMap(self.testdatadir)
        map.open()

        roads = map.getGroupByName("00_Roads")

        roads.open('r')

        reffeatures = [roads.getFeatureByIndex(i) for i in range(0, roads.getFeatureCount())]

        map.close()
        del map

        ## Open for append
        map = createMap(self.testdatadir)
        map.open('a')
        roads = map.getGroupByName("00_Roads")
        roads.open('a')
        map.close()
        del map

        ## Open for read-only again to see if the features are still there
        map = createMap(self.testdatadir)
        map.open()

        roads = map.getGroupByName("00_Roads")

        roads.open('r')

        features = [roads.getFeatureByIndex(i) for i in range(0, roads.getFeatureCount())]

        self.assertEqual(len(features), len(reffeatures))
                
        self.assertEqual(features, reffeatures)
示例#2
0
    def testAppendStreetGrow(self):
        map = createMap(self.testdatadir)
        map.open(mode="a")

        streets, group = map.getLayerAndGroupByName("00_Streets")
        streets.open("a")

        # Add a new street
        newstreet = CellElementPolyline(((16.175, 58.5901), (16.176, 58.5905)), objtype=2)

        newbbox = newstreet.bboxrec.union(streets.bboxrec)
        newbbox = newbbox.buffer(streets.scale)
        
        streets.bboxrec = newbbox

        actual = Set([ce for ce in streets.getCellElements()])
        expected = actual.copy()
        
        newstreet.discretizeGeometry(streets.getCell(1))
#        streets.addCellElement(newstreet)
#        expected.add(newstreet)

        actual = Set([ce for ce in streets.getCellElements()])

        # Test if the new streets exists in the layer object
        self.assertEqual(actual, expected)
        
        # Test if the new street was written to file
        streets.close()
        del streets
        del map

        map = createMap(self.testdatadir)
        map.open(mode="a")

        streets, group = map.getLayerAndGroupByName("00_Streets")
        streets.open("r")

#        actual = Set([ce.serialize(cell) for ce in streets.getCellElements()])
#        expected = Set([ce.serialize(cell) for ce in expected])
        actual = Set([ce for ce in streets.getCellElements()])

        self.assertEqual(len(actual), len(expected))

        if actual != expected:
            print "difference:",actual.symmetric_difference(expected)
            print "actual: ",actual
            print "expected: ",expected

        
        self.assertEqual(actual, expected, "Cell elements don't match after read back")
示例#3
0
    def testAppendStreet(self):
        map = createMap(self.testdatadir)
        map.open(mode="a")

        streets, group = map.getLayerAndGroupByName("00_Streets")
        streets.open("a")

        actual = Set([ce for ce in streets.getCellElements()])
        expected = actual.copy()
        
        # Add a new street
        newstreet = CellElementPolyline(((16.185, 58.5912), (16.186, 58.5915)), objtype=2)
        newstreet.discretizeGeometry(streets.getCell(1))
        streets.addCellElement(newstreet)
        expected.add(newstreet)

        actual = Set([ce for ce in streets.getCellElements()])

        # Test if the new streets exists in the layer object
        self.assertEqual(actual, expected)
        
        # Test if the new street was written to file
        streets.close()
        del streets
        del map

        map = createMap(self.testdatadir)
        map.open()

        streets, group = map.getLayerAndGroupByName("00_Streets")
        streets.open("r")

#        actual = Set([ce.serialize(cell) for ce in streets.getCellElements()])
#        expected = Set([ce.serialize(cell) for ce in expected])
        actual = Set([ce for ce in streets.getCellElements()])
        expected = Set([ce for ce in expected])

        self.assertEqual(len(actual), len(expected))

        if actual != expected:
            for m in actual:
                if m.objtype == 2:
                    print streets.scale[0]
                    print m
                    print newstreet
                    print m==newstreet
        
        self.assertEqual(actual, expected, "Cell elements don't match after read back")
示例#4
0
    def testAddGroup(self):
        map = createMap(self.testdatadir)
        map.open(mode='a')
        map.bigendian = True

        trailgroup = GroupNormal(map, name="00_Trails")

        map.addGroup(trailgroup)

        trailgroup.open("w")

        # Add trail layer and feature to new group
        trails = Layer(map,
                       name="00_Trails",
                       filename="00trails",
                       layertype=LayerTypePolyline)
        trails.open(mode='w')
        map.addLayer(trails)

        trails.setXScale(1e-5)
        trails.setYScale(1e-5)

        trailgroup.addLayer(trails)

        newtrailwkt = "LINESTRING (16.185 58.5912, 16.186 58.5915)"
        newtrail = CellElementPolyline(trails, wkt=newtrailwkt)
        newtrail.discretizeGeometry(trails.getCell(1))
        cellelementrefs = trails.addCellElement(newtrail)
        feature = FeatureNormal(name="Apgatan",
                                layerindex=map.getLayerIndex(trails),
                                objtype=29,
                                cellelementreflist=cellelementrefs)
        trailgroup.addFeature(feature)

        map.writeImage('trails.img')

        map.close()

        os.system("cat " + os.path.join(self.testdatadir, "00map.ini"))

        map = createMap(self.testdatadir)
        map.open('r')

        trailgroup = map.getGroupByName("00_Trails")

        trailgroup.open()

        print "Trails", trails
示例#5
0
    def testAddPointLayer(self):

        points = Layer(self.map, name="Points", filename="points", layertype=LayerTypePoint)
        points.open(mode='w')
        self.map.addLayer(points)

        # Add a new point
        newpoint = CellElementPoint((16.185, 58.5912), objtype=10)
        newpoint.discretizeGeometry(points.getCell(1))
        points.addCellElement(newpoint)

        self.map.close()

        map = createMap(self.testdatadir)
        map.open()

        points, group = map.getLayerAndGroupByName("Points")

        points.open('r')

        actual = Set(points.getCellElements())

        expected = Set([newpoint])
        
        self.assertSetsEqual(actual, expected)
示例#6
0
 def setUp(self):
     self.tempdir = TempDir()
     self.testdatadir = str(self.tempdir)
     self.map = createMap(self.testdatadir)
     self.map.open(mode="w")
     self.map.bbox = ((16.179984999999999, 58.591113999999997), (16.186159, 58.596420000000002))
     self.map.scale = N.array([1e-5, 1e-5])
示例#7
0
    def testAddGroup(self):
        map = createMap(self.testdatadir)
        map.open(mode='a')
        map.bigendian = True

        trailgroup = GroupNormal(map, name="00_Trails")

        map.addGroup(trailgroup)

        trailgroup.open("w")

        # Add trail layer and feature to new group
        trails = Layer(map, name="00_Trails", filename="00trails", layertype=LayerTypePolyline)
        trails.open(mode='w')
        map.addLayer(trails)

        trails.setXScale(1e-5)
        trails.setYScale(1e-5)

        trailgroup.addLayer(trails)
        
        newtrailwkt = "LINESTRING (16.185 58.5912, 16.186 58.5915)"
        newtrail = CellElementPolyline(trails, wkt=newtrailwkt)
        newtrail.discretizeGeometry(trails.getCell(1))
        cellelementrefs = trails.addCellElement(newtrail)
        feature = FeatureNormal(name="Apgatan", layerindex=map.getLayerIndex(trails),
                                objtype=29,
                                cellelementreflist=cellelementrefs)
        trailgroup.addFeature(feature)

        map.writeImage('trails.img')
        
        map.close()

        os.system("cat " +os.path.join(self.testdatadir, "00map.ini"))

        map = createMap(self.testdatadir)
        map.open('r')

        trailgroup = map.getGroupByName("00_Trails")

        trailgroup.open()
        
        print "Trails",trails
示例#8
0
    def testSimple(self):
        map = createMap(self.testdatadir)
        map.open()

        roads = map.getGroupByName("00_Roads")

        roads.open('r')

        for i in range(0, roads.getFeatureCount()):
            feature = roads.getFeatureByIndex(i)
示例#9
0
    def testSimple(self):
        map = createMap(self.testdatadir)
        map.open()

        roads = map.getGroupByName("00_Roads")

        roads.open('r')

        for i in range(0, roads.getFeatureCount()):
            feature = roads.getFeatureByIndex(i)
示例#10
0
    def testAppendPolygon(self):
        map = createMap(self.testdatadir)
        map.open(mode="a")

        parks, group = map.getLayerAndGroupByName("00_Parks")
        parks.open("a")

        # Add a new park
        park = (((16.1837837893217511,58.5911206585042237),(16.1834987729198474,58.5916966585245973),(16.1834275188193715,58.5918046585284173),(16.1833562647188955,58.5918586585303274),(16.1843538221255585,58.5919486585335108),(16.1843894491757965,58.5911746585061337),(16.1844963303265104,58.5911206585042237),(16.1837837893217511,58.5911206585042237)),)
        newpark = CellElementArea(park, objtype=13)

        newbbox = newpark.bboxrec.union(parks.bboxrec)
        newbbox = newbbox.buffer(parks.scale)
        
#        parks.setBBoxRec(newbbox)

        actual = Set([ce for ce in parks.getCellElements()])
        expected = actual.copy()
        
        newpark.discretizeGeometry(parks.getCell(1))
        parks.addCellElement(newpark)
        expected.add(newpark)

        actual = Set([ce for ce in parks.getCellElements()])

        # Test if the new parks exists in the layer object
        self.assertEqual(actual, expected)
        
        # Test if the new street was written to file
        parks.close()
        del parks
        del map

        map = createMap(self.testdatadir)
        map.open(mode="a")

        parks, group = map.getLayerAndGroupByName("00_Parks")
        parks.open("r")

#        actual = Set([ce.serialize(cell) for ce in parks.getCellElements()])
#        expected = Set([ce.serialize(cell) for ce in expected])
        actual = Set([ce for ce in parks.getCellElements()])
示例#11
0
    def testOpenForAppend(self):
        ## Open for read-only and read features
        map = createMap(self.testdatadir)
        map.open()

        roads = map.getGroupByName("00_Roads")

        roads.open('r')

        reffeatures = [
            roads.getFeatureByIndex(i)
            for i in range(0, roads.getFeatureCount())
        ]

        map.close()
        del map

        ## Open for append
        map = createMap(self.testdatadir)
        map.open('a')
        roads = map.getGroupByName("00_Roads")
        roads.open('a')
        map.close()
        del map

        ## Open for read-only again to see if the features are still there
        map = createMap(self.testdatadir)
        map.open()

        roads = map.getGroupByName("00_Roads")

        roads.open('r')

        features = [
            roads.getFeatureByIndex(i)
            for i in range(0, roads.getFeatureCount())
        ]

        self.assertEqual(len(features), len(reffeatures))

        self.assertEqual(features, reffeatures)
示例#12
0
    def testOpenForAppend(self):
        map = createMap(self.testdatadir)
        map.open(mode="a")
        map.close()
        map.writeImage('test8.imi')
        print map.getLayerNames()
        freeways = map.getLayerByName('00_Edificio')
        freeways.open('r')

        print freeways.nlevels
        print freeways.cellnumbers

        print repr(freeways)
示例#13
0
    def testAppendNonePolyline(self):
        map = createMap(self.testdatadir)
        map.open(mode="a")

        streets,group = map.getLayerAndGroupByName("00_Streets")
        streets.open("a")
        expected = Set([ce for ce in streets.getCellElements()])
        streets.markCellModified(1)
        streets.close()
        del streets

        map = createMap(self.testdatadir)
        map.open()

        streets, group = map.getLayerAndGroupByName("00_Streets")
        streets.open("r")

        actual = Set([ce for ce in streets.getCellElements()])

        self.assertEqual(len(actual), len(expected))
        
        self.assertEqual(actual, expected)
示例#14
0
    def testAppendNoneArea(self):
        map = createMap(self.testdatadir)
        map.open(mode="a")

        parks, group = map.getLayerAndGroupByName("00_Parks")
        parks.open("a")
        expected = Set([ce for ce in parks.getCellElements()])
        parks.markCellModified(1)
        parks.close()
        del parks

        map = createMap(self.testdatadir)
        map.open()

        parks, group = map.getLayerAndGroupByName("00_Parks")
        parks.open("r")

        actual = Set([ce for ce in parks.getCellElements()])

        self.assertEqual(len(actual), len(expected))
        
        self.assertEqual(actual, expected)
示例#15
0
    def testSimple(self):
        map = createMap(self.testdatadir)
        map.open("a")

        streets,group = map.getLayerAndGroupByName("00_Streets")
        streets.open("a")

        expected = Set([CellElementPolyline(((16.1757486998903914, 58.5899908940009482), (16.1770312736989581, 58.5901528940066783), (16.1780288311056211, 58.5902788940111350)), objtype=3),
                        CellElementPolyline(((16.1770312736989581, 58.5901528940066783), (16.1766037490961025, 58.5908908940327819), (16.1764612408951507, 58.5911788940429688)), objtype=3),
                        CellElementPolyline(((16.1749649047851562, 58.5906388940238685), (16.1766037490961025, 58.5908908940327819), (16.1779575770051451, 58.5910528940385120)), objtype=3)])

        cell = streets.getCell(1)
        actual = Set([ce for ce in streets.getCellElements()])
        
        self.assertEqual(actual, expected)
示例#16
0
    def testAddPolylineLayer(self):
        trails = Layer(self.map, name="Trails", filename="trails", layertype=LayerTypePolyline)
        trails.open(mode='w')
        self.map.addLayer(trails)

        # Add a new trail
        newtrail = CellElementPolyline(((16.185, 58.5912), (16.186, 58.5915)), objtype=0)
        newtrail.discretizeGeometry(trails.getCell(1))
        trails.addCellElement(newtrail)

        self.map.close()

        map = createMap(self.testdatadir)
        map.open()

        trails, group = map.getLayerAndGroupByName("Trails")

        trails.open('r')

        actual = Set(trails.getCellElements())

        expected = Set([newtrail])
        
        self.assertSetsEqual(actual, expected)
示例#17
0
    def testAddFeature(self):
        map = createMap(self.testdatadir)
        map.open(mode='a')

        roads = map.getGroupByName("00_Roads")

        roads.open('a')

        streets, streetsgroup = map.getLayerAndGroupByName("00_Streets")

        nfeatures=roads.getFeatureCount()
        self.assertEqual(roads.getFeatureCount(), 29)
        
        newstreetwkt = "LINESTRING (16.185 58.5912, 16.186 58.5915)"
        newstreet = CellElementPolyline(streets, wkt=newstreetwkt)
        newstreet.discretizeGeometry(streets.getCell(1))
        cellelementrefs = streets.addCellElement(newstreet)

        feature = FeatureStreet(name="Apgatan",
                                layerindex=map.getLayerIndex(streets),
                                objtype=29,
                                cellelementreflist=cellelementrefs)

        roads.addFeature(feature)

        # Check that the # of features increased
        self.assertEqual(roads.getFeatureCount(), nfeatures+1)

        found=False
        for i in range(0, roads.getFeatureCount()):
            tmpfeature = roads.getFeatureByIndex(i)
            if tmpfeature == feature:
                print feature
                found = True
        self.assertTrue(found, "New feature not found")        

        names = [roads.getFeatureByIndex(i).name for i in range(0, roads.getFeatureCount())]

        self.assertTrue(areSorted(names), "Features are not sorted")

        print roads.layers

        # Re-open map and verify that the new feature is present
        map.close()
        del map
        del streets
        
        map = createMap(self.testdatadir)
        map.open()
        roads = map.getGroupByName("00_Roads")

        print roads.layers

        roads.open('r')

        found = False
        for i in range(0, roads.getFeatureCount()):
            tmpfeature = roads.getFeatureByIndex(i)
            print tmpfeature
            if tmpfeature.name == feature.name:
                streets, streetsgroup = map.getLayerAndGroupByName("00_Streets")
                if tmpfeature == feature:
                    found = True

        # Check that the # of features increased
        self.assertEqual(roads.getFeatureCount(), nfeatures+1)

        self.assertTrue(found, "New feature not found after re-opening the map")        
        names = [roads.getFeatureByIndex(i).name for i in range(0, roads.getFeatureCount())]
        self.assertTrue(areSorted(names), "Features are not sorted")
示例#18
0
    def testAddFeature(self):
        map = createMap(self.testdatadir)
        map.open(mode='a')

        roads = map.getGroupByName("00_Roads")

        roads.open('a')

        streets, streetsgroup = map.getLayerAndGroupByName("00_Streets")

        nfeatures = roads.getFeatureCount()
        self.assertEqual(roads.getFeatureCount(), 29)

        newstreetwkt = "LINESTRING (16.185 58.5912, 16.186 58.5915)"
        newstreet = CellElementPolyline(streets, wkt=newstreetwkt)
        newstreet.discretizeGeometry(streets.getCell(1))
        cellelementrefs = streets.addCellElement(newstreet)

        feature = FeatureStreet(name="Apgatan",
                                layerindex=map.getLayerIndex(streets),
                                objtype=29,
                                cellelementreflist=cellelementrefs)

        roads.addFeature(feature)

        # Check that the # of features increased
        self.assertEqual(roads.getFeatureCount(), nfeatures + 1)

        found = False
        for i in range(0, roads.getFeatureCount()):
            tmpfeature = roads.getFeatureByIndex(i)
            if tmpfeature == feature:
                print feature
                found = True
        self.assertTrue(found, "New feature not found")

        names = [
            roads.getFeatureByIndex(i).name
            for i in range(0, roads.getFeatureCount())
        ]

        self.assertTrue(areSorted(names), "Features are not sorted")

        print roads.layers

        # Re-open map and verify that the new feature is present
        map.close()
        del map
        del streets

        map = createMap(self.testdatadir)
        map.open()
        roads = map.getGroupByName("00_Roads")

        print roads.layers

        roads.open('r')

        found = False
        for i in range(0, roads.getFeatureCount()):
            tmpfeature = roads.getFeatureByIndex(i)
            print tmpfeature
            if tmpfeature.name == feature.name:
                streets, streetsgroup = map.getLayerAndGroupByName(
                    "00_Streets")
                if tmpfeature == feature:
                    found = True

        # Check that the # of features increased
        self.assertEqual(roads.getFeatureCount(), nfeatures + 1)

        self.assertTrue(found,
                        "New feature not found after re-opening the map")
        names = [
            roads.getFeatureByIndex(i).name
            for i in range(0, roads.getFeatureCount())
        ]
        self.assertTrue(areSorted(names), "Features are not sorted")