Skip to content

Commit

Permalink
one file for the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
romer8 committed Jun 10, 2024
1 parent 14792c9 commit d130197
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
45 changes: 44 additions & 1 deletion cli/convert_geom.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
import argparse
from geo.Geoserver import Geoserver
from .utils import _read_and_transform, _create_and_publish_shp
import geopandas as gpd
import zipfile
import os


def _read_and_transform(gpkg_path, layer_name):
gdf = gpd.read_file(gpkg_path, layer=layer_name)
if gdf.crs.to_string() != "EPSG:5070":
gdf = gdf.to_crs(epsg=5070)
return gdf


def _create_and_publish_shp(
gdf,
shp_path,
geoserver_host,
geoserver_port,
geoserver_username,
geoserver_password,
):
gdf.to_file(f"{shp_path}.shp", driver="ESRI Shapefile")
shp_files = [f"{shp_path}.{ext}" for ext in ["shp", "shx", "dbf", "prj"]]

with zipfile.ZipFile(f"{shp_path}.zip", "w") as zipf:
for file in shp_files:
zipf.write(file, arcname=os.path.basename(file))

# remove shapefiles
for file in shp_files:
os.remove(file)

geo = Geoserver(
f"http://{geoserver_host}:{geoserver_port}/geoserver",
username=geoserver_username,
password=geoserver_password,
)

geo.create_shp_datastore(
path=f"{shp_path}.zip",
store_name="hydrofabrics",
workspace="nextgen",
)
# remove zip file
os.remove(f"{shp_path}.zip")


def create_workspace(
Expand Down
45 changes: 0 additions & 45 deletions cli/utils.py

This file was deleted.

0 comments on commit d130197

Please sign in to comment.