JuanCouste / overpass-ql-ts

Overpass QL query builder abstraction with typing
MIT License
5 stars 1 forks source link

Add example how to use string query #9

Closed Djiit closed 6 months ago

Djiit commented 8 months ago

I'm not sure how I can use a query that I can export from Overpass turbo, e.g.:

[out:json][timeout:25];
nwr["changing_table"~"yes"](47.09139684143848,-1.720390319824219,47.38114922279505,-1.4028167724609377);
out geom;
JuanCouste commented 8 months ago

The current best way I think would be:

// get an OverpassApiObject like const api = DefaultOverpassApi();

const results = await api.execJson(
    (s) => s.query(OverpassQueryTarget.NodeWayRelation, { changing_table: /yes/ }),
    { geoInfo: OverpassOutputGeoInfo.Geometry },
    {
        timeout: 25,
        globalBoundingBox: [47.09139684143848, -1.720390319824219, 47.38114922279505, -1.4028167724609377],
    },
);

// do something with results

The query being run would be:

/* Settings */
[timeout:25]
[out:json]
[bbox:47.09139684143848,-1.720390319824219,47.38114922279505,-1.4028167724609377];
/* Statements */
nwr ["changing_table"~"yes"];
/* Output */
._ out geom

There are some changes pending to be merged & published, that would allow this to be written like:

const result = await api.execJson(
    (s) => s.query(OverpassQueryTarget.NodeWayRelation, { changing_table: /yes/ })
        .and(c => c.bbox([47.09139684143848, -1.720390319824219, 47.38114922279505, -1.4028167724609377])),
    { geoInfo: OverpassOutputGeoInfo.Geometry },
    { timeout: 25 },
);

And the query would be like the one you wanted:

/* Settings */
[timeout:25]
[out:json];
/* Statements */
nwr ["changing_table"~"yes"]
    (47.09139684143848, -1.720390319824219, 47.38114922279505, -1.4028167724609377);
/* Output */
._ out geom;

If you are still interested in using this, I'll get this published asap.

JuanCouste commented 8 months ago

Sorry for the wait @Djiit , I somehow did not get notifications for your messages, gotta look into it.

Djiit commented 8 months ago

Thanks for answer. Your example would be a nice addition to the README or the example folder 🙏

JuanCouste commented 6 months ago

There is now documentation on how to interact with this package to execute queries, checkout the wiki