Skip to main content
Question

GDB to CSV

  • 29 August 2020
  • 2 replies
  • 99 views

Hello,

 

I would greatly appreciate if someone could help me conceptualize how I might accomplish this task. I would like to create a CSV that contains every feature in all of the feature classes in a Geodatabase. All of the feature classes have a differing schema, but I would like each one to display in the CSV as:

 

ID / NORTHING / EASTING / ELEVATION / FEATURE_CLASS_NAME / ALL ATTRIBUTES

 

Any input is greatly appreciated.

Thanks!

There's a few pieces required to get the Solution, but is a good learning exercise for how easy each bit is to accomplish in FME! What you are looking for is a variation on Dynamic Workflows / Dynamic Schemas for which would recommend read some of the Tutorials/Help on.

1. Handling Multiple Feature Classes with the same Workflow

So, for the Reader, what you first want to do is send all the Output to a Single Port. The example of where to set it (in this case a FeatureReader) is as below. This way, all data for all Feature Classes will come through the one Port, making it much easier to design the next parts of the Workflow rather than have to setup individual workflows for every single Feature Class.

capture

 

2. Extract X, Y, Z coordinates

You haven't said what types of Features are being read, but getting the EASTING (X), NORTHING (Y) and ELEVATION (Z) as Attributes usually uses the CoordinateExtractor Transformer. Whilst it works fine for Point Features, you may want other intermediate transformers to handle Polylines or Polygons etc. , say with a CentrePointReplacer. For multiple Geometry Types in a Dynamic Workflow, it looks a little like this

capture2

3. Set the Writer so that All Attributes are Written Dynamically

You haven't said whether you want it all in 1 CSV file, or for a 1 CSV File per Feature Class. Either way is to use a Dynamic Writer.

Dynamic Writers need to be told the Schema/Column List they are going to Write. One way of doing this in a conceptually easy way is to send the "Schema" Output Port of the FeatureReader to the "Input" Port of a FeatureWriter, and then set the Writer to use a Dynamic Schema using a "Schema Feature" (FeatureWriter will use the first Feature per Feature Type entering it as being the "Schema Feature"). This will map all in the Input Fields to corresponding Output Fields within the Writer dynamically.

capture4

In this example, the FeatureWriter will create a separate CSV File Name for every Feature Class, called the same Name as the Feature Class. However, if you only want one CSV for all Feature Classes, just delete the default @Value(fme_feature_type) in the Red Circle and replace it with a hard coded string for the CSV file name

capture5

capture6

 

4. Write the fme_feature_type Attribute as an Additional Attribute to get the Feature Class Name.

This is the GDB Class Name Eg. Feature Class Name, for GDBs.

capture7


Fantastic! Thank you. Let me play with this a bit and see if I can get it set up. I may post back if I get stuck.

 

Thank you again. It is much appreciated!


Reply