Skip to main content

I use FME
to extract polygons from an SDE Feature Class and store them to a MS SQL
Non-Spatial Database. The database is used by external software.

There are
information about some files in one table, which are connected to the polygons
I process. There is one table (“polygons”) storing only the File-ID and the
Polygon-IDs, and another table (“Vertices”) storing the polygons’ vertices
(east and north coordinates). For each file there can be several polygons
stored, and for each polygon there are of course several vertices stored.

 

When I
process the polygons, this is how the attributes look like:

Please
notice that there are two polygons belonging to file-ID 121051.

What I have to do now is to
create entrys in the table “polygons” with the given File-ID; the Polygon-ID is
assigned automatically (incrementing) by the DBMS. I use the FeatureWriter to
do this. The result looks like this:

In the next
step I need to store the vertices and the polygon-ID to the table
“vertices”. So first I use the CoordinateExtractor and the ListExploder to extract the vertices from the polygons, and this is my result:

The yellow rows
belong to one polygon, the red ones to another one, but both the yellow an the
red rows describe polygons belonging to a certain file (with file-ID 121051).

When I
store the vertices to the table “vertices” I need to know their polygon-ID, as
this is the connection to the file (via the table “polygons”). To be more
precise, I do not need to know “their” polygon-ID, but I need to know one of
the Polygon-IDs stored to the table “Polygons” with the corresponding File-ID
and I must ensure that I use the same Polygon-ID for all vertices belonging to
a certain Polygon. For example, I could say the vertices in the red lines
belong to Polygon-ID 116459 and the Polygon in the yellow lines belong to
Polygon-ID 116460, or vice versa. It
doesn’t matter which Polygon-ID I use
for which polygon as long as the Polygon-ID belongs to the correct file…

And this is
where I’m stuck! As I know the File-ID, I first thought about using the
SQLExecutor with the SQL-Statement “SELECT polygon_id FROM polygons WHERE
file_id =@Value(myFileId)”. This however only works if there’s one polygon
stored to that file. In case there is more than one polygon stored, the
SQL-Executor returns all the polygon-IDs for each vertex, so my vertices are
doubled, tripled or whatever the number of polygons is, so the result looks like this (extract, sorted):

Any hint is appreciated 🙂 Thanks in advance!

If you use a FeatureMerger to join the resulting features with the table holding Polygon-ID and File-ID it should do the trick (if I understand your data correctly).


I think this table is useless to specify a polygon instance (and its vertices) through either "Polygon-ID" or "File-ID".

It seems that the polygons have unique ID called "objectid" originally. Why not map "Polygon-ID" to the "objectid"?


If I understood correctly you care only about the first file-ID present in the db that meets your specified criteria, so maybe you can use a sampler to keep only one entry having in all attributes the same values except the polygon-ID.

Also might be a better to use a FeatureReader instead of SqlExecutor in your case.


I think this table is useless to specify a polygon instance (and its vertices) through either "Polygon-ID" or "File-ID".

It seems that the polygons have unique ID called "objectid" originally. Why not map "Polygon-ID" to the "objectid"?

Yes, I think you're right: this table is useless. Unfortunately, the database design is preset by the software manufacturer and therefore I have to use and fill this table. However, I just found a solution to my problem and will post it below.

 


I just found a solution to my problem: I use the SQLExecutor using the SQL statement "SELECT polygon_id, myFileID FROM polygons WHERE file_id =@Value(myFileID)" and the option "result attributes only". From the results, I build a list grouped by myFileID. In another step, I count how many polygons there are for each file using the Counter Transformer and the file ID as Counter Name. I store this number to a new attribute "count" for each vertex. Then I merge the vertices with the list I created earlier using the FeatureMerger and a join on FileID. In the last step I set the attribute value of Polygon-ID to "@Value(_list{@Value(_count)}.myFileID)".


Reply