Help creating "corridors"

Peter Borissow peter.borissow at kartographia.com
Sat Feb 8 16:19:12 PST 2025


Here's an example of how I create a buffer, in meters, around a point. Point is in WGS84 (EPSG:4326) and "20" is in meters. 900913 is a (probably obsolete) code for Google Maps Global Mercator (Spherical Mercator in meters)

    select
      st_transform(
        st_buffer(
          st_transform(
            ST_GeomFromText('POINT(39.04307785563378 -77.10195383651495)', 4326), 900913
          ), 20
        ), 4326
      )
    as geom

BTW, if you're using leaflet or openlayers you can do everything you want using javascript. Check out JSTS which is a javascript port of JTS. If I'm not mistaken PostGIS uses GEOS which is the C++ port of JTS.

Peter

-----Original Message-----
From: Luca Bertoncello <lucabert at lucabert.de> 
Sent: Saturday, February 8, 2025 9:16 AM
To: postgis-users at lists.osgeo.org
Subject: Re: Help creating "corridors"

Am 08.02.2025 um 14:11 schrieb Luca Bertoncello:

Hi again

> Now my problem is to create these "corridors", so let's say 20 km left 
> and 20 km right of the lines.
> In other words, I need to convert my lines in polygons, then export 
> them as GeoJSON.
> 
> And now the very question: how can I create these polygons?

Maybe I got something...

So I create two tables:

CREATE TABLE gafor_points
(
  gafor int,
  position int,
  coords geography(POINT)
);

CREATE TABLE gafor_routes
(
  gafor int,
  route geometry
);

In the first table I inserted the data I drawed with my simple Javascript script (see last message).
Then I converted them to the geometries:

INSERT INTO gafor_routes (SELECT gafor, ST_MakeLine(coords::geometry) from gafor_points group by gafor);

and then I create the corridors (example for GAFOR 10):
SELECT gafor, ST_AsGeoJSON(ST_Buffer(route, 0.2, 'endcap=square
join=bevel')) from gafor_routes where gafor = 10;

Now my question: as I said, I'd like to have the corridor 20km left and 20km right of the line.
I got it with the query, usind "0.2" as distance by ST_Buffer, but I got this value by "try and cry".
Reading the docs, the distance for ST_Buffer is:
------
For geometry, the distance is specified in the units of the Spatial Reference System of the geometry. For geography, the distance is specified in meters.
------
Since I use geometry for my route, the unit is the Spatial Reference System of the geometry.
With the query:

SELECT ST_SRID(route) from gafor_routes where gafor = 10;

I see, the system is 4326.

Now the very big question: how to convert meters in "unit of the Spatial Reference System"?

I searched for that, but I didn't found the answer...

Thanks a lot for your help!
Luca Bertoncello
(lucabert at lucabert.de)


More information about the postgis-users mailing list