Subscribe to this thread
Home - General / All posts - Counting pixels in overlapping area

1,741 post(s)
#04-Dec-18 16:36


I have a surface and a drawing containing one area. The area is smaller than the surface, but a part of it is not overlapping the surface. I would like to obtain the number of pixels that are in the overlapping portion.

I cannot find anything in SQL Raster Extension or Spatial Extension. Am I missing something obvious ?

How can I achieve that ?

Thank you.


1,741 post(s)
#04-Dec-18 17:01

I can make a map, transfer selection than run the following query, but I would like something more straightforward :


Select Count([Height (I)]from [surface] where [Selection Mask (I)] = 1 and [Invisible (I)] = False


1,741 post(s)
#04-Dec-18 17:24

I went on this old thread : and came with this:


    SELECT [Surface_Sel][CellCenter]

    FROM [Drawing],

        ( SELECT [Surface].[Selection (I)] AS [Surface_Sel]


                    NewPoint([Surface].[Center X (I)],[Surface].[Center Y (I)]),

                    COORDSYS("Surface" AS COMPONENT) ) As [CellCenter]

        FROM [Surface] where [Invisible (I)] = False)

    WHERE Contains([Drawing].[ID],[CellCenter]))

SET [Surface_Sel] = True

It should be ok to select the wanted pixels.

I still need a second query to count the selected pixels.

Any better way ?


8,516 post(s)
#04-Dec-18 18:35

How about


    --[ID], [Geom (I)],

    HeightSum([Surface][Geom (I)]) / HeightAvg([Surface][Geom (I)])

        AS [n pixels]

FROM [Drawing]

--GROUP BY [ID], [Geom (I)]


That should be fast, no selection needed.


1,741 post(s)
#04-Dec-18 20:11

I was missing the obvious, clearly.

Thanks Tim !

Manifold User Community Use Agreement Copyright (C) 2007-2017 Manifold Software Limited. All rights reserved.