Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Kate_

Pages: [1]
1
Hello Kate,

I think that the program uses bilinear interpolation to calculate the altitud of each shape vertex. So it will use the 4 closests dem pixels to do it. So in example, I placed a line string inside one dem pixel. With DEM edit I set the 8 surrounding pixels plus central one to constant. Then vertices have all the same value...

Hope this makes sense,

Hello, Paulo!

Okay, I understand. (by the way, how did you change the height in DEM?)

In principle, my supervisor said the same thing -- bilinear interpolation, but I would like to have the ability to get the Z coordinate value in shape directly from DEM. Do you happen to know how this can be done?

2
I have a DEM with a 2cm/pixl resolution. When creating a shape within a single pixel, all points within that pixel should have the same elevation value. However, in reality, I am observing differences in elevation values within what should be a single unit of elevation. These elevation differences are also visible in the shape profile.


1. What could be causing these differences in elevation within a single DEM pixel?

2. How can we extract elevation data directly from a DEM without inconsistencies? Unfortunately, updating the altitudes doesn't solve the problem. We also get different elevation values in our shapes (the updated elevation values are NOT shown in the attachment images).

MS 2.2.0 Linux deb.

3
Hello!

1  On computer #1, I created a document using the API of Python to load photos into it.
2. The document is saved on computer #2, where the Metashape server and working node are deployed
3. An AlignPhoto() NetworkTask is sent to the server specifying the path to the project

Error Details:
Code: [Select]
2025-04-22 14:04:51 Matching photos...
2025-04-22 14:04:51 Error: Can't create directory: Permission denied (13): /path/to/project/20250422_1404.files/0/0/point_cloud
2025-04-22 14:04:51 processing failed in 0.202449 sec

Filesystem Information:
Results of ls -l in the project directory:
Code: [Select]
drwxr-xr-x 3 nobody nogroup 4096 апр 22 14:04 20250422_1404.files
-rwxr--r-- 1 nobody nogroup  106 апр 22 14:04 20250422_1404.psx


The Metashape server process is unable to create directories within the project structure due to permission issues. The files are owned by "nobody:nogroup" with permissions that don't allow the server process to write to the directory.


Has anyone encountered a similar issue? Any advice would be greatly appreciated.

4
I would like to obtain the coordinates of the corners of the photo from the project in Metashape. I have discovered scripts for generating footprints. I have also modified them to suit my needs.


Code: [Select]
import Metashape
import multiprocessing
import concurrent.futures
I would like to obtain the coordinates of the corners of the photograph from the project in Metashape. I have discovered scripts for generating footprints. I have also modified them to suit my needs.
def create_footprints():
    """
    Creates four-vertex shape for each aligned camera (footprint) in the active chunk
    and puts all these shapes to a new separate shape layer
    """

    doc = Metashape.Document()
    doc.open("My_project.psx", ignore_lock=True)
    if not len(doc.chunks):
        raise Exception("No chunks!")

    print("Script started...")
    chunk = doc.chunk

    if not chunk.shapes:
        chunk.shapes = Metashape.Shapes()
        chunk.shapes.crs = chunk.crs
    T = chunk.transform.matrix

    if chunk.elevation:
        surface = chunk.elevation
    elif chunk.model:
        surface = chunk.model
    elif chunk.point_cloud:
        surface = chunk.point_cloud
    else:
        surface = chunk.tie_points

    chunk_crs = chunk.crs.geoccs
    if chunk_crs is None:
        chunk_crs = Metashape.CoordinateSystem('WGS84')

    def process_camera(chunk, camera):
        if camera.type != Metashape.Camera.Type.Regular or not camera.transform:
            return  # skipping NA cameras

        sensor = camera.sensor
        w, h = sensor.width, sensor.height
        if sensor.film_camera:
            if "File/ImageWidth" in camera.photo.meta and "File/ImageHeight" in camera.photo.meta:
                w, h = int(camera.photo.meta["File/ImageWidth"]), int(camera.photo.meta["File/ImageHeight"])
            else:
                image = camera.photo.image()
                w, h = image.width, image.height
        corners = list()
        for (x, y) in [[0, 0], [w - 1, 0], [w - 1, h - 1], [0, h - 1]]:
            ray_origin = camera.unproject(Metashape.Vector([x, y, 0]))
            ray_target = camera.unproject(Metashape.Vector([x, y, 1]))
            if type(surface) == Metashape.Elevation:
                dem_origin = T.mulp(ray_origin)
                dem_target = T.mulp(ray_target)
                dem_origin = Metashape.OrthoProjection.transform(dem_origin, chunk_crs, surface.projection)
                dem_target = Metashape.OrthoProjection.transform(dem_target, chunk_crs, surface.projection)
                corner = surface.pickPoint(dem_origin, dem_target)
                if corner:
                    corner = Metashape.OrthoProjection.transform(corner, surface.projection, chunk_crs)
                    corner = T.inv().mulp(corner)
            else:
                corner = surface.pickPoint(ray_origin, ray_target)
            if not corner:
                corner = chunk.tie_points.pickPoint(ray_origin, ray_target)
            if not corner:
                break
            corner = chunk.crs.project(T.mulp(corner))
            corners.append(corner)

        if len(corners) == 4:
            print(camera.label, corners)
        else:
            print("Skipping camera " + camera.label)

    with concurrent.futures.ThreadPoolExecutor(multiprocessing.cpu_count()) as executor:
        executor.map(lambda camera: process_camera(chunk, camera), chunk.cameras)

    Metashape.app.update()
    print("Script finished!")

