Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geo Voronoi polygons out of triangles #11

Closed
misha-panyushkin opened this issue Sep 5, 2018 · 4 comments
Closed

Geo Voronoi polygons out of triangles #11

misha-panyushkin opened this issue Sep 5, 2018 · 4 comments

Comments

@misha-panyushkin
Copy link

Hi,
I'm trying to build Voronoi diagram for "infinite horizon" map. The points - are the cities with defined coordinates [lat, lon].

Input: geoJSON

{
  "features": [
    {
      "geometry": {
        "coordinates": [
          2.1699187,
          41.387917
        ],
        "type": "Point"
      },
      "properties": {},
      "type": "Feature"
    },
    {
      "geometry": {
        "coordinates": [
          7.205232,
          43.66049
        ],
        "type": "Point"
      },
      "properties": {},
      "type": "Feature"
    },
    {
      "geometry": {
        "coordinates": [
          12.4942486,
          41.8905198
        ],
        "type": "Point"
      },
      "properties": {},
      "type": "Feature"
    }
  ],
  "type": "FeatureCollection"
}

Links d3.geoVoronoi(geoJSON).links()
image
Triangles d3.geoVoronoi(geoJSON).triangles()
image
Polygons d3.geoVoronoi(geoJSON).polygons()
image

Can't understand what I'm doing wrong. I will appreciate any help on these.

@Fil
Copy link
Owner

Fil commented Sep 6, 2018

You're not doing anything wrong! The reason for the bad display is that D3 doesn't have the same definition of geojson as the others. (See the introduction in https://github.com/d3/d3-geo).

In d3-geo, all the lines follow the geodesic lines (great circles), and they don't need to be cut at the antimeridian (longitude=180°).

To convert your results to the standard geojson you can use the d3.geoProject utility from https://github.com/d3/d3-geo-projection and do this:

projected = d3.geoProject(
  d3.geoProject(
    polygons,
    d3
      .geoEquirectangular()
      .scale(180 / Math.PI)
      .translate([0, 0])
  ),
  d3.geoIdentity().reflectY(true)
)

After this operation you should be able to see the features correctly.
https://gist.github.com/Fil/f67b0f6ccfa1f072c555775e331c307b

As you can see if you inspect the resulting structure, one of the polygons has been transformed to a multipolygon, which doesn't make sense from a topological point of view… and that is basically the explanation for this (very inconvenient) difference.

We should probably offer a simpler API for this "solution".

@Fil Fil closed this as completed Sep 6, 2018
@Fil
Copy link
Owner

Fil commented Sep 6, 2018

Another reference here: d3/d3-geo#104

@misha-panyushkin
Copy link
Author

@Fil many thanks! I've spent a lot of time finding solution. And now I understand the correct approach!

@misha-panyushkin
Copy link
Author

image

@energizer77 energizer77 mentioned this issue Oct 18, 2022
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants