Home - General / All posts - Distance From polygons to points
 anajera126 post(s) #20-Jul-22 19:59 Hello,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 helpcodeSub 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 Count=Count+1 qry.Text = "ALTER TABLE [POLYGONS] ADD [Dist_"&Count&"] INT ;" qry.Run() 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;" qry.Run()   Next End SubAttachments: DISTANCE_POINTS_TO_POLYGONS.map BiciMapas Mexico GPS Maps & GIS Data www.bicimapas.com.mx
 Sloots595 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.ChrisAttachments: DISTANCE_POINTS_TO_POLYGONS.map http://www.mppng.nl/manifold/pointlabeler
 anajera126 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.Cheers BiciMapas Mexico GPS Maps & GIS Data www.bicimapas.com.mx