Skip to main content
Question

Convert raster and delete old file?


nicholas
Contributor
Forum|alt.badge.img+13

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

4 replies

takashi
Influencer
  • 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+13
  • Author
  • Contributor
  • 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
Influencer
  • July 30, 2019
nicholas wrote:

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+13
  • Author
  • Contributor
  • 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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings