Comments (3)
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.
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.
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)
- Circle intersection test HOT 1
- Point x and y accessors HOT 1
- More easily import polygon points HOT 1
- Why is Polygon.hull() result not counterclockwise ? HOT 2
- feature requests: polygon union, intersection, difference HOT 1
- broken link HOT 1
- Flipping flag for contain HOT 1
- How should a polygon be filled with a slash? HOT 2
- Merge into d3-geometry package? HOT 1
- Add concaveHull (in addition to convexHull) HOT 4
- Porting old function d3.geom.polygon to its newer version HOT 6
- segmentIntersect, lineIntersect?
- Rendering? HOT 1
- polygonContains should be uniform when testing the verteces of the polygon HOT 2
- Clipping? HOT 12
- Point-in-polygon test.
- Why do counterclockwise polygons have positive area? HOT 1
- would it make sense to have a "polygon contains polygon" method? HOT 3
- Hull issue (for v3) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-polygon.