4

I have a shape file in my postGIS database.I have retrieved that into geojson in node.js by using the following code.

var moisql = 'SELECT *, (ST_AsGeoJSON(geom))  from xxx;'

Works fine..But my requirement is i have to convert this geojson file into "TOPOJSON".

SO i have this code:

topojsonOutput = topojson.topology({'collection': geojsonString});

But still i am retrieving geojson file as output..SO please guide me to achieve this..Thanks in advance.

Also when i googled i got this code:

var collection = {type: "FeatureCollection", features: […]}; // GeoJSON
var topology = topojson.topology({collection: collection}); // convert to TopoJSON
console.log(topology.objects.collection); // inspect TopoJSON  

But totally i can't understand this..What i have to give in place of features[..] and collections..

Subburaj
  • 5,114
  • 10
  • 44
  • 87

2 Answers2

2

There's a PostGIS AsTopoJSON function available for PostGIS 2.1.0 and greater. Alternatively, there's the postgis2geojson conversion tool; you might want to look at how it wraps the snippets that ST_AsGeoJSON returns.

banderkat
  • 481
  • 2
  • 6
0

Taken from example here.

var topology = topojson.topology({
        collection: {
          type: "FeatureCollection",
          features: [
            {type: "Feature", geometry: {type: "LineString", coordinates: [[.1, .2], [.3, .4]]}},
            {type: "Feature", geometry: {type: "Polygon", coordinates: [[[.5, .6], [.7, .8]]]}}
          ]
        }
      });
vinayr
  • 11,026
  • 3
  • 46
  • 42