score:2

Accepted answer

I ended up working off of project to bounding box and created a clipping path around the state I wanted to display.

NY State W/ Counties - Clipped

score:2

I know this is a very late answer. However, it might be helpful for other people in the future.

This is an example of how to extract one state from the USA map file:

<!DOCTYPE html>
<meta charset="utf-8">
<style>

path {
        fill: lightgray;
        stroke: #000000;
        stroke-width: 1.5;
        }


path:hover {
        fill:orange;
        cursor:pointer;
      }

#state-borders {
  fill: white;
  stroke: #000000;
  stroke-width: 10.5px;
  stroke-linejoin: round;
  stroke-linecap: round;
  pointer-events: none;
}


</style>
<body> 
  <script src="http://d3js.org/d3.v4.min.js" charset="utf-8"></script>
  <script src="https://d3js.org/topojson.v1.min.js"></script>
<script>

var width = 960,
    height = 500,
    centered;

var projection =  d3.geoAlbersUsa()
    .scale(1370)
    .translate([width / 2, height / 2]);

var path = d3.geoPath()
    .projection(projection);

var svg = d3.select("body").append("svg")
    .attr("width", width)
    .attr("height", height);


d3.json("us-counties-github.json",function(json){
  console.log(json);


    svg.selectAll("path")
       .attr("id", "state_fips")
       .data(topojson.feature(json, json.objects.collection).features.filter(function(d) { return d.properties.state_fips == 36; }))
       .enter()
       .append("path")
       .attr("d", path)
       .attr("stroke","white")
       .attr("fill", "gray");



    });
</script>

*I downloaded the dataset from https://raw.githubusercontent.com/deldersveld/topojson/master/countries/united-states/us-albers-counties.json "the counties are included in this file".

score:5

Once you've established your d3.json wrapper, you can use JavaScript filter method, so if your data has a'state' field:

d3.json(filename, function(error, data){ var single=data.filter(function(d){ return d.state==='Ohio';} }

And then use the new single variable as your data for d3


Related Query

More Query from same tag