OK, I had some fun with this as well. See attached MXB file. It contains two queries and a script. Open the MXB in a new instance of 9, then copy and paste both queries and the script into your MAP file above, then run them in sequence: Step 1 -> Step 2 -> Step 3. Step 1: query. Takes the drawing of lines, runs GeomOverlayTouchingPar on it to find all touching lines and puts IDs of all touching lines into a temporary table (temp). Also creates a second temporary table (temp_out) for the script. Step 2: script, C#. Reads IDs of all touching lines (temp), merges all touching lines into clusters, then writes the cluster ID for each line (temp_out). Step 3: query. Takes the drawing of lines, joins the cluster ID for each line (temp_out), groups lines by cluster ID and merges all lines within a cluster into a single geom (GeomMergeLines and then GeomNormalize to join branches). Outputs the result into yet another temporary table (temp_clusters), adds an RTREE index for the geoms, copies coordinate system info from the original drawing, then creates a new drawing (temp_clusters_d). Try opening temp_clusters_d, it should contain what you want. PS: The code should perhaps be cleaned up a bit. Ie, I am using MFD_ID to identify clusters and these are 64-bit ints, but I am treating them as 32-bit ints in the script. Also, the script should perhaps create the table it writes to by itself, without the help from Step 1, or at least it should start with deleting everything from that table. Attachments:
query-script-query.mxb
|