Skip to content

Instantly share code, notes, and snippets.

@mdsumner
Last active February 12, 2025 19:55
Show Gist options
  • Save mdsumner/d19bee6a8c0e393373a6eadf93078ac4 to your computer and use it in GitHub Desktop.
Save mdsumner/d19bee6a8c0e393373a6eadf93078ac4 to your computer and use it in GitHub Desktop.
sf::gdal_utils("vectortranslate", "OAPIF:https://ogc-api.nrw.de/inspire-us-feuerwehr", tf <- tempfile(tmpdir = "/vsimem", fileext = ".fgb"), options = c("-f", "FlatGeobuf", "-where", "name = 'Schwelm'"))
terra::vect(tf)
class       : SpatVector
 geometry    : points
 dimensions  : 1, 22  (geometries, attributes)
 extent      : 381347.8, 381347.8, 5682950, 5682950  (xmin, xmax, ymin, ymax)
 source      : file75f1385c8c91.fgb (governmentalservice)
 coord. ref. : ETRS89 / UTM zone 32N (EPSG:25832)
 names       :    id    name       inspireId serviceType.title serviceType.href
 type        : <chr>   <chr>           <chr>             <chr>            <chr>
 values      : LtS01 Schwelm https://geodat~ Brandschutzdienst  http://inspire~
 areaOfResponsibility.1.title areaOfResponsibility.1.href
                        <chr>                       <chr>
                  Breckerfeld             https://regist~
 pointOfContact.address.thoroughfare pointOfContact.address.locatorDesignator
                               <chr>                                    <chr>
                           Hauptstr.                                       92
 pointOfContact.address.postCode (and 12 more)
                           <chr>
                           58332
@mdsumner
Copy link
Author

mdsumner commented Feb 12, 2025

and with gdalraster (there'd be a way to use "where" to avoid the layer name in the sql)

library(gdalraster) ## I'm using from github
dsn <- "OAPIF:https://ogc-api.nrw.de/inspire-us-feuerwehr"
sql <- "SELECT * FROM governmentalservice WHERE name = 'Schwelm'"
ds <- new(GDALVector, dsn, sql)
ds$getFeatureCount()
[1] 1

@mdsumner
Copy link
Author

or to iterate (also see that ArrowStream will make this better for "batches", but I don't have capacity to explore more atm, this is so cool tho)

dsn <- "OAPIF:https://ogc-api.nrw.de/inspire-us-feuerwehr"
ds <- new(GDALVector, dsn)
for (i in seq_len(ds$getFeatureCount())) print(str(ds$getNextFeature()))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment