Пример #1
0
    def translate(msg):
        datafile = '/tmp/{}.json'.format(uuid.uuid4())

        data = {
            'height': msg.info.height,
            'width': msg.info.width,
            'resolution': msg.info.resolution,
            'origin_x': msg.info.origin.position.x,
            'origin_y': msg.info.origin.position.y,
            'data': msg.data
        }

        # Save the message data to be read by external translator.
        with open(datafile, 'w') as f:
            json.dump(data, f)

        # Run external translator.
        geotiffFilename = '/tmp/{}.tif'.format(uuid.uuid4())

        script_dir = catkin_find(project='qgis_ros', path='scripts', first_match_only=True)[0]
        rasterize_script = Path(script_dir) / 'msg_to_geotiff.py'

        subprocess.check_call([str(rasterize_script), datafile, geotiffFilename])

        # Return filename.
        return geotiffFilename
Пример #2
0
def find_resource(pkg, resource_name, filter_fn=None, rospack=None):
    """
    Warning: unstable API due to catkin.

    Locate the file named resource_name in package, optionally
    matching specified filter.  find_resource() will return a list of
    matches, but only for a given scope.  If the resource is found in
    the binary build directory, it will only return matches in that
    directory; it will not return matches from the ROS_PACKAGE_PATH as
    well in this case.

    :param filter: function that takes in a path argument and
        returns True if the it matches the desired resource, ``fn(str)``
    :param rospack: `rospkg.RosPack` instance to use
    :returns: lists of matching paths for resource within a given scope, ``[str]``
    :raises: :exc:`rospkg.ResourceNotFound` If package does not exist
    """

    # New resource-location policy in Fuerte, induced by the new catkin
    # build system:
    #   (1) Use catkin_find to find libexec and share locations, look
    #       recursively there.  If the resource is found, done.
    #       Else continue:
    #   (2) If ROS_PACKAGE_PATH is set, look recursively there.  If the
    #       resource is found, done.  Else raise
    #
    # NOTE: package *must* exist on ROS_PACKAGE_PATH no matter what

    if rospack is None:
        rospack = rospkg.RosPack()

    # lookup package as it *must* exist
    pkg_path = rospack.get_path(pkg)

    source_path_to_packages = rospack.get_custom_cache('source_path_to_packages', {})

    # if found in binary dir, start with that.  in any case, use matches
    # from ros_package_path
    matches = []
    search_paths = catkin_find(
        search_dirs=['libexec', 'share'], project=pkg, first_matching_workspace_only=True,
        source_path_to_packages=source_path_to_packages)

    # persist mapping of packages in rospack instance
    if source_path_to_packages:
        rospack.set_custom_cache('source_path_to_packages', source_path_to_packages)

    for search_path in search_paths:
        matches.extend(_find_resource(search_path, resource_name, filter_fn=filter_fn))

    matches.extend(_find_resource(pkg_path, resource_name, filter_fn=filter_fn))

    # Uniquify the results, in case we found the same file twice, while keeping order
    unique_matches = []
    for match in matches:
        if match not in unique_matches:
            unique_matches.append(match)
    return unique_matches
Пример #3
0
def find_resource(pkg, resource_name, filter_fn=None, rospack=None):
    """
    Warning: unstable API due to catkin.

    Locate the file named resource_name in package, optionally
    matching specified filter.  find_resource() will return a list of
    matches, but only for a given scope.  If the resource is found in
    the binary build directory, it will only return matches in that
    directory; it will not return matches from the ROS_PACKAGE_PATH as
    well in this case.
    
    :param filter: function that takes in a path argument and
        returns True if the it matches the desired resource, ``fn(str)``
    :param rospack: `rospkg.RosPack` instance to use
    :returns: lists of matching paths for resource within a given scope, ``[str]``
    :raises: :exc:`rospkg.ResourceNotFound` If package does not exist 
    """

    # New resource-location policy in Fuerte, induced by the new catkin 
    # build system:
    #   (1) Use catkin_find to find libexec and share locations, look
    #       recursively there.  If the resource is found, done.
    #       Else continue:
    #   (2) If ROS_PACKAGE_PATH is set, look recursively there.  If the
    #       resource is found, done.  Else raise
    #
    # NOTE: package *must* exist on ROS_PACKAGE_PATH no matter what

    if rospack is None:
        rospack = rospkg.RosPack()

    # lookup package as it *must* exist
    pkg_path = rospack.get_path(pkg)

    source_path_to_packages = rospack.get_custom_cache('source_path_to_packages', {})

    # if found in binary dir, start with that.  in any case, use matches
    # from ros_package_path
    matches = []
    search_paths = catkin_find(
        search_dirs=['libexec', 'share'], project=pkg, first_matching_workspace_only=True,
        source_path_to_packages=source_path_to_packages)

    # persist mapping of packages in rospack instance
    if source_path_to_packages:
        rospack.set_custom_cache('source_path_to_packages', source_path_to_packages)

    for search_path in search_paths:
        matches.extend(_find_resource(search_path, resource_name, filter_fn=filter_fn))

    matches.extend(_find_resource(pkg_path, resource_name, filter_fn=filter_fn))

    # Uniquify the results, in case we found the same file twice, while keeping order
    unique_matches = []
    for match in matches:
        if match not in unique_matches:
            unique_matches.append(match)
    return unique_matches
Пример #4
0
 def GetPackageBinaries(self, request, context):
     result = fms.PathList()
     binaries = []
     try:
         path = get_pkg_path(request.name)
         self._get_binaries(path, binaries)
         result.items.extend(binaries)
         # find binaries in catkin workspace
         from catkin.find_in_workspaces import find_in_workspaces as catkin_find
         search_paths = catkin_find(search_dirs=['libexec', 'share'],
                                    project=request.name,
                                    first_matching_workspace_only=True)
         for p in search_paths:
             self._get_binaries(p, binaries)
     except Exception:
         import traceback
         print(traceback.format_exc())
         pass
     return result
Пример #5
0
 def on_package_selected(self, package):
     self.binary_field.clear()
     if self.packages and package in self.packages:
         self.binary_field.setEnabled(True)
         path = self.packages[package]
         binaries = self._getBinaries(path).keys()
         try:
             # find binaries in catkin workspace
             from catkin.find_in_workspaces import find_in_workspaces as catkin_find
             search_paths = catkin_find(search_dirs=['libexec', 'share'], project=package, first_matching_workspace_only=True)
             for p in search_paths:
                 binaries += self._getBinaries(p).keys()
         except:
             pass
         binaries = list(set(binaries))
         binaries.sort()
         self.binary_field.addItems(binaries)
         self.package = package
         self.binary = self.binary_field.currentText()
Пример #6
0
 def on_package_selected(self, package):
   self.binary_field.clear()
   if self.packages and self.packages.has_key(package):
     self.binary_field.setEnabled(True)
     self.args_field.setEnabled(True)
     self.ns_field.setEnabled(True)
     self.name_field.setEnabled(True)
     path = self.packages[package]
     binaries = self._getBinaries(path).keys()
     try:
       # find binaries in catkin workspace
       from catkin.find_in_workspaces import find_in_workspaces as catkin_find
       search_paths = catkin_find(search_dirs=['libexec', 'share'], project=package, first_matching_workspace_only=True)
       for p in search_paths:
         binaries += self._getBinaries(p).keys()
     except:
       pass
     binaries.sort()
     self.binary_field.addItems(binaries)
     self.package = package
     root, ext = os.path.splitext(os.path.basename(self.binary_field.currentText()))
     self.name_field.setText(root)