Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
savente93 committed Aug 21, 2023
1 parent 67886ae commit 7910777
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
35 changes: 35 additions & 0 deletions debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# import hydromt and setup logging
import geopandas as gpd
import pandas as pd
import hydromt
from hydromt.log import setuplog
import numpy as np

logger = setuplog("read vector data", log_level=10)

data_catalog = hydromt.DataCatalog(logger=logger, data_libs=["artifact_data"])
gdf = data_catalog.get_geodataframe("gadm_level3")
gdf_subset = data_catalog.get_geodataframe(
"gadm_level3", bbox=gdf[:5].total_bounds, variables=["GID_0", "NAME_3"]
)
fn = "tmpdir/xy.csv"
df = pd.DataFrame(
columns=["x_centroid", "y"],
data=np.vstack([gdf_subset.centroid.x, gdf_subset.centroid.y]).T,
)
df["name"] = gdf_subset["NAME_3"]
df.to_csv(fn) # write to file

data_source = {
"GADM_level3_centroids": {
"path": fn,
"data_type": "GeoDataFrame",
"driver": "vector_table",
"crs": 4326,
"driver_kwargs": {"x_dim": "x_centroid"},
}
}
data_catalog.from_dict(data_source)
data_catalog["GADM_level3_centroids"]
breakpoint()
data_catalog.get_geodataframe("GADM_level3_centroids")
29 changes: 29 additions & 0 deletions tmpdir/xy.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
,x_centroid,y,name
0,11.838395117002248,46.266420927145944,Tonadico
1,11.790628852015486,46.250124244511376,Siror
2,11.583525513530201,46.271041435411526,Ziano Di Fiemme
3,11.644162126707185,46.31324741192871,Predazzo
4,11.885506995436247,46.32814011147681,Canale d' Agordo
5,11.846946171343525,46.35937794540328,Falcade
6,11.706954259676763,46.365224477360016,Moena
7,11.754089726316863,46.393714236924055,Soraga
8,11.644297816908956,46.41103968769534,Vigo Di Fassa
9,11.565313881903297,46.424987277558984,Nova Levante
10,11.725591166292068,46.42965741122807,Pozza Di Fassa
11,11.932763106514594,46.43008793522448,Rocca Pietore
12,11.91737673411145,46.04162195540287,Feltre
13,11.646902977008196,46.12190235570463,Castello Tesino
14,11.724745988947115,46.05889087675679,Lamon
15,11.653921809696659,46.09364316810098,Cinte Tesino
16,11.804255860938607,46.071500738970954,Sovramonte
17,11.582413382930849,46.14718628486252,Pieve Tesino
18,11.700785771321256,46.20049874366438,Canal San Bovo
19,11.787346686823344,46.150824156901884,Imer
20,11.815737618666692,46.16003196682739,Mezzano
21,11.87896382869404,46.17026633586807,Transacqua
22,11.829870722781738,46.17648051681102,Fiera Di Primiero
23,11.811416140959986,46.470190140780936,Canazei
24,11.708415361706866,46.4662063122973,Mazzin
25,11.582705158689166,46.475981586553424,Tires
26,11.927925721047652,46.49880770055794,Livinallongo Del Col Di Lana
27,11.712822890552333,46.49157620956803,Campitello Di Fassa

0 comments on commit 7910777

Please sign in to comment.