Function polars_gdal::df_from_resource
source · pub fn df_from_resource<P: AsRef<Path>>(
path: P,
params: Option<ReadParams<'_>>
) -> Result<DataFrame, Error>
Expand description
Given a filepath or a URI, read the resource into a dataframe.
The simplest resource is a file on the local filesystem, in which case we would simply pass in a filepath.
Fetching resources over http(s) is supported using a URL.
Connecting to PostGIS is supported using a postgres://user:pass@host/dbname
URI in combination with setting Params::layer_name
to the name of the table.
Formats supported include GeoJSON, Shapefile, SpatialLite database, KML, and others. See https://gdal.org/drivers/vector/index.html for a full list of supported formats. Some formats require additional libraries to be installed.
Local file example
use polars_gdal::df_from_resource;
let df = df_from_resource("my_shapefile.shp", None).unwrap();
println!("{}", df);
Remote file example
use polars_gdal::df_from_resource;
let df = df_from_resource("https://raw.githubusercontent.com/ebrelsford/geojson-examples/master/queens.geojson", None).unwrap();
println!("{}", df);
PostGIS example
use polars_gdal::{df_from_resource, Params};
let mut params = crate::Params::default();
params.layer_name = Some("some_table_name");
let df = df_from_resource("postgresql://user:pass@hostname/dbname", Some(params)).unwrap();
println!("{}", df);