2

I'm using ST_MakeEnvelope in PostGIS to try and make geometries that cross the international dateline (antimeridian), but they are making a shape that wraps the other way around the globe.

The geometry I want is one which covers the eastern half of Australia and the dateline.

It looks something like:

ST_MakeEnvelope(133, -49, -170, 0, 4283)

But:

ST_Intersects(ST_SetSRID(ST_MakePoint(150, -25), 4283), ST_MakeEnvelope(133, -49, -170, 0, 4283));

returns false. The shape goes the wrong way around the world!

If I just take:

ST_Intersects(ST_SetSRID(ST_MakePoint(150, -25), 4283), ST_MakeEnvelope(133, -49, 180,v0, 4283));

I get true, as expected.

How can I set a direction to my envelope? Or should I create a polygon some other way?

(If you're wondering: I'm trying to select geometries in a table for a map view, and when the view includes the dateline, nothing is shown on the map)

[ETA]

If it helps, the box actually arrives in Spherical Mercator, looking something like:

14855319.859171, -6294627.0589708, 21149946.918142, 0

But calling ST_Transform:

st_transform(st_makeenvelope(14855319.859171, -6294627.0589708, 21149946.918142, 0, 900913), 4283)

Results in geometries with the negative-valued longitudes:

SRID=4283;POLYGON((133.447608799776 -49.1163523261112,133.447608799776 0,-170.006794251165 0,-170.006794251165 -49.1163523261112,133.447608799776 -49.1163523261112))
2

2 Answers 2

1

For an ordinary grid -180/180 use the geography, just check the command maybe you will need to switch to ST_makebox2D.

Otherwise if dealing with regions around the -180/180 it is better to switch to a 0/360° or consider using another projection.

0

Running your query in QGis I got the following result : QGis Envelope and Point

Aso, the make envelope parameters are wrong. The function description states : "'args: xmin, ymin, xmax, ymax, srid=unknown - Creates a rectangular Polygon formed from the given minimums and maximums. Input values must be in SRS specified by the SRID.'".

Running the following query you can verify that the function actually fixes this issue :

WITH 
    ENVELOPE AS ( select ST_MakeEnvelope(133, -49, -170, 0, 4283) AS geom),
    POINT AS (select ST_SetSRID(ST_MakePoint(150, -25), 4283) as geom)
SELECT 
    st_xmin(ENVELOPE.geom) AS X_MIN,
    st_ymin(ENVELOPE.geom) AS Y_MIN,
    st_xmax(ENVELOPE.geom) AS X_MAX,
    st_ymax(ENVELOPE.geom) AS Y_MAX,
    st_xmin(POINT.geom) AS POINT_X,
    st_ymin(POINT.geom) AS POINT_Y
FROM ENVELOPE, POINT;

But, as you can see from the result, your point's X coordinate is outside Xmin and Xmax (150 > 133 > -170), so ST_intersects will always return false..

Also, take a look at the EPSG:4283 and the EPSG:4326 projections, and set your envelope's coordinates accordingly.

1
  • If you look at my edit, you'll see I only get those SRID 4283 values from ST_Transform. In spherical mercator the coordinates are correct, in that the third is larger than the first, and the fourth larger than the second. Perhaps there is something I need to be telling ST_Transform?
    – Cathy
    Mar 4, 2014 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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