// A city's open data: parks published as a shapefile, put on a web map as GeoJSON, and an export for the GIS team.
//
//   quillo run shapefile.qwe      then open http://localhost:8080/parks

use "shapefile.qwer"

route GET /parks {
    let parks = shapefile_to_geojson("shapefile_sample.shp")?
    {
        info: shapefile_info("shapefile_sample.shp")?,
        names: parks.features | map((f) => f.properties.name),
        first: parks.features[0],
        // The same layer as it is usually sent: zipped, in a folder.
        from_zip: len(shapefile_to_geojson("shapefile_sample.zip")?.features),
    }
}

route GET /parks.geojson = shapefile_to_geojson("shapefile_sample.zip")?

// Bus stops exported for the GIS team, then read back.
route GET /export {
    let stops = { type: "FeatureCollection", features: [
        { type: "Feature", properties: { stop: "Centraal", lines: 12, sheltered: true }, geometry: { type: "Point", coordinates: [4.900, 52.378] } },
        { type: "Feature", properties: { stop: "Dam", lines: 7, sheltered: false }, geometry: { type: "Point", coordinates: [4.893, 52.373] } },
    ] }
    let n = shapefile_from_geojson(stops, "data/stops/stops.shp")?
    { written: n, back: shapefile_to_geojson("data/stops/stops.shp")?.features[1], mixed: shapefile_from_geojson({ type: "FeatureCollection", features: [stops.features[0], { type: "Feature", properties: {}, geometry: { type: "LineString", coordinates: [[0, 0], [1, 1]] } }] }, "data/x.shp").error }
}
