2

I have a polyline (bus route) which I want to split where it intersects with other lines (not polylines) I have created.

I'm happy to initially do it manually to see how it works, although I would ideally prefer to do it all entirely in MapBasic due to the amount of data I have to get through.

2

You need to go thru a few steps to achieve this:

  1. Make sure there is a node in the intersection. You can do this via the OverlayNodes() function.

  2. Now you can find the intersection and the nodes of the intersection using the IntersectNodes() function.

  3. You now have to loop thru the polyline to find the node number. You can do this by comparing the coordinates of the node from IntersectsNodes() with the coordinates of each node in the polyline. You can extract the coordinates with CentroidX() and CentroidY(). You can also calculate the distance between the nodes and compare this to a threshold value. Use ObjectDistance() to find the distance between the nodes or Distance() to find the distance between the coordinates.

  4. Now that you have found the node number, you can use ExtractNodes() to extract the first and last part of the polyline and insert these into the table again.

I have shared a MapBasic module amongst a lot of other modules that you might find helpful. The module is called ObjLib and can be found here on Github: mbLibrary

It has some improved functions for searching for nodes in polylines and other useful functions.

0

An alternative approach using table level commands would be the following:

  1. Insert the route polyline and all the crossing lines into a temp table
  2. Objects Combine all the objects in the temp table together
  3. Objects Disaggregate the resulting object - this will split lines wherever they intersected prior to being combined
  4. Select the intersecting lines from the temp table (now split where they cross the bus route) using the start and end points of the original crossing lines.
  5. Delete the selections made in the previous step to leave the bus route broken into sections where the crossing lines intersected.

If you want to process multiple bus routes in the same operation, you would need to use Create Object as Union in step 2, ensuring that each bus route and its crossing lines share a common ID value that is different from other routes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.