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

reverse an arc #14

Open
pedro-vicente opened this issue Jun 25, 2018 · 8 comments
Open

reverse an arc #14

pedro-vicente opened this issue Jun 25, 2018 · 8 comments

Comments

@pedro-vicente
Copy link

The spec says

A negative arc index indicates that the arc at the ones’ complement of the index must be reversed to reconstruct the geometry: -1 refers to the reversed first arc,

what does it mean a "reversed arc"? how do you reverse an arc?

@scardine
Copy link

Does it has to do with polygons containing holes? I remember reading something like "if the main polygon is clockwise the hole must be conter-clockwise" or something like that but can't remember where.

@mbostock
Copy link
Member

(No, it’s not related to holes.)

TopoJSON allows you to reference a reversed arc in a geometry so that when geometries share an arc, but some geometries need the arc in the opposite direction, the geometries can reference the same arc.

This occurs very commonly when you have neighboring geometries. For example, California and Nevada share a border, but given that both would typically have the same winding order, the shared border must be reversed between the two polygons if you want to share the arc. You could avoid reversing arcs if you don’t care about sharing arcs between neighboring polygons, but that would largely defeat the benefit of a topological geometry format.

A reversed arc means that rather than the arc’s points going p_0, p_1, … p_n, the points go p_n, p_{n-1}, … p_0.

@pedro-vicente
Copy link
Author

pedro-vicente commented Jun 25, 2018

@mbostock
thank you. I did a topojson library and I think that was the missing thing. On polygons that have reversed arcs I was having strange results , like the points "jumping" out of sequence to the other side of the polygon.
see the attached image example
untitled

@mbostock
Copy link
Member

Nice! Yes, it looks like you need to reverse the subsequences of points represented by the negative arc indexes.

@pedro-vicente
Copy link
Author

pedro-vicente commented Jun 25, 2018

@mbostock
thanks. If you want to give it a try, it's here,

https://github.com/pedro-vicente/render_geojson

I did this graphical interface just to debug this issue. The 2 green arrows in the toolbar allow to navigate polygons and points inside each polygon (at the moment only polygons are rendered)

the example in the image is czech-republic-regions.topojson. It includes the examples from the topojson page too.

@pedro-vicente
Copy link
Author

@mbostock
Phew, this was a tough cookie. I was doing an arc reversal before the point transformation (the transformation where index 0 is absolute coordinates, and next indices are deltas).
Of course the reversal has to be done after the coordinates transformation (from the scale and transform)

@pedro-vicente
Copy link
Author

so, after this all looks good

untitled

@pedro-vicente
Copy link
Author

and here the us.json file (US counties), rendering by the Wt web toolkit (with a made Leaflet branch)
https://github.com/pedro-vicente/wt

untitled2

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

3 participants