# D3,GeoJSON Data, Earth Texture

**URL:** <https://discourse.threejs.org/t/d3-geojson-data-earth-texture/14702>\
**Category:** Questions\
**Tags:** geo-json, textures\
**Created:** [April 27, 2020, 8:19pm UTC](https://discourse.threejs.org/t/d3-geojson-data-earth-texture/14702 "2020-04-27T20:19:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ali\_Zien](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ali_zien/32/12022_2.png) [@Ali\_Zien](https://discourse.threejs.org/u/Ali_Zien)\
**Post date:** [April 27, 2020, 8:19pm UTC](https://discourse.threejs.org/t/d3-geojson-data-earth-texture/14702/1 "2020-04-27T20:19:55Z")

</div>

Hello, I am importing data from GeoJSON to create a dynamic Earth that has borders and countries data…the problem is everything is done but I don’t know how can I add the D3 SVG map [BOTTOM] as an texture on my threejs Earth [TOP].

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/f/f6a159e91c40f26edb01e4dc2d5a214cdf64cc91.png)

Chart code:

```
 function GeoChart({ data, property }) {
 const svgRef = useRef();
    const wrapperRef = useRef();
    const dimensions = useResizeObserver(wrapperRef);

useEffect(() => {
  
  const svg = select(svgRef.current);
   const { width, height } =
    dimensions || wrapperRef.current.getBoundingClientRect();
   const projection = geoMercator().fitSize([width, height], data);

const pathGenerator = geoPath().projection(projection);

console.log(
  width,
  height,
  wrapperRef,
  dimensions,
  wrapperRef.current.getBoundingClientRect()
);
svg
  .selectAll(".country")
  .data(data.features)
  .join("path")
  .attr("class", "country")
  .attr("d", (feature) => pathGenerator(feature));
 }, [data, dimensions, property]);
 return (
<div ref={wrapperRef} style={{ marginBottom: "2rem" }}>
  <svg ref={svgRef}></svg>
</div>
);
}

```

The threejs Earth:

```
import data from "./custom.geo.json";
 import GeoChart from "./GeoChart/GeoChart.js";

function Earth() {

 const [property, setProperty] = useState("pop_est");

 const ref = useRef();

useEffect(() => {

var scene = new THREE.Scene();

var camera = new THREE.PerspectiveCamera(

  75,

  window.innerWidth / window.innerHeight,

  0.1,

  1000

);

camera.position.z = 1;

// camera.position.set(250, 200, 250);

// camera.lookAt(0, 0, 0);

var renderer = new THREE.WebGLRenderer({ antialias: true });

renderer.setClearColor("#FFFFFF");

renderer.setSize(window.innerWidth, window.innerHeight);

var light = new THREE.AmbientLight(0x404040, 3);

scene.add(light);

ref.current.appendChild(renderer.domElement);

var controls = new OrbitControls(camera, renderer.domElement);

var render = function () {

  controls.update();

  requestAnimationFrame(render);

  renderer.render(scene, camera);

};

var geometry = new THREE.SphereGeometry(0.5, 32, 32);

var material = new THREE.MeshPhongMaterial();

material.map = THREE.ImageUtils.loadTexture(texture);

var earthMesh = new THREE.Mesh(geometry, material);

scene.add(earthMesh);render(); }, []);
return (

<div>

  <div ref={ref} />

  <GeoChart data={data} property={property} />

</div>
```

---

<div class="post-metadata">

**Author:** ![amitlzkpa](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/amitlzkpa/32/1735_2.png) [@amitlzkpa](https://discourse.threejs.org/u/amitlzkpa)\
**Post date:** [April 28, 2020, 4:03am UTC](https://discourse.threejs.org/t/d3-geojson-data-earth-texture/14702/2 "2020-04-28T04:03:11Z")

</div>

If the map was in Equirectangular projection the texture mapper would map it correctly. The flat map there looks like Mercator projection.

---

<div class="post-metadata">

**Author:** ![Ali\_Zien](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ali_zien/32/12022_2.png) [@Ali\_Zien](https://discourse.threejs.org/u/Ali_Zien)\
**Post date:** [April 29, 2020, 5:07am UTC](https://discourse.threejs.org/t/d3-geojson-data-earth-texture/14702/3 "2020-04-29T05:07:10Z")

</div>

sorry for my ignorance, but could you explain how can I apply that ?  
material.map = THREE.ImageUtils.loadTexture();

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [April 29, 2020, 8:14am UTC](https://discourse.threejs.org/t/d3-geojson-data-earth-texture/14702/4 "2020-04-29T08:14:47Z")

</div>

> [@Ali\_Zien](#):
>
> material.map = THREE.ImageUtils.loadTexture();

What version of `three.js` are you using? `ImageUtils.loadTexture()` is actually deprecated. Please use [TextureLoader](https://threejs.org/docs/index.html#api/en/loaders/TextureLoader) instead.

In any event, `three.js` can’t perform the conversion from `Mercator` to `Equirectangular` for you. This is something you have to figure out by yourself.

It’s also not possible to apply SVG as a texture. You have to convert it to PNG or JPEG first.

---

<div class="post-metadata">

**Author:** ![amitlzkpa](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/amitlzkpa/32/1735_2.png) [@amitlzkpa](https://discourse.threejs.org/u/amitlzkpa)\
**Post date:** [April 29, 2020, 3:52pm UTC](https://discourse.threejs.org/t/d3-geojson-data-earth-texture/14702/5 "2020-04-29T15:52:32Z")

</div>

I think you can create a PNG out of the SVG through the canvas object.

```auto
var svgCanvas = document.getElementById("svg-canvas");
var textureImg = svgCanvas.toDataURL("image/png");

```

Something like that, but haven’t tested it, so could be wrong.

* * *

For changing the projection from Mercator to Equirectangular, D3 might have something to do that.
