Question

Hi All, I have some shapefiles which include various geometry types (polygons, line, points) and they are located in different folders based on regions. I want to filter these based on geometry type . Can someone help please.


I used the Directory and File Pathnames reader to go through folders and select all shapefiles.

Then trying to use GeometryExtractor and GeometryFilter to filter line shapefiles but GeometryExtractor output has no geometry. Then I'm using the GeometryReplacer to replace the geometry but again the output has no geometry and the GeometryFilter cannot filter lines.

I'm very new to FME so please go easy!

Thanks in advance.


10 replies

Badge +11

If you attach a sample of the data, it would be easier to solve your question

Userlevel 5
Badge +29

Hey, assuming your folder structure is something like...

C:\data\
   region1
        shp
        shp
   region2
        shp
        shp
        ......
...

Its a pretty straight forward. You need to make use of wildcards on the Shapefile reader. Your reader path will be "C:\data\**\*.shp". This will traverse through all folders in "C:\data" and find/read any file ending in shp.

 

Then you'll want to use a geometry filter and filter area (polygon), line and point

Hey, assuming your folder structure is something like...

C:\data\
   region1
        shp
        shp
   region2
        shp
        shp
        ......
...

Its a pretty straight forward. You need to make use of wildcards on the Shapefile reader. Your reader path will be "C:\data\**\*.shp". This will traverse through all folders in "C:\data" and find/read any file ending in shp.

 

Then you'll want to use a geometry filter and filter area (polygon), line and point

@hkingsbury​ Thanks for the answer.

Yes that's how the data structure is and the path reader just like you mentioned it traverse through all folders and read the .shp files. The path output is all good I can see all shapefiles selected. 

But when I'm using the Geometry Extractor and then Geometry Filter it does not filter anything (output is "Unfiltered"). When I check it in Inspector it says there is no geometry.

I'm using the Geometry Extractor before Geometry Filter for this no geometry reason but still it doesn't seem to work.

Hey, assuming your folder structure is something like...

C:\data\
   region1
        shp
        shp
   region2
        shp
        shp
        ......
...

Its a pretty straight forward. You need to make use of wildcards on the Shapefile reader. Your reader path will be "C:\data\**\*.shp". This will traverse through all folders in "C:\data" and find/read any file ending in shp.

 

Then you'll want to use a geometry filter and filter area (polygon), line and point

@hkingsbury​ 

Userlevel 5
Badge +29

Hey, assuming your folder structure is something like...

C:\data\
   region1
        shp
        shp
   region2
        shp
        shp
        ......
...

Its a pretty straight forward. You need to make use of wildcards on the Shapefile reader. Your reader path will be "C:\data\**\*.shp". This will traverse through all folders in "C:\data" and find/read any file ending in shp.

 

Then you'll want to use a geometry filter and filter area (polygon), line and point

Really close @steve731​ . Instead of the Directory and File Pathnames reader (which just reads what files/directories you have) use the Esri Shapefile reader. You don't need the GeomReplacer or Extractor, just the FIlter

Thanks @hkingsbury​ . Using the Esri Shapefile reader I can filter the shapefiles easier but the problem is I need to have below attributes (as an example) included in the output as well. Which is only possible if I use the Directory and File Pathnames reader to start with.

I would appreciate your help. Do you know if there is any way to be able to filter the shapefiles with geometry and also include below attributes? possibly an option to filter them through Directory and File Pathnames reader then find a way to be able to extract the geometry too?

 

Userlevel 5
Badge +29

Thanks @hkingsbury​ . Using the Esri Shapefile reader I can filter the shapefiles easier but the problem is I need to have below attributes (as an example) included in the output as well. Which is only possible if I use the Directory and File Pathnames reader to start with.

I would appreciate your help. Do you know if there is any way to be able to filter the shapefiles with geometry and also include below attributes? possibly an option to filter them through Directory and File Pathnames reader then find a way to be able to extract the geometry too?

 

What you're looking for is the FeatureReader. So you'll set the format to SHP, and the Dataset to the attribute that contains the complete path (path_directory_windows). At the bottom under "Attribute and Geometry Handling" set accumulation mode to "Merge Initiator and Result". I would also reccomend setting Output Ports (under Output) to "Single Output Port". This will then read in the data in the shapefiles and maintain the filename and directory

What you're looking for is the FeatureReader. So you'll set the format to SHP, and the Dataset to the attribute that contains the complete path (path_directory_windows). At the bottom under "Attribute and Geometry Handling" set accumulation mode to "Merge Initiator and Result". I would also reccomend setting Output Ports (under Output) to "Single Output Port". This will then read in the data in the shapefiles and maintain the filename and directory

@hkingsbury​ So the  Directory and File Pathnames reader would be directly connected to the FeatureReader?

What you're looking for is the FeatureReader. So you'll set the format to SHP, and the Dataset to the attribute that contains the complete path (path_directory_windows). At the bottom under "Attribute and Geometry Handling" set accumulation mode to "Merge Initiator and Result". I would also reccomend setting Output Ports (under Output) to "Single Output Port". This will then read in the data in the shapefiles and maintain the filename and directory

@hkingsbury​ I run this with the specification that you mentioned above but unfortunately it does not maintain geometry. The output comes out with no geometry.

Userlevel 5
Badge +29

What you're looking for is the FeatureReader. So you'll set the format to SHP, and the Dataset to the attribute that contains the complete path (path_directory_windows). At the bottom under "Attribute and Geometry Handling" set accumulation mode to "Merge Initiator and Result". I would also reccomend setting Output Ports (under Output) to "Single Output Port". This will then read in the data in the shapefiles and maintain the filename and directory

@steve731​  see attached, hopefully that helps

Reply