def test_to_netcdf(tmpdir): gdf = gpd.read_file(TEST_INPUT_DATA_DIR / "soil_data_flat.geojson") vxd = vectorxarray.from_geodataframe(gdf) output_file = tmpdir / "test_vector.nc" vxd.vector.to_netcdf(output_file) vxd2 = vectorxarray.open_dataset(str(output_file)) assert_test_dataframes_equal(gdf, vxd2.vector.to_geodataframe())
def test_multidimensional_error(): gdf = gpd.read_file(TEST_INPUT_DATA_DIR / "soil_data_flat.geojson") vxd = vectorxarray.from_geodataframe(gdf) vxd2 = vxd.copy() vxd.coords["time"] = parse("20170516T000000") vxd2.coords["time"] = parse("20170517T000000") merged_vxd = xarray.concat([vxd, vxd2], dim="time") with pytest.raises(ValueError): merged_vxd.vector.plot(column="sandtotal_r")
def test_from_geodataframe(): gdf = gpd.read_file(TEST_INPUT_DATA_DIR / "soil_data_flat.geojson") vxd = vectorxarray.from_geodataframe(gdf) assert all(gdf.geometry == vxd.geometry.values) assert sorted(gdf.columns.tolist() + ["spatial_ref"]) == sorted( vxd.variables) assert gdf.crs == vxd.rio.crs assert "geometry" in vxd.coords assert "spatial_ref" in vxd.coords
def test_from_geodataframe(): gdf = gpd.read_file( os.path.join(TEST_INPUT_DATA_DIR, "soil_data_flat.geojson")) vxd = vectorxarray.from_geodataframe(gdf) assert all(gdf.geometry == vxd.geometry.values) assert sorted(gdf.columns.tolist() + ["crs"]) == sorted(vxd.variables) assert gdf.crs == vxd.crs.attrs["crs_wkt"] assert "geometry" in vxd.coords assert "crs" in vxd.coords
def test_to_geodataframe(): gdf = gpd.read_file(TEST_INPUT_DATA_DIR / "soil_data_flat.geojson") gdf2 = vectorxarray.from_geodataframe(gdf).vector.to_geodataframe() assert_test_dataframes_equal(gdf, gdf2)