Forum

Author Topic: KML export script  (Read 2289 times)

szabo.robert@bimlab.hu

  • Newbie
  • *
  • Posts: 7
    • View Profile
KML export script
« on: April 02, 2019, 09:27:06 PM »
Dear Support!

Could you please help me, what is wrong with my script below?
I get an error message that says: "Can't create file. Access denied. (5): (*path to be exported)"
Attached the error message window.

chunk=Metashape.app.document.chunk
kmlpath=Metashape.app.getExistingDirectory("Export mappa")
kmlformat=Metashape.ShapesFormatKML
kmlprojection=Metashape.CoordinateSystem("EPSG::4326")
chunk.exportShapes(path=kmlpath, format=kmlformat, projection=kmlprojection, polygons_as_polylines=True, export_labels=False, export_attributes=True)

Thanks for your support!
« Last Edit: April 02, 2019, 09:29:58 PM by szabo.robert@bimlab.hu »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Re: KML export script
« Reply #1 on: April 02, 2019, 10:30:01 PM »
Hello szabo.robert,

The path argument in exportShapes operation should point to the file (with KML extension in your case), however, it seems to be a path to the folder instead.
Best regards,
Alexey Pasumansky,
Agisoft LLC

szabo.robert@bimlab.hu

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: KML export script
« Reply #2 on: April 02, 2019, 10:58:06 PM »
Thank you for the very quick answer!
Now it works:

chunk=Metashape.app.document.chunk
shapepath=Metashape.app.getExistingDirectory()
kmlformat=Metashape.ShapesFormatKML
dxfformat=Metashape.ShapesFormatDXF
kmlprojection=Metashape.CoordinateSystem("EPSG::4326")
dxfprojection=Metashape.CoordinateSystem("EPSG::23700")

chunk.exportShapes(path=shapepath+"\\depo.kml", format=kmlformat, projection=kmlprojection, polygons_as_polylines=True, export_labels=False, export_attributes=True)
chunk.exportShapes(path=shapepath+"\\depo.dxf", format=dxfformat, projection=dxfprojection, polygons_as_polylines=True, export_labels=False, export_attributes=True)

szabo.robert@bimlab.hu

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: KML export script
« Reply #3 on: April 02, 2019, 11:31:08 PM »
Hello szabo.robert,

The path argument in exportShapes operation should point to the file (with KML extension in your case), however, it seems to be a path to the folder instead.

Dear Alexey!

How can I script the path name to be an argument, so I can use this script in batch processes?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14854
    • View Profile
Re: KML export script
« Reply #4 on: April 03, 2019, 06:24:47 PM »
Hello szabo.robert,

If you wish to make a script that saves the shapes for all the chunks in the active project, you can do the following:

Code: [Select]
import Metashape
shapepath=Metashape.app.getExistingDirectory()
kmlformat=Metashape.ShapesFormatKML
dxfformat=Metashape.ShapesFormatDXF
kmlprojection=Metashape.CoordinateSystem("EPSG::4326")
dxfprojection=Metashape.CoordinateSystem("EPSG::23700")

labels = set()
for chunk in Metashape.app.document.chunks:
    if chunk.shapes:
         label = chunk.label
         num = chunk.key
         while label in labels:
             label = chunk.label + "_"  + str(num)
             num += 1
         labels.add(label)
           
        chunk.exportShapes(path=shapepath+"\\" + label + ".kml", format=kmlformat, projection=kmlprojection, polygons_as_polylines=True, export_labels=False, export_attributes=True)
        chunk.exportShapes(path=shapepath+"\\" + label + ".dxf", format=dxfformat, projection=dxfprojection, polygons_as_polylines=True, export_labels=False, export_attributes=True)
This code should export the shapes for all the available chunks to the same directory, but using individual filenames according to the chunk label.
Best regards,
Alexey Pasumansky,
Agisoft LLC