loadExtension('libspatialite.so'); # select all the data $rs = $grassuserdb->query('SELECT id, name, company, x, y FROM users;'); # start to create geojson $geojson = array( 'type' => 'FeatureCollection', 'features' => array() ); # for each row create a feature into geojson while ($row = $rs->fetchArray()) { $lon = floatval(trim($row[3])); $lat = floatval(trim($row[4])); $latlon = array($lon,$lat); $feature = array( "type" => "Feature", "id" => floatval(trim($row[0])), "properties" => array( "name" => trim($row[1]), "company" => trim($row[2]) ), "geometry" => array("type" => "Point", "coordinates" => $latlon) ); array_push($geojson['features'], $feature); } # close connection $grassuserdb->close(); # return geojson file header('Content-type: application/json',true); echo json_encode($geojson); ?>