Solved

Reading PRJ file from zip with shps


Badge

I have a gazillion zip files with shapefiles and their sidecarts. I want to generate a list with the shapefile name and CRS. Attempts so far:

 

  • Use a reader, specify shp, read the zips: doesn't work, FME doesn't know the systems and CoordinateSystemExtractor returns almost nothing

 

  • The system is named in the prj, so I could extract it with the Python caller: nope, you can't specify prj in the reader, so good luck reading prj from the zip.

 

  • Extract the zips creating a mess (at this point I am already better off using plain Python), ctrl+f prj and load them as text, then try to expose the fme_basename with the AttributeExposer: FME doesn't show it (if I expose the fme_basename right in the reader, in "Format attributes", it does show it however but that's not what I want)

 

  • storm off to the forums <-- you are here

 

So is there a sane way to do this?

icon

Best answer by ebygomm 10 May 2021, 18:38

View original

8 replies

Badge +10

I'm not sure why the first option isn't working if the prj files are present.

 

However, if you want to read the prj files from the zip as text you can use the following syntax in a feature reader with format Text File, where you have an attribute containing your zip filename

@Value(filename)\**\*.prj

Capture

Badge

When FME doesn't know the CRS (in my particular case it's DB_REF) it returns nothing even if the prj contains all the info.

 

The reader won't let me use that. When I specify the file it asks for, the text is overwritten by the path. Supplying the zip through the initiator port doesn't do anything either.

 

Screenshot 2021-05-10 140819

Badge +10

When FME doesn't know the CRS (in my particular case it's DB_REF) it returns nothing even if the prj contains all the info.

 

The reader won't let me use that. When I specify the file it asks for, the text is overwritten by the path. Supplying the zip through the initiator port doesn't do anything either.

 

Screenshot 2021-05-10 140819

Have you got single output port selected? If you have it shouldn't be asking you to specify the file.

Badge

Have you got single output port selected? If you have it shouldn't be asking you to specify the file.

Yep. Retried it with a new reader as well, same result.

 

Screenshot 2021-05-10 173745

Badge +10

Have you got single output port selected? If you have it shouldn't be asking you to specify the file.

Do you have an attribute called filename on the feature you are triggering the featurereader with?

Badge +10

If you point this workspace to the folder that contains your zip files does it work?

Badge

If you point this workspace to the folder that contains your zip files does it work?

Yep, this worked. Only had to additionally expose "fme_basename" in the generic port. Thanks!

Badge +10

Yep, this worked. Only had to additionally expose "fme_basename" in the generic port. Thanks!

If you send zip files into the featurereader that don't have a prj file you will get features exiting the rejected port of the featurereader. This may not be an issue for you but something to be aware of.

 

In the past I've used a python caller to check for the existence of a file in a zip before attempting to read it directly from the zip (i think this is still a python only thing, i don't think you can get the list of files in a zip without extracting with FME yet)

Reply