create_footprints()

When I execute this code in the console of Metashape, I receive the necessary coordinates of the corners.

Code: [Select]
LoadProject: path = My_project.psx
loaded project in 0 sec
Finished processing in 0 sec (exit code 1)
Script started...
photo_name1 [Vector([lat_data_corners(0,0), lon_data_corners(0,0), evl_data_corners(0,0)]), Vector([lat_data_corners(w - 1, 0), lon_data_corners(w - 1, 0), evl_data_corners(w - 1, 0)]), Vector([lat_data_corners(w - 1, h - 1), lon_data_corners(w - 1, h - 1), evl_data_corners(w - 1, h - 1)]), Vector([lat_data_corners(0, h - 1), lon_data_corners(0, h - 1), evl_data_corners(0, h - 1)])]
...
photo_name99 [Vector([lat_data_corners(0,0), lon_data_corners(0,0), evl_data_corners(0,0)]), Vector([lat_data_corners(w - 1, 0), lon_data_corners(w - 1, 0), evl_data_corners(w - 1, 0)]), Vector([lat_data_corners(w - 1, h - 1), lon_data_corners(w - 1, h - 1), evl_data_corners(w - 1, h - 1)]), Vector([lat_data_corners(0, h - 1), lon_data_corners(0, h - 1), evl_data_corners(0, h - 1)])]
Script finished!

But if I want to run this script frome console of my computer (w/o start Metashape) I got this:

Code: [Select]
LoadProject: path = My_project.psx
loaded project in 0.001 sec
Script started...
Script finished!

I attempted to discern the source of the error. I inserted several print statements into my code:


Code: [Select]
if type(surface) == Metashape.Elevation:
                dem_origin = T.mulp(ray_origin)
                dem_target = T.mulp(ray_target)
                print('1',dem_origin, dem_target)
                dem_origin = Metashape.OrthoProjection.transform(dem_origin, chunk_crs, surface.projection)
                dem_target = Metashape.OrthoProjection.transform(dem_target, chunk_crs, surface.projection)
                corner = surface.pickPoint(dem_origin, dem_target)
                print('2',dem_origin, dem_target)
                print(corner)
                if corner:
                    corner = Metashape.OrthoProjection.transform(corner, surface.projection, chunk_crs)
                    corner = T.inv().mulp(corner)
                    print(corner)

And now I know that
Code: [Select]
print('2',dem_origin, dem_target) not work. I get only date from
Code: [Select]
print('1',dem_origin, dem_target)
Could you please help me to understand how to get data from photos using Python scripts without starting the Metashape application?


UPDATE:

