Forum

Author Topic: Exporting shapes in a different coordinate system  (Read 11719 times)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Exporting shapes in a different coordinate system
« Reply #15 on: April 13, 2017, 12:44:44 PM »
Hello Thibaud,

You need to loop through all the vertices of every shapes and convert the coordinates from EPSG::4326 to EPSG::3948. Then change chunk.shapes.crs.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Exporting shapes in a different coordinate system
« Reply #16 on: April 13, 2017, 01:06:19 PM »
I think it should be something like the following:

Code: [Select]
chunk = PhotoScan.app.document.chunk
shapes = chunk.shapes
source = shapes.crs
out = PhotoScan.CoordinateSystem("EPSG::3948")
for shape in chunk.shapes:
      shape.vertices = [PhotoScan.CoordinateSystem.transform(v, source, out) for v in shape.vertices]
shapes.crs = out
Best regards,
Alexey Pasumansky,
Agisoft LLC

Thibaud Capra

  • Full Member
  • ***
  • Posts: 101
  • Master Student in Geodetic Engineering & Surveying
    • View Profile
    • INSA de Strasbourg, Topography Engineering (French)
Re: Exporting shapes in a different coordinate system
« Reply #17 on: April 18, 2017, 12:11:41 PM »
Hello Alexey,

Thanks for your precious help, as usual!

I'm also trying to export my shapes, using chunk.exportShapes as you recommended. My question is, if I have multiple shape layers, will it create one shape file per layer or one merged shape file?

I'd like to keep my shapes separated according to the shape layers, using maybe the shape layer's name to identify them. Is it possible?
Best regards.
--
Thibaud CAPRA
Master Student in Geodetic Engineering, Cartography & Surveying
Master Thesis in Automated Processing of UAV-based Photogrammetric Data (ResearchGate Link)
INSA de Strasbourg, FRANCE
--

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Exporting shapes in a different coordinate system
« Reply #18 on: April 18, 2017, 12:18:16 PM »
Hello Thibaud,

In chunk.exportShapes() function there's optional "groups" argument that can be used, if you wish to export only certain layers. Otherwise, all shape layers will be saved to the same file.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Thibaud Capra

  • Full Member
  • ***
  • Posts: 101
  • Master Student in Geodetic Engineering & Surveying
    • View Profile
    • INSA de Strasbourg, Topography Engineering (French)
Re: Exporting shapes in a different coordinate system
« Reply #19 on: April 18, 2017, 01:46:43 PM »
Hello Alexey,

I don't get the shape group creation part.
Are groups the corresponding layers by default? Or do I have to assign them first to each different ShapeGroup key? If need be, how do I do that?
For example, I made a small test project with two layers I want to export (see below) as two different shape files.

For now, I have the following code:

Code: [Select]
import os, PhotoScan

doc = PhotoScan.app.document
chunk = doc.chunk
shapes = chunk.shapes
source = shapes.crs
out = PhotoScan.CoordinateSystem("EPSG::3948")
type_chunk = ['Green']

for chunk in doc.chunks:
    if not any(type_chunk[0] in chunk.label for type_chunk in type_chunk):
        for shape in chunk.shapes:
            shape.vertices = [PhotoScan.CoordinateSystem.transform(v, source, out) for v in shape.vertices]
        shapes.crs = out
    print("""Les SHP de """ + chunk.label + """ ont été transformées avec succès !""")

for chunk in doc.chunks:   
    for shape in chunk.shapes:
        if not any(type_chunk[0] in chunk.label for type_chunk in type_chunk):
            chunk.exportShapes(path = "C:\\PFE_CAPRA\\Essais_Shapes\\Green.shp", groups = ShapeGroup(key = 1))
            chunk.exportShapes(path = "C:\\PFE_CAPRA\\Essais_Shapes\\Approche.shp", groups = ShapeGroup(key = 2))

Thanks
Best regards.
--
Thibaud CAPRA
Master Student in Geodetic Engineering, Cartography & Surveying
Master Thesis in Automated Processing of UAV-based Photogrammetric Data (ResearchGate Link)
INSA de Strasbourg, FRANCE
--

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Exporting shapes in a different coordinate system
« Reply #20 on: April 18, 2017, 02:10:03 PM »
Hello Thibaud,

I would rather use something like the following:
Code: [Select]
for layer in chunk.shapes.groups:
      chunk.exportShapes(path, groups = layer)
« Last Edit: April 18, 2017, 03:19:57 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

Thibaud Capra

  • Full Member
  • ***
  • Posts: 101
  • Master Student in Geodetic Engineering & Surveying
    • View Profile
    • INSA de Strasbourg, Topography Engineering (French)
Re: Exporting shapes in a different coordinate system
« Reply #21 on: April 18, 2017, 03:12:17 PM »
Hello Alexey,

Code: [Select]
for layer in chunk.shapes.layers:
      chunk.exportShapes(path, groups = layer)

I think this layer export method works in 1.3.x, I am currently using PhotoScan 1.2.6 Build 2834... I have the following error message:

Traceback (most recent call last):
File "C:\PFE_CAPRA\Essais_Shapes\Script_Shapes.py", line 18, in <module>
for layer in chunk.shapes.layers:
AttributeError: 'PhotoScan.Shapes' object has no attribute 'layers'


