Filter by Point in Polygon and Return County Name

Visto 17 veces
Saltar al primer mensaje no leído

Zac Rinehart

no leída,
22 mar 2017, 1:10:5022/3/17
a d3-js
Hey I'm using topojson to create a map, I also have user inputs for lat/long. With this, I'd like to create a function that returns the FIPS id of the county when the user clicks search. I tried two approaches:
First:

var containing_county = us.objects.counties.geometries.filter(function(polygon) {
       
return d3.polygonContains(polygon, [long.value, lat.value]);
   
});
   console
.log(containing_county)
 
});

And then:
   var containing_county = topojson.feature(us, us.objects.counties).features.filter(function(d) { 
return d3.polygonContains(d.geometry, [long.value, lat.value]);
   console
.log(containing_county)
   
});
What should this filter look like? 

Minimalist block here (might have to full screen it to see inputs):
https://bl.ocks.org/diggetybo/6d35e5ecd17992650d0a23896e649b25

sandeep edara

no leída,
22 mar 2017, 2:22:3122/3/17
a d3-js

Hi Zac,

Have created a block with a solution,
Tested using following lat : 39.99 and long : -109.99


Regards,
Sandeep.
Se ha eliminado el mensaje

Zac Rinehart

no leída,
22 mar 2017, 2:38:5522/3/17
a d3-js
Wow, great work. I'm looking over it now to see how you did it. Thanks so much!
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos