Re: [postgis-users] [Raster] Finding pixels intersecting an extent (polygon)

2015-02-06 Thread Jean Marchal
For the posterity, I modified very slightly the query by changing the
returnband argument of ST_Intersection to return only one band.

WITH foo AS (
SELECT
ST_AsRaster(
ST_GeomFromText('POLYGON ((-52.54178994517749 46.99199259385565,
-52.54178994517749 46.996897959881, -52.53436080387823 46.996897959881,
-52.53436080387823 46.99199259385565, -52.54178994517749
46.99199259385565))', 4269),
rast,
'8BUI',
touched := True
) AS rast
FROM elev
LIMIT 1
)
SELECT
ST_Intersection(
elev.rast,
foo.rast,
'BAND1'
) AS rast
FROM elev
JOIN foo
ON ST_Intersects(elev.rast, foo.rast)

Thanks again,

Jean

2015-02-05 15:29 GMT-08:00 Jean Marchal jean.d.marc...@gmail.com:

 It worked! Thanks a lot!

 Jean

 2015-02-05 15:18 GMT-08:00 Bborie Park dustym...@gmail.com:

 Try something like:

 WITH foo AS (
 SELECT
 ST_AsRaster(
 ST_GeomFromText('POLYGON ((-52.54178994517749 46.99199259385565,
 -52.54178994517749 46.996897959881, -52.53436080387823 46.996897959881,
 -52.53436080387823 46.99199259385565, -52.54178994517749
 46.99199259385565))', 4269),
 rast,
 '8BUI',
 touched := True
 ) AS rast
 FROM elev
 LIMIT 1
 )
 SELECT
 ST_Intersection(
 elev.rast,
 foo.rast
 ) AS rast
 FROM elev
 JOIN foo
 ON ST_Intersects(elev.rast, foo.rast)

 The idea is to explicitly convert the geometry into a raster using one of
 the elev rasters as a reference. The touched := True slightly changes the
 behavior of the rasterization.

 From the docs:

 The optional touched parameter defaults to false and maps to the GDAL
 ALL_TOUCHED rasterization option, which determines if pixels touched by
 lines or polygons will be burned.

 On Thu, Feb 5, 2015 at 2:45 PM, Jean Marchal jean.d.marc...@gmail.com
 wrote:

 Bborie,

 I am running PostGIS 2.1.5. Here is the output of the
 postgis_full_version():

 POSTGIS=2.1.5 r13152 GEOS=3.3.3-CAPI-1.7.4 PROJ=Rel. 4.7.1, 23
 September 2009 GDAL=GDAL 1.9.0, released 2011/12/29 LIBXML=2.8.0
 LIBJSON=UNKNOWN RASTER

 My query looks like this:

 SELECT ST_Intersection(ST_GeomFromText('POLYGON ((-52.54178994517749
 46.99199259385565, -52.54178994517749 46.996897959881, -52.53436080387823
 46.996897959881, -52.53436080387823 46.99199259385565, -52.54178994517749
 46.99199259385565))', 4269), rast) as rast
 FROM elev

 David,

 This query does not returns all the polygons that intersect my polygon.
 I think it returns only those where the centroid is inside the polygon or
 is it covered based? (like 50% of the pixel intersect with the polygon).

 Thanks for your rapid answers!

 Jean

 2015-02-05 14:31 GMT-08:00 David Haynes hayne...@gmail.com:

 select ST_Clip(r.rast,p.geom) as rast
 from polygon p inner join raster r on ST_intersects(r.rast, p.geom)

 This returns a raster which has all pixels inside the polygon

 On Thu, Feb 5, 2015 at 4:05 PM, Jean Marchal jean.d.marc...@gmail.com
 wrote:

 Hi list,

 I am trying to return all the pixels in a raster that intersect (not
 just touch) an extent (say a rectangle). I tried ST_Clip and
 ST_Intersection(raster, geom) but they don't return all the pixels that
 intersect my extent polygon. Do I have to vectorize the raster first using
 ST_PixelAsPolygons or there is a better / more efficient way to proceed?

 Ultimately the goal is to fetch the resulting raster in R.

 Thanks,

 Jean

 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users



 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users



 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users



 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users



___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

Re: [postgis-users] [Raster] Finding pixels intersecting an extent (polygon)