« Last Edit: April 18, 2017, 03:18:43 PM by Thibaud Capra »
Best regards.
--
Thibaud CAPRA
Master Student in Geodetic Engineering, Cartography & Surveying
Master Thesis in Automated Processing of UAV-based Photogrammetric Data (ResearchGate Link)
INSA de Strasbourg, FRANCE
--

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Exporting shapes in a different coordinate system
« Reply #22 on: April 18, 2017, 03:20:18 PM »
Hello Thibaud,

It was my mistake, should be chunk.shapes.groups.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Thibaud Capra

  • Full Member
  • ***
  • Posts: 101
  • Master Student in Geodetic Engineering & Surveying
    • View Profile
    • INSA de Strasbourg, Topography Engineering (French)
Re: Exporting shapes in a different coordinate system
« Reply #23 on: April 18, 2017, 04:52:01 PM »
Hello Alexey,

I think this layer grouping is too recent, as I have the following error now:

     chunk.exportShapes(path, groups = layer)
 TypeError: 'groups' is an invalid keyword argument for this function


Or is it some error in my code?

Code: [Select]
import os, PhotoScan

doc = PhotoScan.app.document
chunk = doc.chunk
shapes = chunk.shapes

path = "C:\\PFE_CAPRA\\Essais_Shapes\\Shapes"
for chunk in doc.chunks:   
    for layer in chunk.shapes.groups:
        chunk.exportShapes(path, groups = layer)
Best regards.
--
Thibaud CAPRA
Master Student in Geodetic Engineering, Cartography & Surveying
Master Thesis in Automated Processing of UAV-based Photogrammetric Data (ResearchGate Link)
INSA de Strasbourg, FRANCE
--

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Exporting shapes in a different coordinate system
« Reply #24 on: April 18, 2017, 04:56:21 PM »
Hello Thibaud,

In the version 1.2.6 exportShapes() has only path and items arguments, so it seems that the code can be applied to version 1.3 only.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Thibaud Capra

  • Full Member
  • ***
  • Posts: 101
  • Master Student in Geodetic Engineering & Surveying
    • View Profile
    • INSA de Strasbourg, Topography Engineering (French)
Re: Exporting shapes in a different coordinate system
« Reply #25 on: April 18, 2017, 05:04:58 PM »
Hello Alexey,

Too bad, I'll see if I change the rest of the scripts I wrote to adapt it to 1.3.x to allow me to export automatically all my shapes, or stick to what I have for now and export my shapes the old-fashioned way, aka manually!

As usual, thanks for the great support!
Best regards.
--
Thibaud CAPRA
Master Student in Geodetic Engineering, Cartography & Surveying
Master Thesis in Automated Processing of UAV-based Photogrammetric Data (ResearchGate Link)
INSA de Strasbourg, FRANCE
--

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Exporting shapes in a different coordinate system
« Reply #26 on: April 18, 2017, 05:06:44 PM »
Hello Thibaud,

Alternative way in 1.2.6 could be removing all shape layers, except the required, export, then re-open of the project. Or duplicating the original chunk for each layer export and then removing the duplicate.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Thibaud Capra

  • Full Member
  • ***
  • Posts: 101
  • Master Student in Geodetic Engineering & Surveying
    • View Profile
    • INSA de Strasbourg, Topography Engineering (French)
Re: Exporting shapes in a different coordinate system
« Reply #27 on: April 18, 2017, 05:13:21 PM »
Hello Alexey,

The problem is, I have shapes in multiple chunks, would this work in a for loop doing roughly this:

Code: [Select]
for chunk in doc.chunks:
    Delete all layers but one based on layer labels
    Export layer
    Reopen project
    Export next layer the same way
    Loop through chunks

Additional difficulty (but I found a way around for this one), it musn't loop through all the chunks but only those with some specific keyword in the chunk label.
Wouldn't closing the project reset the progress in the various chunks?

I'm aware of the fact that this is a very specific question, but my aim is to automatize as much of the processing as possible!
Best regards.
--
Thibaud CAPRA
Master Student in Geodetic Engineering, Cartography & Surveying
Master Thesis in Automated Processing of UAV-based Photogrammetric Data (ResearchGate Link)
INSA de Strasbourg, FRANCE
--

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Exporting shapes in a different coordinate system
« Reply #28 on: April 18, 2017, 05:32:19 PM »
Hello Thibaud,

Then you can consider using chunk duplicates:

for chunk in list(doc.chunks):
     loop though the index of the shape layers
           temp_chunk = chunk.copy()
           remove all layers but one
           export layer
           remove temp_chunk
Best regards,
Alexey Pasumansky,
Agisoft LLC

Thibaud Capra

  • Full Member
  • ***
  • Posts: 101
  • Master Student in Geodetic Engineering & Surveying
    • View Profile
    • INSA de Strasbourg, Topography Engineering (French)
Re: Exporting shapes in a different coordinate system
« Reply #29 on: April 18, 2017, 05:40:00 PM »
Hello Alexey,

Can I remove layers based on their labels? If so, how?
I'm using keywords in the labels to determine where to export the file. (The same way I use keywords in chunk labels to process different LODs in one batch)
Best regards.
--
Thibaud CAPRA
Master Student in Geodetic Engineering, Cartography & Surveying
Master Thesis in Automated Processing of UAV-based Photogrammetric Data (ResearchGate Link)
INSA de Strasbourg, FRANCE
--