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

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

Hi,

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.

vincent

1,972 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 :

--SQL

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

vincent

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

I went on this old thread : http://www.georeference.org/forum/t105858.15#105925 and came with this:

UPDATE (

    SELECT [Surface_Sel][CellCenter]

    FROM [Drawing],

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

                 AssignCoordSys(

                    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 ?

tjhb
10,094 post(s)
#04-Dec-18 18:35

How about

SELECT

    --[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.

vincent

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

I was missing the obvious, clearly.

Thanks Tim !

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