2015-02-05 Thread Bborie Park
ST_Intersection(rast, geom) does vectorize the raster before intersecting
with the polygon. ST_Clip(rast, geom) rasterizes the polygon before
intersecting with the raster.

Can you provide more information? Such as the query and the version of
PostGIS?

-bborie

On Thu, Feb 5, 2015 at 2:05 PM, Jean Marchal jean.d.marc...@gmail.com
wrote:

 Hi list,

 I am trying to return all the pixels in a raster that intersect (not just
 touch) an extent (say a rectangle). I tried ST_Clip and
 ST_Intersection(raster, geom) but they don't return all the pixels that
 intersect my extent polygon. Do I have to vectorize the raster first using
 ST_PixelAsPolygons or there is a better / more efficient way to proceed?

 Ultimately the goal is to fetch the resulting raster in R.

 Thanks,

 Jean

 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

[postgis-users] [Raster] Finding pixels intersecting an extent (polygon)

2015-02-05 Thread Jean Marchal
Hi list,

I am trying to return all the pixels in a raster that intersect (not just
touch) an extent (say a rectangle). I tried ST_Clip and
ST_Intersection(raster, geom) but they don't return all the pixels that
intersect my extent polygon. Do I have to vectorize the raster first using
ST_PixelAsPolygons or there is a better / more efficient way to proceed?

Ultimately the goal is to fetch the resulting raster in R.

Thanks,

Jean
___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

Re: [postgis-users] [Raster] Finding pixels intersecting an extent (polygon)

2015-02-05 Thread David Haynes
select ST_Clip(r.rast,p.geom) as rast
from polygon p inner join raster r on ST_intersects(r.rast, p.geom)

This returns a raster which has all pixels inside the polygon

On Thu, Feb 5, 2015 at 4:05 PM, Jean Marchal jean.d.marc...@gmail.com
wrote:

 Hi list,

 I am trying to return all the pixels in a raster that intersect (not just
 touch) an extent (say a rectangle). I tried ST_Clip and
 ST_Intersection(raster, geom) but they don't return all the pixels that
 intersect my extent polygon. Do I have to vectorize the raster first using
 ST_PixelAsPolygons or there is a better / more efficient way to proceed?

 Ultimately the goal is to fetch the resulting raster in R.

 Thanks,

 Jean

 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

Re: [postgis-users] [Raster] Finding pixels intersecting an extent (polygon)

2015-02-05 Thread Bborie Park
Try something like:

WITH foo AS (
SELECT
ST_AsRaster(
ST_GeomFromText('POLYGON ((-52.54178994517749 46.99199259385565,
-52.54178994517749 46.996897959881, -52.53436080387823 46.996897959881,
-52.53436080387823 46.99199259385565, -52.54178994517749
46.99199259385565))', 4269),
rast,
'8BUI',
touched := True
) AS rast
FROM elev
LIMIT 1
)
SELECT
ST_Intersection(
elev.rast,
foo.rast
) AS rast
FROM elev
JOIN foo
ON ST_Intersects(elev.rast, foo.rast)

The idea is to explicitly convert the geometry into a raster using one of
the elev rasters as a reference. The touched := True slightly changes the
behavior of the rasterization.

From the docs:

The optional touched parameter defaults to false and maps to the GDAL
ALL_TOUCHED rasterization option, which determines if pixels touched by
lines or polygons will be burned.

On Thu, Feb 5, 2015 at 2:45 PM, Jean Marchal jean.d.marc...@gmail.com
wrote:

 Bborie,

 I am running PostGIS 2.1.5. Here is the output of the
 postgis_full_version():

 POSTGIS=2.1.5 r13152 GEOS=3.3.3-CAPI-1.7.4 PROJ=Rel. 4.7.1, 23
 September 2009 GDAL=GDAL 1.9.0, released 2011/12/29 LIBXML=2.8.0
 LIBJSON=UNKNOWN RASTER

 My query looks like this:

 SELECT ST_Intersection(ST_GeomFromText('POLYGON ((-52.54178994517749
 46.99199259385565, -52.54178994517749 46.996897959881, -52.53436080387823
 46.996897959881, -52.53436080387823 46.99199259385565, -52.54178994517749
 46.99199259385565))', 4269), rast) as rast
 FROM elev

 David,

 This query does not returns all the polygons that intersect my polygon. I
 think it returns only those where the centroid is inside the polygon or is
 it covered based? (like 50% of the pixel intersect with the polygon).

 Thanks for your rapid answers!

 Jean

 2015-02-05 14:31 GMT-08:00 David Haynes hayne...@gmail.com:

 select ST_Clip(r.rast,p.geom) as rast
 from polygon p inner join raster r on ST_intersects(r.rast, p.geom)

 This returns a raster which has all pixels inside the polygon

 On Thu, Feb 5, 2015 at 4:05 PM, Jean Marchal jean.d.marc...@gmail.com
 wrote:

 Hi list,

 I am trying to return all the pixels in a raster that intersect (not
 just touch) an extent (say a rectangle). I tried ST_Clip and
 ST_Intersection(raster, geom) but they don't return all the pixels that
 intersect my extent polygon. Do I have to vectorize the raster first using
 ST_PixelAsPolygons or there is a better / more efficient way to proceed?

 Ultimately the goal is to fetch the resulting raster in R.

 Thanks,

 Jean

 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users



 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users



 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

