Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion knime_extension/src/nodes/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ def execute(self, exec_context: knext.ExecutionContext):
0.4, "Reading file (This might take a while without progress changes)"
)

import geopandas as gpd

def urlread(url: str) -> gpd.GeoDataFrame:
try:
gdf = gpd.read_file(url)
return gdf
except Exception as e1:
if url.startswith("http") and url.endswith(".zip"):
try:
vsizip_url = "/vsizip/vsicurl/" + url
gdf = gpd.read_file(vsizip_url)
return gdf
except Exception as e2:
raise RuntimeError(f"Error:{e2}")
else:
raise RuntimeError(f"Error:{e1}")

if self.data_url.lower().endswith(".kml"):
import fiona

Expand Down Expand Up @@ -132,7 +149,7 @@ def execute(self, exec_context: knext.ExecutionContext):
):
gdf = gp.read_parquet(self.data_url)
else:
gdf = gp.read_file(self.data_url)
gdf = urlread(self.data_url)

if "<Row Key>" in gdf.columns:
gdf = gdf.drop(columns="<Row Key>")
Expand Down
3 changes: 2 additions & 1 deletion knime_extension/src/nodes/opendata.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def execute(self, exec_context: knext.ExecutionContext):

County5Fips = self.StateFips + self.County3Fips

base_url = "https://www2.census.gov/geo/tiger/TIGER2020PL/STATE/"
base_url = "ftp://ftp2.census.gov/geo/tiger/TIGER2020PL/STATE/"

if self.StateFips != self.County3Fips and self.County3Fips != "*":
data_url = f"{base_url}{Statepath}/{County5Fips}/tl_2020_{County5Fips}_{self.geofile}.zip"
Expand All @@ -219,6 +219,7 @@ def execute(self, exec_context: knext.ExecutionContext):
if self.geofile == "roads":
self.geofile = "prisecroads"
data_url = f"{base_url}{Statepath}/{County5Fips}/tl_2020_{County5Fips}_{self.geofile}.zip"
# data_url = "/vsizip/vsicurl/" + data_url
gdf = gp.read_file(data_url)
gdf.reset_index(drop=True, inplace=True)
return knext.Table.from_pandas(gdf)
Expand Down