From 877ddc536eb54c6b5f8fe54b0b2b6bf0caa89a98 Mon Sep 17 00:00:00 2001 From: Stuart Lynn Date: Tue, 23 Apr 2024 13:04:33 +0100 Subject: [PATCH 1/3] First pass at function to retrive features from a flatgeobuff --- Cargo.lock | 763 +++++++++++++++++++++++++++++++++++++++++++++++++++-- Cargo.toml | 8 +- src/geo.rs | 192 ++++++++++++++ src/lib.rs | 1 - 4 files changed, 940 insertions(+), 24 deletions(-) create mode 100644 src/geo.rs diff --git a/Cargo.lock b/Cargo.lock index 0cdc4f4..c3cd5b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -197,6 +197,218 @@ dependencies = [ "zstd", ] +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + +[[package]] +name = "assert-json-diff" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e4f2b81832e72834d7518d8487a0396a28cc408186a2e8854c0f98011faf12" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "async-attributes" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3203e79f4dd9bdda415ed03cf14dae5a2bf775c683a00f94e9cd1faf0f596e5" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136d4d23bcc79e27423727b36823d86233aad06dfea531837b038394d11e9928" +dependencies = [ + "concurrent-queue", + "event-listener 5.3.0", + "event-listener-strategy 0.5.1", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b10202063978b3351199d68f8b22c4e47e4b1b822f8d43fd862d5ea8c006b29a" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand 2.0.2", + "futures-lite 2.3.0", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.2.1", + "async-executor", + "async-io 2.3.2", + "async-lock 3.3.0", + "blocking", + "futures-lite 2.3.0", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock 2.8.0", + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-lite 1.13.0", + "log", + "parking", + "polling 2.8.0", + "rustix 0.37.27", + "slab", + "socket2 0.4.10", + "waker-fn", +] + +[[package]] +name = "async-io" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcccb0f599cfa2f8ace422d3555572f47424da5648a4382a9dd0310ff8210884" +dependencies = [ + "async-lock 3.3.0", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite 2.3.0", + "parking", + "polling 3.7.0", + "rustix 0.38.32", + "slab", + "tracing", + "windows-sys 0.52.0", +] + +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener 2.5.3", +] + +[[package]] +name = "async-lock" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d034b430882f8381900d3fe6f0aaa3ad94f2cb4ac519b429692a1bc2dda4ae7b" +dependencies = [ + "event-listener 4.0.3", + "event-listener-strategy 0.4.0", + "pin-project-lite", +] + +[[package]] +name = "async-object-pool" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb901c30ebc2fc4ab46395bbfbdba9542c16559d853645d75190c3056caf3bc" +dependencies = [ + "async-std", +] + +[[package]] +name = "async-process" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" +dependencies = [ + "async-io 1.13.0", + "async-lock 2.8.0", + "async-signal", + "blocking", + "cfg-if", + "event-listener 3.1.0", + "futures-lite 1.13.0", + "rustix 0.38.32", + "windows-sys 0.48.0", +] + +[[package]] +name = "async-signal" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afe66191c335039c7bb78f99dc7520b0cbb166b3a1cb33a03f53d8a1c6f2afda" +dependencies = [ + "async-io 2.3.2", + "async-lock 3.3.0", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix 0.38.32", + "signal-hook-registry", + "slab", + "windows-sys 0.52.0", +] + +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-attributes", + "async-channel 1.9.0", + "async-global-executor", + "async-io 1.13.0", + "async-lock 2.8.0", + "async-process", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite 1.13.0", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + [[package]] name = "async-stream" version = "0.3.5" @@ -219,6 +431,12 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "async-task" +version = "4.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" + [[package]] name = "async-trait" version = "0.1.80" @@ -239,6 +457,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.2.0" @@ -272,6 +496,32 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" +[[package]] +name = "basic-cookies" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67bd8fd42c16bdb08688243dc5f0cc117a3ca9efeeaba3a345a18a6159ad96f7" +dependencies = [ + "lalrpop", + "lalrpop-util", + "regex", +] + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitflags" version = "1.3.2" @@ -284,6 +534,22 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +[[package]] +name = "blocking" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" +dependencies = [ + "async-channel 2.2.1", + "async-lock 3.3.0", + "async-task", + "fastrand 2.0.2", + "futures-io", + "futures-lite 2.3.0", + "piper", + "tracing", +] + [[package]] name = "brotli" version = "3.5.0" @@ -432,6 +698,15 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "concurrent-queue" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -522,6 +797,33 @@ dependencies = [ "winapi", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "doc-comment" version = "0.3.3" @@ -540,6 +842,15 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +[[package]] +name = "ena" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c533630cf40e9caa44bd91aadc88a75d75a4c3a12b4cfde353cbed41daa1e1f1" +dependencies = [ + "log", +] + [[package]] name = "encoding_rs" version = "0.8.34" @@ -583,6 +894,65 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b90ca2580b73ab6a1f724b76ca11ab632df820fd6040c336200d2c1df7b3c82c" +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d93877bcde0eb80ca09131a08d23f0a5c18a620b01db137dba666d18cd9b30c2" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b215c49b2b248c855fb73579eb1f4f26c38ffdc12973e20e07b91d78d5646e" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d9944b8ca13534cdfb2800775f8dd4902ff3fc75a50101466decadfdf322a24" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" +dependencies = [ + "event-listener 4.0.3", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "332f51cb23d20b0de8458b86580878211da09bcd4503cb579c225b3d124cabb3" +dependencies = [ + "event-listener 5.3.0", + "pin-project-lite", +] + [[package]] name = "fallible-streaming-iterator" version = "0.1.9" @@ -595,12 +965,27 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95765f67b4b18863968b4a1bd5bb576f732b29a4a28c7cd84c09fa3e2875f33c" +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "fastrand" version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "flatbuffers" version = "23.5.26" @@ -631,7 +1016,7 @@ dependencies = [ "bytes", "fallible-streaming-iterator", "flatbuffers", - "geozero 0.12.0", + "geozero", "http-range-client", "log", "reqwest 0.11.27", @@ -722,6 +1107,34 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand 1.9.0", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-lite" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" +dependencies = [ + "fastrand 2.0.2", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + [[package]] name = "futures-macro" version = "0.3.30" @@ -788,9 +1201,9 @@ dependencies = [ [[package]] name = "geozero" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b1b9a1eeae9ad09e12ec50243956105184b26440f81f978cd3aae009b214d4d" +checksum = "61d25cc15c7e5b86cd8dadea56bb78c46f346d4fb09022e7cbba0839c890d0a1" dependencies = [ "geo-types", "geojson", @@ -800,17 +1213,6 @@ dependencies = [ "wkt", ] -[[package]] -name = "geozero" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61d25cc15c7e5b86cd8dadea56bb78c46f346d4fb09022e7cbba0839c890d0a1" -dependencies = [ - "log", - "serde_json", - "thiserror", -] - [[package]] name = "getrandom" version = "0.2.14" @@ -836,6 +1238,18 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "gloo-timers" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b995a66bb87bebce9a0f4a95aed01daca4872c050bfcb21653361c03bc35e5c" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "h2" version = "0.3.26" @@ -1000,6 +1414,34 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "httpmock" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08ec9586ee0910472dec1a1f0f8acf52f0fdde93aea74d70d4a3107b4be0fd5b" +dependencies = [ + "assert-json-diff", + "async-object-pool", + "async-std", + "async-trait", + "base64 0.21.7", + "basic-cookies", + "crossbeam-utils", + "form_urlencoded", + "futures-util", + "hyper 0.14.28", + "lazy_static", + "levenshtein", + "log", + "regex", + "serde", + "serde_json", + "serde_regex", + "similar", + "tokio", + "url", +] + [[package]] name = "humantime" version = "2.1.0" @@ -1023,7 +1465,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.5.6", "tokio", "tower-service", "tracing", @@ -1106,7 +1548,7 @@ dependencies = [ "http-body 1.0.0", "hyper 1.3.1", "pin-project-lite", - "socket2", + "socket2 0.5.6", "tokio", "tower", "tower-service", @@ -1156,6 +1598,26 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "ipnet" version = "2.9.0" @@ -1195,12 +1657,58 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + +[[package]] +name = "lalrpop" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cb077ad656299f160924eb2912aa147d7339ea7d69e1b5517326fdcec3c1ca" +dependencies = [ + "ascii-canvas", + "bit-set", + "ena", + "itertools", + "lalrpop-util", + "petgraph", + "pico-args", + "regex", + "regex-syntax 0.8.3", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", + "walkdir", +] + +[[package]] +name = "lalrpop-util" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507460a910eb7b32ee961886ff48539633b788a36b65692b95f225b844c82553" +dependencies = [ + "regex-automata", +] + [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "levenshtein" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db13adb97ab515a3691f56e4dbab09283d0b86cb45abd991d8634a9d6f501760" + [[package]] name = "lexical" version = "6.1.1" @@ -1286,6 +1794,22 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.5.0", + "libc", +] + +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -1307,6 +1831,9 @@ name = "log" version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" +dependencies = [ + "value-bag", +] [[package]] name = "lz4" @@ -1409,6 +1936,12 @@ dependencies = [ "tempfile", ] +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + [[package]] name = "now" version = "0.1.3" @@ -1535,6 +2068,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "parking" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1592,6 +2131,31 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "petgraph" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +dependencies = [ + "fixedbitset", + "indexmap", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pico-args" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" + [[package]] name = "pin-project" version = "1.1.5" @@ -1624,6 +2188,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" +dependencies = [ + "atomic-waker", + "fastrand 2.0.2", + "futures-io", +] + [[package]] name = "pkg-config" version = "0.3.30" @@ -1898,6 +2473,37 @@ dependencies = [ "version_check", ] +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + +[[package]] +name = "polling" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645493cf344456ef24219d02a768cf1fb92ddf8c92161679ae3d91b91a637be3" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix 0.38.32", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "popgetter_cli" version = "0.1.0" @@ -1907,7 +2513,8 @@ dependencies = [ "clap", "enum_dispatch", "flatgeobuf", - "geozero 0.11.0", + "geozero", + "httpmock", "polars", "reqwest 0.12.3", "serde", @@ -1924,6 +2531,12 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + [[package]] name = "proc-macro2" version = "1.0.81" @@ -2030,6 +2643,17 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_users" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + [[package]] name = "regex" version = "1.10.4" @@ -2208,6 +2832,20 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.37.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + [[package]] name = "rustix" version = "0.38.32" @@ -2217,7 +2855,7 @@ dependencies = [ "bitflags 2.5.0", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.13", "windows-sys 0.52.0", ] @@ -2415,6 +3053,16 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_regex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8136f1a4ea815d7eac4101cfd0b16dc0cb5e1fe1b8609dfd728058656b7badf" +dependencies = [ + "regex", + "serde", +] + [[package]] name = "serde_tokenstream" version = "0.2.0" @@ -2454,6 +3102,18 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27f6278552951f1f2b8cf9da965d10969b2efdea95a6ec47987ab46edfe263a" +[[package]] +name = "similar" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + [[package]] name = "slab" version = "0.4.9" @@ -2508,6 +3168,16 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b" +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.6" @@ -2566,6 +3236,19 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe895eb47f22e2ddd4dabc02bce419d2e643c8e3b585c78158b349195bc24d82" +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared", + "precomputed-hash", +] + [[package]] name = "strsim" version = "0.11.1" @@ -2680,11 +3363,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", - "fastrand", - "rustix", + "fastrand 2.0.2", + "rustix 0.38.32", "windows-sys 0.52.0", ] +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + [[package]] name = "thiserror" version = "1.0.58" @@ -2705,6 +3399,15 @@ dependencies = [ "syn 2.0.60", ] +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -2734,7 +3437,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.6", "tokio-macros", "windows-sys 0.48.0", ] @@ -2921,6 +3624,12 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "untrusted" version = "0.7.1" @@ -2950,6 +3659,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "value-bag" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74797339c3b98616c009c7c3eb53a0ce41e85c8ec66bd3db96ed132d20cfdee8" + [[package]] name = "vcpkg" version = "0.2.15" @@ -2962,6 +3677,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "waker-fn" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" + [[package]] name = "walkdir" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index 030fa6b..5f134b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,6 @@ name = "popgetter" path = "src/lib.rs" [dependencies] -flatgeobuf = "4.0" -geozero = "0.11.0" anyhow = "1.0.75" serde = { version = "1.0", features = ["derive"] } serde_json = {version="1.0"} @@ -19,6 +17,12 @@ polars = {version ="0.33.2", features=["lazy","aws", "parquet"]} typify = "0.0.16" chrono = "0.4.37" reqwest = {version = "0.12.3", features = ["json"]} +<<<<<<< HEAD strum = "0.26" strum_macros = "0.26" enum_dispatch = "0.3" +======= +flatgeobuf = "4.1.0" +geozero = {version = "0.12.0", features= []} +httpmock = "0.7.0-rc.1" +>>>>>>> fb462fe (First pass at function to retrive features from a flatgeobuff) diff --git a/src/geo.rs b/src/geo.rs new file mode 100644 index 0000000..a7703a1 --- /dev/null +++ b/src/geo.rs @@ -0,0 +1,192 @@ +use std::collections::HashMap; +use flatgeobuf::{ FeatureProperties, HttpFgbReader, geozero}; +use geozero::ToWkt; +use anyhow::Result; + +/// Function to request geometries from a remotly hosted FGB +/// +/// `file_url`: The url of the file to read from +/// +/// `bbox`: an optional bounding box to filter the features by +/// +/// Returns: a Result object containing a vector of (geometry, properties). +pub async fn get_geometries(file_url:&str, bbox:Option<&[f64;4]>) -> Result)>>{ + let fgb = HttpFgbReader::open(file_url) + .await?; + + let mut fgb = if let Some(bbox) = bbox{ + fgb.select_bbox(bbox[0],bbox[1],bbox[2],bbox[3]) + .await? + } + else{ + fgb + .select_all() + .await? + }; + + let mut features = Vec::new(); + + while let Some(feature) = fgb.next().await? { + let props = feature.properties()?; + let geom = feature.to_wkt()?; + features.push((geom, props)); + } + Ok(features) +} + +#[cfg(test)] +mod tests { + use super::*; + use flatgeobuf::{geozero::PropertyProcessor, ColumnType, FgbWriter, GeometryType}; + use ::geozero::{ColumnValue, geojson::GeoJson}; + use httpmock::prelude::*; + + fn test_fgb()-> FgbWriter<'static>{ + let mut fgb = FgbWriter::create("countries", GeometryType::Polygon).unwrap(); + fgb.add_column("id", ColumnType::String ,|_fbb,col| { col.nullable=false} ); + fgb.add_column("val", ColumnType::Float,|_fbb,col| { col.nullable=false} ); + let geom1 = GeoJson(r#" + { + "coordinates": [ + [ + [ + -2.3188783647485707, + 52.69979322604925 + ], + [ + -2.5454719671669466, + 52.15312184913398 + ], + [ + -2.013470682738614, + 51.91675689282138 + ], + [ + -1.6883550645436003, + 52.297957365071426 + ], + [ + -1.865690550690033, + 52.79521231460612 + ], + [ + -2.3188783647485707, + 52.69979322604925 + ] + ] + ], + "type": "Polygon" + } + "#); + + let geom2 = GeoJson(r#" + { + "coordinates": [ + [ + [ + -0.12189002707808072, + 51.69745608244253 + ], + [ + -0.663758311409083, + 51.538416425565146 + ], + [ + -0.3977386344766103, + 51.38495470191404 + ], + [ + -0.0627732105033374, + 51.37880690189908 + ], + [ + 0.16381686538463214, + 51.54453889108953 + ], + [ + -0.12189002707808072, + 51.69745608244253 + ] + ] + ], + "type": "Polygon" + } + "#); + + fgb.add_feature_geom(geom1,|feat|{ + feat.property(0,"id" ,&ColumnValue::String("one")).unwrap(); + feat.property(1,"val" ,&ColumnValue::Float(0.2)).unwrap(); + }).unwrap(); + + fgb.add_feature_geom(geom2,|feat|{ + feat.property(0,"id" ,&ColumnValue::String("two")).unwrap(); + feat.property(1,"val" ,&ColumnValue::Float(30.0) ).unwrap(); + }).unwrap(); + + fgb + } + + fn mock_fgb_server()->MockServer{ + let fgb = test_fgb(); + let mut buffer:Vec = vec![]; + fgb.write(&mut buffer).unwrap(); + + // Mock out a server + let server = MockServer::start(); + server.mock(|when, then| { + when.method(GET) + .path("/fgb_example.fgb"); + then.status(200) + .header("content-type", "") + .body(buffer); + }); + server + } + + #[tokio::test] + async fn test_loading_geometries() { + // Generate a test FGB server + let server = mock_fgb_server(); + + // Get the geometries + let geoms = get_geometries(&server.url("/fgb_example.fgb"),None ).await; + assert!(geoms.is_ok(),"The geometry call should not error"); + let geoms = geoms.unwrap(); + + assert_eq!(geoms.len(),2, "Should recover two features"); + // Order seems to get moved around when reading back + let feature2 = &geoms[0]; + let feature1 = &geoms[1]; + assert_eq!(feature1.0, "POLYGON((-2.3188783647485707 52.69979322604925,-2.5454719671669466 52.15312184913398,-2.013470682738614 51.91675689282138,-1.6883550645436003 52.297957365071426,-1.865690550690033 52.79521231460612,-2.3188783647485707 52.69979322604925))" , "feature_1 should have the correct geometry"); + assert_eq!(feature2.0, "POLYGON((-0.12189002707808072 51.69745608244253,-0.663758311409083 51.538416425565146,-0.3977386344766103 51.38495470191404,-0.0627732105033374 51.37880690189908,0.16381686538463214 51.54453889108953,-0.12189002707808072 51.69745608244253))", "feature_2 should have the correct geometry"); + assert_eq!(feature1.1.get("id").unwrap(), "one" , "feature_1 Should have the correct id"); + assert_eq!(feature2.1.get("id").unwrap(), "two" , "feature_2 Should have the correct id"); + assert_eq!(feature1.1.get("val").unwrap(), "0.2" , "feature_1 Should have the correct value"); + assert_eq!(feature2.1.get("val").unwrap(), "30" , "feature_2 Should have the correct value"); + } + + #[tokio::test] + async fn test_loading_geometries_with_bbox() { + // Generate a test FGB server + let server = mock_fgb_server(); + // Get the geometries + let bbox = [ -3.018_352_090_792_945, + 51.795_056_187_175_82, + -1.373_095_490_899_146_4, + 53.026_908_220_355_35, + ]; + let geoms = get_geometries(&server.url("/fgb_example.fgb"),Some(&bbox)).await; + + assert!(geoms.is_ok(),"The geometry call should not error"); + let geoms = geoms.unwrap(); + + assert_eq!(geoms.len(),1, "Should recover one features"); + // Order seems to get moved around when reading back + println!("{geoms:#?}"); + let feature1 = &geoms[0]; + assert_eq!(feature1.0, "POLYGON((-2.3188783647485707 52.69979322604925,-2.5454719671669466 52.15312184913398,-2.013470682738614 51.91675689282138,-1.6883550645436003 52.297957365071426,-1.865690550690033 52.79521231460612,-2.3188783647485707 52.69979322604925))" , "feature_1 should have the correct geometry"); + assert_eq!(feature1.1.get("id").unwrap(), "one" , "feature_1 Should have the correct id"); + assert_eq!(feature1.1.get("val").unwrap(), "0.2" , "feature_1 Should have the correct value"); + } + +} diff --git a/src/lib.rs b/src/lib.rs index a6af140..184dab7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ use anyhow::Result; use metadata::{load_metadata, MetricMetadata, SourceDataRelease}; - pub mod data_request_spec; pub mod metadata; From da41b51362354c3e03a77970e124b28447d3300c Mon Sep 17 00:00:00 2001 From: Stuart Lynn Date: Tue, 23 Apr 2024 13:09:58 +0100 Subject: [PATCH 2/3] Missed merge --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5f134b0..23b85f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,12 +17,9 @@ polars = {version ="0.33.2", features=["lazy","aws", "parquet"]} typify = "0.0.16" chrono = "0.4.37" reqwest = {version = "0.12.3", features = ["json"]} -<<<<<<< HEAD strum = "0.26" strum_macros = "0.26" enum_dispatch = "0.3" -======= flatgeobuf = "4.1.0" geozero = {version = "0.12.0", features= []} httpmock = "0.7.0-rc.1" ->>>>>>> fb462fe (First pass at function to retrive features from a flatgeobuff) From 160c2281eae8ac746c8a2407e74ad5b47f010066 Mon Sep 17 00:00:00 2001 From: Stuart Lynn Date: Tue, 23 Apr 2024 16:37:57 +0100 Subject: [PATCH 3/3] Rebase with main and using BBox for input --- src/data_request_spec.rs | 19 ++++++++++++++++++- src/geo.rs | 7 ++++--- src/lib.rs | 3 ++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/data_request_spec.rs b/src/data_request_spec.rs index f97193b..0730d81 100644 --- a/src/data_request_spec.rs +++ b/src/data_request_spec.rs @@ -1,5 +1,8 @@ use serde::{Deserialize, Serialize}; -use std::str::FromStr; +use std::{ + ops::{Index, IndexMut}, + str::FromStr, +}; #[derive(Serialize, Deserialize, Debug)] pub struct DataRequestSpec { @@ -26,6 +29,20 @@ pub struct Polygon; #[derive(Clone, Debug, Serialize, Deserialize)] pub struct BBox(pub [f64; 4]); +impl Index for BBox { + type Output = f64; + + fn index(&self, index: usize) -> &Self::Output { + &self.0[index] + } +} + +impl IndexMut for BBox { + fn index_mut(&mut self, index: usize) -> &mut Self::Output { + &mut self.0[index] + } +} + impl FromStr for BBox { type Err = &'static str; fn from_str(value: &str) -> Result { diff --git a/src/geo.rs b/src/geo.rs index a7703a1..84b77a4 100644 --- a/src/geo.rs +++ b/src/geo.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use flatgeobuf::{ FeatureProperties, HttpFgbReader, geozero}; use geozero::ToWkt; use anyhow::Result; +use crate::data_request_spec::BBox; /// Function to request geometries from a remotly hosted FGB /// @@ -10,7 +11,7 @@ use anyhow::Result; /// `bbox`: an optional bounding box to filter the features by /// /// Returns: a Result object containing a vector of (geometry, properties). -pub async fn get_geometries(file_url:&str, bbox:Option<&[f64;4]>) -> Result)>>{ +pub async fn get_geometries(file_url:&str, bbox:Option<&BBox>) -> Result)>>{ let fgb = HttpFgbReader::open(file_url) .await?; @@ -170,11 +171,11 @@ mod tests { // Generate a test FGB server let server = mock_fgb_server(); // Get the geometries - let bbox = [ -3.018_352_090_792_945, + let bbox = BBox([ -3.018_352_090_792_945, 51.795_056_187_175_82, -1.373_095_490_899_146_4, 53.026_908_220_355_35, - ]; + ]); let geoms = get_geometries(&server.url("/fgb_example.fgb"),Some(&bbox)).await; assert!(geoms.is_ok(),"The geometry call should not error"); diff --git a/src/lib.rs b/src/lib.rs index 184dab7..dcbdde4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ use anyhow::Result; -use metadata::{load_metadata, MetricMetadata, SourceDataRelease}; +use metadata::{load_metadata, SourceDataRelease}; pub mod data_request_spec; +pub mod geo; pub mod metadata; pub struct Popgetter {