Re: [postgis-users] [Raster] Finding pixels intersecting an extent (polygon)

2015-02-05 Thread Jean Marchal
It worked! Thanks a lot!

Jean

2015-02-05 15:18 GMT-08:00 Bborie Park dustym...@gmail.com:

 Try something like:

 WITH foo AS (
 SELECT
 ST_AsRaster(
 ST_GeomFromText('POLYGON ((-52.54178994517749 46.99199259385565,
 -52.54178994517749 46.996897959881, -52.53436080387823 46.996897959881,
 -52.53436080387823 46.99199259385565, -52.54178994517749
 46.99199259385565))', 4269),
 rast,
 '8BUI',
 touched := True
 ) AS rast
 FROM elev
 LIMIT 1
 )
 SELECT
 ST_Intersection(
 elev.rast,
 foo.rast
 ) AS rast
 FROM elev
 JOIN foo
 ON ST_Intersects(elev.rast, foo.rast)

 The idea is to explicitly convert the geometry into a raster using one of
 the elev rasters as a reference. The touched := True slightly changes the
 behavior of the rasterization.

 From the docs:

 The optional touched parameter defaults to false and maps to the GDAL
 ALL_TOUCHED rasterization option, which determines if pixels touched by
 lines or polygons will be burned.

 On Thu, Feb 5, 2015 at 2:45 PM, Jean Marchal jean.d.marc...@gmail.com
 wrote:

 Bborie,

 I am running PostGIS 2.1.5. Here is the output of the
 postgis_full_version():

 POSTGIS=2.1.5 r13152 GEOS=3.3.3-CAPI-1.7.4 PROJ=Rel. 4.7.1, 23
 September 2009 GDAL=GDAL 1.9.0, released 2011/12/29 LIBXML=2.8.0
 LIBJSON=UNKNOWN RASTER

 My query looks like this:

 SELECT ST_Intersection(ST_GeomFromText('POLYGON ((-52.54178994517749
 46.99199259385565, -52.54178994517749 46.996897959881, -52.53436080387823
 46.996897959881, -52.53436080387823 46.99199259385565, -52.54178994517749
 46.99199259385565))', 4269), rast) as rast
 FROM elev

 David,

 This query does not returns all the polygons that intersect my polygon. I
 think it returns only those where the centroid is inside the polygon or is
 it covered based? (like 50% of the pixel intersect with the polygon).

 Thanks for your rapid answers!

 Jean

 2015-02-05 14:31 GMT-08:00 David Haynes hayne...@gmail.com:

 select ST_Clip(r.rast,p.geom) as rast
 from polygon p inner join raster r on ST_intersects(r.rast, p.geom)

 This returns a raster which has all pixels inside the polygon

 On Thu, Feb 5, 2015 at 4:05 PM, Jean Marchal jean.d.marc...@gmail.com
 wrote:

 Hi list,

 I am trying to return all the pixels in a raster that intersect (not
 just touch) an extent (say a rectangle). I tried ST_Clip and
 ST_Intersection(raster, geom) but they don't return all the pixels that
 intersect my extent polygon. Do I have to vectorize the raster first using
 ST_PixelAsPolygons or there is a better / more efficient way to proceed?

 Ultimately the goal is to fetch the resulting raster in R.

 Thanks,

 Jean

 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users



 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users



 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users



 ___
 postgis-users mailing list
 postgis-users@lists.osgeo.org
 http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

___
postgis-users mailing list
postgis-users@lists.osgeo.org
http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users