Jump to content

Creating and displaying mesh from GeoJSON coordinates


Treant
 Share

Recommended Posts

Hi, I want to create city map with 3D buildings. I have GeoJSON with building data. I'm using this data to make 2D polygonal mesh (building shape).

http://www.babylonjs-playground.com/#10IOII#14 (I've used example values)

Is there way to add 3'rd dimension to it? I want to use my 2D mesh as base for 3D Object. Is it possible to store this 3D object as Vector3? I want to map all verticles and keep them around for future use. (I'm starting with babylon.js, i don't know is this proper way to do it.)

{
   "type":"FeatureCollection",
   "features":[
      {
         "id":"w26358613",
         "properties":{
            "levels":8
         },
         "geometry":{
            "type":"Polygon",
            "coordinates":[
               [
                  [
                     13.426143,
                     52.51832
                  ],
                  [
                     13.426195,
                     52.518392
                  ],
                  [
                     13.426155,
                     52.518423
                  ],
                  [
                     13.426192,
                     52.518479
                  ],
                  [
                     13.426252,
                     52.518476
                  ],
                  [
                     13.426296,
                     52.51854
                  ],
                  [
                     13.426473,
                     52.518496
                  ],
                  [
                     13.426319,
                     52.518275
                  ],
                  [
                     13.426143,
                     52.51832
                  ]
               ]
            ]
         },
         "type":"Feature"
      }
   ]
}

 

Link to comment
Share on other sites

I will give you guys update on this.

I managed to parse geoJSON data and made Vector3 shapes out of it. :) (pic 1)

jpBVtj9.png

Then I extruded building shapes:

ZiFwDKo.png

All i need now is outline like in pic related: uSzHXSj.png

From what I read you can't use renderOutline() method on extruded shapes. I've seen this demo http://www.babylonjs-playground.com/#E51MJ#11 as an example of outline, but i can't apply it to my extruded shapes.
Should I construct my 3D mesh in some other way? I only have Vector3 outlines of buildings.

 

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...
On 12/2/2016 at 9:25 AM, Treant said:

I will give you guys update on this.

I managed to parse geoJSON data and made Vector3 shapes out of it. :) (pic 1)

 

Hey Treant!

Could you explain me how did you "convert" the geoJSON data into Vector3?

Thx in advance!
Tim

Link to comment
Share on other sites

  • 2 months later...

Most of the time geoJSON are made of latitude/longitude coordinates which you can easily translate to babylonJS Vector3 with this function
 

let getVectorFromLatlng = (lat:number, lng:number, radius) => {

  var phi = (90-lat)*(Math.PI/180),
  theta = (lng+180)*(Math.PI/180),
  x = (radius) * Math.sin(phi)*Math.cos(theta),
  z = (radius) * Math.sin(phi)*Math.sin(theta),
  y = (radius) * Math.cos(phi);
  return new BABYLON.Vector3(x/3, y/3, z/3);
}

 

Link to comment
Share on other sites

  • 3 months later...
On 10/14/2018 at 3:30 PM, pichou said:

Most of the time geoJSON are made of latitude/longitude coordinates which you can easily translate to babylonJS Vector3 with this function
 


let getVectorFromLatlng = (lat:number, lng:number, radius) => {

  var phi = (90-lat)*(Math.PI/180),
  theta = (lng+180)*(Math.PI/180),
  x = (radius) * Math.sin(phi)*Math.cos(theta),
  z = (radius) * Math.sin(phi)*Math.sin(theta),
  y = (radius) * Math.cos(phi);
  return new BABYLON.Vector3(x/3, y/3, z/3);
}

 

Hey :)

could you advise me how to load and render a geojson data file (this one for example https://a.data.osmbuildings.org/0.2/anonymous/tile/16/35210/21492.json )

Link to comment
Share on other sites

Here is the functions I created to draw world border lines from a geojson  file around a 3D sphere in https://wazana.io :
 

addWorldLines () {
    $.getJSON("yougeojsonfileurl", (data) => {
      let features = data.features;
      for (let i = 0; i < features.length; i++) {
        let geo = features[ i ].geometry;
        let coord = geo.coordinates;
        if (geo.type == 'Polygon') {
          this.buildLine(coord);
        } else {
          for (let j = 0; j < coord.length; j++) {
            this.buildLine(coord[j]);
          }
        }
      }
      this.setStyle();
    });
  }

  worldLines = [];
  buildLine (coord:Array<any>) {
    let gradient = BABYLON.Color3.FromHexString(Colors.gradient);
    for (let i = 0; i < coord.length; i++) {
      let poly = coord;
      let babylonGeo = [];
      for (let i = 0; i < poly.length; i++) {
        let pos =this. getVectorFromLatlng(poly[1], poly[0], this.radius);
        babylonGeo.push(pos);
      }
      let line = BABYLON.Mesh.CreateLines('sbline'+i, babylonGeo, this.scene);
      line.parent = this.sphere;
      line.isPickable = false;
      line.color = gradient;
      this.worldLines.push(line);
    }
  }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...