Saturday, 16 July 2016

Point sampling along a pole-wrapping coastline with PostGIS


I am working on a task that requires me to get sample points every 1000 km along coastlines, and have run into a problem with Antarctica. From what I can tell, it seems to be an issue with the use of geometry in the functions, when really I think geography should be used for this operation.


Using the function from this very similar question, I am able to produce a result that looks like this: bad result.


As you can see, ST_AddMeasure() and ST_LocateAlong() don't seem to treat the geometry spherically, which results in many points that sit on the South Pole. A point was even added on the clip along the date line (left side). Per the documentation of these two functions, only geometry can be used.


The code used to generate the polygon and the points can be found here, but this is the SQL used to generate the points:


CREATE TABLE atest AS WITH line AS 
(SELECT
id,
ST_ExteriorRing((ST_Dump(geom)).geom) AS geom

FROM line_sample_test),
linemeasure AS
(SELECT
ST_AddMeasure(line.geom, 0, (ST_Length(line.geom))::int) AS linem,
generate_series(0, (ST_Length(line.geom))::int, 10) AS i
FROM line),

geometries AS (
SELECT
i,

ST_LocateAlong(linem, i) AS geom
FROM linemeasure)

SELECT
* from geometries;

How can I generate points at every 1000 Km along this coastline?




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...