Giter Club home page Giter Club logo

Comments (3)

mbostock avatar mbostock commented on May 14, 2024

Are you confusing d3.geoArea from d3-geo with d3.polygonArea from this repository, d3-polygon?

d3.geoArea takes a GeoJSON object as input, and assumes it is in spherical coordinates (x = longitude and y = latitude in degrees). It computes the spherical area the GeoJSON object.

path.area also takes a GeoJSON object as input, but you can use path.projection to project the GeoJSON object before computing its planar area. Most commonly this is used to project spherical geometry to planar geometry, but if the projection is null or a d3.geoIdentity instance, you can pass planar geometry to path.area and it will compute the (possibly transformed) planar area.

Lastly d3.polygonArea only accepts an array of coordinates representing a ring as input. (This common definition of a polygon is simpler than the one GeoJSON uses, as the GeoJSON definition allows polygons to have holes.)

If you have a spherical GeoJSON MultiPolygon geometry object and you want to compute the spherical area of a constituent polygon, you’ll need to do something like this:

// Given a MultiPolygon GeoJSON geometry object…
var multiPolygon = {type: "MultiPolygon", coordinates: []};

// Construct a Polygon GeoJSON geometry object from the multipolygon.
var polygon0 = {type: "Polygon", coordinates: multiPolygon.coordinates[0]};

// Compute the spherical area of that polygon.
var area = d3.geoArea(polygon0);

Please use Stack Overflow tag d3.js to ask for help. Although I make an effort to assist everyone that asks, I am not always available to provide help promptly or directly. Stack Overflow provides a better collaborative forum for self-help: tens of thousands of D3-related questions have already been asked there, and some answered questions may be relevant to you.

When asking for help, please include a link to a live example that demonstrates the issue, preferably on bl.ocks.org. It is often impossible to debug from code snippets alone. Isolate the issue and reduce your code as much as possible before asking for help. The less code you post, the easier it is for someone to debug, and the more likely you are to get a helpful response.

If you have a question about D3’s behavior and want to discuss it with other users, also consider the d3-js Google Group or joining the d3-js Slack.

Thank you! 🤗

from d3-polygon.

katossky avatar katossky commented on May 14, 2024

Thank you for untangling the d3.geoArea, path.area and d3.polygonArea functions. I may have opened this issue at the wrong location.

But I was not looking for help :) I was just suggesting that d3.geoArea too could work directly with a list of coordinates. (Although I also get your point that it's not that difficult to work around, it took me quite a while to figure out how to do it.)

from d3-polygon.

mbostock avatar mbostock commented on May 14, 2024

d3.geoArea takes a GeoJSON object. An array of coordinates is not a GeoJSON object, and it would be difficult to infer what type of geometry an array of coordinates represents (ring, polygon, multipolygon, etc.). That’s kind of the point of GeoJSON: to tell you what an array of coordinates represents.

from d3-polygon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.