# Intersect polygons (in planar coords) with polygons (in geo coords).

**URL:** https://talk.observablehq.com/t/intersect-polygons-in-planar-coords-with-polygons-in-geo-coords/4987
**Category:** Help
**Created:** [April 27, 2021, 2:07pm UTC](https://talk.observablehq.com/t/intersect-polygons-in-planar-coords-with-polygons-in-geo-coords/4987 "2021-04-27T14:07:19Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![neocarto](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/neocarto/32/6554_2.png) [@neocarto](https://talk.observablehq.com/u/neocarto)
#### Post date: [April 27, 2021, 2:07pm UTC](https://talk.observablehq.com/t/intersect-polygons-in-planar-coords-with-polygons-in-geo-coords/4987/1 "2021-04-27T14:07:19Z")

</div>

Dear community, i want to intersect polygons (in planar coordinates) with polygons (in geo coordinates).

See [World Grids / neocarto / Observable](https://observablehq.com/d/d8d2d51551fe67a0)

Red hexagons are in planar coordinates (svg document). The Black polygon (world outline) is in geographical coordinates (lat, lon). What I want to do is intersect the red polygons (planar) with the black polygon (geo).

 ![map1](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/c/c3a48cee2ef59920bab0bc5d8c1271029a4797d7.png)

To solve that, I tried to unproject reds hexagons. It works in most cases. But at world scale, when dots are outside the sphere, I have some problems (as you can see)

 ![map2](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/e/e992c66e54361cc3a8a3904682598bab8f7f449b.png)

And when I try to project each points defining the world outline, the result is surprising…

 ![map3](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/d/dda5b785385a0a8ac3a0946fe5aac7cb7d063e87.png)

From a more general point of view, I need to convert geometries with planar coordinates (in the coordinates of the svg document) into geometries with lat,lon coordinates (from a geojson or topojson). And vice versa. This operation is easy for points with projection() and projection.invert(). Is there the same type of function ready to use for more complex geometries (polygons with holes, multipolygons, etc).

Well, I’m not sure to be clear. But any help is welcome 🙂

---

<div class="post-metadata">

### Author: ![mcmcclur](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mcmcclur/32/2364_2.png) [@mcmcclur](https://talk.observablehq.com/u/mcmcclur)
#### Post date: [April 27, 2021, 2:23pm UTC](https://talk.observablehq.com/t/intersect-polygons-in-planar-coords-with-polygons-in-geo-coords/4987/2 "2021-04-27T14:23:11Z")

</div>

Is there a computational reason you need to do this? Or, is it just for display purposes? If the latter, then perhaps you could accomplish your objective with a [clipPath](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/clipPath).

---

<div class="post-metadata">

### Author: ![neocarto](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/neocarto/32/6554_2.png) [@neocarto](https://talk.observablehq.com/u/neocarto)
#### Post date: [April 27, 2021, 2:44pm UTC](https://talk.observablehq.com/t/intersect-polygons-in-planar-coords-with-polygons-in-geo-coords/4987/3 "2021-04-27T14:44:55Z")

</div>

Yes. My idea is to allocate values according to polygons intersections. With Turf.js I gess.

 ![IMG_20210427_164307](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/6/67a434aa6fafe8ddca1087d0a9df8df12298df8c.jpeg)

---

<div class="post-metadata">

### Author: ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)
#### Post date: [April 27, 2021, 8:17pm UTC](https://talk.observablehq.com/t/intersect-polygons-in-planar-coords-with-polygons-in-geo-coords/4987/4 "2021-04-27T20:17:03Z")

</div>

Have you looked into d3-geo’s [clipping capabilities](https://github.com/d3/d3-geo#clipping)?

---

<div class="post-metadata">

### Author: ![neocarto](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/neocarto/32/6554_2.png) [@neocarto](https://talk.observablehq.com/u/neocarto)
#### Post date: [April 28, 2021, 7:20am UTC](https://talk.observablehq.com/t/intersect-polygons-in-planar-coords-with-polygons-in-geo-coords/4987/5 "2021-04-28T07:20:52Z")

</div>

Yes. But I was not able to solve my problem like that. I think my main problem is that I have 2 geometries with different coordinate system.

---

<div class="post-metadata">

### Author: ![neocarto](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/neocarto/32/6554_2.png) [@neocarto](https://talk.observablehq.com/u/neocarto)
#### Post date: [April 30, 2021, 7:07am UTC](https://talk.observablehq.com/t/intersect-polygons-in-planar-coords-with-polygons-in-geo-coords/4987/6 "2021-04-30T07:07:29Z")

</div>

Well. I found a solution. Final result available here [World Grids & some GIS operations / neocarto / Observable](https://observablehq.com/@neocartocnrs/world-grids-turf). Thanks to all 🙏
