0

I have OSM .shp file of buildings. I created vertices along each line of the building in that way: vertices (red) & mid points (green). The mid points made by ST_Line_Interpolate_Point() after breaking the buildings to lines.

I have single location (blue star) from which I want to make lines to all vertices, such that the lines not intersects the buildings (blue lines OK, black lines NOT OK).

enter image description here

I started that way:

WITH cross_lines AS (
  SELECT DISTINCT ST_MakeLine(vertices.geom, ST_GeomFromText('POINT(lon lat)', 4326)) AS lines_geom
  FROM vertices, buildings  --vertices are green+red
)
SELECT DISTINCT cross_lines.lines_geom
FROM cross_lines, buildings
WHERE ST_Touches(cross_lines.lines_geom, buildings.geom);

The result is as follows:

  1. I use ST_Touches and not ST_Intersects because from some reason it gives me best results. It gives me almost all the lines but-
  2. It ignores the mid points made by ST_Line_Interpolate_Point() (green).

Is it possible ST_Line_Interpolate_Point not locating points exactly on the lines of the buildings?

  • I would create a temporary table where building polygons would have real materialized vertices at the midpoints. Now you rely on that ST_Line_Interpolate_Point and ST_Touches are doing floating point computing so that the result is equal to the last bit. – user30184 Aug 22 '15 at 15:30
  • @user30184 Thnaks, How can I create such table with "materialized vertices"? – michael Aug 29 '15 at 5:08
  • 1
    Using temporary table was perhaps not so great idea. Better option would be to use ST_Snap as in gis.stackexchange.com/questions/160134/… but it may be a bit tricky to use in in-the-fly inside your query. – user30184 Aug 29 '15 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.