# D3 filter toposon by state id?

**URL:** <https://talk.observablehq.com/t/d3-filter-toposon-by-state-id/5044>\
**Category:** Help\
**Created:** [May 11, 2021, 12:20am UTC](https://talk.observablehq.com/t/d3-filter-toposon-by-state-id/5044 "2021-05-11T00:20:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheeMattOliver](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/theemattoliver/32/4959_2.png) [@TheeMattOliver](https://talk.observablehq.com/u/TheeMattOliver)\
**Post date:** [May 11, 2021, 12:20am UTC](https://talk.observablehq.com/t/d3-filter-toposon-by-state-id/5044/1 "2021-05-11T00:20:30Z")

</div>

I would like to filter the counties in the D3 topojson in the `topojson.feature()` call by state FIPS

Here’s the relevant code:

```
svg.append("g")
.selectAll("path")
.data(topojson.feature(geo, geo.objects.counties).features) // <-- this line would ideally be:
// .data(topojson.feature(geo, geo.objects.counties.geometries.filter(f => f.id.includes("48")).features) //
.join("path")
  .attr("fill", d => colorScale(turnoutPerc.get(d.id)))
  .attr("d", path)
.on('mousemove', (event,d) => {
  d3.select(event.currentTarget)
    .raise()
    .style('stroke', "#000")
    .style('stroke-width', 2)
    .style('cursor', 'pointer');

```

Currently, on hover, county geometry shapes in bordering states are visible, since those are technically still being drawn onto the canvas.

```
svg.append("g")
    .selectAll("path")
    .data(topojson.feature(geo, geo.objects.counties).features).filter(d => d.id.includes("48")) 

```

doesn’t work either.

Observable notebook [here](https://observablehq.com/@theemattoliver/filter-d3-albers-projection-by-state).

Would appreciate if someone could take a look! Thanks!

 ![Screen Shot 2021-05-10 at 7.20.57 PM](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/7/777db677cafd6571ca57d2467b69370cfa4fd894.png)

---

<div class="post-metadata">

**Author:** ![TheeMattOliver](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/theemattoliver/32/4959_2.png) [@TheeMattOliver](https://talk.observablehq.com/u/TheeMattOliver)\
**Post date:** [May 11, 2021, 11:47pm UTC](https://talk.observablehq.com/t/d3-filter-toposon-by-state-id/5044/2 "2021-05-11T23:47:59Z")

</div>

Solution:

`.data(topojson.feature(geo, geo.objects.counties).features.filter(d => d.id.slice(0, 2) === "48"))`
