Skip to main content
Question

How to extract multiple coordinate pairs and match nearest neighbor?


Forum|alt.badge.img

I can see what needs to be done, but I am not sure how to configure FME to do it.

The issue is trying to get the coordinates of the first endpoint of a call-out or leader line pair, associate those coordinates with the text label of that call-out/leader, and output the coordinates and the text label as a CSV file.

 

 

The algorithm is to

 

1. Take the middle coordinate of the call-out/leader pair of lines, and match it to the nearest neighbor text label.

 

2. Take the first coordinate of that same call-out/leader pair of lines, and output those coordinates plus the text label.

 

 

The call-out/leader coordinates to which I refer are the FME coordinate triplet that are associated with the call-out/leader pairs of lines.

23 replies

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • April 21, 2017

Assuming the call out has a frame (balloon, closed polyline or arc) around the text?

( if no frame present you can maybe get away with a neighbourfinder between leaders and text (or textinsertionpoint) depending on conflicting leaders or balloons)

If so separate the leaders form the balloons using for instance a loopdetector (can alos be done using a areabuilder, non areas are thus not closed polylines).

Spatialrelator lines vs balloons. To relate id's.

Spatialrelator begin and endvertex of leaders vs balloons, to detect wich end touches balloons. (if you need it)

Else snip (using Snipper) the leader by percentage 50,50 (gives you the center point)

Spatial relator text (or textinsertionpoint) objects vs balloons to relate id's.

Create csv


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • April 21, 2017
Any chance you can supply some sample data?

 

 


Forum|alt.badge.img
itay wrote:
Any chance you can supply some sample data?

 

 

 

Here is a sample view of a portion of a .dwg file with the callouts (dark blue) and labels (green text).

 


Forum|alt.badge.img
I've tried various experiments with NearestNeighbor and different coordinates of the leader, but NearestNeighbor seems to be rather random as to what it thinks is its nearest neighbor. I've tried introducing range values, but when I use what should be reasonable values nothing matches.

 

 


itay
Supporter
Forum|alt.badge.img+17
  • Supporter
  • April 24, 2017
michaellampi wrote:
I've tried various experiments with NearestNeighbor and different coordinates of the leader, but NearestNeighbor seems to be rather random as to what it thinks is its nearest neighbor. I've tried introducing range values, but when I use what should be reasonable values nothing matches.

 

 

 

The neighborfinder or nearest neighbour is the right way to go, would it be possible for you to add some sample data, for example a clip of the data shown?

takashi
Evangelist
  • April 25, 2017

Hi @michaellampi, if the callout/leading line is a Line geometry having three vertices and the label text is a Text geometry, I think you can transfer the text string (i.e. fme_text_string attribute) of a label text to the closest line using the NeighborFinder with this setting.

  • Input Ports: Lines -> Base, Texts -> Candidate
  • Number of Neighbors to Find: 1
  • Maximum Distance: <not set>

You can then extract coordinates of any vertex from the line output from the Matched port with the CoordinateExtractor.


Forum|alt.badge.img
takashi wrote:

Hi @michaellampi, if the callout/leading line is a Line geometry having three vertices and the label text is a Text geometry, I think you can transfer the text string (i.e. fme_text_string attribute) of a label text to the closest line using the NeighborFinder with this setting.

  • Input Ports: Lines -> Base, Texts -> Candidate
  • Number of Neighbors to Find: 1
  • Maximum Distance: <not set>

You can then extract coordinates of any vertex from the line output from the Matched port with the CoordinateExtractor.

Thank you, Takashi. This is exactly the approach I was taking, but the matching is not working very well. I have tried leaving the range value unspecified, which often matches the wrong vertex with the label, resulting in an incorrect target being selected. I have tried restricting the range to a value that should be within the distance to the anchor point of the text, and then no (or very few) matches are made. I have tried intermediate values, and while more matches are being made, a lot aren't - until I start seeing bad matches again.

 

 


Forum|alt.badge.img
Unfortunately, the smallest file I have to upload showing this is 3.9MB in size.

 

 


takashi
Evangelist
  • April 25, 2017
michaellampi wrote:
Thank you, Takashi. This is exactly the approach I was taking, but the matching is not working very well. I have tried leaving the range value unspecified, which often matches the wrong vertex with the label, resulting in an incorrect target being selected. I have tried restricting the range to a value that should be within the distance to the anchor point of the text, and then no (or very few) matches are made. I have tried intermediate values, and while more matches are being made, a lot aren't - until I start seeing bad matches again.

 

 

