From a9d96b978cd2238be930be0386ec900f89c39f2c Mon Sep 17 00:00:00 2001 From: Jordan Gilbert Date: Thu, 30 Nov 2023 09:33:28 -0700 Subject: [PATCH] josh custom proj --- .../New_Custom_Riverscapes_Project (1).py | 152 +++++++++++++++++ .../packages/rsxml/examples/joshs_custom.py | 160 ++++++++++++++++++ python/packages/rsxml/scripts/createEnv.sh | 4 +- 3 files changed, 314 insertions(+), 2 deletions(-) create mode 100644 python/packages/rsxml/examples/New_Custom_Riverscapes_Project (1).py create mode 100644 python/packages/rsxml/examples/joshs_custom.py diff --git a/python/packages/rsxml/examples/New_Custom_Riverscapes_Project (1).py b/python/packages/rsxml/examples/New_Custom_Riverscapes_Project (1).py new file mode 100644 index 00000000..6b287fdb --- /dev/null +++ b/python/packages/rsxml/examples/New_Custom_Riverscapes_Project (1).py @@ -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()) diff --git a/python/packages/rsxml/examples/joshs_custom.py b/python/packages/rsxml/examples/joshs_custom.py new file mode 100644 index 00000000..300df949 --- /dev/null +++ b/python/packages/rsxml/examples/joshs_custom.py @@ -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()) diff --git a/python/packages/rsxml/scripts/createEnv.sh b/python/packages/rsxml/scripts/createEnv.sh index 23cc58f4..48c763b7 100755 --- a/python/packages/rsxml/scripts/createEnv.sh +++ b/python/packages/rsxml/scripts/createEnv.sh @@ -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