2

I need to find out which polygon is having more area by filtering unique ID. the problem is I have 1000 of features which I need to find out highest occupied area for every unique value...

tp find out highest covered area

since I have 1000 of features I need to do in an automated way instead of finding out manually, please help me to solve with some Python script or by using field calculator queries.

3

Tested on QGIS 2.18 and QGIS 3.4

I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer...

Let's assume we have 10 features in "layer" accordingly, where each feature has a unique "Name" and mutual "Group" attributes, see image below.

input

With the following Query, it is possible to achieve the result

SELECT l.geometry, l.MosaicName, l.Name, MAX(ROUND(st_area(l.geometry), 2)) AS sqm
FROM Layer AS l
GROUP BY l.MosaicName
ORDER BY sqm DESC

Mind the CRS. Alternatively you can apply ROUND(st_area(st_transform(l.geometry,*SRID*)), 2) if you require area in square feets. Therefore, you have to have an SRID.

output

The output Virtual Layer will provide features with the biggest area in square meters in each group accordingly.

Answering @Gobinath's comment, you can Save As... a new shapefile going through a common procedure with Right mouse click over the Virtual Layer.

  • 1
    Thank You, @Taras. I got the results. – Gobinath Jun 3 at 14:34
  • " lol " ......... – snaileater Jun 3 at 15:13
  • Sorry, I know what do you mean @snaileater – Taras Jun 3 at 15:16
  • No need to be sorry then ... one way to play it in a more fair way would have been to put your completary elements in a comment ... – snaileater Jun 3 at 15:17
  • you are most likely right...indeed, honestly I was not willing to still your thoughts. Shall I do it though? – Taras Jun 3 at 15:37
4

You can achieve this using the DB Manager of QGIS.

You choose Database / Database Manager / Database Manager then Virtual Layers / Qgis Layers you can then try queries like the following :

select area, max(st_area(geometry)) from your_layer_name
group by area_id

You have to adapt the attribute's name according to your data structure...

You can then load the result in QGIS layer manager.

  • Thanks @snaileater, It works for me but I have a little issue I would like to save as new shape-file (which I queried) with all columns. The issue is it only returning the two column so How do I do that ? – Gobinath Jun 3 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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