Tuesday 25 April 2017

qgis - Finding pseudo nodes in free GIS software?


Software gvSIG OA Digital Edition 2010 have tools topology for finding pseudo nodes in linear geometry. I set cluster tolerance 0.00002 and maximum number of errors -10000 for 20000 link count linear geometry. But unsuccessful result.


Are there any solutions that find pseudo nodes in free GIS software?


I need to layer pseudo nodes (one solution to this problem - to use tools topology of ArcInfo, but priority for me is to use free software). Linear geometry created several users in QGIS 1.8.0 in PostGIS (v. 2.0.1) database.


Add new image: 12 linear features with three pseudo nodes in A (line 4/5), B (line 6/7), C (line 9/10). Pseudo nodes should be points instead - two linear features with intersection in one point (node) should be one linear feature (line 4/5 - line 4, ...).


Is it possible to make a request in PostGIS, which will result in a layer of pseudo nodes?


Add new image of examples pseudo nodes: if I receive for linear layer point layer pseudo nodes (blue rects) I corrected following errors in linear layer: A - add missing geometry, B - snapped line in intersection, C - remove pseudo node.


enter image description here


enter image description here



enter image description here



Answer



Here a generic soluion, that you can impĺement with PostGIS or any other OGC-compliant software.



NOTE: as I say before, a key concept in FOSS and GIS is standardization: the best solutions adopt standards, like OGC ones.





Your problem is to "find pseudo nodes"... But I think that it is a little more, "find non-pseudo nodes and join lines of pseudo nodes". My solution can be used for both.


OGC standards offer:





  • ST_Boundary(geom): to detect the nodes of the lines




  • ST_Dump(geom): to put each single node in a SQL table record.




  • ST_DWithin, ST_Equals, ST_SnapToGrid, ST_Snap can be used for change tolerance. I am using ST_DWithin.





We can suppose that your main problem can be specified with these objects and properties,




  • there are only line segments (of a table linesegment), represented by a LINESTRING geometry... I not tested with MULTILNE, if you have geometrytype=MULTIPOINT, you can split and cast MULTILINEs with ST_Dump and ST_LineMerge;




  • each line segment have a (geometry ID) gid and a (color ID) idline.




So, the first step is to obtain the nodes that comes from joining lines,



CREATE TABLE cache_bounds AS
SELECT gid as gid_seg, (ST_Dump(ST_Boundary(the_geom))).geom AS the_geom,
gid as color
-- if you not have something for "color label" of lines, use gid.
FROM linesegment;
ALTER TABLE cache_bounds ADD column gid serial PRIMARY KEY;

CREATE TABLE cache_joinnodes AS
-- Use your TOLERANCE instead "1" at ST_DWithin and ST_Buffer.
SELECT *, array_length(colors,1) as ncolors FROM (

SELECT gid, array_distinct(array_cat(a_colors,b_colors)) as colors, the_geom FROM (
SELECT
a.gid, array_agg(a.color) as a_colors, array_agg(b.color) as b_colors
, st_buffer(a.the_geom,1) as the_geom -- any one to represent the join point.
FROM cache_bounds a, cache_bounds b
WHERE a.gid>b.gid AND ST_DWithin(a.the_geom,b.the_geom,1)
-- use ST_equals(a.the_geom,b.the_geom) if no tolerance.
GROUP BY a.gid, a.the_geom
) as t
) as t2;


NOTE: using caches because they are faster than views. Use "EXPLAIN SELECT ..." to check CPU time, it can take a long time.


Here cycles and continuous (same color) lines are detected as ncolors=1 points, and the pseudo nodes by ncolors=2 points, so, you have a layer with that points.


Your table of "good nodes" is with the original "bounding points" and without "pseudo nodes".


CREATE VIEW vw_joinnodes_full AS
SELECT b.*, j.ncolors
FROM cache_joinnodes j INNER JOIN cache_bounds b
ON j.gid=b.gid;

CREATE TABLE cache_good_nodes AS

SELECT *
FROM vw_joinnodes_full
WHERE ncolors=1 OR ncolors>2;

-- IF NEED ... CREATE VIEW vw_correct_linesegment AS ...

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...