I think such wrong matching could appear only if two or more pairs of Text and Line lie very close or overlap each other. Is there such a condition?

 


Forum|alt.badge.img
takashi wrote:
I think such wrong matching could appear only if two or more pairs of Text and Line lie very close or overlap each other. Is there such a condition?

 

I understand; however, while there are a couple of places where this occurs, this is not the situation in most cases.

 

 


takashi
Evangelist
  • April 25, 2017
michaellampi wrote:
Thank you, Takashi. This is exactly the approach I was taking, but the matching is not working very well. I have tried leaving the range value unspecified, which often matches the wrong vertex with the label, resulting in an incorrect target being selected. I have tried restricting the range to a value that should be within the distance to the anchor point of the text, and then no (or very few) matches are made. I have tried intermediate values, and while more matches are being made, a lot aren't - until I start seeing bad matches again.

 

 

Could you please post a sample dataset? No need to upload whole original data. Convert only label texts and callout/leading lines into FFS format (compressed) and upload that.

 

 


Forum|alt.badge.img
takashi wrote:
Could you please post a sample dataset? No need to upload whole original data. Convert only label texts and callout/leading lines into FFS format (compressed) and upload that.

 

 

I don't know how to do that. I tried adding a writer to take the layer output, but it doesn't seem to actually write anything even though some 7K+ items were extracted.

 

 


takashi
Evangelist
  • April 25, 2017
michaellampi wrote:
I don't know how to do that. I tried adding a writer to take the layer output, but it doesn't seem to actually write anything even though some 7K+ items were extracted.

 

 

Just add an FFS writer to the workspace, create two writer feature types, and write texts and lines into them. You can also specify compression level of the destination FFS file. e.g.

 

 


takashi
Evangelist
  • April 25, 2017
michaellampi wrote:
I don't know how to do that. I tried adding a writer to take the layer output, but it doesn't seem to actually write anything even though some 7K+ items were extracted.

 

 

alternatively, if possible, you can upload the original data to a web service such as Google Drive etc. and share the link with us.

 

 


Forum|alt.badge.img
testlabellineffs.zip

This is really a .ffs file, not a .zip. The uploader doesn't seem to like .ffs extensions.


takashi
Evangelist
  • April 25, 2017
michaellampi wrote:
testlabellineffs.zip

This is really a .ffs file, not a .zip. The uploader doesn't seem to like .ffs extensions.

There were irregular texts as shown in this screenshot (surrounded red rectangles). I think the unexpected matching occurs in these parts.

 

How do you want to resolve those irregular texts?

 


Forum|alt.badge.img

There are some interesting things that seem to occur when these drawings are imported into FME. Labels get misplaced somehow, and leaders and text seem to move around as you see here.

Try this smaller set, rather than the larger one. I can also upload a PNG showing how they appear in the drawing.testlabellineffs2.zipgp-deck06-zone5-model.pdf


takashi
Evangelist
  • April 25, 2017
michaellampi wrote:

There are some interesting things that seem to occur when these drawings are imported into FME. Labels get misplaced somehow, and leaders and text seem to move around as you see here.

Try this smaller set, rather than the larger one. I can also upload a PNG showing how they appear in the drawing.testlabellineffs2.zipgp-deck06-zone5-model.pdf

Some lines in the FFS file seems to have been flipped horizontal.

 

Would the texts and lines be shown correctly if you read them with FME reader and send the texts and lines to FME Data Inspector?

 


Forum|alt.badge.img

I don't think so. This seems to be how FME interprets the file. I presumed it to be a bug.


takashi
Evangelist
  • April 25, 2017
michaellampi wrote:

I don't think so. This seems to be how FME interprets the file. I presumed it to be a bug.

There could be a potential bug if FME Data Inspector couldn't display the features correctly even though FME read the original dataset directly. If so, contact Safe support.


Forum|alt.badge.img

You see the leaders that are wrong should have their line that is supposed to underline the text is 180 degrees from the associated text? That's what I presume to be an FME bug.


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • April 25, 2017

thus taking into account this issue, all you need to do is a neigbourfinder, with leaders as bases.

Unmatched bases need to be rotated 180 around the knee-joint. Then neighbor find those again.


Forum|alt.badge.img
gio wrote:

thus taking into account this issue, all you need to do is a neigbourfinder, with leaders as bases.

Unmatched bases need to be rotated 180 around the knee-joint. Then neighbor find those again.

Fonts will change the text size but not the leader orientation. 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings