Beispiel #1
0
    def setUp(self):
        '''Build an sdf file from a known set of data'''
        osmDict = {}
        osmDict = getOsmFile([-75.93, 40.61, -75.90, 40.62], 'map.osm')
        osmRoads = Osm2Dict(-75.93, 40.61, osmDict)
        (roadPointWidthMap,
         modelPoseMap,
         buildingLocationMap) = osmRoads.getMapDetails()

        #Initialize the getSdf class
        sdfFile = GetSDF()

        #Set up the spherical coordinates
        sdfFile.addSphericalCoords(osmRoads.getLat(), osmRoads.getLon())

        #add Required models
        sdfFile.includeModel("sun")

        for model in modelPoseMap.keys():
            points = modelPoseMap[model]['points']
            sdfFile.addModel(modelPoseMap[model]['mainModel'],
                             model,
                             [points[0, 0], points[1, 0], points[2, 0]])

        for building in buildingLocationMap.keys():
            sdfFile.addBuilding(buildingLocationMap[building]['mean'],
                                buildingLocationMap[building]['points'],
                                building,
                                buildingLocationMap[building]['color'])

        #Include the roads in the map in sdf file
        for road in roadPointWidthMap.keys():
            sdfFile.addRoad(road)
            sdfFile.setRoadWidth(roadPointWidthMap[road]['width'], road)
            points = roadPointWidthMap[road]['points']
            for point in range(len(points[0, :])):
                sdfFile.addRoadPoint([points[0, point],
                                      points[1, point],
                                      points[2, point]],
                                     road)
        #output sdf File
        sdfFile.writeToFile('outFile.sdf')
Beispiel #2
0
    def setUp(self):
        '''Build an sdf file from a known set of data'''
        osmDict = {}
        osmDict = getOsmFile([-75.93, 40.61, -75.90, 40.62], 'map.osm')
        osmRoads = Osm2Dict(-75.93, 40.61, osmDict)
        (roadPointWidthMap, modelPoseMap,
         buildingLocationMap) = osmRoads.getMapDetails()

        #Initialize the getSdf class
        sdfFile = GetSDF()

        #Set up the spherical coordinates
        sdfFile.addSphericalCoords([-75.93, 40.61, -75.90, 40.62])

        #add Required models
        sdfFile.includeModel("sun")

        for model in modelPoseMap.keys():
            points = modelPoseMap[model]['points']
            sdfFile.addModel(modelPoseMap[model]['mainModel'], model,
                             [points[0, 0], points[1, 0], points[2, 0]])

        for building in buildingLocationMap.keys():
            sdfFile.addBuilding(buildingLocationMap[building]['mean'],
                                buildingLocationMap[building]['points'],
                                building,
                                buildingLocationMap[building]['color'])

        #Include the roads in the map in sdf file
        for road in roadPointWidthMap.keys():
            sdfFile.addRoad(road)
            sdfFile.setRoadWidth(roadPointWidthMap[road]['width'], road)
            points = roadPointWidthMap[road]['points']
            for point in range(len(points[0, :])):
                sdfFile.addRoadPoint(
                    [points[0, point], points[1, point], points[2, point]],
                    road)
        #output sdf File
        sdfFile.writeToFile('outFile.sdf')
Beispiel #3
0
    if option != 'N':
        args.imageFile = 'map.png'

if args.inputOsmFile:
    f = open(args.inputOsmFile, 'r')
    root = etree.fromstring(f.read())
    f.close()
    args.boundingbox = [float(root[0].get('minlon')),
                        float(root[0].get('minlat')),
                        float(root[0].get('maxlon')),
                        float(root[0].get('maxlat'))]
print (' _______________________________')
print ('|')
print ('| Downloading the osm data ... ')
osmDictionary = getOsmFile(args.boundingbox,
                           args.osmFile, args.inputOsmFile)

# if args.imageFile:
#     if TIMER:
#         tic()
#     print "Building the image file ..."
#     args.imageFile = args.directory + args.imageFile
#     getMapImage(args.osmFile, args.imageFile)
#     if TIMER:
#         toc()

#Initialize the class
osmRoads = Osm2Dict(args.boundingbox[0], args.boundingbox[1],
                    args.boundingbox[2], args.boundingbox[3],
                    osmDictionary, flags)
Beispiel #4
0
    if option != 'N':
        args.imageFile = 'map.png'

if args.inputOsmFile:
    f = open(args.inputOsmFile, 'rb')
    root = etree.fromstring(f.read())
    f.close()
    args.boundingbox = [float(root[0].get('minlon')),
                        float(root[0].get('minlat')),
                        float(root[0].get('maxlon')),
                        float(root[0].get('maxlat'))]
print (' _______________________________')
print ('|')
print ('| Downloading the osm data ... ')
osmDictionary = getOsmFile(args.boundingbox,
                           args.osmFile, args.inputOsmFile)

# if args.imageFile:
#     if TIMER:
#         tic()
#     print ("Building the image file ...")
#     args.imageFile = args.directory + args.imageFile
#     getMapImage(args.osmFile, args.imageFile)
#     if TIMER:
#         toc()

