?I need to construct numerous polygons to represent road segments (road assets) and have more than 1000 to do. I have a road centreline and a script that will plot points at known intervals along this line say every 10 or 100m. I need to write a script, if possible, that will create a polygon of say 5m wide either side of the centreline and between say 0 and 350m along the centreline and then repeat to create another polygon from 350 to 500m long at 5m either side of the centreline. Is this possible?
This is very much possible as we can write mapbasic script to create buffer of 5m on the road centreline. I need one clarity on this and that is are we trying to create one polygon for each road segment or is it that we have a road segment that needs to have multiple polygons for that as you mentioned 0 to 350, 350 to 500.
Md. Aslam Khan
Thanks for the clarification. I am unable to find the snapshot though.
I am attaching a snapshot of my undurstanding to your query. A road always comprises of numerous segments and they vary in length and that is not a problem when it comes to writing a mapbasic script.
In my snapshot I have taken account of a single road named ABC which is having four segments. If we need a 5m buffer for each of the segments than it is doable.
Here goes my attachment ...
Here is the approach that will do the job for you.
First you need to get hold of the road segments by querying by the road name and then loop through all the segments one by one. When you have the segment inside the loop, you can create a buffer around it using Buffer function as in the snippet.
Dim o_line, o_polygon As Object
o_line = line_seg.obj
o_polygon = Buffer( o_line, 10, 5, "m")
Buffer( inputobject, resolution, width, unit_name )
inputobject is an object expression.
resolution is a SmallInt value representing the number of nodes per circle at each corner.
width is a float value representing the radius of the buffer; if width is negative, and if inputobject is a closed object, the object returned represents an object smaller than the original object. If the width is negative, and the object is a linear object (line, polyline, arc) or a point, then the absolute value of width is used to produce a positive buffer.
unit_name is the name of the distance unit (e.g., "mi" for miles, "km" for kilometers) used by width.
Please let me know if this helps you out or you need any further assistance.
There might also be a different approach to solving your case as you are looking for clean edges but it can be quite tricky to get right especially where the road is turning.
You can see the principles of the method in the image below.
The idea is to use the individual segments as a base line and then create two points perpendicular to the base line. These points will become the nodes in the new polygon around your road segments.
@Uffe Kousgaard? has a neat little tool called Toolbox that come with sourcecode: http://www.routeware.dk/toolbox.php. In the source code (AddNodes.mb) you can find the algorythms for calculating the offset points - the feature is called Add Nodes.
The downloaded file is with the name toolbox.7z. You need to extract it by doing a right click on it and then going for to Extract to toolbox option. Please install winrar if you dont have that installed. You will now have a folder with toolbox, get into it and you will have toolbox.mbx and toolbox64.mbx. Double click on any of them according to the Mapinfo version installed and it will be loaded up in mapinfo.
@Angelene Wright? - Here is the direct link: http://www.routeware2.dk/toolbox.7z
Click on the link (or copy past into browser) and it will download automatically.