relume Posted June 1, 2018 Share Posted June 1, 2018 Hello I am back 😐 to the recurrent problem of finding/selecting points or other 2D objects within an other 2D polygon or polyline. As long the number of points to be selected are small or smaller than the number of the "selecting" 2D polygons, then I can iterate over every point to check if it is inside a "selecting" 2D polygon by "vs.FindObjAtPt_GetObj". But if I have a (very) large number of points and a smaller number of "selecting" 2D polygons the above approach is inappropriate, due to the huge iteration over every point. So I thought I would be possible to use/adopt the polygon selection tool to "embrace" the relevant points (to be found) by a 2D polygon. But actually I can not see any way how to script this – how to get by scripting a given 2D polygon in to the polygon selection tool to "embrace" the relevant points. I would appreciate any idea how to get the problem solved, many thanks in advance, relume Quote Link to comment
JBenghiat Posted June 1, 2018 Share Posted June 1, 2018 If you're needing to select points as part of the script, you can use CallTool() to temporarily use the selection tool. Otherwise, iteration is not so bad, and what would happen internally anyway. I would use ForEachObjectInList() or ForeachObjectInLayer() to iterate over objects, and test with PtInPoly() Quote Link to comment
relume Posted June 3, 2018 Author Share Posted June 3, 2018 Hello Thank very much you for your hints and considering my questions. The command vs.CallTool() is not applicable, because I have to use an allready existent polygon as selection perimeter and do not want any user inteaction. Iterating over every point to check by vs.PtInPoly if it is on/witin the actual polygon is some kind of "brute force", as I have to iterated first over every polygon an then itereate over all points to be checked for each polygon. But it seems that there is no other approach to do it. I wondered if there would be any VW criteria to select objects by a x/y range (select all objects where x/y is >= as xTop/yTop AND x/y is <= xBottom/yBottom) in order to optimise somebit the iteration process by reducing the amount of relevant points to check after in detail if they are within a certain polygon. But unfortunately such numerical/grafical criteria search is not available in VW as it is part of every GIS-tool. By looking again at the VW search criterias I found the "location" critearia. If an object has a given name, it is possible to formulate a search criteria that looks for points/objects that are within the object with the given name: import vs vs.DSelectAll() vs.SelectObj("(INSYMBOL & INOBJECT & (L='LayerToSearchIn') & (LOC='MySelectionPolygon'))"); With this search criteria the solution is much easier (I do not know the details about performance differences) but of course for every polygone to test a name (a temporary unique name) has to be given: import vs def searchPoints_for_MyPolygon(vMyPolygon_handle): # the original name of the object to be processed has to be retrieved vMyPolygon_Name_org = vs.GetName(vMyPolygon_handle) vMyPolygon_Name_temp = 'MyPolygon_temp_unique_name' vs.SetName(vMyPolygon_handle, vMyPolygon_Name_temp) # a temp. unique name has to be given for the case the name = "" for correct selection vSelectionCriteria_Points = "(INSYMBOL & INOBJECT & (L='LayerToSearchIn') & (LOC='"+vMyPolygon_Name_temp+"'))" vPointsFound = vs.Count(vSelectionCriteria_Points) vs.SelectObj(vSelectionCriteria_Points) vs.AlrtDialog("Points found: " + str(vPointsFound)) vs.SetName(vMyPolygon_handle, vMyPolygon_Name_org) # the original object name has to be reassigned vs.DSelectAll() vSelectionCriteria_MyPolygons = "INSYMBOL & INOBJECT & (L='LayerWithMyPolygons')" vs.ForEachObject(searchPoints_for_MyPolygon,vSelectionCriteria_MyPolygons) vs.AlrtDialog('finished') best regards, relume Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.