topojson / topojson-client

Manipulate TopoJSON, such as to merge shapes, and convert it back to GeoJSON.
ISC License
211 stars 63 forks source link

topojson.feature of a FeatureCollection of MultiPolygons returns a "Feature" object with null as geometry property #33

Closed MathiasVersichele closed 2 years ago

MathiasVersichele commented 2 years ago

I have the topojson file in attachment: topojson_issue.json.txt

which I made with the "pytopojson" library. I'm pretty confident it looks ok, library doesn't complain but I guess there isn't an online validator. Geojson-wise it's a feature collection of 20 multipolygons. I use the following snippet in javascript:

d3.json("https://75.119.131.164/data/hourly_homezones.json", function(error, topology) {
    console.log(topojson.feature(topology, topology.objects.my_geojson.geometries));
};

which returns:

image

I don't think this is an expected response. I expect a featurecollection of multipolygons.

Any foolish mistake I'm making ? Or is this a bug ?

mbostock commented 2 years ago

What happens if you do this?

topojson.feature(topology, topology.objects.my_geojson)
MathiasVersichele commented 2 years ago

Uncaught TypeError: Cannot read properties of undefined (reading 'objects') at Object.<anonymous> (coverage.html:69:53) at Object.t (d3.v3.min.js:1:1565) at XMLHttpRequest.i (d3.v3.min.js:1:10120)

thrown at the console.log line

mbostock commented 2 years ago

Cannot read properties of undefined (reading 'objects')

This means that topology is undefined, which means it’s not even calling topojson.feature, so there must be a bug elsewhere.

I can’t reproduce this.

https://observablehq.com/d/e78f899d7a22df38

MathiasVersichele commented 2 years ago

I kept trying and trying, finally works, don't really know why it didn't before. Not a bug indeed. Thx for investigating @mbostock !