Skip to main content
2 of 2
replaced http://gis.stackexchange.com/ with https://gis.stackexchange.com/

It looks like you copied the SQL from here, but it is not clear that you need the ST_Transform to SRID of 2223. Use the SQL @kttii included in a comment, and replace the 2223 with that number.

The way you have it written with the && operator, you are comparing bounding boxes rather than the line itself. This may give you unexpected results if a line curves around a lot. I suspect you would prefer ST_Intersects, so you would have something like this:

SELECT * 
FROM pipeline_denorm
WHERE 
  ST_Intersects(pipeline_denorm.wkb_geometry,
     ST_MakeEnvelope(-121.76986352563478, 
                      37.85809027719253, 
                     -121.19308129907228, 
                      38.07462286323802, 
                      4326
                    )
                );

You only need to add the ST_Transform if the SRID of the wkb_geometry column is different than 4326.

Nate Wanner
  • 1.6k
  • 9
  • 16