1

I have a new polyline and need to remove duplicating parts from it. New polyline is compared to other polylines stored in PostGIS table.

I have a query that removes duplicates from line newTrack comparing it to existTrack.

SELECT ST_AsGeoJSON(ST_Difference(newTrack.newGeo::geometry, existTrack.existGeo::geometry))
FROM (SELECT geography as newGeo
    FROM binndr_road
    WHERE id = 39267) as newTrack,
    (SELECT geography as existGeo
    FROM binndr_road
    WHERE id = 39274) as existTrack;

But I have no idea how to compare newTrack with all lines stored in the table.

1

You need to Union the Existing Tracks like this:

SELECT ST_AsGeoJSON(ST_Difference(newTrack.newGeo::geometry, existTrack.existGeo::geometry))
FROM
(
    SELECT geography as newGeo
    FROM binndr_road
    WHERE id = 39267
) as newTrack,
(
    SELECT ST_UNION(geography) as existGeo
    FROM binndr_road
    WHERE id != 39267
) as existTrack;

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.