Comments (5)
Wow, thank you so much for your work. This is excellent! Many thanks!
from topojson.
You are right. I can reproduce this with solely StrataID
is 2
as well:
strata_data = strata_data[strata_data.StrataID.isin(["2"])]
strata_data.plot(categorical=True, cmap='tab10', legend=True, column='StrataID', alpha=0.6)
and
(
tp.Topology(strata_data, prequantize=False)
.to_gdf()
.plot(categorical=True, cmap='tab10', legend=True, column='StrataID', alpha=0.6)
)
The good thing though, is that it serialise OK into altair:
tp.Topology(strata_data, prequantize=False).to_alt(color='properties.StrataID:N')
from topojson.
Simplified example to continue testing:
from shapely import geometry
import topojson as tp
mp = geometry.shape({
"type": "MultiPolygon",
"coordinates": [
[
[[0, 0], [20, 0], [10, 20], [0, 0]], # CCW
[[3, 2], [10, 16], [17, 2], [3, 2]], # CW
],
[[[6, 4], [14, 4], [10, 12], [6, 4]]], # CCW
]
})
topo = tp.Topology(mp, prequantize=False)
topo.to_alt(color='type:N') # this goes well
topo.to_gdf().plot(alpha=0.5) # this not
topo.to_gdf().iloc[0].geometry.wkt # newly introduced ')' and '('s
'MULTIPOLYGON (((0 0, 20 0, 10 20, 0 0)), ((3 2, 17 2, 10 16, 3 2)), ((6 4, 14 4, 10 12, 6 4)))'
mp.wkt # original wkt
'MULTIPOLYGON (((0 0, 20 0, 10 20, 0 0), (3 2, 10 16, 17 2, 3 2)), ((6 4, 14 4, 10 12, 6 4)))'
from topojson.
I've added a test here and have been trying to understand what happens or what should happen around here in the Hashmap
class:
arcs = []
for geom in geoms:
arcs_in_geom = self._data[bk_objects][geom] # bk_objects = "bookkeeping_geoms"
for idx_arc, arc_ref in enumerate(arcs_in_geom):
arc_ids = self._data[bk_element][arc_ref] # bk_element = "bookkeeping_arcs"
if len(arc_ids) > 1 and key != "coordinates":
self._inner = True if idx_arc > 0 else False
arc_ids = self._backward_arcs(arc_ids)
arcs.append(arc_ids)
return arcs
After Dedup
the object looks as follow:
from topojson.core.dedup import Dedup
from topojson.core.hashmap import Hashmap
Dedup(
{'bbox': (0.0, 0.0, 20.0, 20.0),
'bookkeeping_arcs': [[0], [1], [2]], <<<<<<<<<
'bookkeeping_coords': [],
'bookkeeping_duplicates': [],
'bookkeeping_geoms': [[0, 1], [2]], <<<<<<<<<
'bookkeeping_shared_arcs': [],
'coordinates': [],
'junctions': [<shapely.geometry.point.Point object at 0x7fb94fe7e520>,
<shapely.geometry.point.Point object at 0x7fb953843df0>,
<shapely.geometry.point.Point object at 0x7fb953843e80>],
'linestrings': [array([[ 0., 0.],
[20., 0.],
[10., 20.],
[ 0., 0.]]),
array([[ 3., 2.],
[10., 16.],
[17., 2.],
[ 3., 2.]]),
array([[ 6., 4.],
[14., 4.],
[10., 12.],
[ 6., 4.]])],
'objects': {0: {'arcs': [0, 1], 'type': 'MultiPolygon'}},
'type': 'Topology'}
)
This still seems to be okay. bookkeeping_geoms
is [[0, 1], [2]]
, so len()
is two and bookkeeping_arcs
is [[0], [1], [2]]
meaning that the linestrings do not contain shared segments.
But after Hashmap
it looks as follow:
Hashmap(mp)
Hashmap(
{'bbox': (0.0, 0.0, 20.0, 20.0),
'coordinates': [],
'linestrings': [array([[ 0., 0.],
[20., 0.],
[10., 20.],
[ 0., 0.]]),
array([[ 3., 2.],
[10., 16.],
[17., 2.],
[ 3., 2.]]),
array([[ 6., 4.],
[14., 4.],
[10., 12.],
[ 6., 4.]])],
'objects': {'data': {'geometries': [{'arcs': [[[0]], [[1]], [[2]]], <<<<<<<<<
'type': 'MultiPolygon'}],
'type': 'GeometryCollection'}},
'type': 'Topology'}
)
len
of the arcs
should stay 2, but has become 3. And the arc
does not reflect the geom
anymore. The nested hole has become a unique polygon in the multipolygon instead of a hole in the first polygon...
It is a bit complicated, help welcome 🙏
from topojson.
This issue is fixed by PR #168 🥳.
Result will become:
This took quite some time unfortunately.
from topojson.
Related Issues (20)
- Converting GeoJSON FeatureCollection to TopoJSON HOT 1
- BUG: `Topology.to_gdf` should keep the original index HOT 2
- holes in multipolygons are lost by simplification HOT 4
- Deprecation warning for shapely 2.0 HOT 3
- Wrong topologies/arcs being created? HOT 7
- Creating a topology for data without junctions and shared_coords=False, prequantize=False gives error
- Bug: polygons that entirely fill islands in another polygon are often not dedupped
- shared_coords=True vs shared_coords=False HOT 5
- Linestrings that follow the same path but where one contains extra redundant points are not deduplicated
- enh: include features that are possible with shapely 2.0
- tests failing, natural earth dataset changed HOT 2
- RuntimeWarning: invalid value encountered in cast HOT 3
- IndexError: pop index out of range when instanciating Topology with a list of GeoDataFrame HOT 10
- Coordinates not reported correctly on Multipoint with only one point HOT 2
- Excessive memory usage with prequantization enabled HOT 5
- serialize_as_geojson outputs invalid GeoJSON HOT 2
- Topojson >=1.6 requires Python >=3.8, but there is no guard against Python <3.8 HOT 2
- Feature: Use geojson feature/geometry id if exists HOT 4
- Converting TopoJson to a GeoJSon object_name not changing HOT 2
- simplification using a %-like value
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 topojson.