Subscribe to this thread
Home - General / All posts - Distance From polygons to points
126 post(s)
#20-Jul-22 19:59


I need to calculate the distance from all the polygons in one drawing (POLYGONS) to each point in a second drawing (POINTS) and add it in a separate column to the POLYGONS drawing.

The script should create one column in POLYGONS for each point in POINTS and fill it with the distance from each other.

I am doing it with a combination of SQL/Vbscript with the code shown below, but all columns are being filled with the value of what seems to be the last point.

I would appreciate some guidance on how can I grab the Geom ID for each individual point in POINTS in the distance calculation?

I am using Manifold 8 and I am attaching a Map file for reference.

Thanks in advance for any help


Sub Main

 Set theActiveDoc = Application.ActiveDocument

 Set theCompSet = theActiveDoc.ComponentSet

 Set POINTS = theCompSet.Item("POINTS Table")

 Set POINTSRecSet = POINTS.RecordSet

 set qry = theCompSet("Query"

 Count =0


 for each rec in POINTSRecSet


 qry.Text = "ALTER TABLE [POLYGONS] ADD [Dist_"&Count&"] INT ;"


 qry.Text = "UPDATE(SELECT CentroidInner(POLYGONS.ID),POLYGONS.Dist_"&Count&",POINTS.ID, Distance(CentroidInner(POLYGONS.ID), POINTS.ID) as newdist FROM POLYGONS,POINTS) SET Dist_"&Count&" = newdist;"





End Sub


BiciMapas Mexico GPS Maps & GIS Data


595 post(s)
#21-Jul-22 09:53

Have a look at the attached map.

Warning: in case of many points, storing each distance as a column is not a good idea.



126 post(s)
#21-Jul-22 14:56

Hello Chris,

Thank you very much, it provides the result I was aiming for and learnt something new.

I did a test with 2400 plus polygons and 61 points and all good.

This is the first step to create a full script for the Geomarketing Huff probabilistic model.


BiciMapas Mexico GPS Maps & GIS Data

Manifold User Community Use Agreement Copyright (C) 2007-2021 Manifold Software Limited. All rights reserved.