# Extract polygons having certain number of points

**URL:** <https://forum.generic-mapping-tools.org/t/extract-polygons-having-certain-number-of-points/3980>\
**Category:** Q&A\
**Tags:** gmt\
**Created:** [May 31, 2023, 1:49pm UTC](https://forum.generic-mapping-tools.org/t/extract-polygons-having-certain-number-of-points/3980 "2023-05-31T13:49:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![piyushether](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/piyushether/32/87_2.png) [@piyushether](https://forum.generic-mapping-tools.org/u/piyushether)\
**Post date:** [May 31, 2023, 1:49pm UTC](https://forum.generic-mapping-tools.org/t/extract-polygons-having-certain-number-of-points/3980/1 "2023-05-31T13:49:27Z")

</div>

Hello!

I’ll be surprised if I can extract those polygons (from xx.gmtfile) having certain numbers of points (from yy.csv). I did the other way using `gmt select` to extract out the points for certain polygons, but I wonder if `GMT` can do the prior one. Thank you.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [May 31, 2023, 6:11pm UTC](https://forum.generic-mapping-tools.org/t/extract-polygons-having-certain-number-of-points/3980/2 "2023-05-31T18:11:01Z")

</div>

Yes 🙂

---

<div class="post-metadata">

**Author:** ![piyushether](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/piyushether/32/87_2.png) [@piyushether](https://forum.generic-mapping-tools.org/u/piyushether)\
**Post date:** [June 1, 2023, 12:51am UTC](https://forum.generic-mapping-tools.org/t/extract-polygons-having-certain-number-of-points/3980/3 "2023-06-01T00:51:58Z")

</div>

@PlanetGus, thank you for positive response. Could you suggest a command of ‘GMT’ can perform a task on a non-grid file?

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [June 1, 2023, 12:15pm UTC](https://forum.generic-mapping-tools.org/t/extract-polygons-having-certain-number-of-points/3980/4 "2023-06-01T12:15:15Z")

</div>

Can you be more clear on what you have and what you want?

From what I understand, you have :

- some polygons
- some points

And you want to know the number of points within each polygon.

Is that correct?

---

<div class="post-metadata">

**Author:** ![piyushether](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/piyushether/32/87_2.png) [@piyushether](https://forum.generic-mapping-tools.org/u/piyushether)\
**Post date:** [June 1, 2023, 12:59pm UTC](https://forum.generic-mapping-tools.org/t/extract-polygons-having-certain-number-of-points/3980/5 "2023-06-01T12:59:55Z")

</div>

Noooooo… @PlanetGus

I have two files.  
(1) multi polygon file having `.gmtfile` extension  
(2) point file in `.csv` format

I want to extract those polygons having a certain amount of points.  
For instance, extracting the polygons has more than 20 points. I hope I will clear here.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [June 1, 2023, 1:15pm UTC](https://forum.generic-mapping-tools.org/t/extract-polygons-having-certain-number-of-points/3980/6 "2023-06-01T13:15:48Z")

</div>

It looks like a job for `contour` with `-Q` and `-D`
