Skip to content

Commit

Permalink
josh custom proj
Browse files Browse the repository at this point in the history
  • Loading branch information
jtgilbert committed Nov 30, 2023
1 parent 7857dbe commit a9d96b9
Show file tree
Hide file tree
Showing 3 changed files with 314 additions and 2 deletions.
152 changes: 152 additions & 0 deletions python/packages/rsxml/examples/New_Custom_Riverscapes_Project (1).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# in your code you would write:
from rsxml.project_xml import (
Project,
MetaData,
Meta,
ProjectBounds,
Coords,
BoundingBox,
Dataset,
GeoPackageDatasetTypes,
Realization,
)
import tempfile
# logging is always a good practice
from rsxml import Logger
from datetime import datetime


def main(filepath: str):
log = Logger('Project')

# Create a new Riverscapes Project from scratch
project = Project(
name='Bear River Watershed Conservation Prioritization',
proj_path='WCP',
project_type='Watershed Conservation Prioritization',
description='Priority LTPBR segments within the Bear River watershed. Transient storage was estimated across these segments and summarized at different scales and groupings',
citation='',
bounds=ProjectBounds(
centroid=Coords(-111.39, 41.62),
bounding_box=BoundingBox(-112, -110, 39, 43),
filepath='project_Bounds.json',
),
meta_data=MetaData(values=[Meta('', '')]),
realizations=[
Realization(
xml_id='REALIZATION1',
name='WCP for Bear River Watershed',
product_version='1.0.0',
date_created=datetime(2023, 9, 25),
summary='',
description='',
meta_data=MetaData(values=[Meta('', '')]),
inputs=[
Dataset(
xml_id='Land_Ownership',
name='Land Ownership',
path='Context/Land_Ownership.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='',
),
Dataset(
xml_id='HUC4',
name='Bear River HUC 4 Boundary',
path='Context/WBHU4.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='',
),
Dataset(
xml_id='HUC8_1',
name='Upper Bear HUC 8',
path='Context/WBDHU8_16010101.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='',
),
Dataset(
xml_id='HUC8_2',
name='Central Bear HUC 8',
path='Context/WBDHU8_16010102.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='',
),
Dataset(
xml_id='HUC8_3',
name='Bear Lake HUC 8',
path='Context/WBDHU8_16010201.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='',
),
Dataset(
xml_id='HUC8_4',
name='Middle Bear HUC 8',
path='Context/WBDHU8_16010202.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='',
),
Dataset(
xml_id='HUC8_5',
name='Little Bear-Logan HUC 8',
path='Context/WBDHU8_16010203.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='',
),
Dataset(
xml_id='HUC8_6',
name='Lower Bear-Malad HUC8',
path='Context/WBDHU8_16010204.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='',
)
],
outputs=[
Dataset(
xml_id='Ownership_Parcels',
name='Private Land Parcels',
path='Outputs/Bear_River_Parcels.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='Private parcels identified by TU as having potential interst in LTPBR',
),
Dataset(
xml_id='Reaches',
name='Potential LTBPR Reaches',
path='Outputs/Reaches.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='These reaches were identified by either the BRAT model, reaches on identified private parcels, or ones identified by the USFS',
),
Dataset(
xml_id='VBET_DGO',
name='VBET DGO',
path='Outputs/VBET_DGO.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='',
description='',
),
]
)
]
)

# Write your new XML file to disk
project.write('/mnt/c/Users/jordang/Downloads/project.rs.xml')

log.info('done')


if __name__ == '__main__':
with tempfile.NamedTemporaryFile(prefix='project.rs.', suffix='.xml') as f:
print("\n\nConsole Output\n========================================================================\n")
main(f.name)
print("\n\nProject XML\n========================================================================\n")
with open(f.name, 'r') as f:
print(f.read())
160 changes: 160 additions & 0 deletions python/packages/rsxml/examples/joshs_custom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# in your code you would write:
from rsxml.project_xml import (
Project,
MetaData,
Meta,
ProjectBounds,
Coords,
BoundingBox,
Dataset,
GeoPackageDatasetTypes,
Realization,
)
import tempfile
# logging is always a good practice
from rsxml import Logger
from datetime import datetime


def main(filepath: str):
log = Logger('Project')

# Create a new Riverscapes Project from scratch
project = Project(
name='Bear River Watershed Conservation Prioritization',
proj_path='WCP',
project_type='Watershed Conservation Prioritization',
description='This is a test project',
citation='This is a citation',
bounds=ProjectBounds(
centroid=Coords(-111.39, 41.62),
bounding_box=BoundingBox(-112, 39, -110, 43),
filepath='project_Bounds.json',
),
meta_data=MetaData(values=[Meta('Test', 'Test Value')]),
realizations=[
Realization(
xml_id='test',
name='Test Realization',
product_version='1.0.0',
date_created=datetime(2021, 1, 1),
summary='This is a test realization',
description='This is a test realization',
meta_data=MetaData(values=[Meta('Test', 'Test Value')]),
inputs=[
Dataset(
xml_id='input1',
name='InputDS1',
path='Context/Land_Ownership.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
),
Dataset(
xml_id='input2',
name='InputDS2',
path='Context/WBHU4.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
),
Dataset(
xml_id='input3',
name='InputDS3',
path='Context/WBDHU8_16010101.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
),
Dataset(
xml_id='input4',
name='InputDS4',
path='Context/WBDHU8_16010102.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
),
Dataset(
xml_id='input5',
name='InputDS5',
path='Context/WBDHU8_16010201.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
),
Dataset(
xml_id='input6',
name='InputDS6',
path='Context/WBDHU8_16010202.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
),
Dataset(
xml_id='input7',
name='InputDS7',
path='Context/WBDHU8_16010203.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
),
Dataset(
xml_id='input8',
name='InputDS8',
path='Context/WBDHU8_16010204.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
)
],
outputs=[
Dataset(
xml_id='output1',
name='OutputDS1',
path='Outputs/Bear_River_Parcels.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
),
Dataset(
xml_id='output2',
name='OutputDS2',
path='Outputs/Reaches.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
),
Dataset(
xml_id='output3',
name='OutputDS3',
path='Outputs/VBET_DGO.shp',
ds_type=GeoPackageDatasetTypes.VECTOR,
summary='This is a input dataset',
description='This is a input dataset',
)
# Dataset(
# xml_id='output4',
# name='OutputDS4',
# path='Outputs/Storage.png',
# ds_type=GeoPackageDatasetTypes.PNG,
# summary='This is a input dataset',
# description='This is a input dataset',
# ),
]
)
]
)

# Write your new XML file to disk
project.write('/mnt/c/Users/jordang/Downloads/project.rs.xml')

log.info('done')


if __name__ == '__main__':
with tempfile.NamedTemporaryFile(prefix='project.rs.', suffix='.xml') as f:
print("\n\nConsole Output\n========================================================================\n")
main(f.name)
print("\n\nProject XML\n========================================================================\n")
with open(f.name, 'r') as f:
print(f.read())
4 changes: 2 additions & 2 deletions python/packages/rsxml/scripts/createEnv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set -eu

# On OSX you must have run `brew install gdal` so that the header files are findable
python3 --version
python3 -m venv .venv
python3.11 --version
python3.11 -m venv .venv
# Make sure pip is at a good version
.venv/bin/python3 -m pip install --upgrade pip

Expand Down

0 comments on commit a9d96b9

Please sign in to comment.