Home - General / All posts - Expand bounds of Voronoi drawing?
 boomerbubba15 post(s) #16-Jul-14 21:19 I have created a Voronoi area drawing from a point drawing X successfully, either by using the Transform tool in the Manifold user interface or by using the Voronoi function in SQL spatial extensions. Either way, the resulting drawing is clipped or bounded by a rectangle, the dimensions of which I don't understand.My problem is that I wish to use the areas to select points from a different point drawing Y to group sets of points in Y where the Voronoi areas define their nearest X point with the a "SELECT * FROM X, Y WHERE Contains(X.[ID], Y.[ID)" statement. But one of my points in Y happens to lie outside the Voronoi drawing's outer rectangle so the SELECT misses it. Presumably, other points might also be missed someday.Curiously, the Nearest Neighbor Transform, which otherwise agrees completely with the Voronoi areas for all points in Y that lie inside the bounded rectangle, correctly links the orphan point to what obviously is its corresponding X point.Is there a way to force creation of a Voronoi drawing with a larger bounding rectangle? I have played with the tolerance parameter of the Voronoi function. But whatever this parameter is (?), I cannot get it to produce a larger drawing.
 ColinD1,973 post(s) #16-Jul-14 23:11 Check out this linkhttp://www.georeference.org/forum/t88464.11 Aussie Nature Shots
 boomerbubba15 post(s) #20-Jul-14 00:33 Thanks. Worked for me.It's a little more complex than I really need because I only have one area (which I defined by a bounding box drawing created for this purpose) rather than a set of areas to worry about. But I like the generality of this method.
 oeaulong261 post(s) #18-Jul-14 22:11 Not to detract from the reference from ColinD. I simply use 4 points, dummy points added to the set of points normally used. Depending on how you might trim it to a smaller polygon later would help figure how far out the dummy points are placed. Some post-Voronoi minor deletion that is fairly visual to remove the extraneous area records and dummy points and prep for your clipping transform.
 fani_197416 post(s) #30-Jul-14 12:59 hi all,I am trying to use the same script mention by ColinD Script runs for only one polygon and then it gives me a syntax error. I have no idea what is wrong.any suggestions.
 tjhb9,409 post(s) #30-Jul-14 22:30 The code in that thread is not scripts but queries (SQL).
 fani_197416 post(s) #31-Jul-14 09:25 thanks for your reply and i have tried now with queries and got the same output.Attached is the map file in which i am trying to use this queries.Can you please have a look and explain what exactly i am doing wrong.Attachments: Voronoi and ClipIntersect Objective.map
 tjhb9,409 post(s) #31-Jul-14 09:47 [I misunderstood here. Still looking.]
 tjhb9,409 post(s) #31-Jul-14 11:22 I agree there's something odd here. I need to sleep on it to figure out what.
 tjhb9,409 post(s) #31-Jul-14 12:30 I haven't found the problem with the old query yet. I will. (At first sight it doesn't seem to do what it used to do. Some behaviour may have changed within Manifold--or more likely I am making a mistake.)In the meantime, here's a better query to do the same thing. It does what we would expect (and is slightly more robust, and quicker).That is, it subdivides each area that containing one or more points, into the parts lying closest to each such point. In other words, it draws internal Voronoi areas.OPTIONS COORDSYS("Areas" AS COMPONENT);SELECT [ID], --[Area], ClipIntersect([Region], [Area]) AS [Subdivision]FROM (SELECT   [ID], [Area],  Voronoi([Point set]) AS [Regions] FROM  (SELECT   [ID], [Area],   AllCoords(    CASE [Pivot].[Position]     WHEN "inner" THEN Project([Inner points], COORDSYS("Areas" AS COMPONENT))      -- points inside this area     WHEN "outer" THEN ConvertToPoint(Scale(BoundingBox([Area]), 3))      -- scaled peripheral points (note 1)    END    ) AS [Point set]  FROM   (SELECT    [A].[ID], [A].[Geom (I)] AS [Area],    AllCoords([P].[ID]) AS [Inner points]   FROM    (SELECT * FROM [Areas]    WHERE IsArea([ID])    ) AS [A]    INNER JOIN    (SELECT * FROM [Points]     WHERE IsPoint([ID])    ) AS [P]    ON Touches([A].[ID], [P].[ID])    AND NOT Adjacent([A].[ID], [P].[ID])   GROUP BY [A].[ID], [A].[Geom (I)]   )   CROSS JOIN   (VALUES ("inner"), ("outer") NAMES ([Position])) AS [Pivot]  GROUP BY [ID], [Area]  ) )SPLIT BY Branches([Regions]) AS [Region]LEAVING Touches([Region], [Area]);-- Note 1-- Scaling the area's bounding box by 3-- ensures that every point within the area-- lies at least as close to every other such point-- as to any point on the outer edge-- (Think of a circle drawn about any point-- on the edge of the unscaled bounding box-- with radius equal to its width or height)Attachments: Subdivide areas by points b.txt
 fani_197416 post(s) #31-Jul-14 13:22 hi tjhb,I have tried this new query as well and it is also not working It is really strange. This may be version problem? I am using Manifold 8.0 build 8.0.29.0 on Windows Server 2008 (German) with service pack 1.Any ideas?
 tjhb9,409 post(s) #31-Jul-14 13:43 The new query is working as it should, and the old query works correctly (though inefficiently) if adjusted as below.So the problem is likely to be elsewhere.Can you say what you're trying to do, and with what data?It would also help if you could expand on what you mean by "not working". The two reports above—Script runs for only one polygon and then it gives me a syntax errori have tried now with queries and got the same output—frankly don't sound right. The most important thing is to say what you are trying to do. (And possibly post some sample data.)
 tjhb9,409 post(s) #31-Jul-14 13:26 There was (in a sense) no problem with the old query. It simply didn't check that the areas drawing only contained areas, and the points drawing only contained points. In the sample data, the points drawing in fact contains several areas as well as points--a sample of the desired output. I had made a change to filter them out--but wrongly. Here is how it should be.OPTIONS COORDSYS("Areas" AS COMPONENT);SELECT [ID], ClipIntersect([Branch], [Area]) AS [Region]FROM (SELECT   [ID], [Geom (I)] AS [Area],  Voronoi(AllCoords([P])) AS [Branches] FROM  (  SELECT   [A].[ID], [A].[Geom (I)],   Project([P].[ID], COORDSYS("Areas" AS COMPONENT)) AS [P]  FROM   (SELECT * FROM [Areas]    WHERE IsArea([ID])   ) AS [A]   INNER JOIN   (SELECT * FROM [Points]    WHERE IsPoint([ID])   ) AS [P]   ON Touches([A].[ID], [P].[ID])  UNION  SELECT   [A].[ID], [A].[Geom (I)],   ConvertToPoint(Scale(BoundingBox([A].[ID]), 3))  FROM   (SELECT * FROM [Areas]    WHERE IsArea([ID])   ) AS [A]   INNER JOIN   (SELECT * FROM [Points]    WHERE IsPoint([ID])   ) AS [P]   ON Touches([A].[ID], [P].[ID])  ) GROUP BY [ID], [Geom (I)] )SPLIT BY Branches([Branches]) AS [Branch]LEAVING Touches([Branch], [Area]);In any case, this query is inefficient (using joins is wasteful). The new query is better written and more efficient. (And it too does check that points are just points and areas just areas.)By the way I apologise for the skinny indenting. This seems to be an Internet Explorer thing (I usually use Firefox, which does it better).Attachments: Subdivide areas by points a corrected.txt
 fani_197416 post(s) #31-Jul-14 13:51 At last query runs with out any errors and created a table with ID and Geometry column name "Region".Can you please explain how to convert this table to a shapefile as i want to see the output polygons.Thanks a lot of for you efforts for improving this query, i am sure it will help lot of other people as well.
 fani_197416 post(s) #31-Jul-14 15:28 here is manifold project as you have asked in your last post.Attachments: myproj2.map
 oeaulong261 post(s) #31-Jul-14 22:01 The best way is to link to the same manifold map choosing the query as a table with Geometry column.This gets you a drawing linked to the query results.See the manifold page for more.http://www.georeference.org/doc/create_a_linked_drawing_from_a_geocoded_table.htm
 fani_197416 post(s) #01-Aug-14 08:49 Thanks oeaulong, that works, i think i have to spend more time on Manifold.