Postgis / exporting data as a geojson #1207
-
|
I have created a custom component "geojson" to export data from a postgis database. It works, but I had to introduce a script to go back to my source file and I don't understand why. I am looking to find a proper way to do it. I based my component s a variant of the "csv" component where "When csv is used as a header component (without a shell), it will trigger a download of the CSV file directly on page load." So from If anybody can explain to me where I am wrong, thanks in advance ! plot_geojson_export_single_0.sql : SET project_id = (SELECT project_id FROM project_plots WHERE plot_id=$plot_id::INTEGER);
SET redirect_page = '/e_project_plots/plot_main_display_4.sql?project_id';
SELECT
'geojson' AS component,
'Exporter un fichier geojson' AS title,
'plot_id_' || $plot_id AS filename,
$redirect_page::TEXT AS redirect_page,
$project_id::INTEGER AS project_id,
(SELECT
jsonb_build_object(
'type', 'Feature',
'geometry', ST_AsGeoJSON(plot_geom)::jsonb,
'properties', jsonb_build_object(
'plot_id', plot_id,
'project_id', project_id,
'plot_title', plot_title,
'plot_description', plot_description,
'building_id', building_id,
'plot_code_postal', plot_code_postal,
'plot_code_land_registry', plot_code_land_registry,
'plot_code_insee', plot_code_insee
)
)::text FROM project_plots WHERE plot_id = $plot_id::integer) AS content;
geojson.handlebars : |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Hi ! You don't need a custom component for this, just use the built it download or json+http_header components:
select
'http_header' as component,
format('attachment; filename="plot_id_%s.geojson"', $plot_id) as "Content-Disposition";
select 'json' as component,
json_build_object(
'type', 'Feature',
...
) as contents; |
Beta Was this translation helpful? Give feedback.
Hi !
You don't need a custom component for this, just use the built it download or json+http_header components: