span8
span4
span8
span4
The FeatureWriter allows you to write data at any point in your 亚搏在线workflow,not only at the end of the workspace as with a 'conventional' writer.This gives you the opportunity to post-process the results.This example will cover one of the potential ways to use the FeatureWriter,which includes post-processing and integrating third party tools.
For an overview of FeatureWriter transformer,see the blog post:FME 2016 Sneak Peak: The FeatureWriter Transformer
In a conventional 亚搏在线workflow,FME reads the data and writes using the reader and writer feature types - see the workspace in the attachment:FeatureWriter_Begin.fmwt.This workspace reads from a CAD file,transforms and validates the data and then writes the results to a GeoPackage database.
Note: Although this example writes to a GeoPackage database,it is applicable to any spatial database such as Esri Geodatabase,SQL Server,Oracle Spatial,PosGIS,etc.
This approach has only limited scope for additional processing after all the data has been written.You can use a Python or TCL shutdown script or a database writer SQL to Run Before/After Write,but these approaches have some limitations
The FeatureWriter expands the possibilities for 亚搏在线workflows by allowing writing data mid-workflow,followed by additional data transformation.This is useful when it is desirable to do something with the data after it has been written.
Here are a few possibilities for the FeatureWriter,all accomplished within a single workspace:
1.Simple procedures previously accomplished with scripts or manually:
2.Complex tasks that required chained workspaces using WorkspaceRunner or FMEServerJobSubmitters:
3.Notifications to FME Server
4.Integrations with third party tools for data transformation in FME without waiting for a new reader:
This FeatureWriter demo validates a CAD dataset and emails a validation report to the data validation manager after all the features have been written.
Source data is the CAD file with a City of Vancouver water network,water mains,valves,hydrants.The dataset contains a number of attributes related to information about the water network objects
TheFeatureWriter_Begin.fmwworkspace includes the following basic steps:
1.Read the CAD data and transform attributes
2.Validate water network attribute values
3.Extract error messages and validation tests of failed water network objects
4.Write the valid feature to the GeoPackage CADValidationReport table
Run theFeatureWriter_Begin.fmwworkspace and inspect the resulting GeoPackage in FME Data Inspector.
Your going to modify the workspace by:
You can replace the AutoCAD reader with a FeatureReader.This would allow you to pre-process the data,clean-up database tables using SQLExecutor or trigger the read using an external input.In this example we'll just use the Creator transformer.
1.Open the workspaceFeatureWriter_Begin.fmw
2.Disable,but do not delete,the AutoCAD reader.
3.Add aCreatortransformer.
4.Add aFeatureReaderand select the Autodesk AutoCAD Map 3D Object Data format and the AutoCAD DWG file:CofVWater_small.dwg.Configure the FeatureReader as shown below:
In the AutoCAD Parameters dialog,make sure you uncheckExplode Blocks into Entitiesas shown below:
Select all the AutoCAD layers under Feature Types to Read
5.Connect the output ports to the appropriate AttributeManager transformers (not all of the feature types need to be connected).
6.Test your FeatureReader by running the modified workspace.If the results look good,delete the AutoCAD reader.
7.Save the workspace.
You're now going to add a FeatureWriter to the workspace,replacing the 'conventional' GeoPackage writer.
1.Disable,but do not delete,the GeoPackage writer
2.Add a FeatureWriter transformer and open the Parameters dialog.Configure the FeatureWriter parameters:
Now we can do some simple post- processing or validation of the output.For example,you could create an attribute or spatial index using the SQLExecutor.In this workspace you are going to validate the number of features written.FME reports the number of features written but sometimes this might not match the actual number of features inserted into the database.This can occur if you are using transactions and one of the inserts fails.You're going to add a SQLExecutor to check the number of records in the database after all the features have been written by the FeatureWriter.
1.Add an Inspector transformer to the Summary port of the FeatureWriter and run the workspace.The Summary port of the FeatureWriter outputs a single feature with a list of all the feature types written:
Where 'name' is the table name and 'count' is the number of features FME thought it wrote.
3.Connect aListExploderto the Summary port of the FeatureWriter.Select the _feature_type{} list.This will result in a separate summary feature for each feature type that was written.
4.Connect a SQLExecutor to the Elements port of the ListExploder.Build the following query:
SELECT COUNT(*) AS "rows" FROM "@Value(name)"
This queries the database and returns the row count of each table in the 'name' attribute.
5.Add a TestFilter to compare the 'count' value of features written vs.'rows' value returned by the SQLExectutor.
6.Add Inspectors and then run the workspace and check the results.
Cleanup
7.The last step,if you comfortable that all your changes are working correctly,would be to delete the original AutoCAD reader and the original GeoPackage writer and clean-up your workspace.Save your work.
The workspace in the attachmentFeatureWriter_Final.fmwthas some additional ideas that you can investigate:
JSON reader: In the final workspace we use a JSON reader to initiate the FeatureReader - this would allow you to publish this workspace to FME Server and drive the validation using a directory watcher publication.
DropboxConnector: The DropboxConnector allows you to move the GeoPackage database file to a dropbox folder.If you don't have a dropbox account you'll need to disable this transformer.Or try one of the other connectors: GoogleDriveConnector,OneDriveConnector,BoxConnector.
Emailer: The final workspace includes an Emailer that will email the validation GeoPackage database file to a friend.You'll need to configure the Emailer with your own email account information or disable the transformer to avoid errors.
Note: The demo workspace will return a warning if the Emailer is not configured correctly for your email account.Necessary configuration can includeconfiguring SMTPfor Gmail,and generating aApp specific passwordif two step authentication is used.Same for the DropboxConnector.If you don't have suitable accounts,just disable these transformers
Merging or Joining Spreadsheet or Database Data
Performing native spatial queries on database tables using the SQLExecutor
Using the SQLExecutor or SQLCreator to issue commands to a database
Performing spatial queries on database tables using the FeatureReader
Using the SQLExecutor to do a SQL Join
Splitting SQL statements using the FME_SQL_DELIMITER directive
Executing a Stored Procedure on Microsoft SQL Server with FME
The SQLCreator and SQLExecutor Transformers
© 2019 亚搏在线Safe Software Inc |Legal