Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert ocean shape file into topojson

Tags:

d3.js

topojson

I have gdal 1.10.1 and topojson 1.4.0 installed on my MacOs 10.7.5. I have downloaded the ne_110m_ocean form Natural Earth.

I successfully transformed the shape file in GeoJSON:

ogr2ogr \
  -f GeoJSON \
  ocean.json \
  ne_110m_ocean.shp

Then I transformed the GeoJSON into topojson:

topojson \
  -o ocean_tj.json \
  ocean=ocean.json \

When I plot using the GeoJSON file all works fine.

d3.json("ocean.json", function(json) {
  svg.selectAll("path")
 .data(json.features)
 .enter()
 .append("path")
 .attr("d", path)
 .style("fill", "steelblue");
});

When I plot using the topojson file, instead of having the polygons of the oceans I get the polygons of the lands!!!!

d3.json("ocean_tj.json", function(topology) {
var ocean = topojson.feature(topology, topology.objects.ocean); 
svg.append("path")
.datum(ocean)
.attr("d", path)
.style("fill", "red");
});

Can anyone help?

Thanks in advance

like image 365
poujoo Avatar asked Oct 02 '22 20:10

poujoo


1 Answers

Using the option --no-force-clockwise fix the issue:

topojson -o ocean_tj.json ocean=ocean.json --no-force-clockwise
like image 54
Pablo Navarro Avatar answered Oct 12 '22 10:10

Pablo Navarro