#Initialize the class
osmRoads = Osm2Dict(args.boundingbox[0], args.boundingbox[1],
                    args.boundingbox[2], args.boundingbox[3],
                    osmDictionary, flags)
Beispiel #5
0
 def testEmptyBox(self):
     '''test to check the output, if the bounding box is empty'''
     self.assertEqual(getOsmFile(self.boxEmpty,
                                 self.fileName), None)
     self.dataDict.clear()
Beispiel #6
0
 def testInputFile(self):
     '''tests to check the output, if a osm file is directly given'''
     self.assertNotEqual(getOsmFile(self.boxEmpty,
                                    self.emptyFileName,
                                    self.fileName), None)
     self.dataDict.clear()
Beispiel #7
0
 def testInputFile(self):
     '''tests to check the output, if a osm file is directly given'''
     self.assertNotEqual(
         getOsmFile(self.boxEmpty, self.emptyFileName, self.fileName), None)
     self.dataDict.clear()
Beispiel #8
0
 def testBox(self):
     '''test to check if the function works for a correct bounding box '''
     self.assertNotEqual(getOsmFile(self.boxValid,
                                    self.fileName), {})
     self.dataDict.clear()
Beispiel #9
0
 def testEmptyBox(self):
     '''test to check the output, if the bounding box is empty'''
     self.assertEqual(getOsmFile(self.boxEmpty, self.fileName), None)
     self.dataDict.clear()
Beispiel #10
0
 def testBox(self):
     '''test to check if the function works for a correct bounding box '''
     self.assertNotEqual(getOsmFile(self.boxValid, self.fileName), {})
     self.dataDict.clear()
Beispiel #11
0
    def parse_osm_(self):
        if not self.args:
            self.parse_args_()

        flags = []
        if self.args.buildings:
            flags.append('b')
        if self.args.models:
            flags.append('m')
        if self.args.roads:
            flags.append('r')
        if not (self.args.roads or self.args.models
                or self.args.buildings) or self.args.displayAll:
            flags.append('a')

        if not os.path.exists(self.args.directory):
            os.makedirs(self.args.directory)

        self.args.osmFile = self.args.directory + '/' + self.args.osmFile
        self.args.outFile = self.args.directory + '/' + self.args.outFile

        osmDictionary = {}

        if self.args.inputOsmFile:
            f = open(self.args.inputOsmFile, 'r')
            root = etree.fromstring(f.read())
            f.close()
            self.args.boundingbox = [
                root[0].get('minlon'), root[0].get('minlat'),
                root[0].get('maxlon'), root[0].get('maxlat')
            ]

        else:
            if not self.arg.boundingbox:
                print("Can not get osm file from server without bounding box")
                sys.exit("No bounding box for target area")

            print("Downloading the osm data ... ")

        osmDictionary = getOsmFile(self.args.boundingbox, self.args.osmFile,
                                   self.args.inputOsmFile)

        #Initialize Osm Dictionary class
        osmRoads = Osm2Dict(self.args.boundingbox[0], self.args.boundingbox[1],
                            osmDictionary, flags)

        print("Extracting the map data for gazebo ...")
        #Get Road and model details
        roadPointWidthMap, modelPoseMap, buildingLocationMap = osmRoads.getMapDetails(
        )

        print("Building sdf file ...")
        #Initialize the getSdf class
        sdfFile = GetSDF()

        #Set up the spherical coordinates
        sdfFile.setOffset(self.args.boundingbox)
        sdfFile.addGroundPlane(self.args.boundingbox)
        sdfFile.addSphericalCoords(self.args.boundingbox)

        #Add Required models
        for model in modelPoseMap.keys():
            points = modelPoseMap[model]['points']
            sdfFile.addModel(modelPoseMap[model]['mainModel'], model,
                             [points[0, 0], points[1, 0], points[2, 0]])

        for building in buildingLocationMap.keys():

            sdfFile.addBuilding(buildingLocationMap[building]['mean'],
                                buildingLocationMap[building]['points'],
                                building,
                                buildingLocationMap[building]['color'])

        #Include the roads in the map in sdf file
        for road in roadPointWidthMap.keys():
            sdfFile.addRoad(road)
            sdfFile.setRoadWidth(roadPointWidthMap[road]['width'], road)
            points = roadPointWidthMap[road]['points']
            for point in range(len(points[0, :])):
                sdfFile.addRoadPoint(
                    [points[0, point], points[1, point], points[2, point]],
                    road)

        #Output sdf File
        sdfFile.writeToFile(self.args.outFile)
Beispiel #12
0
 def setUp(self):
     self.osmDict = {}
     self.osmDict = getOsmFile([-75.38, 40.606, -75.377, 40.609], 'map.osm')
     self.testClass = Osm2Dict(-75.93, 40.61, self.osmDict)
Beispiel #13
0
 def setUp(self):
     self.osmDict = {}
     self.osmDict = getOsmFile([-75.38, 40.606, -75.377, 40.609], 'map.osm')
     self.testClass = Osm2Dict(-75.93, 40.61, self.osmDict)