我正在尝试从postgis postgresql数据库中的一些GIS点数据的SQL查询构建一个GeoJSON对象。下面是我的node.js app.js代码片段。
目前为止,我了解如何构建类型和要素,但不知道如何将属性数组附加到每个GeoJSON记录中(在下面的代码中,所有内容都在最后呈现,与要素不相关)。
问题:我需要做什么才能使属性附加(汇总)到构建GeoJSON的循环中的每条记录上,以便它看起来更像这个http://www.geojson.org/geojson-spec.html#examples?
目前为止,我了解如何构建类型和要素,但不知道如何将属性数组附加到每个GeoJSON记录中(在下面的代码中,所有内容都在最后呈现,与要素不相关)。
问题:我需要做什么才能使属性附加(汇总)到构建GeoJSON的循环中的每条记录上,以便它看起来更像这个http://www.geojson.org/geojson-spec.html#examples?
`function GrabData(bounds, res){
pg.connect(conn, function(err, client){
var moisql = 'SELECT ttl, (ST_AsGeoJSON(the_geom)) as locale from cpag;'
client.query(moisql, function(err, result){
var featureCollection = new FeatureCollection();
for(i=0; i<result.rows.length; i++){
featureCollection.features[i] = JSON.parse(result.rows[i].locale);
featureCollection.properties[i] = JSON.parse(result.rows[i].ttl); //this is wrong
}
res.send(featureCollection);
});
});
}
function FeatureCollection(){
this.type = 'FeatureCollection';
this.features = new Array();
this.properties = new Object; //this is wrong
}
`