# Polygon Contains Cartographic

**URL:** <https://community.cesium.com/t/polygon-contains-cartographic/9172>\
**Category:** CesiumJS\
**Created:** [March 18, 2020, 2:56pm UTC](https://community.cesium.com/t/polygon-contains-cartographic/9172 "2020-03-18T14:56:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chet.brittingham](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/chet.brittingham/32/2023_2.png) [@chet.brittingham](https://community.cesium.com/u/chet.brittingham)\
**Post date:** [March 18, 2020, 2:56pm UTC](https://community.cesium.com/t/polygon-contains-cartographic/9172/1 "2020-03-18T14:56:20Z")

</div>

**I see that Rectangle has a “contains” method that will tell you if a cartographic location is inside the rectangle.**

**Does anyone have a suggestion on how to accomplish this with a Polygon?**

---

<div class="post-metadata">

**Author:** ![omar](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/omar/32/1999_2.png) [@omar](https://community.cesium.com/u/omar)\
**Post date:** [March 19, 2020, 12:15pm UTC](https://community.cesium.com/t/polygon-contains-cartographic/9172/2 "2020-03-19T12:15:04Z")

</div>

There isn’t a built-in way to do this as far as I’m aware, but detecting if a point is inside a polygon is a common graphics operation (you’ll find a few different algorithms if you google that).

You could use a library like TurfJS and give it the coordinates of your polygons/points: [https://turfjs.org/docs/#pointsWithinPolygon](https://turfjs.org/docs/#pointsWithinPolygon)

What kind of application are you working on?

---

<div class="post-metadata">

**Author:** ![chet.brittingham](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/chet.brittingham/32/2023_2.png) [@chet.brittingham](https://community.cesium.com/u/chet.brittingham)\
**Post date:** [March 19, 2020, 3:50pm UTC](https://community.cesium.com/t/polygon-contains-cartographic/9172/3 "2020-03-19T15:50:38Z")

</div>

Thanks. I ended up finding turfjs after making this post.

I have found that turfjs doesn’t handle polygons that cross the antimeridian very well. (It works if you translate longitudes to 0-360, but not crossing from negative to positive.)

Handling the specific lat/lon boundary conditions is the main reason I was looking for a library.

This would be a nice feature to expand in cesium at some point.
