Skip to main content
Question

Convert raster and delete old file?

  • July 26, 2019
  • 4 replies
  • 23 views

nicholas
Contributor
Forum|alt.badge.img+14

I have a directory containing several hundred raster images in geotiff format

I would like to convert them to ecw format

As file space is limited, I would prefer to;

- iterate through the geotiffs one by one

- convert a geotiff into an ecw, saved in the same directory

- delete the original geotiff

- move onto the next geotiff

Can anyone outline the structure of a workbench that does this?

Thanks

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

takashi
Celebrity
  • 7843 replies
  • July 26, 2019

Hi @nicholas, a possible way is:

  1. Create a workspace that converts a single GeoTIFF to an ECW.
  2. Create another workspace: read GeoTIFF file paths in a specified folder with a PATH reader, call the first workspace with a WorkspaceRunner (Wait for Job to Complete: Yes) to convert GeoTIFF to ECW, and remove the source GeoTIFF file whenever a translation completed.

The second workspace looks like this.

0684Q00000ArKt6QAF.png

# PythonCaller Script Example: Remove a file.
import os
def processFeature(feature):
    os.remove(feature.getAttribute('path_unix'))

nicholas
Contributor
Forum|alt.badge.img+14
  • Author
  • Contributor
  • 116 replies
  • July 29, 2019

I have it almost, but not quite, working

There is an error with the PythonCaller

 

WorkspaceRunner: Successfully ran workspace `D:/2019/07/tif2ecw/geotiff2ecw.fmw'

PythonFactory failed to load python symbol `FeatureProcessor'

Factory proxy not initialized

PythonCaller(PythonFactory): PythonFactory failed to process feature

Path Reader: Closing the PATH Reader

A fatal error has occurred. Check the logfile above for details

Translation FAILED with 4 error(s) and 1 warning(s) (0 feature(s) output)

 

 

My settings for the PythonCaller are;

Class or Function to Process Features: FeatureProcessor

# PythonCaller Script Example: Remove a file.

import os

def processFeature(feature):

os.remove(feature.getAttribute('path_windows'))

 

 


takashi
Celebrity
  • 7843 replies
  • July 30, 2019

I have it almost, but not quite, working

There is an error with the PythonCaller

 

WorkspaceRunner: Successfully ran workspace `D:/2019/07/tif2ecw/geotiff2ecw.fmw'

PythonFactory failed to load python symbol `FeatureProcessor'

Factory proxy not initialized

PythonCaller(PythonFactory): PythonFactory failed to process feature

Path Reader: Closing the PATH Reader

A fatal error has occurred. Check the logfile above for details

Translation FAILED with 4 error(s) and 1 warning(s) (0 feature(s) output)

 

 

My settings for the PythonCaller are;

Class or Function to Process Features: FeatureProcessor

# PythonCaller Script Example: Remove a file.

import os

def processFeature(feature):

os.remove(feature.getAttribute('path_windows'))

 

 

You have to set the name of function or class which you intend to execute - "processFeature" in my example - to the Class or Function to Process Features parameter in the PythonCaller.

See also the help on the transformer: PythonCaller


nicholas
Contributor
Forum|alt.badge.img+14
  • Author
  • Contributor
  • 116 replies
  • July 30, 2019

I have found a solution, which is to replace the PythonCaller with a SystemCaller.

This works for me, because the dos command is quite simple

del @Value(path_windows)

I realise that PythonCaller is more flexible, but I don't know Python well enough to make it work