Solved

Read and write Shapefile in same workbench


Hi, the following problem:

 

I want to update attributes of a shape file. To do this, I first read them in using a reader (regardless of whether it is a "shapefile reader" or a FeatureReader transformer), update them and then overwrite them using a writer.

 

When I execute the Workbench step by step, everything works. If I run all steps at once, I get the error message

 

SHAPEFILE writer: Shapefile writer: Failed to write to file '<pathToFile>\\Grid.dbf'. Please ensure that the file is not open by FME or another process, you have sufficient privileges to write this file, and that sufficient disk space is available.

 

It looks like the reader is blocking the .dbf file. Does anyone have any advice on how to proceed?

icon

Best answer by egge 6 March 2023, 11:19

View original

3 replies

Userlevel 1
Badge +11

Yes, it is very well possible that the reader is blocking parts of the shapefile when you execute the whole workspace at once. A possible solution may be to copy the shapefile to a temp folder, read it in from there, update the attributes and overwrite the shapefile in the source folder (and clean up the temp folder at the end of the process)

Userlevel 5
Badge +25

Depending on what you do in the the workspace itself, it may be that FME is already writing the first features while it hasn't actually read the last ones yet. In that case it blocks the writing (which is a good thing, the other option is to completely destroy the file...).

 

You can try to circumvent this by making sure all of the reading is done before continuing to write. A FeatureHolder as your first transformer would do the trick.

 

However, I would be very wary to employ a strategy like this and would, personally, prefer to work with temp files as @egge​ suggests.

Thank you for your answers.

It may indeed be that my workflow is already trying to start writing before the file has been completely read in. The FeatureHolder could certainly be tried again -  I haven't looked at it yet.

I have now gone the temporary file route though - While a bit more cumbersome than I had hoped, it works that way 👌🏻

Reply