You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, I have an issue and a "hacked" solution that worked for me.
I have several (100) cities that I would like to color the county they are in based on a score that they are given in an array.
I call geoContains with the following parameters: geoContains(county, points). When mapped, several counties now "contain" New York City (pretty much the "rust belt" and along the northern border).
I dug through the code posted here and noticed the following issue when comparing it to Json topography data:
geoContains line 37: This is where the coordinates of the polygon are passed to the polygonContains (object.coordinates);
polygonContains line 2: This takes the length of the polygon array that was passed in (object.coordinates). For all polygons in the above-referenced Json file, the length of this array is 1 and it contains another array that has all the coordinates to create the polygon. This is where the error occurs.
I've gotten around this by passing the correct coordinates array into the polygonContains function rather than the array that holds the array or going through the geoContains function. It works beautifully.
I wanted to point this out as an issue and also give people the cause and eventual solution to the problem. I'm just a newb programmer (less than 6 months programming, self taught, and one week working in d3), so I am not sure if I am doing this correctly. I spent a lot of time combing the internet trying to figure out what was wrong, so I'm hoping the above helps someone else out.
The text was updated successfully, but these errors were encountered:
d3.geoContains expects WSG84 spherical coordinates (longitude, latitude), not projected coordinates.
Using polygonContains from https://github.com/d3/d3-polygon is a good solution, but as you've discovered it doesn't manage GeoJSON, only a flat list of the polygon’s vertices.
In GeoJSON, polygons are defined as the intersection of rings: if there are two rings, the second can represent a hole in the first (a lake inside a country).
I hope this clarifies the subject. Glad you found a solution that works for your case!
So, I have an issue and a "hacked" solution that worked for me.
I have several (100) cities that I would like to color the county they are in based on a score that they are given in an array.
I call geoContains with the following parameters: geoContains(county, points). When mapped, several counties now "contain" New York City (pretty much the "rust belt" and along the northern border).
I dug through the code posted here and noticed the following issue when comparing it to Json topography data:
geoContains line 37: This is where the coordinates of the polygon are passed to the polygonContains (object.coordinates);
polygonContains line 2: This takes the length of the polygon array that was passed in (object.coordinates). For all polygons in the above-referenced Json file, the length of this array is 1 and it contains another array that has all the coordinates to create the polygon. This is where the error occurs.
I've gotten around this by passing the correct coordinates array into the polygonContains function rather than the array that holds the array or going through the geoContains function. It works beautifully.
I wanted to point this out as an issue and also give people the cause and eventual solution to the problem. I'm just a newb programmer (less than 6 months programming, self taught, and one week working in d3), so I am not sure if I am doing this correctly. I spent a lot of time combing the internet trying to figure out what was wrong, so I'm hoping the above helps someone else out.
The text was updated successfully, but these errors were encountered: