Skip to main content

I am totally new to FME.

I would like to merge all the shapefiles located in the all the folders called 2012. Any ideas how to do it?

 

It depends :)

  • Are all shapes the same geometrytype? Points, lines or Polygons. Because if it is mixed, something need to be done to output the different geometries as shape can have only one geometrytpe. (Create an attribute for geometrytype and do a group by this attribute.)
  • Does the input have attributes? Have all datasets the same attributes? Because if it is mixed, you need to do something to combine all these attributeschema’s. (SchemaScanner to generate schemafeature per geometrytype.)
  • Are all shapes in the same coordinate system? Because they need to be in the same system to be merged. Can be done using a Reprojector.

Hello, are the shapefiles always the same amount of folders deep? You can chain a couple of FeatureReaders set to Directory and File Pathnames. 

FeatureReader 1 reads Directory and returns Dir 1 and Dir 2 paths, FeatureReader 2 reads Dir 1 and Dir 2 and returns the 6 subfolders, et cetera. The last FeatureReader is set to Shapefile.

With Testers in between the FeatureReaders you can e.g. implement checks to exclude non-shapefiles, or direct the correct .shp paths to the final SHP FeatureReader.


It depends :)

  • Are all shapes the same geometrytype? Points, lines or Polygons. Because if it is mixed, something need to be done to output the different geometries as shape can have only one geometrytpe. (Create an attribute for geometrytype and do a group by this attribute.)
  • Does the input have attributes? Have all datasets the same attributes? Because if it is mixed, you need to do something to combine all these attributeschema’s. (SchemaScanner to generate schemafeature per geometrytype.)
  • Are all shapes in the same coordinate system? Because they need to be in the same system to be merged. Can be done using a Reprojector.

One way to do this:

  • Creator to initiate process.
  • FeatureReader to read the shapefiles.
    • Select folder to read, inc subfolders.
    • Set output to Signe Output Port.
  • Reprojector to get all data in the same coordinate system.
  • GeometryFilter to split point, line, area.

  • AttributeCreators to create attribute fme_feature_type_name = point, line or polygon.

  • SchemaScanner to generate SchemaFeature.

    • Group by fme_feature_type_name.

    • Ignore ^fme_|^multi_|^csv_|GeometryType

  • Dynamic FeatureWriter to write per fme_feature_type_name.

    • Group By fme_feature_type_name.

 

I attached a sample workspace doing this.


It depends :)

  • Are all shapes the same geometrytype? Points, lines or Polygons. Because if it is mixed, something need to be done to output the different geometries as shape can have only one geometrytpe. (Create an attribute for geometrytype and do a group by this attribute.)
  • Does the input have attributes? Have all datasets the same attributes? Because if it is mixed, you need to do something to combine all these attributeschema’s. (SchemaScanner to generate schemafeature per geometrytype.)
  • Are all shapes in the same coordinate system? Because they need to be in the same system to be merged. Can be done using a Reprojector.

All are polygons with the same attributes and in the same coordinate system.


It depends :)

  • Are all shapes the same geometrytype? Points, lines or Polygons. Because if it is mixed, something need to be done to output the different geometries as shape can have only one geometrytpe. (Create an attribute for geometrytype and do a group by this attribute.)
  • Does the input have attributes? Have all datasets the same attributes? Because if it is mixed, you need to do something to combine all these attributeschema’s. (SchemaScanner to generate schemafeature per geometrytype.)
  • Are all shapes in the same coordinate system? Because they need to be in the same system to be merged. Can be done using a Reprojector.

All are polygons with the same attributes and in the same coordinate system.

Then you can just use a FeatureReader to read all data and a FeatureWriter to write it in one shape. The attached workspace will also work, just remove the Reprojector.


It depends :)

  • Are all shapes the same geometrytype? Points, lines or Polygons. Because if it is mixed, something need to be done to output the different geometries as shape can have only one geometrytpe. (Create an attribute for geometrytype and do a group by this attribute.)
  • Does the input have attributes? Have all datasets the same attributes? Because if it is mixed, you need to do something to combine all these attributeschema’s. (SchemaScanner to generate schemafeature per geometrytype.)
  • Are all shapes in the same coordinate system? Because they need to be in the same system to be merged. Can be done using a Reprojector.

One way to do this:

  • Creator to initiate process.
  • FeatureReader to read the shapefiles.
    • Select folder to read, inc subfolders.
    • Set output to Signe Output Port.
  • Reprojector to get all data in the same coordinate system.
  • GeometryFilter to split point, line, area.

  • AttributeCreators to create attribute fme_feature_type_name = point, line or polygon.

  • SchemaScanner to generate SchemaFeature.

    • Group by fme_feature_type_name.

    • Ignore ^fme_|^multi_|^csv_|GeometryType

  • Dynamic FeatureWriter to write per fme_feature_type_name.

    • Group By fme_feature_type_name.

 

I attached a sample workspace doing this.

Thank you very much for your reply. Unfortunately, as I have the FME version 2022.2.1.0, I cannot see the FeatureReader , that it is just what I am interested in. 

If I use C:\Data\**\*.shp as Dataset in the Reader, I am merging all the shapefiles, but I am interested in merging only shapefiles in the folders named “CLC2012”. 

Is there any way to filter the subfolders in this reader to get only subfolders named CLC2012?


Thank you very much for your reply. Unfortunately, as I have the FME version 2022.2.1.0, I cannot see the FeatureReader , that it is just what I am interested in. 

If I use C:\Data\**\*.shp as Dataset in the Reader, I am merging all the shapefiles, but I am interested in merging only shapefiles in the folders named “CLC2012”. 

Is there any way to filter the subfolders in this reader to get only subfolders named CLC2012?

 

Several options:

  • In the FeatureReader, right to the Dataset field, click on the arrow, choose Select Multiple Folders/Files…
  • Use a FeatureReader, type Directory and File Pathnames, to scan a directory and filter on *.shp. This will result in a feature for each shapefile.
  • Use something like a Tester to get the subset you need.
  • Connect this to a second FeatureReader, reading the shapefile, use the attribute path_windows as input in the Dataset field.

Reply