MapInfo Pro

 View Only
  • 1.  Line in the middle of Polygon

    Posted 07-31-2024 08:20
    Edited by Saqib Amin 07-31-2024 13:06

    Hi All,

    I have a dataset which has multiple polygons, I have been asked to represent the same dataset as a line dataset. Basically it's polygons of various roads and footpaths.

    I don't have FME, is there a way I can create a centre line in the middle of the polygon from start to end?

    Many thanks,

    Saqib



    ------------------------------
    Saqib Amin
    ------------------------------



  • 2.  RE: Line in the middle of Polygon

    Posted 07-31-2024 22:24

    Hi Saqib,

    How about the following steps - this will create approximate centrelines.  That is, they won't be perfectly placed an equidistance from each side of the road or footpath.  You will need to ensure you are running the "MapCad" MapBasic Tool Add In, which will provide the required tools under the "Spatial" tab.

    1. Ensure your polygons have a unique ID
    2. Convert to lines
    3. Identify end lines based on their short length, and delete.  Prior to deletion, you might be able to double-check that you have selected the right lines by ensuring they intersect with a neighbouring polygon.  This double-check won't work in all cases, however.
    4. Delete the lines on one side of the road.  This can be done by differentiating lines based on their direction of travel.  The following selects lines travelling north to south: Select * from road_poly_test where ObjectGeography(obj, OBJ_GEO_LINEENDY) - ObjectGeography(obj, OBJ_GEO_LINEBEGY) <=0 into NorthSouthLinesOnce these are selected, delete them from the table.
    5. Combine Using Column - combine lines based on your unique ID column, storing results in a new table.  You'll probably want to use the "Value" method for the aggregation.
    6. Create parallel lines.  You will not know which side the parallel lines are to be placed, so choose the "both sides" option.  Also choose the "Delete source object" option.  Hopefully you can choose an appropriate distance based on the average width of the original polygons.
    7. Compare the results to the original polygons – select all lines that are not within a polygon and delete:

      First, select all within an original polygon:

      Select * from road_poly_test As "l", road_casement_polygon As "p" where str$(l.obj)="line" And l.obj within p.obj Into insideLines

      Then invert the selection:

      And delete.  Result:
    8. Clean up your results:

      Examples:

      Check for lines that are made of multiple segments – these will have gaps that need to be fixed.  These might have occurred at Step 3, where small lines were deleted.

      Check for polygons that do not contain a road centreline, or contain more than one road centreline.



    ------------------------------
    James Nolet
    GIS Manager
    Caf Consulting
    Mentone office, VIC, Australia
    ------------------------------



  • 3.  RE: Line in the middle of Polygon

    Posted 08-01-2024 10:01
    Edited by Saqib Amin 08-01-2024 10:01

    Many thanks James,

    I'll give this a go and let you know how I get on.



    ------------------------------
    Saqib Amin
    ------------------------------