Exemplo n.º 1
0
 def wrapper(*args, **kwargs):
     point_cloud_id = kwargs.get("pointCloudId")
     point_cloud = PointCloudService.get(point_cloud_id)
     if point_cloud.task \
             and point_cloud.task.status not in ["FINISHED", "FAILED"]:
         logger.info("point cloud:{} is not in terminal state".format(
             point_cloud_id))
         abort(404, "Point cloud is currently being updated")
     return fn(*args, **kwargs)
Exemplo n.º 2
0
 def wrapper(*args, **kwargs):
     projectId = kwargs.get("projectId")
     proj = ProjectsService.get(projectId)
     if not proj:
         abort(404, "No project found")
     pointCloudId = kwargs.get("pointCloudId")
     point_cloud = PointCloudService.get(pointCloudId)
     if not point_cloud:
         abort(404, "No point cloud found!")
     if point_cloud.project_id != projectId:
         abort(404, "Point cloud not part of project")
     return fn(*args, **kwargs)
Exemplo n.º 3
0
def get_point_cloud_info(pointCloudId: int) -> dict:
    """
    Get info on las files
    :param pointCloudId: int
    :return: None
    """
    from geoapi.services.point_cloud import PointCloudService

    point_cloud = PointCloudService.get(pointCloudId)
    path_to_original_point_clouds = get_asset_path(
        point_cloud.path, PointCloudService.ORIGINAL_FILES_DIR)
    input_files = get_point_cloud_files(path_to_original_point_clouds)

    return [{'name': os.path.basename(f)} for f in input_files]
Exemplo n.º 4
0
 def get(self, projectId: int, pointCloudId: int):
     return PointCloudService.get(pointCloudId)
Exemplo n.º 5
0
def convert_to_potree(self, pointCloudId: int) -> None:
    """
    Use the potree converter to convert a LAS/LAZ file to potree format
    :param pointCloudId: int
    :return: None
    """
    from geoapi.models import Feature, FeatureAsset
    from geoapi.services.point_cloud import PointCloudService

    point_cloud = PointCloudService.get(pointCloudId)

    path_to_original_point_clouds = get_asset_path(
        point_cloud.path, PointCloudService.ORIGINAL_FILES_DIR)
    path_temp_processed_point_cloud_path = get_asset_path(
        point_cloud.path, PointCloudService.PROCESSED_DIR)

    input_files = [
        get_asset_path(path_to_original_point_clouds, file)
        for file in os.listdir(path_to_original_point_clouds)
        if pathlib.Path(file).suffix.lstrip('.').lower() in
        PointCloudService.LIDAR_FILE_EXTENSIONS
    ]

    outline = get_bounding_box_2d(input_files)

    command = [
        "PotreeConverter", "--verbose", "-i", path_to_original_point_clouds,
        "-o", path_temp_processed_point_cloud_path, "--overwrite",
        "--generate-page", "index"
    ]
    if point_cloud.conversion_parameters:
        command.extend(point_cloud.conversion_parameters.split())
    logger.info("Processing point cloud (#{}):  {}".format(
        pointCloudId, " ".join(command)))
    subprocess.run(command, check=True, capture_output=True, text=True)

    # Create preview viewer html (with no menu and now nsf logo)
    with open(
            os.path.join(path_temp_processed_point_cloud_path, "preview.html"),
            'w+') as preview:
        with open(
                os.path.join(path_temp_processed_point_cloud_path,
                             "index.html"), 'r') as viewer:
            content = viewer.read()
            content = re.sub(r"<div class=\"nsf_logo\"(.+?)</div>",
                             '',
                             content,
                             flags=re.DOTALL)
            content = content.replace("viewer.toggleSidebar()",
                                      "$('.potree_menu_toggle').hide()")
            preview.write(content)

    if point_cloud.feature_id:
        feature = point_cloud.feature
    else:
        feature = Feature()
        feature.project_id = point_cloud.project_id

        asset_uuid = uuid.uuid4()
        base_filepath = make_project_asset_dir(point_cloud.project_id)
        asset_path = os.path.join(base_filepath, str(asset_uuid))
        fa = FeatureAsset(uuid=asset_uuid,
                          asset_type="point_cloud",
                          path=get_asset_relative_path(asset_path),
                          feature=feature)
        feature.assets.append(fa)
        point_cloud.feature = feature

    feature.the_geom = from_shape(geometries.convert_3D_2D(outline), srid=4326)
    point_cloud.task.status = "FINISHED"
    point_cloud.task.description = ""

    point_cloud_asset_path = get_asset_path(feature.assets[0].path)
    shutil.rmtree(point_cloud_asset_path, ignore_errors=True)
    shutil.move(path_temp_processed_point_cloud_path, point_cloud_asset_path)

    try:
        db_session.add(point_cloud)
        db_session.add(feature)
        db_session.commit()
    except:
        db_session.rollback()
        raise