I remove
Code: [Select]
    with concurrent.futures.ThreadPoolExecutor(multiprocessing.cpu_count()) as executor:
        executor.map(lambda camera: process_camera(chunk, camera), chunk.cameras)

And use just

Code: [Select]

    for camera in chunk.cameras:
        process_camera(chunk, camera)


And I got this error:

Code: [Select]
    dem_origin = Metashape.OrthoProjection.transform(dem_origin, surface.projection, chunk_crs)
TypeError: transform() argument 3 must be Metashape.Metashape.OrthoProjection, not Metashape.Metashape.CoordinateSystem


Why does this code work well in the Metashape app and not like a Python script?


UPDATE2:

My application has is 2.1.2 version

My venv for running python scripts has 2.0.3 version


UPDATE3:

I updated the version in my virtual environment and received the expected results.

To summarize, when you are copying code, make sure to do it thoroughly!

Code: [Select]
# Checking compatibility
compatible_major_version = "2.1"
found_major_version = ".".join(Metashape.app.version.split('.')[:2])
if found_major_version != compatible_major_version:
    raise Exception("Incompatible Metashape version: {} != {}".format(found_major_version, compatible_major_version))


Thank you for attention :)

5
Python and Java API / Re: Get GeoPandas DataFrame from chunk shapes
« on: October 16, 2024, 09:58:01 AM »

from shapely.geometry import Polygon
import geopandas as gpd

def extract(chunk):
   for shape in chunk.shapes:

        if shape.geometry.type != Geometry.Type.PolygonType:
            continue

       
        polygon = Polygon([(v.x, v.y) for v in shape.geometry.coordinates[0]])

        road_seg.append({
                          'geometry': polygon
                      })

    return gpd.GeoDataFrame(road_seg, crs=chunk.crs.wkt) if road_seg else None

6
Python and Java API / Get GeoPandas DataFrame from chunk shapes
« on: October 13, 2024, 06:39:29 PM »
Good day,

Is there a way to obtain shape groups (chunk.shapes.groups[index]) in a format suitable for working with GeoPandas? Currently, I have to export them to GeoJSON and then read them using GeoPandas.

Is it possible to directly create a GeoDataFrame from Metashape shapes without the need for exporting to a file?

Thank you!

7
General / Re: Local coordinate system (in meters) in python
« on: October 01, 2024, 10:34:27 AM »
Hello katemosolova,

I see two general approaches:

1. Generate DEM in UTM projection for the given area (or transform original DEM from WGS to proper UTM projection), then estimate the coordinates of the polygon center and use its XY values as offsets in your calculations,
2. Build DEM using Planar (Top XY) projection - it will give you local Cartesian coordinate system. To shift the origin of that system some Python coding will be necessary to configure proper matrix for the projection plane definition.

Probably, the first approach would be better in your case, if you have shapes defined in WGS84 coordinate system - they should be also transformed to same UTM projection.


Alexey, thank you for your answer and suggestions!

But it seems to me that everything should be simpler, because I don't need a translation to UTM. I need a local, relative coordinate system. After all, I don't need to translate what I will build using a local coordinate system back to WGS84.

Only my telemetry is in WGS84, and calculations (let's say I need to know the length of something) are in meters.

In principle, it is not even necessary to put 0.0 at the center of DEM. Any point from which I will calculate my local values ​​will do for me.

Therefore, I think that I need something like this:

Take any point of the polygon (I will always have them, but a lot)
Take it as (0,0)
Based on this, calculate the relative distance to the rest of the points (make something like a coordinate grid)

Are there any solutions to such problems?

8
General / Local coordinate system (in meters) in python
« on: September 30, 2024, 12:37:15 PM »
I have a DEM in WGS84. 

For calculations, I need to use meters (for example, to use the lines_centerlines library). 

My polygons look like this: 

POLYGON Z ((lot[degWGS84] lat[degWGS84] elevation[m], etc.)) 

Is there a way in Python to take a central point of my DEM and set it as (0,0) in a Cartesian 2D coordinate system? 

I assume that the DEM  is not large enough for the curvature of the Earth to introduce significant errors in the calculations. 


Thank you!

Pages: [1]