├── .gitignore ├── .hgignore ├── Lib └── pyuac.py ├── Readme.adoc ├── apt └── Readme.md ├── arcplus ├── AttributedMultiRingBuffer.py ├── arcgisscripting.py ├── arcplus.py ├── autocrop.ClipNoData.pyt.xml ├── autocrop.pyt ├── autocrop.pyt.xml ├── report-versions.py └── xx-calc-trans.py ├── gis ├── AliasFeatureclassConversion.py ├── Tango-Palette.gpl ├── asSVG.py ├── canvec │ ├── Using CanVec at Musings.desktop │ ├── db-friendly-names.txt │ ├── download-yukon-gml.bat │ ├── gml2shp.bat │ ├── gml2shp_friendly_layers.bat │ └── unpack-canvec-zips.bat ├── gdal_extras │ ├── Readme.txt │ ├── bin │ │ ├── fortiff.cmd │ │ ├── fusion.py │ │ ├── gdal-help.bat │ │ ├── gdal_vrtmerge.py │ │ ├── gdalcopyproj.py │ │ └── gdalsetnull.py │ ├── data │ │ └── NTS-50kindex.csv │ ├── gdal-extras-install.bat │ ├── gdal_plugins │ │ ├── gdal_SDE_91.dll │ │ └── gdal_SDE_92.dll │ ├── pics │ │ └── bcg_tool.xpm │ ├── proj_lib │ │ └── yukon_albers.epsg │ ├── setfw_portable.cmd │ └── tools │ │ └── Tool_BrightContrastGamma.py ├── geobase │ ├── Automatic download and conversion of Geobase Road Network at Musings.desktop │ └── nrn2yukon.bat ├── list-fc-aliases.py ├── misc │ ├── cov2shp.cmd │ ├── nts-html-table.htm │ ├── nts_map_as_html_table.py │ └── tissot │ │ ├── generate_tissot.py │ │ ├── tissot.dbf │ │ ├── tissot.prj │ │ ├── tissot.shp │ │ └── tissot.shx ├── o4w_extras │ ├── Readme.txt │ ├── bin │ │ ├── BuildAptExe.bat │ │ ├── TestAptExe.bat │ │ ├── apt.py │ │ ├── cyg-apt.py │ │ ├── gdal-makeworld.py │ │ ├── gdalcopyproj.py │ │ ├── gdalsetnull.py │ │ ├── proj2wkt.py │ │ └── wkt2proj.py │ ├── install-o4w-extras.bat │ ├── share │ │ ├── gdal │ │ │ └── NTS-50kindex.csv │ │ └── proj │ │ │ └── _put__ntv2_0.gsb__here.URL │ ├── tests │ │ └── apt-from-scratch.bat │ └── xcopy_exclude.txt ├── qgis │ ├── h3-grid-from-layer.py │ ├── h3-in-qgis.assets │ │ ├── h3-edit-min-max.png │ │ ├── h3-results.png │ │ └── h3-select-and-open.png │ └── h3-in-qgis.md ├── recursive_apr_update │ ├── .viminfo │ ├── Copy of replace.vim │ ├── ReadMe.txt │ ├── build-replace.vim │ ├── replace.src.txt │ ├── replace.vim │ ├── rgn_update.tws │ ├── set-vim.bat │ ├── upgrade-all.bat │ ├── vim │ │ ├── vim57 │ │ │ └── _put_vim_runtime_here_ │ │ └── vimrc │ ├── viminfo │ └── worknotes.txt ├── uninstall-ALL-ArcGIS-products.bat ├── xx-set-alias.py └── yt30m_dem │ ├── 50kdem │ ├── 50k_dem.tws │ ├── 50k_dem_anudem.tws │ ├── _ReadMe.aml │ ├── _TODO.txt │ ├── _readme-anudem.txt │ ├── _template.aml │ ├── adem2grid.aml │ ├── anudem.aml │ ├── append_elev.aml │ ├── append_h2o.aml │ ├── border-tiles.txt │ ├── build_dem_cmd.aml │ ├── clip_100m.aml │ ├── clip_lakes.aml │ ├── cover2generate.aml │ ├── dem2lib.aml │ ├── find_paths.aml │ ├── flat_lakes.aml │ ├── flip_streams.aml │ ├── float2int.aml │ ├── flowdirect.aml │ ├── get_akpnts.aml │ ├── grid2catalog.aml │ ├── index-all.txt │ ├── job.list.txt │ ├── kill_flipgrids.aml │ ├── kill_locks.aml │ ├── make_buffers.aml │ ├── make_dems.aml │ ├── make_flipgrid.aml │ ├── make_shade.aml │ ├── make_tilestruct.aml │ ├── mosaic_250k.aml │ ├── nuke.aml │ ├── out2anudem.aml │ ├── pkg_250k.aml │ ├── pkg_50k.aml │ ├── redo-center.aml │ ├── rinse.aml │ ├── run_anudem.aml │ ├── scrap.aml │ ├── sed.txt │ ├── update-library.aml │ └── whole-hog.aml │ ├── LICENSE.txt │ ├── depends │ ├── UNIX2DOS.EXE │ ├── cygwin1.dll │ ├── gunzip.exe │ ├── gzip.exe │ └── sed.exe │ ├── readme.txt │ ├── resources │ ├── FW geomorphometry DEM creation from digitized map (Summary of Replies).txt │ ├── Overview.txt │ └── SUM_contour-biasing.txt │ └── setenv_50kdem.aml ├── metril └── import_onenote_zip.py ├── other ├── OpenWithNotepad.reg ├── RelaunchElevated.cmd ├── RelaunchElevated_EmbeddedScripts.cmd ├── RemoveOpenWithNotepad.reg ├── add2shims.bat ├── args.py ├── assoc-py.cmd ├── bats │ ├── chrome-me-um.bat │ ├── dupe-search.bat │ ├── enable-remote-desktop.bat │ ├── make-bat-for-py.bat │ ├── paint.bat │ ├── printpdf.bat │ └── search-path.bat ├── cmdline.bat ├── cmdline.py ├── create-leobat.bat ├── cyg-apt.py ├── dezoomify.rb ├── doskey-aliases.txt ├── doskey-reload.bat ├── foobar.py ├── ftype-py-arc10.cmd ├── ftype-py-from-env.cmd ├── get-unc-path.bat ├── install-pip.py ├── micromamba │ └── install-micromamba.cmd ├── pdf-extract │ ├── .gitignore │ ├── Environment.md │ ├── Extract images from PDF without resampling, in python - Stack Overflow.URL │ ├── extract-pdf-img-alex.py │ ├── extract-pdf-img.py │ └── requirements.txt ├── pdf2jpg │ ├── bin │ │ ├── pdf2jpg-all.bat │ │ ├── pdf2jpg-dir.bat │ │ ├── pdf2jpg.bat │ │ └── test-pdf-files.bat │ ├── pdf2jpg.md │ └── setenv.bat ├── proj-dir │ ├── Readme.md │ ├── scripts │ │ └── x-help.bat │ └── setenv.bat ├── psh │ ├── Microsoft.PowerShell_profile.ps1 │ ├── Update-SessionEnvironment.ps1 │ └── install-winget.ps1 ├── remote-install-vnc.bat ├── replace_mspaint_with_paintdotnet.reg ├── replace_notepad_with_LightTable.reg ├── replace_notepad_with_notepad++.reg ├── replace_notepad_with_notepad2.reg ├── rewrite-maphew2mhwgov.sh ├── rewrite-mhwgov2maphew.sh ├── show_ad_group_members.py ├── time_cmd.py ├── win10-start-menu-no-internet-results.reg ├── xx-convert-mov2m4v.bat ├── xx-convert-wma2mp3.bat └── xxcopy-change-install-date.bat ├── register-python ├── classy-reggie.bat ├── classy-reggie.py ├── list-python-installs.py ├── list-registry.py ├── register-python.bat ├── register-python.py ├── samples │ ├── hkcu_py-reg_d-drive.reg │ ├── hklm_o4wpy-reg_23.reg │ ├── hklm_o4wpy-reg_d-drive.reg │ ├── hklm_x64_default_install.reg │ ├── hklm_x64_py27.reg │ ├── hklm_x64_pyqt4_py27.reg │ └── py25_x32_default_install.reg ├── switch-python.py ├── walk-registry.py ├── win-specialfolders.py └── xx-parse.py ├── scrapbook ├── kml2wld.sh └── tag2semver.py ├── tools ├── Readme.md └── gitignore_to_fossil.py └── win-remote-reboot.ps1 /.gitignore: -------------------------------------------------------------------------------- 1 | /other/micromamba/micromamba.tar.bz2 2 | -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | *.pyc 3 | google-code.txt 4 | *.egg-info 5 | -------------------------------------------------------------------------------- /Readme.adoc: -------------------------------------------------------------------------------- 1 | = Matt's code thicket 2 | 3 | A sometimes-tended garden of things a _hewer of maps_ has made 4 | and copied that can occasionally be turned to useful work. 5 | 6 | -------------------------------------------------------------------------------- /apt/Readme.md: -------------------------------------------------------------------------------- 1 | *2014-Oct-24* 2 | 3 | Apt has moved to 4 | [https://github.com/maphew/apt](https://github.com/maphew/apt) 5 | 6 | -------------------------------------------------------------------------------- /arcplus/AttributedMultiRingBuffer.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Moved to https://github.com/maphew/arcplus 3 | ''' 4 | -------------------------------------------------------------------------------- /arcplus/arcgisscripting.py: -------------------------------------------------------------------------------- 1 | ## Here for archival purposes. It's not needed for Arcplus any more. 2 | ## 2010-Aug-11 3 | '''---------------------------------------------------------------------------------- 4 | arcgisscripting.py 5 | Version: 0.9.1 6 | Author: Philippe Le Grand 7 | Required Argumuments: None 8 | Description: This module serves to replace ESRI's arcgisscripting.dll 9 | on configurations where it is not available 10 | 11 | arcgisscripting is a custom dll module that is build against the 12 | python24.dll library; you cannot get it to work under python25; 13 | you have to use the old style pywin32 system instead. 14 | 15 | Assuming you have pywin32 installed for python 2.5, the script 16 | below can serve as a wrapper that will allow you to circumvent 17 | the problem. Just save it as arcgisscripting.py in your 18 | pythonpath 19 | -- http://forums.esri.com/Thread.asp?c=93&f=1729&t=216040 20 | 21 | 22 | This script is free software; you can redistribute it and/or modify 23 | it under the terms of the GNU General Public License as published by 24 | the Free Software Foundation; either version 2 of the License, or 25 | (at your option) any later version. 26 | 27 | This program is distributed in the hope that it will be useful, 28 | but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 30 | GNU General Public License for more details. 31 | 32 | A copy of the GNU General Public License may be obtained 33 | online at 34 | 35 | http://www.gnu.org/copyleft/gpl.html 36 | 37 | or by writing to the 38 | 39 | Free Software Foundation, Inc., 40 | 51 Franklin Street, Fifth Floor, 41 | Boston, MA 02110-1301 USA 42 | 43 | ----------------------------------------------------------------------------------''' 44 | 45 | import win32com.client 46 | 47 | def create(licensetype=None): 48 | gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1") 49 | if licensetype is not None: 50 | Licensed=gp.SetProduct(licensetype) 51 | if not (Licensed in ["NotLicensed","Failed"]): 52 | return gp 53 | #Either the licensetype was not set, or it failed 54 | #Try to get the highest possible license 55 | types = ["ArcInfo","ArcEditor","ArcView"] 56 | for license in types: 57 | Licensed=gp.CheckProduct(license) 58 | if not (Licensed in ["NotLicensed","Failed"]): 59 | Licensed = gp.SetProduct(license) 60 | print "geoprocessor started with license: %s (%s)"%(license,Licensed) 61 | return gp 62 | else: 63 | print "license %s is %s"%(license,Licensed) 64 | gp.AddError("No License available for geoprocessor") 65 | raise ValueError,"No License available for geoprocessor" 66 | 67 | if (__name__=="__main__"): 68 | gp=create() 69 | 70 | -------------------------------------------------------------------------------- /arcplus/arcplus.py: -------------------------------------------------------------------------------- 1 | #@+leo-ver=5-thin 2 | #@+node:maphew.20120201135209.1859: * @file arcplus.py 3 | ''' arcplus.py: functions missing from regular ol' arcpy module ''' 4 | 5 | import os, arcgisscripting 6 | gp = arcgisscripting.create(9.3) 7 | 8 | #@+others 9 | #@+node:maphew.20110208134351.3123: ** list All Feature Classes 10 | def listAllFeatureClasses (gdb,**kwargs): 11 | ''' list all Feature Classes in a geodatabase or coverage recursively (normal listFeatureClasses does not recurse)''' 12 | 13 | gp.workspace = gdb 14 | 15 | if not kwargs.has_key('fc_filter'): fc_filter = '*' 16 | else: fc_filter = kwargs ['fc_filter'] 17 | 18 | if not kwargs.has_key('fd_filter'): fd_filter = '*' 19 | else: fd_filter = kwargs ['fd_filter'] 20 | 21 | print 'Looking in %s for "%s" ' % (gp.workspace,fc_filter) 22 | 23 | fcs = [] 24 | for fds in gp.ListDatasets(fd_filter,'feature') + ['']: 25 | for fc in gp.ListFeatureClasses(fc_filter,'',fds): 26 | #print '%s\\%s' % (fds,fc) 27 | fcs.append(os.path.join(fds,fc)) 28 | 29 | return fcs 30 | 31 | #@+node:maphew.20110314104726.3195: *3* extended docstring 32 | ''' 33 | Optional keyword arguments, for example: 34 | 35 | fc_filter = 'HD_*', fd_filter = '*Hydro* 36 | 37 | will process only feature classes that start with 'HD_' within feature datasets containing '*Hydro*' 38 | 39 | Thank you Gotchula: 40 | @url http://gis.stackexchange.com/questions/5893/list-all-feature-classes-in-gdb-including-within-feature-datasets 41 | and http://stackoverflow.com/questions/3394835/args-and-kwargs 42 | ''' 43 | #@-others 44 | #@-leo 45 | -------------------------------------------------------------------------------- /arcplus/autocrop.ClipNoData.pyt.xml: -------------------------------------------------------------------------------- 1 | 2 | 20130322084846001.0TRUE20130503143406Clip NoDataArcToolbox Tool 3 | -------------------------------------------------------------------------------- /arcplus/autocrop.pyt.xml: -------------------------------------------------------------------------------- 1 | 2 | 20130322084845001.0TRUE20130503143405c:\arcgis\desktop10.1\Help\gpautocropArcToolbox Toolbox 3 | -------------------------------------------------------------------------------- /arcplus/report-versions.py: -------------------------------------------------------------------------------- 1 | r''' 2 | Report ArcGIS Pro's primary library versions 3 | From 4 | 5 | 6 | Locate ArcGIS Pro's python folder with Everything Search CLI: 7 | 8 | es pro-py 9 | --> C:\ArcGIS\bin\Python\envs\arcgispro-py3 10 | 11 | Run: 12 | C:\ArcGIS\bin\Python\envs\arcgispro-py3\python.exe path\to\arcplus\report-versions.py 13 | 14 | --> python: 3.9.16 [MSC v.1931 64 bit (AMD64)] 15 | matplotlib 3.6.0 16 | numpy: 1.20.1 17 | scipy: 1.6.2 18 | ''' 19 | import sys 20 | import matplotlib 21 | import numpy 22 | import scipy 23 | print(f'python:\t\t{sys.version}') 24 | print(f'matplotlib:\t{matplotlib.__version__}') 25 | print(f'numpy:\t\t{numpy.__version__}') 26 | print(f'scipy:\t\t{scipy.__version__}') 27 | -------------------------------------------------------------------------------- /arcplus/xx-calc-trans.py: -------------------------------------------------------------------------------- 1 | #@+leo-ver=5-thin 2 | #@+node:maphew.20120203103945.1813: * @file xx-calc-trans.py 3 | ''' scratchpad file: test out ideas for how to calculate transparency percentage of each ring buffer given approximate start and end values. 4 | ''' 5 | ring_width = 1000 # width of each buffer ring 6 | num_rings = 7 # total number of rings to create 7 | darkest = 50 # uppermost layer transparency % 8 | lightest = 80 # lowermost layer transparency % 9 | 10 | first_ring = ring_width # 1000 11 | 12 | #@+others 13 | #@+node:maphew.20120203121800.1759: ** get_transparency_dict 14 | def get_transparency_dict(darkest, lightest, steps): 15 | '''build dictionary of transparency percentages with specified number of steps 16 | Returns {0:50, 1:55, 2:60 ...}''' 17 | transparency_dict = {} 18 | stepsize = (lightest - darkest) / steps # percent to lighten/darken each ring 19 | for e,i in enumerate(range(darkest, lightest, stepsize)): 20 | # print "Ring #",e+1, "transparency is", i 21 | transparency_dict[e + 1] = i 22 | return transparency_dict 23 | #@-others 24 | 25 | transparency_dict = get_transparency_dict(darkest, lightest, num_rings) 26 | 27 | import arcpy 28 | 29 | wspace = 'd:/s/default.gdb' 30 | in_fc = 'FNTT' 31 | out_fc = in_fc + '_buffers' 32 | num_rings = 7 33 | ring_width = 1000 34 | ring_type = 'INSIDE' 35 | 36 | sideType = "OUTSIDE_ONLY" 37 | endType = "ROUND" 38 | dissolveType = "LIST" 39 | dissolveFields = "NAME;TYPE" # attributes we want to keep, adjust as needed 40 | 41 | arcpy.env.workspace = wspace 42 | 43 | buffered_fcs = [] 44 | for current_ring in range(1, num_rings + 1): 45 | transparency = transparency_dict[current_ring] 46 | width = str(ring_width * current_ring) 47 | buf_fc = arcpy.ValidateTableName('xxx_' + out_fc + width) 48 | 49 | print "...Buffer #{0:2d} width {1} transparency {2}".format(current_ring, width, transparency) 50 | 51 | if ring_type == 'INSIDE': 52 | arcpy.Buffer_analysis(in_fc, buf_fc, '-'+width, sideType, endType, dissolveType, dissolveFields) 53 | else: 54 | arcpy.Buffer_analysis(in_fc, buf_fc, width, sideType, endType, dissolveType, dissolveFields) 55 | 56 | # store buffer width as attribute value 57 | arcpy.AddField_management(buf_fc, 'Width', "TEXT", "", "", 16) 58 | arcpy.CalculateField_management(buf_fc, 'Width', width, "PYTHON") 59 | 60 | # store transparency also 61 | arcpy.AddField_management(buf_fc, 'Transparency', "SHORT") 62 | arcpy.CalculateField_management(buf_fc, 'Transparency', transparency, "PYTHON") 63 | 64 | buffered_fcs.append(buf_fc) 65 | 66 | # arrange buffers from largest to smallest width 67 | # so the draw order is correct after merging 68 | buffered_fcs.sort() 69 | buffered_fcs.reverse() 70 | 71 | print("...Merging intermediate buffers into {0}".format(out_fc)) 72 | arcpy.Merge_management(buffered_fcs, out_fc) 73 | 74 | # remove temporary intermediate files 75 | print("...Removing intermediate files") 76 | for fc in arcpy.ListFeatureClasses('xxx_*'): 77 | arcpy.Delete_management(fc) 78 | #@-leo 79 | -------------------------------------------------------------------------------- /gis/AliasFeatureclassConversion.py: -------------------------------------------------------------------------------- 1 | import ConversionUtils, time 2 | 3 | ConversionUtils.gp.Overwriteoutput = 1 4 | 5 | #Define message constants so they may be translated easily 6 | msgErrorInvalidOutPath = "Output path does not exist" 7 | msgSuccess = "successfully converted to " 8 | msgFailed = "Failed to convert " 9 | 10 | # Argument 1 is the list of feature classes to be converted 11 | inFeatureClasses = ConversionUtils.gp.GetParameterAsText(0) 12 | 13 | # The list is split by semicolons ";" 14 | inFeatureClasses = ConversionUtils.SplitMultiInputs(inFeatureClasses) 15 | 16 | # The output workspace where the shapefiles are created 17 | outWorkspace = ConversionUtils.gp.GetParameterAsText(1) 18 | 19 | # Set the destination workspace parameter (which is the same value as the output workspace) 20 | # the purpose of this parameter is to allow connectivity in Model Builder. 21 | ConversionUtils.gp.SetParameterAsText(2,outWorkspace) 22 | 23 | # Set the progressor 24 | ConversionUtils.gp.SetProgressor("step", "Converting multiple feature classes ...", 0, len(inFeatureClasses)) 25 | 26 | # Loop through the list of input feature classes and convert/copy each to the output geodatabase or folder 27 | for inFeatureClass in inFeatureClasses: 28 | try: 29 | # Set the progressor label 30 | ConversionUtils.gp.SetProgressorLabel("Converting " + inFeatureClass) 31 | 32 | # Generate a valid output output name 33 | outFeatureClass = ConversionUtils.GenerateOutputName(inFeatureClass, outWorkspace) 34 | 35 | # Copy/Convert the inFeatureClasses to the outFeatureClasses 36 | ConversionUtils.CopyFeatures(inFeatureClass, outFeatureClass) 37 | 38 | # If the Copy/Convert was successfull add a message stating this 39 | ConversionUtils.gp.AddMessage("%s %s %s" % (inFeatureClass, msgSuccess, outFeatureClass)) 40 | 41 | except Exception, ErrorDesc: 42 | # Except block for the loop. If the tool fails to convert one of the feature classes, it will come into this block 43 | # and add warnings to the messages, then proceed to attempt to convert the next input feature class. 44 | msgWarning = msgFailed + "%s" % inFeatureClass 45 | msgStr = ConversionUtils.gp.GetMessages(2) 46 | ConversionUtils.gp.AddWarning(ConversionUtils.ExceptionMessages(msgWarning, msgStr, ErrorDesc)) 47 | 48 | ConversionUtils.gp.SetProgressorPosition() 49 | 50 | time.sleep(0.5) 51 | -------------------------------------------------------------------------------- /gis/Tango-Palette.gpl: -------------------------------------------------------------------------------- 1 | GIMP Palette 2 | Name: Tango icons 3 | Columns: 3 4 | # 5 | 252 233 79 Butter 1 6 | 237 212 0 Butter 2 7 | 196 160 0 Butter 3 8 | 138 226 52 Chameleon 1 9 | 115 210 22 Chameleon 2 10 | 78 154 6 Chameleon 3 11 | 252 175 62 Orange 1 12 | 245 121 0 Orange 2 13 | 206 92 0 Orange 3 14 | 114 159 207 Sky Blue 1 15 | 52 101 164 Sky Blue 2 16 | 32 74 135 Sky Blue 3 17 | 173 127 168 Plum 1 18 | 117 80 123 Plum 2 19 | 92 53 102 Plum 3 20 | 233 185 110 Chocolate 1 21 | 193 125 17 Chocolate 2 22 | 143 89 2 Chocolate 3 23 | 239 41 41 Scarlet Red 1 24 | 204 0 0 Scarlet Red 2 25 | 164 0 0 Scarlet Red 3 26 | 238 238 236 Aluminium 1 27 | 211 215 207 Aluminium 2 28 | 186 189 182 Aluminium 3 29 | 136 138 133 Aluminium 4 30 | 85 87 83 Aluminium 5 31 | 46 52 54 Aluminium 6 32 | -------------------------------------------------------------------------------- /gis/canvec/Using CanVec at Musings.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Version=1.0 3 | Encoding=UTF-8 4 | Name=Link to Using CanVec at Musings 5 | Type=Link 6 | URL=http://www.uttara.ca/blog/gis/using-canvec 7 | Icon=gnome-fs-bookmark 8 | -------------------------------------------------------------------------------- /gis/canvec/db-friendly-names.txt: -------------------------------------------------------------------------------- 1 | Database Name Friendly Name 2 | BS_1250009 Navigational aid 3 | BS_1370009 Residential area 4 | BS_2000009 Parabolic antenna 5 | BS_2010009 Building 6 | BS_2060009 Chimney 7 | BS_2080009 Tank 8 | BS_2120009 Cross 9 | BS_2230009 Transmission line 10 | BS_2240009 Wall or fence 11 | BS_2310009 Pipeline (Sewage or liquid waste) 12 | BS_2350009 Well 13 | BS_2380009 Underground reservoir 14 | BS_2440009 Silo 15 | BS_2530009 Tower 16 | EN_1120009 Power transmission line 17 | EN_1180009 Pipeline 18 | EN_1340009 Valve 19 | EN_1360049 Gas and oil facilities 20 | EN_1360059 Transformer station 21 | EN_2170009 Wind-operated device 22 | FO_1030009 Contour 23 | FO_1080019 Landform 24 | FO_1080029 Esker 25 | FO_1080039 Glacial debris undifferentiated 26 | FO_1080049 Moraine 27 | FO_1080059 Sand 28 | FO_1080069 Tundra polygon 29 | FO_1080079 Pingo 30 | FO_1200009 Elevation point 31 | FO_2570009 Contour imperial 32 | FO_2610009 Elevation point imperial 33 | HD_1140009 Permanent snow and ice 34 | HD_1150009 Coastal water 35 | HD_1450009 Manmade hydrographic entity 36 | HD_1460009 Hydrographic obstacle entity 37 | HD_1470009 Single line watercourse 38 | HD_1480009 Waterbody 39 | HD_1490009 Island 40 | IC_1350019 Pit 41 | IC_1350029 Quarry 42 | IC_1350039 Extraction area 43 | IC_1350049 Mine 44 | IC_1350059 Peat cutting 45 | IC_1360019 Domestic waste 46 | IC_1360029 Industrial solid waste 47 | IC_1360039 Industrial and commercial area 48 | IC_2110009 Lumber yard 49 | IC_2360009 Auto wrecker 50 | IC_2600009 Mining area 51 | LI_1210009 NTS50K boundary polygon 52 | LX_1000019 Lookout 53 | LX_1000029 Ski centre 54 | LX_1000039 Cemetery 55 | LX_1000049 Fort 56 | LX_1000059 Designated area 57 | LX_1000069 Marina 58 | LX_1000079 Sports track or Race track 59 | LX_1000089 Golf course 60 | LX_2030009 Camp 61 | LX_2070009 Drive-in theatre 62 | LX_2200009 Botanical garden 63 | LX_2210009 Shrine 64 | LX_2220009 Historical site or Point of interest 65 | LX_2260009 Amusement park 66 | LX_2270009 Park or sports field 67 | LX_2280009 Footbridge 68 | LX_2400009 Ruins 69 | LX_2420009 Trail 70 | LX_2460009 Stadium 71 | LX_2480009 Campground 72 | LX_2490009 Picnic site 73 | LX_2500009 Golf drining range 74 | LX_2510009 Exhibition ground 75 | LX_2560009 Zoo 76 | SS_1320019 Tundra pond 77 | SS_1320029 Palsa bog 78 | SS_1320039 Saturated soil 79 | SS_1320049 Wetland 80 | SS_1320059 String bog 81 | TO_2520009 Toponym 82 | TR_1020009 Railway 83 | TR_1190009 Runway 84 | TR_1750009 Ferry connection segment [GeoBase] 85 | TR_1760009 Road segment [GeoBase] 86 | TR_1770009 Junction [GeoBase] 87 | TR_1780009 Blocked passage [GeoBase] 88 | TR_1790009 Toll point [GeoBase] 89 | TR_2320009 Turntable 90 | VE_1240009 Wooded area 91 | VE_2290009 Cut line 92 | -------------------------------------------------------------------------------- /gis/canvec/download-yukon-gml.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: rev 0.1, 2007 May 02, maphew@gmail.com 3 | echo. 4 | echo. Going to download 1:50,000 CanVec data for Yukon as GML, which could 5 | echo. take awhile. This script can be aborted and rerun, it will resume 6 | echo. where it left off. 7 | echo. 8 | setlocal 9 | 10 | call :ChkReqs wget.exe 11 | goto :EOF 12 | 13 | :ChkReqs 14 | :: test for wget, if it is in path we can carry on. 15 | if exist "%~$PATH:1" ( 16 | call :Download ) else ( 17 | echo %1 not found! can't continue 18 | ) 19 | goto :EOF 20 | 21 | :Download 22 | set urlRoot=ftp://ftp2.cits.rncan.gc.ca/pub/canvec/50k_gml 23 | 24 | :: Change these NTS numbers as required for your area of interest 25 | set QuadList=115 105 095 106 116 117 114 094 104 26 | 27 | for %%a in (%QuadList%) do ( 28 | wget --recursive --continue --level=3 --no-host-directories --cut-dirs=2 %urlRoot%/%%a/* 29 | ) 30 | goto :EOF 31 | -------------------------------------------------------------------------------- /gis/canvec/gml2shp.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: Merge all gml files in specified directory to shapefiles, with optional OGR parameters 3 | :: 4 | if "%2" =="" goto :Usage 5 | 6 | :: Handle command line arguments, 7 | :: kudos to Patrick Cuff - http://stackoverflow.com/questions/382587 8 | for /f "tokens=1-3*" %%a in ("%*") do ( 9 | set srcDir=%1 10 | set outDir=%2 11 | set arg3=%%c 12 | set argTheRest=%%d 13 | ) 14 | 15 | set ogrArgs= -f "esri shapefile" 16 | 17 | :: OGR parameters to project from NAD83CSRS to Yukon Albers 18 | set yt_alb="+proj=aea +lat_1=61.66666666666666 +lat_2=68.0 +lat_0=59.0 +lon_0=-132.5 +x_0=500000 +y_0=500000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs" 19 | 20 | if "%arg3%"=="yukon" ( 21 | set ogrArgs=%ogrArgs% -s_srs epsg:4617 -t_srs %yt_alb% ) else ( 22 | set ogrArgs=%ogrArgs% %argTheRest% 23 | ) 24 | 25 | call :Main 26 | goto :EOF 27 | 28 | :Main 29 | pushd %srcDir% 30 | for %%f in (*.gml) do ( 31 | echo Processing %%f 32 | REM convert from GML to SHP and merge 33 | if not exist [%outDir%] (call :New %%f) else (call :Append %%f) 34 | ) 35 | popd 36 | goto :EOF 37 | 38 | :New 39 | echo ogr2ogr %ogrArgs% %outDir% %1 40 | ogr2ogr %ogrArgs% -append %outDir% %1 41 | goto :eof 42 | 43 | :Append 44 | echo ogr2ogr %ogrArgs% -update -append %outDir% %1 45 | ogr2ogr %ogrArgs% -update -append %outDir% %1 46 | goto :eof 47 | 48 | :Usage 49 | echo. 50 | echo. Usage: %~n0 [path\to\*.gml] [output dir] {ogr arguments} 51 | echo. 52 | -------------------------------------------------------------------------------- /gis/canvec/gml2shp_friendly_layers.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enabledelayedexpansion 3 | 4 | if [%2] ==[] goto :Usage 5 | 6 | set _inFile=%1 7 | set _outDir=%2 8 | 9 | set _yt_alb="+proj=aea +lat_1=61_66666666666666 +lat_2=68_0 +lat_0=59_0 +lon_0=-132_5 +x_0=500000 +y_0=500000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs" 10 | set _opt=-s_srs epsg:4617 -t_srs %_yt_alb% 11 | 12 | :Main 13 | for /f "skip=1 tokens=1,2*" %%g in (bin\db-friendly-names.txt) do ( 14 | set inLayer=%%g 15 | set outLayer=%%h %%i 16 | 17 | echo Processing "%_inFile%" 18 | if not exist "%_outDir%\!outLayer!*" ( 19 | echo ogr2ogr -append %_opt% -nln "!outLayer!" %_outdir% "%_inFile%" !inLayer! 20 | ogr2ogr -append %_opt% -nln "!outLayer!" %_outdir% "%_inFile%" !inLayer!) else ( 21 | rem echo___ogr2ogr -update -append %opt% -nln "!outLayer!" %outdir% %inFile% !inLayer! 22 | ogr2ogr -update -append -nln "!outLayer!" "%_outdir%" "%_inFile%" !inLayer! %_opt% 23 | ) 24 | 25 | ) 26 | goto :eof 27 | 28 | :Usage 29 | echo_ 30 | echo_ Usage: %~n0 [path\to\*_gml] [output dir] {optional ogr arguments} 31 | echo_ 32 | -------------------------------------------------------------------------------- /gis/canvec/unpack-canvec-zips.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo. 3 | echo. Unpack downloaded CanVec files for area of interest. 4 | echo. 5 | 6 | :: Set to 1:50,000 NTS numbers for area of interest 7 | set tileList=116b14 116b15 116b16 116a13 116b11 116b10 116b09 116a12 116b06 116b07 116b08 116a05 116b03 116b02 116b01 116a04 8 | 9 | if "%2" == "" goto :Usage 10 | 11 | set xsrc=%1 12 | set dst=%2 13 | set _home=%cd% 14 | 15 | if not exist %dst% mkdir %dst% 16 | 17 | call :unZip 18 | call :Organise 19 | goto :EOF 20 | 21 | :UnZip 22 | for %%f in (%tileList%) do ( 23 | for /f "tokens=*" %%a in ('dir /s/b %src%\*%%f*') do unzip -n -d %dst% %%a 24 | ) 25 | goto :EOF 26 | 27 | :Organise 28 | :: put all docs & metadata into it's own folder 29 | cd %dst% 30 | mkdir meta 31 | for %%f in (*.html *.txt *.xml *.xsd) do move %%f meta 32 | cd %_home% 33 | goto :EOF 34 | 35 | :Usage 36 | echo. 37 | echo. Usage: %~n0 [path\to\canvec_archives] [output dir] 38 | echo. 39 | 40 | -------------------------------------------------------------------------------- /gis/gdal_extras/Readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/gdal_extras/Readme.txt -------------------------------------------------------------------------------- /gis/gdal_extras/bin/fortiff.cmd: -------------------------------------------------------------------------------- 1 | for %%a in (*.tif) do %* 2 | -------------------------------------------------------------------------------- /gis/gdal_extras/bin/gdal-help.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo. 3 | if [%GDAL_DATA%]==[] goto :NoGDAL 4 | 5 | gdalinfo --version 6 | 7 | echo. & echo Available exe commands: & echo. 8 | dir /d %GDAL_DATA%\..\bin\*.exe |find ".exe" 9 | echo. & echo Available python commands: & echo. 10 | dir /d %GDAL_DATA%\..\bin\*.py |find ".py" 11 | 12 | goto :EOF 13 | 14 | :NoGDAL 15 | echo ERROR: GDAL environment not set 16 | echo. 17 | -------------------------------------------------------------------------------- /gis/gdal_extras/bin/gdalcopyproj.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # ****************************************************************************** 3 | # $Id$ 4 | # 5 | # Name: gdalcopyproj.py 6 | # Project: GDAL Python Interface 7 | # Purpose: Duplicate the geotransform and projection metadata from 8 | # one raster dataset to another, which can be useful after 9 | # performing image manipulations with other software that 10 | # ignores or discards georeferencing metadata. 11 | # Author: Schuyler Erle, schuyler@nocat.net 12 | # 13 | # ****************************************************************************** 14 | # Copyright (c) 2005, Frank Warmerdam 15 | # 16 | # Permission is hereby granted, free of charge, to any person obtaining a 17 | # copy of this software and associated documentation files (the "Software"), 18 | # to deal in the Software without restriction, including without limitation 19 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 20 | # and/or sell copies of the Software, and to permit persons to whom the 21 | # Software is furnished to do so, subject to the following conditions: 22 | # 23 | # The above copyright notice and this permission notice shall be included 24 | # in all copies or substantial portions of the Software. 25 | # 26 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 27 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 29 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 31 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 32 | # DEALINGS IN THE SOFTWARE. 33 | # ****************************************************************************** 34 | # 35 | # $Log$ 36 | try: 37 | from osgeo import gdal 38 | except ImportError: 39 | import gdal 40 | 41 | import sys 42 | import os.path 43 | 44 | if len(sys.argv) < 3: 45 | print("Usage: gdalcopyproj.py source_file dest_file") 46 | sys.exit(1) 47 | 48 | input = sys.argv[1] 49 | dataset = gdal.Open(input) 50 | if dataset is None: 51 | print("Unable to open", input, "for reading") 52 | sys.exit(1) 53 | 54 | projection = dataset.GetProjection() 55 | geotransform = dataset.GetGeoTransform() 56 | 57 | if projection is None and geotransform is None: 58 | print("No projection or geotransform found on file" + input) 59 | sys.exit(1) 60 | 61 | output = sys.argv[2] 62 | dataset2 = gdal.Open(output, gdal.GA_Update) 63 | 64 | if dataset2 is None: 65 | print("Unable to open", output, "for writing") 66 | sys.exit(1) 67 | 68 | if geotransform is not None: 69 | dataset2.SetGeoTransform(geotransform) 70 | 71 | if projection is not None: 72 | dataset2.SetProjection(projection) 73 | -------------------------------------------------------------------------------- /gis/gdal_extras/bin/gdalsetnull.py: -------------------------------------------------------------------------------- 1 | #@+leo-ver=5-thin 2 | #@+node:maphew.20100601093031.2394: * @file gdalsetnull.py 3 | #@@language python 4 | #@@tabwidth -4 5 | #@+<> 6 | #@+node:maphew.20100601093031.2403: ** <>> and license 7 | #!/usr/bin/env python 8 | #****************************************************************************** 9 | # $Id: gdalsetnull.py 2008-07-08 maphew $ 10 | # 11 | # Project: GDAL 12 | # Purpose: Simple command line program to set speficied raster value NODATA, 13 | # without creating a new raster. 14 | # Author: Matt Wilkie, maphew@gmail.com 15 | # 16 | #****************************************************************************** 17 | # Copyright (c) 2000, Frank Warmerdam 18 | # 19 | # Permission is hereby granted, free of charge, to any person obtaining a 20 | # copy of this software and associated documentation files (the "Software"), 21 | # to deal in the Software without restriction, including without limitation 22 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 23 | # and/or sell copies of the Software, and to permit persons to whom the 24 | # Software is furnished to do so, subject to the following conditions: 25 | # 26 | # The above copyright notice and this permission notice shall be included 27 | # in all copies or substantial portions of the Software. 28 | # 29 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 30 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 32 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 34 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 35 | # DEALINGS IN THE SOFTWARE. 36 | #****************************************************************************** 37 | #@-<> 38 | #@+<> 39 | #@+node:maphew.20100601093031.2402: ** <> 40 | import sys 41 | import os.path 42 | try: 43 | from osgeo import gdal 44 | except ImportError: 45 | import gdal 46 | #@-<> 47 | #@+others 48 | #@+node:maphew.20100601093031.2401: ** usage 49 | if len(sys.argv) < 2: 50 | print "Usage: gdalsetnull.py raster_file null_value {null band2} {null band3} ..." 51 | sys.exit(1) 52 | #@+node:maphew.20100601093031.2400: ** Main 53 | input = sys.argv[1] 54 | null_value = sys.argv[2] 55 | 56 | dataset = gdal.Open( input, gdal.GA_Update ) 57 | if dataset is None: 58 | print 'Unable to open', input, 'for writing' 59 | sys.exit(1) 60 | 61 | for band_num in range(1, dataset.RasterCount+1): 62 | band = dataset.GetRasterBand(band_num) 63 | print 'Initial nodata for band %s \t %s' % (band_num,band.GetNoDataValue() ) 64 | 65 | # the 2nd commandline argument is for band#1, arg3 for band2, etc. 66 | arg_num = band_num + 1 67 | # optionally set different nodata values for each bands 68 | if arg_num > 2: 69 | if sys.argv[arg_num]: 70 | null_value = sys.argv[band_num] 71 | 72 | # FIXME: handle case where we want to remove nodata altogether (change to 'None') 73 | band.SetNoDataValue( float(null_value) ) 74 | 75 | print 'Output nodata for band %s \t %s' % (band_num,band.GetNoDataValue() ) 76 | #@-others 77 | #@-leo 78 | -------------------------------------------------------------------------------- /gis/gdal_extras/gdal-extras-install.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: there are few things which are not included in the default fwtools install which I always need to add later. 3 | if %GDAL_DATA%=="" goto :NotGdalShell 4 | if %FWTOOLS_DIR%=="" goto :NotGdalShell 5 | setlocal 6 | 7 | :: remember where we started from 8 | set rememberCD=%cd% 9 | 10 | :: Root gdal_exrtas home dir to the same directory this script exists in 11 | set gd-extras=%~dp0 12 | :: Rmove trailing backslash 13 | set gd-extras=%gd-extras:~0,-1% 14 | echo gdal_extras home is %gd-extras% & echo. 15 | 16 | 17 | :: copy each of the files in bin and data to gdal, but only if they don't exist already 18 | :Bin 19 | cd /d %gd-extras%\bin 20 | for %%a in (*) do ( 21 | if not exist "%FWTOOLS_DIR%\bin\%%~nxa" copy "%%a" "%FWTOOLS_DIR%\bin\%%~nxa" 22 | ) 23 | :Data 24 | cd /d %gd-extras%\data 25 | for %%a in (*) do ( 26 | if not exist "%FWTOOLS_DIR%\data\%%~nxa" copy "%%a" "%FWTOOLS_DIR%\data\%%~nxa" 27 | ) 28 | :Tools 29 | cd /d %gd-extras%\tools 30 | for %%a in (*) do ( 31 | if not exist "%FWTOOLS_DIR%\tools\%%~nxa" copy "%%a" "%FWTOOLS_DIR%\tools\%%~nxa" 32 | ) 33 | goto skip 34 | 35 | :Combined 36 | for %%b in (bin, data, tools, pics) do ( 37 | cd /d %gd-extras%\%%b 38 | for %%a in (*) do ( 39 | if not exist "%FWTOOLS_DIR%\%%b\%%~nxa" copy "%%a" "%FWTOOLS_DIR%\%%b\%%~nxa" 40 | ) 41 | ) 42 | 43 | :skip 44 | :: for fwtools on a portable device 45 | copy /-y %gd-extras%\setfw_portable.cmd %FWTOOLS_DIR%\ 46 | 47 | :: change gdal_SDE_92.dll to match version of SDE (e.g. 9.1 or 9.2) 48 | rem copy /-y %gd-extras%\gdal_plugins\gdal_SDE_91.dll %FWTOOLS_DIR%\gdal_plugins\gdal_SDE.dll 49 | 50 | :: Add Yukon Albers (epsg:3578) to projection list (won't be needed after next epsg update) 51 | rem type %gd-extras%\proj_lib\yukon_albers.epsg >> %PROJ_LIB%\epsg 52 | 53 | :Samples 54 | ::: create a batch file to run each of the samples. 55 | cd /d %FWTOOLS_DIR%\bin 56 | for %%a in (*.py) do ( 57 | if not exist %%~na.bat echo @python "%%FWTOOLS_DIR%%\bin\%%a" %%* > %%~na.bat 58 | ) 59 | 60 | cd /d %rememberCD% 61 | goto :EOF 62 | 63 | :NotGdalShell 64 | echo. 65 | echo. Error! GDAL_DATA and/or FWTOOLS_DIR environment is not set 66 | echo. Are you sure this is an FWTools or GDAL shell? 67 | echo. 68 | goto :EOF 69 | -------------------------------------------------------------------------------- /gis/gdal_extras/gdal_plugins/gdal_SDE_91.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/gdal_extras/gdal_plugins/gdal_SDE_91.dll -------------------------------------------------------------------------------- /gis/gdal_extras/gdal_plugins/gdal_SDE_92.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/gdal_extras/gdal_plugins/gdal_SDE_92.dll -------------------------------------------------------------------------------- /gis/gdal_extras/pics/bcg_tool.xpm: -------------------------------------------------------------------------------- 1 | /* XPM */ 2 | static char * bcg_tool_xpm[] = { 3 | "22 22 66 1", 4 | " c None", 5 | ". c #000000", 6 | "+ c #474747", 7 | "@ c #E3E3E3", 8 | "# c #FAFAFA", 9 | "$ c #FDFDFD", 10 | "% c #F9F9F9", 11 | "& c #D3D3D3", 12 | "* c #434343", 13 | "= c #B7B7B7", 14 | "- c #FCFCFC", 15 | "; c #F7F7F7", 16 | "> c #F6F6F6", 17 | ", c #D7D7D7", 18 | "' c #959595", 19 | ") c #B0B0B0", 20 | "! c #F5F5F5", 21 | "~ c #A1A1A1", 22 | "{ c #4D4D4D", 23 | "] c #1E1E1E", 24 | "^ c #F2F2F2", 25 | "/ c #F3F3F3", 26 | "( c #F4F4F4", 27 | "_ c #D1D1D1", 28 | ": c #909090", 29 | "< c #414141", 30 | "[ c #F8F8F8", 31 | "} c #F1F1F1", 32 | "| c #6D6D6D", 33 | "1 c #262626", 34 | "2 c #606060", 35 | "3 c #323232", 36 | "4 c #D0D0D0", 37 | "5 c #333333", 38 | "6 c #9F9F9F", 39 | "7 c #353535", 40 | "8 c #010101", 41 | "9 c #ECECEC", 42 | "0 c #A3A3A3", 43 | "a c #585858", 44 | "b c #C2C2C2", 45 | "c c #484848", 46 | "d c #454545", 47 | "e c #4C4C4C", 48 | "f c #2B2B2B", 49 | "g c #5B5B5B", 50 | "h c #C8C8C8", 51 | "i c #E2E2E2", 52 | "j c #A0A0A0", 53 | "k c #181818", 54 | "l c #A4A4A4", 55 | "m c #FBFBFB", 56 | "n c #6F6F6F", 57 | "o c #0A0A0A", 58 | "p c #B2B2B2", 59 | "q c #3C3C3C", 60 | "r c #070707", 61 | "s c #D2D2D2", 62 | "t c #888888", 63 | "u c #9A9A9A", 64 | "v c #E8E8E8", 65 | "w c #EBEBEB", 66 | "x c #CDCDCD", 67 | "y c #D9D9D9", 68 | "z c #D6D6D6", 69 | "A c #ACACAC", 70 | " ", 71 | " ", 72 | " ", 73 | " ...... ", 74 | " .+@#$$%&*. ", 75 | " .=-#;>>>>,'. ", 76 | " .)#!~{]^//(_:. ", 77 | " <[}|123//(((45 ", 78 | " .,;67238/(!!>90. ", 79 | " .(^a23..(!!>>;b. ", 80 | " .%}cd...!!>>;;_. ", 81 | " .(^ef...!>>;;[&. ", 82 | " .;^g58..>>;;[%h. ", 83 | " .i(j1k..>;[[%}l. ", 84 | " +m!no..;[[%%b5 ", 85 | " .p%>jqr[[%%st. ", 86 | " .uv[;[[>wxt. ", 87 | " .q=,yz4A5. ", 88 | " ...... ", 89 | " ", 90 | " ", 91 | " "}; 92 | -------------------------------------------------------------------------------- /gis/gdal_extras/proj_lib/yukon_albers.epsg: -------------------------------------------------------------------------------- 1 | # Yukon_Albers_NAD83 2 | <3578> +proj=aea +lat_1=61.66666666667 +lat_2=68.0 +lat_0=59.0 +lon_0=-132.5 +x_0=500000 +y_0=500000 +ellps=GRS80 +datum=NAD83 +units=m 3 | -------------------------------------------------------------------------------- /gis/gdal_extras/setfw_portable.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: A simple script to allow one to use FWTools for Windows from a USB device 3 | :: without installing anything on the host. 4 | :: 5 | :: Save with .cmd extension to ensure command.com is not used (a hold over 6 | :: from Win9x). The script will only work on Windows 2000 and newer. 7 | :: 8 | :: Initial version 2007 Feb 16, Matt Wilkie (maphew@gmail.com) [mhw] 9 | :: 2007-OCt-25 [mhw] added missing call for setfwenv.bat, (thanks to Farley Klotz) 10 | 11 | if not %cmdextversion% GEQ 2 goto :WrongCmd 12 | 13 | :Main 14 | cls & echo. 15 | rem Root fwtools home dir to the same directory this script exists in 16 | set FWTOOLS_DIR=%~dp0 17 | rem Rmove trailing backslash 18 | set FWTOOLS_DIR=%FWTOOLS_DIR:~0,-1% 19 | echo FWTools home is %FWTOOLS_DIR% & echo. 20 | 21 | rem Add fwtools bin directory to path and make sure gdal is there. 22 | for %%a in (gdalinfo.exe) do ( 23 | if [%%~dp$PATH:a]==[] path=%FWTOOLS_DIR%\bin;%PATH% 24 | ) 25 | gdalinfo --version || goto :NotFound 26 | 27 | rem Configure environment for python modules, proj lib data, drivers, etc. 28 | call %FWTOOLS_DIR%\bin\setfwenv.bat 29 | 30 | rem Add local preferences (e.g. for "--config" parameters) 31 | rem For 'gdaladdo', use external pyramids in .aux file 32 | set USE_RRD=YES 33 | rem Up the default amount of memory used 34 | set GDAL_CACHEMAX=512 35 | 36 | rem Remember the yukon albers projection parameters. 37 | set ytalbers="+proj=aea +lat_1=61.66666666666666 +lat_2=68 +lat_0=59 +lon_0=-132.5 +x_0=500000 +y_0=500000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs" 38 | 39 | rem List available commands 40 | echo. & echo Available exe commands are: & echo. 41 | dir /d %FWTOOLS_DIR%\bin\*.exe |find ".exe" 42 | echo. & echo Available python commands are: & echo. 43 | dir /d %FWTOOLS_DIR%\bin\*.py |find ".py" 44 | 45 | goto :EOF 46 | 47 | :WrongCmd 48 | echo. 49 | echo Sorry, this script requires CMD.exe with extension 50 | echo version 2 or above (Windows 2000 or later) 51 | echo. 52 | echo Yours appears to be: %CMDEXTVERSION% 53 | echo. 54 | goto :EOF 55 | 56 | :NotFound 57 | echo. 58 | echo Sorry, I can't find GDAL Utilities 59 | echo. 60 | -------------------------------------------------------------------------------- /gis/geobase/Automatic download and conversion of Geobase Road Network at Musings.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Version=1.0 3 | Encoding=UTF-8 4 | Name=Link to Automatic download and conversion of Geobase Road Network at Musings 5 | Type=Link 6 | URL=http://www.uttara.ca/blog/gis/automatic-download-and-conversion-of-geobase-road-network 7 | Icon=gnome-fs-bookmark 8 | -------------------------------------------------------------------------------- /gis/geobase/nrn2yukon.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: rev 0.1 ~ 2007 Nov 10, Matt Wilkie - maphew@gmail.com 3 | echo. 4 | echo. Going to download National Road Network files from Geobase 5 | echo. for Yukon and adjacent regions. 6 | echo. When finished downloading I will attempt to unpack the archives 7 | echo. and project the data to Yukon Albers, in shapefiles. 8 | echo. 9 | echo. 10 | setlocal 11 | 12 | call :ChkReqs wget.exe 13 | call :Unpack 14 | call :gml2shp 15 | goto :EOF 16 | 17 | :ChkReqs 18 | :: test for wget, if it is in path we can carry on. 19 | if exist “%~$PATH:1″ ( 20 | call :D ownload ) else ( 21 | echo %1 not found! can’t continue 22 | ) 23 | goto :EOF 24 | 25 | :Download 26 | set urlRoot=http://ftp2.cits.rncan.gc.ca/pub/geobase/official/nrn_rrn/ 27 | 28 | :: Regions to download (ab = alberta, etc.) 29 | set regions=yt nt bc ab 30 | 31 | :: gml or shapefiles? 32 | set type=gml 33 | rem set type=shp 34 | 35 | if not exist zips mkdir zips 36 | cd zips 37 | for %%a in (%regions%) do ( 38 | wget –continue %urlRoot%/%%a/nrn_rrn_%%a_%type%_en.zip 39 | ) 40 | cd .. 41 | 42 | goto :EOF 43 | 44 | :Unpack 45 | :: FIXME: chkreq is hardcoded to download on successful check 46 | rem call :ChkReqs 7z.exe 47 | if not exist unpack mkdir unpack 48 | cd unpack 49 | 7z x ..\zips\*.zip 50 | cd .. 51 | 52 | echo. 53 | echo. Finished unpacking. 54 | echo. 55 | goto :EOF 56 | 57 | :gml2shp 58 | echo. 59 | echo. Now I’m going to convert from GML to shapefile, 60 | echo. and project to Yukon Albers in the process. 61 | echo. This could take awhile. 62 | echo. 63 | 64 | :: projection parameters. Example is of NAD83CSRS in lat-long to NAD83 Yukon Albers 65 | :: refer to gdal/ogr docs for more info on how to use these parameters 66 | set prj_params=-s_srs epsg:4617 -t_srs epsg:3578 67 | for %%a in (%regions%) do ( 68 | echo ogr2ogr -f “esri shapefile” -overwrite %prj_params% %%a unpack\NRN_%%a*.gml 69 | ogr2ogr -f “esri shapefile” -overwrite %prj_params% %%a unpack\NRN_%%a*.gml 70 | ) 71 | goto :EOF 72 | -------------------------------------------------------------------------------- /gis/list-fc-aliases.py: -------------------------------------------------------------------------------- 1 | # my first start-to-finish script using Leo Editor 2 | # Displays the names and aliases for all the feature classes in a geodatabases 3 | # (prep work for learning how to import Canvec feature classes from GML, while 4 | # making use of 5 | # http://code.google.com/p/maphew/source/browse/trunk/gis/canvec/db-friendly-names.txt) 6 | # Matt Wilkie, begun 2009 May 01 7 | import sys, arcgisscripting 8 | gp = arcgisscripting.create(9.3) 9 | ws_root = sys.argv[1] 10 | gp.workspace = ws_root 11 | 12 | name_table = {} 13 | 14 | def getDataSets(): 15 | ''' Get feature datasets in current workspace and call listFeatureClassNames on each ''' 16 | fds = gp.ListDatasets() 17 | for fd in fds: 18 | print ("\n%s\%s:") % (gp.workspace, fd) 19 | listFeatureClassNames(fd) 20 | return 21 | 22 | def listFeatureClassNames(path): 23 | ''' Build table of Feature Class Name <-> Alias Names from FCs in specified path''' 24 | gp.workspace = path 25 | fcs = gp.ListFeatureClasses() 26 | for fc in fcs: 27 | desc = gp.describe(fc) 28 | #print '%s \t %s' % (desc.aliasname, desc.name) 29 | name_table[desc.name] = desc.aliasname 30 | gp.workspace = ws_root 31 | return 32 | 33 | def reportResult(table): 34 | ''' Print alias <-> feature class lookup table ''' 35 | print '%s -- %50s' % ('Alias', 'Feature Class') 36 | for name, aliasname in sorted(table.items()): 37 | print '%s -- %50s' % (aliasname, name) 38 | return 39 | 40 | getDataSets() 41 | listFeatureClassNames(ws_root) # catch feature classes not in Feature Dataset container 42 | reportResult(name_table) 43 | -------------------------------------------------------------------------------- /gis/misc/cov2shp.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: 2008-April-16 - Matt.wilkie@gov.yk.ca - this script is public domain 3 | :: 4 | :: Need an automated way to convert coverage to shape with out knowing ahead of time geometry type (line, point, poly) 5 | :: ArcCatalog drag 'n drop for coverages doesn't work, and FeatureClassToFeatureclassMultuple is broken for coverages 6 | :: so using ogr2ogr instead (which is faster anyway) 7 | :: 8 | :: Only polygons, lines and points are handled, so Region subcoverages and node networks etc. need to processed elsewhere 9 | 10 | if [%2] == [] goto Usage 11 | set incov=%1 12 | set outshp=%2 13 | set debug=%3 14 | 15 | if not exist %incov% goto NoCov 16 | 17 | set scratchDir=%outshp%_%random% 18 | mkdir %scratchDir% 19 | 20 | if not exist %outshp% mkdir %outshp% 21 | 22 | :Cov2shp 23 | ogr2ogr %scratchDir%\%incov% %incov% 24 | :: polygons 25 | if exist %incov%\pal.adf ( 26 | copy %scratchDir%\%incov%\PAL.* %outshp%\%incov%_ply.* > nul 27 | goto :EndCov2shp rem With polys we don't need the lines or label points, so skip 28 | ) 29 | :: lines, then points 30 | if exist %incov%\arc.adf copy %scratchDir%\%incov%\ARC.* %outshp%\%incov%_lin.* > nul 31 | if exist %incov%\pat.adf copy %scratchDir%\%incov%\LAB.* %outshp%\%incov%_pnt.* > nul 32 | :EndCov2shp 33 | 34 | ::CleanUp 35 | if /i not [%debug%]==[--debug] ( 36 | rd /s/q %scratchDir% 37 | ) else ( 38 | echo. --debug specified, not removing "%scratchDir%" 39 | ) 40 | 41 | ::Report results 42 | echo. 43 | echo. Results in "%outshp%": 44 | echo. 45 | dir /b %outshp%\%incov%* 46 | echo. 47 | echo. Note: polygon islands still need to be manually removed 48 | 49 | goto :EOF 50 | 51 | :Usage 52 | echo. 53 | echo. -={ Cover to Shape }=- 54 | echo. 55 | echo. %~n0 [in cover] [out directory] {--debug} 56 | echo. 57 | goto :EOF 58 | 59 | :NoCov 60 | echo. 61 | echo. Input "%1" not found 62 | echo. 63 | goto :EOF 64 | -------------------------------------------------------------------------------- /gis/misc/nts-html-table.htm: -------------------------------------------------------------------------------- 1 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
117C 117D
117B 117A
116NO 116P
116JK 116I 106L 106K
116FG 116H 106E 106F
116BC 116A 106D 106C 106B
115NO 115P 105M 105N 105O 105P
115JK 115I 105L 105K 105J 105I
115FG 115H 105E 105F 105G 105H 095E
115BC 115A 105D 105C 105B 105A 095D 095C
-------------------------------------------------------------------------------- /gis/misc/nts_map_as_html_table.py: -------------------------------------------------------------------------------- 1 | '''Print Yukon NTS tile names as html table with links, arranged in same order as they appear in a map index. 2 | 3 | 2015-Aug-19, Matt.Wilkie@gov.yk.ca 4 | License: X/MIT 5 | ''' 6 | 7 | nts_txt_ordered = '''117C 117D 8 | 117B 117A 9 | 116NO 116P 10 | 116JK 116I 106L 106K 11 | 116FG 116H 106E 106F 12 | 116BC 116A 106D 106C 106B 13 | 115NO 115P 105M 105N 105O 105P 14 | 115JK 115I 105L 105K 105J 105I 15 | 115FG 115H 105E 105F 105G 105H 095E 16 | 115BC 115A 105D 105C 105B 105A 095D 095C 17 | ''' 18 | 19 | style = '''''' 28 | 29 | def link(txt, prefix=None): 30 | return '{txt}'.format(prefix=prefix, txt=txt) 31 | 32 | 33 | if __name__ == '__main__': 34 | print style 35 | print '' 36 | for row in nts_txt_ordered.splitlines(): 37 | print '' 38 | for x in row.split(): 39 | ## prefix = '/maps/media/uploads/pdf-maps/Administrative_Boundaries_' 40 | prefix = 'xxx/' 41 | print '' 42 | print '' 43 | print '
',link(x, prefix),'
' 44 | 45 | -------------------------------------------------------------------------------- /gis/misc/tissot/generate_tissot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Tissot Circles 3 | # Represent perfect circles of equal area on a globe 4 | # but will appear distorted in ANY 2d projection. 5 | # Used to show the size, shape and directional distortion 6 | # by Matthew T. Perry 7 | # 12/10/2005 8 | 9 | import ogr 10 | import os 11 | import osr 12 | 13 | output = 'tissot.shp' 14 | debug = False 15 | 16 | # Create the Shapefile 17 | driver = ogr.GetDriverByName('ESRI Shapefile') 18 | if os.path.exists(output): 19 | driver.DeleteDataSource(output) 20 | ds = driver.CreateDataSource(output) 21 | layer = ds.CreateLayer(output, geom_type=ogr.wkbPolygon) 22 | 23 | # Set up spatial reference systems 24 | latlong = osr.SpatialReference() 25 | ortho = osr.SpatialReference() 26 | latlong.ImportFromProj4('+proj=latlong') 27 | 28 | # For each grid point, reproject to ortho centered on itself, 29 | # buffer by 640,000 meters, reproject back to latlong, 30 | # and output the latlong ellipse to shapefile 31 | for x in range(-165,180,30): 32 | for y in range (-60,90,30): 33 | f= ogr.Feature(feature_def=layer.GetLayerDefn()) 34 | wkt = 'POINT(%f %f)' % (x, y) 35 | p = ogr.CreateGeometryFromWkt(wkt) 36 | p.AssignSpatialReference(latlong) 37 | proj = '+proj=ortho +lon_0=%f +lat_0=%f' % (x,y) 38 | ortho.ImportFromProj4(proj) 39 | p.TransformTo(ortho) 40 | b = p.Buffer(640000) 41 | b.AssignSpatialReference(ortho) 42 | b.TransformTo(latlong) 43 | f.SetGeometryDirectly(b) 44 | layer.CreateFeature(f) 45 | f.Destroy() 46 | 47 | ds.Destroy() 48 | -------------------------------------------------------------------------------- /gis/misc/tissot/tissot.dbf: -------------------------------------------------------------------------------- 1 | _<A FIDN 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 -------------------------------------------------------------------------------- /gis/misc/tissot/tissot.prj: -------------------------------------------------------------------------------- 1 | GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]] -------------------------------------------------------------------------------- /gis/misc/tissot/tissot.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/misc/tissot/tissot.shp -------------------------------------------------------------------------------- /gis/misc/tissot/tissot.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/misc/tissot/tissot.shx -------------------------------------------------------------------------------- /gis/o4w_extras/Readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/o4w_extras/Readme.txt -------------------------------------------------------------------------------- /gis/o4w_extras/bin/BuildAptExe.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | @echo. 3 | @echo. Build standalone apt.exe 4 | @echo. 5 | if [%3]==[] goto :Usage 6 | setlocal 7 | set pyinstaller=%1 8 | set aptpy=%2 9 | set rev=r%3 10 | set aptexe=%~dp2\%~n2-%rev%.exe 11 | 12 | :Main 13 | pushd %pyinstaller% 14 | @echo on 15 | python Makespec.py --onefile --out=.\apt-%rev% %aptpy% 16 | python Build.py .\apt-%rev%\apt.spec 17 | move .\apt-%rev%\dist\apt.exe %aptexe% 18 | @echo off 19 | popd 20 | goto :eof 21 | 22 | :Usage 23 | @echo. 24 | @echo. %0 [path\to\pyinstaller\dir] [path\to\apt.py] [apt_version_#] 25 | @echo. 26 | goto :eof 27 | -------------------------------------------------------------------------------- /gis/o4w_extras/bin/TestAptExe.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | if [%1]==[] goto :Usage 3 | setlocal 4 | set aptexe=%1 5 | 6 | :Main 7 | prompt $g 8 | @echo on 9 | set path=. 10 | set osgeo4w_root=%temp%\%aptexe% 11 | %aptexe% setup 12 | %aptexe% update 13 | %aptexe% install msvcrt 14 | %aptexe% list 15 | %aptexe% remove msvcrt 16 | @goto :eof 17 | 18 | :Usage 19 | echo. 20 | echo. %0 [apt-r###.exe to test] 21 | echo. 22 | goto :eof 23 | -------------------------------------------------------------------------------- /gis/o4w_extras/bin/gdalcopyproj.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #****************************************************************************** 3 | # $Id$ 4 | # 5 | # Name: gdalcopyproj.py 6 | # Project: GDAL Python Interface 7 | # Purpose: Duplicate the geotransform and projection metadata from 8 | # one raster dataset to another, which can be useful after 9 | # performing image manipulations with other software that 10 | # ignores or discards georeferencing metadata. 11 | # Author: Schuyler Erle, schuyler@nocat.net 12 | # 13 | #****************************************************************************** 14 | # Copyright (c) 2005, Frank Warmerdam 15 | # 16 | # Permission is hereby granted, free of charge, to any person obtaining a 17 | # copy of this software and associated documentation files (the "Software"), 18 | # to deal in the Software without restriction, including without limitation 19 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 20 | # and/or sell copies of the Software, and to permit persons to whom the 21 | # Software is furnished to do so, subject to the following conditions: 22 | # 23 | # The above copyright notice and this permission notice shall be included 24 | # in all copies or substantial portions of the Software. 25 | # 26 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 27 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 29 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 31 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 32 | # DEALINGS IN THE SOFTWARE. 33 | #****************************************************************************** 34 | # 35 | # $Log$ 36 | try: 37 | from osgeo import gdal 38 | except ImportError: 39 | import gdal 40 | 41 | import sys 42 | import os.path 43 | 44 | if len(sys.argv) < 3: 45 | print "Usage: gdalcopyproj.py source_file dest_file" 46 | sys.exit(1) 47 | 48 | input = sys.argv[1] 49 | dataset = gdal.Open( input ) 50 | if dataset is None: 51 | print 'Unable to open', input, 'for reading' 52 | sys.exit(1) 53 | 54 | projection = dataset.GetProjection() 55 | geotransform = dataset.GetGeoTransform() 56 | 57 | if projection is None and geotransform is None: 58 | print 'No projection or geotransform found on file' + input 59 | sys.exit(1) 60 | 61 | output = sys.argv[2] 62 | dataset2 = gdal.Open( output, gdal.GA_Update ) 63 | 64 | if dataset2 is None: 65 | print 'Unable to open', output, 'for writing' 66 | sys.exit(1) 67 | 68 | if geotransform is not None: 69 | dataset2.SetGeoTransform( geotransform ) 70 | 71 | if projection is not None: 72 | dataset2.SetProjection( projection ) 73 | 74 | -------------------------------------------------------------------------------- /gis/o4w_extras/bin/gdalsetnull.py: -------------------------------------------------------------------------------- 1 | #@+leo-ver=5-thin 2 | #@+node:maphew.20100601093031.2394: * @file gdalsetnull.py 3 | #@@language python 4 | #@@tabwidth -4 5 | #@+<> 6 | #@+node:maphew.20100601093031.2403: ** <>> and license 7 | #!/usr/bin/env python 8 | #****************************************************************************** 9 | # $Id: gdalsetnull.py 2008-07-08 maphew $ 10 | # 11 | # Project: GDAL 12 | # Purpose: Simple command line program to set speficied raster value NODATA, 13 | # without creating a new raster. 14 | # Author: Matt Wilkie, maphew@gmail.com 15 | # 16 | #****************************************************************************** 17 | # Copyright (c) 2000, Frank Warmerdam 18 | # 19 | # Permission is hereby granted, free of charge, to any person obtaining a 20 | # copy of this software and associated documentation files (the "Software"), 21 | # to deal in the Software without restriction, including without limitation 22 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 23 | # and/or sell copies of the Software, and to permit persons to whom the 24 | # Software is furnished to do so, subject to the following conditions: 25 | # 26 | # The above copyright notice and this permission notice shall be included 27 | # in all copies or substantial portions of the Software. 28 | # 29 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 30 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 32 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 34 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 35 | # DEALINGS IN THE SOFTWARE. 36 | #****************************************************************************** 37 | #@-<> 38 | #@+<> 39 | #@+node:maphew.20100601093031.2402: ** <> 40 | import sys 41 | import os.path 42 | try: 43 | from osgeo import gdal 44 | except ImportError: 45 | import gdal 46 | #@-<> 47 | #@+others 48 | #@+node:maphew.20100601093031.2401: ** usage 49 | if len(sys.argv) < 2: 50 | print "Usage: gdalsetnull.py raster_file null_value {null band2} {null band3} ..." 51 | sys.exit(1) 52 | #@+node:maphew.20100601093031.2400: ** Main 53 | input = sys.argv[1] 54 | null_value = sys.argv[2] 55 | 56 | dataset = gdal.Open( input, gdal.GA_Update ) 57 | if dataset is None: 58 | print 'Unable to open', input, 'for writing' 59 | sys.exit(1) 60 | 61 | for band_num in range(1, dataset.RasterCount+1): 62 | band = dataset.GetRasterBand(band_num) 63 | print 'Initial nodata for band %s \t %s' % (band_num,band.GetNoDataValue() ) 64 | 65 | # the 2nd commandline argument is for band#1, arg3 for band2, etc. 66 | arg_num = band_num + 1 67 | # optionally set different nodata values for each bands 68 | if arg_num > 2: 69 | if sys.argv[arg_num]: 70 | null_value = sys.argv[band_num] 71 | 72 | # FIXME: handle case where we want to remove nodata altogether (change to 'None') 73 | band.SetNoDataValue( float(null_value) ) 74 | 75 | print 'Output nodata for band %s \t %s' % (band_num,band.GetNoDataValue() ) 76 | #@-others 77 | #@-leo 78 | -------------------------------------------------------------------------------- /gis/o4w_extras/bin/proj2wkt.py: -------------------------------------------------------------------------------- 1 | '''Convert Well Known Text (WKT) spatial reference to Proj4. 2 | 3 | Adapted from http://spatialnotes.blogspot.ca/2010/11/converting-wkt-projection-info-to-proj4.html 4 | ''' 5 | import os 6 | import sys 7 | import string 8 | import osgeo.osr 9 | 10 | if (len(sys.argv) <> 2): 11 | print "Usage: proj2wkt.py '[Proj4 Projection Text]'" 12 | else: 13 | srs = osgeo.osr.SpatialReference() 14 | srs.ImportFromProj4(sys.argv[1]) 15 | print srs.ExportToWkt() -------------------------------------------------------------------------------- /gis/o4w_extras/bin/wkt2proj.py: -------------------------------------------------------------------------------- 1 | '''Convert Well Known Text (WKT) spatial reference to Proj4. 2 | 3 | Adapted from http://spatialnotes.blogspot.ca/2010/11/converting-wkt-projection-info-to-proj4.html 4 | ''' 5 | import os 6 | import sys 7 | import string 8 | import osgeo.osr 9 | 10 | if (len(sys.argv) <> 2): 11 | print "Usage: wkt2proj.py '[WKT Projection Text]'" 12 | else: 13 | srs = osgeo.osr.SpatialReference() 14 | srs.ImportFromWkt(sys.argv[1]) 15 | print srs.ExportToProj4() 16 | print srs -------------------------------------------------------------------------------- /gis/o4w_extras/install-o4w-extras.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo. 3 | echo. Installing a few extra goodies into OSGeo4W 4 | echo. 5 | 6 | :: Environment settings 7 | if [%OSGEO4W_ROOT%]==[] goto :EnvNotSet 8 | set homedir=%cd% 9 | 10 | :xcopy 11 | cd /d %~dp0 12 | call :Excludes 13 | xcopy /s /exclude:xcopy_exclude.txt /d /y .\* %OSGEO4W_ROOT%\ 14 | call :MakeBats 15 | cd %homedir% 16 | goto :Done 17 | 18 | :MakeBats 19 | cd /d %OSGEO4W_ROOT%\bin 20 | for %%g in (*.py) do ( 21 | if not exist %%~ng.bat echo @python "%%OSGEO4W_ROOT%%\bin\%%g" %%* > %%~ng.bat 22 | ) 23 | goto :EOF 24 | 25 | :EnvNotSet 26 | echo. 27 | echo. *** OSGEO4W_ROOT not found. 28 | echo. *** Please run install-o4w-extras.bat from within OSGeo4W shell. 29 | echo. 30 | :: pause for a few seconds. 31 | ping localhost -n 5 >nul 32 | goto :EOF 33 | 34 | :Excludes 35 | del xcopy_exclude.txt 36 | for %%g in (.svn tests xcopy_exclude.txt install-o4w-extras.bat *.reg) do ( 37 | echo %%g >> xcopy_exclude.txt 38 | ) 39 | goto :eof 40 | 41 | :Done 42 | echo. 43 | echo. Finished. 44 | echo. -------------------------------------------------------------------------------- /gis/o4w_extras/share/proj/_put__ntv2_0.gsb__here.URL: -------------------------------------------------------------------------------- 1 | [InternetShortcut] 2 | URL=http://yukongis.ca/bin/view/Main/InstallNTv2 3 | -------------------------------------------------------------------------------- /gis/o4w_extras/tests/apt-from-scratch.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo. 3 | echo. Install OSGeo4W from scratch 4 | echo. 5 | echo. THIS WILL REMOVE EXISTING C:\OSGEO_4W! 6 | echo. 7 | 8 | if not [%1]==[yes] goto :Usage 9 | 10 | :SetEnv 11 | setlocal 12 | set pythonpath= 13 | set osgeo4w_root=C:\OSGeo4W 14 | set osgeo4w_root_msys=%osgeo4w_root% 15 | ::set o4w-apt=c:\OSGeo4W.extras\bin\o4w-apt.py 16 | ::set python=d:\PortablePython1.0\python.exe 17 | ::echo %python% %o4w-apt% %%* > apt.bat 18 | echo @apt-r43.exe %%*> apt.bat 19 | 20 | :CleanSlate 21 | if exist %osgeo4w_root% rd /s/q %osgeo4w_root% 22 | md %osgeo4w_root% 23 | 24 | :DoIt 25 | call apt setup 26 | call apt update 27 | call apt install gdal 28 | 29 | :Test 30 | %osgeo4w_root%\bin\gdalinfo --version 31 | 32 | goto :eof 33 | 34 | :Usage 35 | echo. if you don't say "%0 yes" I won't do it. 36 | -------------------------------------------------------------------------------- /gis/o4w_extras/xcopy_exclude.txt: -------------------------------------------------------------------------------- 1 | .svn 2 | tests 3 | xcopy_exclude.txt 4 | install-o4w-extras.bat 5 | hkcu_py-reg_d-drive.reg 6 | hklm_o4wpy-reg_23.reg 7 | hklm_o4wpy-reg_d-drive.reg 8 | py25_x32_default_install.reg 9 | -------------------------------------------------------------------------------- /gis/qgis/h3-in-qgis.assets/h3-edit-min-max.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/qgis/h3-in-qgis.assets/h3-edit-min-max.png -------------------------------------------------------------------------------- /gis/qgis/h3-in-qgis.assets/h3-results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/qgis/h3-in-qgis.assets/h3-results.png -------------------------------------------------------------------------------- /gis/qgis/h3-in-qgis.assets/h3-select-and-open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/qgis/h3-in-qgis.assets/h3-select-and-open.png -------------------------------------------------------------------------------- /gis/qgis/h3-in-qgis.md: -------------------------------------------------------------------------------- 1 | # Qgis & H3 2 | *Using Uber's [H3 hex grid system][1] in Qgis* 3 | 4 | https://github.com/maphew/code/tree/master/gis/qgis: 5 | 6 | * h3-grid-from-layer.py - the script 7 | * h3-in-qgis.md - this doc 8 | 9 | ## Usage 10 | 11 | From Qgis: 12 | 13 | 1. Select a template layer in table of contents to get extent from 14 | 1. Optionally select specific features 15 | 2. *Processing tool box >> Open existing script: [h3-grid-from-layer.py][0]* 16 | 3. OR: *Plugins >> Python console >> Open editor >> load script: [h3-grid-from-layer.py][0]* 17 | 4. Edit variables (particularly min/max resolution levels) 18 | 5. Run 19 | 20 | ![screenshot: select extents layer, open script](h3-in-qgis.assets/h3-select-and-open.png) 21 | 22 | ![screenshot: edit min/max hexes](h3-in-qgis.assets/h3-edit-min-max.png) 23 | 24 | ![screenshot: result](h3-in-qgis.assets/h3-results.png) 25 | 26 | ## Preparation 27 | 28 | If using Qgis via standard installer open **OSGeo4W shell** as administrator and install H3 with pip: 29 | 30 | ``` 31 | pip install H3 32 | ``` 33 | 34 | **OR** if you use **conda** create and install Qgis with H3: 35 | 36 | conda create -n qgis 37 | conda activate qgis 38 | conda install qgis 39 | conda install h3-py 40 | 41 | qgis 42 | 43 | ### More info: 44 | 45 | - https://gis.stackexchange.com/questions/119495/does-qgis-work-with-anaconda 46 | 47 | 48 | ## Troubleshooting 49 | 50 | Unsolved: how to get Qgis to add user profile to python search path? 51 | 52 | Work around: Run OSGeo4W Shell as administrator before running pip. (You might have to uninstall the user space package.) 53 | 54 | ``` 55 | $ pip install h3 56 | Defaulting to user installation because normal site-packages is not writeable 57 | Requirement already satisfied: h3 in c:\users\matt\appdata\roaming\python\python39\site-packages (3.7.3) 58 | ``` 59 | 60 | Related: https://gis.stackexchange.com/questions/395708/missing-optional-dependency-tables-in-qgis 61 | 62 | [1]: https://h3geo.org/ 63 | [0]: https://github.com/maphew/code/blob/master/gis/qgis/h3-grid-from-layer.py -------------------------------------------------------------------------------- /gis/recursive_apr_update/.viminfo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/recursive_apr_update/.viminfo -------------------------------------------------------------------------------- /gis/recursive_apr_update/Copy of replace.vim: -------------------------------------------------------------------------------- 1 | :" 2 | :" % = current file 3 | :" s = substitute 4 | :" no = no 'magic' pattern matching 5 | :" trailing '/e' turns off 'pattern not found' messages 6 | :" w = write file 7 | :" 8 | :%sno/d:\/rrgis\/250k\/q/z:\/arcdata\/250k\/boundary\/q/e 9 | :%sno/d:\/rrgis\/250k\/info\/q/z:\/arcdata\/250k\/boundary\/info\/q/e 10 | :%sno/d:\/rrgis\/250k\/boundary/z:\/arcdata\/250k\/boundary/e 11 | :%sno/d:\/rrgis\/250k\/theme/z:\/arcdata\/250k\/theme/e 12 | :%sno/d:\/rrgis\/50k\/theme/z:\/arcdata\/50k\/theme/e 13 | :%sno/d:\/rrgis\/1000k/z:\/arcdata\/1000k/e 14 | :%sno/d:\/rrgis/z:\/arcdata_old/e 15 | :%sno/z:\/arcdata\/lib250/z:\/arcdata_old\/250k/e 16 | :%sno/z:\/arcdata\/arcdata/z:\/arcdata/e 17 | :%sno/z:\/arcdata_old\/arcdata/z:\/arcdata_old/e 18 | :" %sno/z:\/arcdata_old\/1000k/z:\arcdata\/1000k/e 19 | :" %sno/\/1000k\/boundary\/border/\/1000k\/boundary\/mborder/e 20 | :" %sno/\/1000k\/boundary\/codist/\/1000k\/boundary\/mcodist/e 21 | :" %sno/\/1000k\/boundary\/fntt/\/1000k\/boundary\/mfntt/e 22 | :" %sno/\/1000k\/boundary\/gma/\/1000k\/boundary\/mgma/e 23 | :" %sno/\/1000k\/boundary\/oa/\/1000k\/boundary\/moa/e 24 | :" %sno/\/1000k\/boundary\/park/\/1000k\/boundary\/mpark/e 25 | :" %sno/\/1000k\/boundary\/rtc/\/1000k\/boundary\/mrtc/e 26 | :" %sno/\/1000k\/boundary\/info\/border/\/1000k\/boundary\/info\/mborder/e 27 | :" %sno/\/1000k\/boundary\/info\/codist/\/1000k\/boundary\/info\/mcodist/e 28 | :" %sno/\/1000k\/boundary\/info\/fntt/\/1000k\/boundary\/info\/mfntt/e 29 | :" %sno/\/1000k\/boundary\/info\/gma/\/1000k\/boundary\/info\/mgma/e 30 | :" %sno/\/1000k\/boundary\/info\/oa/\/1000k\/boundary\/info\/moa/e 31 | :" %sno/\/1000k\/boundary\/info\/park/\/1000k\/boundary\/info\/mpark/e 32 | :" %sno/\/1000k\/boundary\/info\/rtc/\/1000k\/boundary\/info\/mrtc/e 33 | :%sno/"Forest\ Inventory\ 250"/"Forest\ Inventory\ 50k"/e 34 | :%sno/"rr50\.forest"/"Forest\ Inventory\ 50k\.forest_cover"/e 35 | :%sno/"Forest\ Inventory\ 250.forest_cover"/"Forest\ Inventory\ 50k\.forest_cover"/e 36 | :%sno/"forest\ inventory.forest_cover"/"Forest\ Inventory\ 50k\.forest_cover"/e 37 | :%sno/"forest\ inventory\ 250.forest_cover"/"Forest\ Inventory\ 50k\.forest_cover"/e 38 | :%sno/250k\/theme\/forestry/50k\/theme\/forestry/e 39 | :%sno/"rr250\./"rr250-old\./e 40 | :%sno/"rr50\./"rr50-old\./e 41 | :%sno/"rr1000\.coast/"base\ 1000k\.coast/e 42 | :%sno/"rr1000\.water/"base\ 1000k\.water/e 43 | :%sno/"rr1000\.river/"base\ 1000k\.river/e 44 | :%sno/"rr1000\.ice/"base\ 1000k\.ice/e 45 | :%sno/"rr1000\.contour/"base\ 1000k\.contour/e 46 | :%sno/"rr1000\.hypsometry/"base\ 1000k\.hypsometry/e 47 | :%sno/"rr1000\.access/"base\ 1000k\.access/e 48 | :%sno/"rr1000\.places/"base\ 1000k\.places/e 49 | :%sno/"rr1000\.ocean/"base\ 1000k\.ocean/e 50 | :%sno/z:\/arcdata\/250k\/base/z:\/arcdata_old\/250k\/base/e 51 | :%sno/z:\/arcdata\/50k\/base/z:\/arcdata_old\/50k\/base/e 52 | :%sno/z:\/arcdata\/1000k\/boundary/z:\/arcdata_old\/1000k\/boundary/e 53 | :%sno/z:\/arcdata\/250k\/boundary/z:\/arcdata_old\/250k\/boundary/e 54 | :%sno/z:\/arcdata\/50k\/boundary/z:\/arcdata_old\/50k\/boundary/e 55 | :%sno/\/lims\//\/base\//e 56 | :%sno/"rr250-old\.-lims/"rr250-old\./e 57 | :w 58 | -------------------------------------------------------------------------------- /gis/recursive_apr_update/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ---={ Recursively Update .APR File Paths }=--- 2 | 3 | I fielded a question this morning about how to fix ArcView3 project files (.apr) when moving their source data around -- from D:\GIS\Projects --> X:\GIS\Projects\2006. In answering the question I rediscovered an old script I wrote which recursively does this for all folders under the current one. As I'm about to move to a new computer and throw out or archive (nearly the same thing) my old stuff, yet this particular piece might still of use to someone, I figured I'd plunk it in my source code repository for future reference. 4 | 5 | This is not something you can just download and run, but to use as an aid or template in building your own scripts. 6 | 7 | 2008 Feb 29, matt.wilkie@gov.yk.ca 8 | -------------------------------------------------------------------------------- /gis/recursive_apr_update/build-replace.vim: -------------------------------------------------------------------------------- 1 | :" go through file list and change: 2 | :" C:\Vince\Arc view\105m.apr 3 | :" to: 4 | :" :e! C:/Vince/Arc\ view/105m.apr 5 | :" :w C:/Vince/Arc\ view/105m.apr.orig 6 | :" :source! x:/replace.vim 7 | :" 8 | :%s/\\/\//ge " switch backslash to foreslash 9 | :%s/ /\\\ /ge " preface a space with a backslash 10 | :%s/[~@!#$%^&()}{;'",.]/\\&/ge " do the same for punctuation characters 11 | :" 12 | :" ^.*$ match whole line (c:/vince/105m/105m.apr) 13 | :" :e! &\r put :edit in front (:e! c:/vince/105m/105m.apr) 14 | :" :w &.orig\r make backup (:w c:/vince/105m/105m.apr) 15 | :" :source! x:\/replace.vim add run replace script 16 | :" 17 | :%s/^.*$/:e! &\r:w &.orig\r:source! x:\/replace.vim/e 18 | :" 19 | :w! apr-list.vim " save as script 20 | :q " exit vim 21 | -------------------------------------------------------------------------------- /gis/recursive_apr_update/replace.src.txt: -------------------------------------------------------------------------------- 1 | # this file is not kept up to date 2 | # ---------------------------------------------------------------------- 3 | # -delete blank lines 4 | # /^$ 5 | # dd 6 | # -spaces and periods must be escaped with a backslash, eg: "\ " 7 | # 8 | # -search&replace "/" to "\/" 9 | # :%sno/\//\\\//g 10 | # -remove spaces not preceded by a backslash 11 | # :%sno/ // 12 | # -insert at beginning of line: :%sno/ 13 | # :%sno/^/:%sno\// 14 | # -replace double tabs with single 15 | # :%sno/ / /g 16 | # replace tabs with "/" 17 | # :%sno/ /\//g 18 | # 19 | # Libraries Available: 20 | # ==================== 21 | # Base 1000k 22 | # Forest Inventory 50k 23 | # Bathymetry 50k 24 | # Base 250k 25 | # Base 50k 26 | # av 250k text 27 | # av 50k text 28 | # 29 | # 30 | # find replace 31 | # ---------------------------------------------------------------------- 32 | # 33 | # this line is only necessary for processing the backup/test copies of 34 | # the user .apr files on our local network. 35 | # Path:\t"c:/ Path:\t"x:/rgn_update/dcooley/c 36 | 37 | d:/rrgis/250k/q z:/arcdata/250k/boundary/q 38 | d:/rrgis/250k/info/q z:/arcdata/250k/boundary/info/q 39 | 40 | d:/rrgis/250k/boundary z:/arcdata/250k/boundary 41 | d:/rrgis/1000k/boundary z:/arcdata/1000k/boundary 42 | 43 | d:/rrgis/1000k/theme z:/arcdata/1000k/theme 44 | d:/rrgis/250k/theme z:/arcdata/250k/theme 45 | d:/rrgis/50k/theme z:/arcdata/50k/theme 46 | 47 | d:/rrgis z:/arcdata_old 48 | 49 | z:/arcdata/lib250 z:/arcdata_old/250k 50 | z:/arcdata/arcdata z:/arcdata 51 | 52 | /1000k/boundary/border /1000k/boundary/mborder 53 | /1000k/boundary/codist /1000k/boundary/mcodist 54 | /1000k/boundary/fntt /1000k/boundary/mfntt 55 | /1000k/boundary/gma /1000k/boundary/mgma 56 | /1000k/boundary/oa /1000k/boundary/moa 57 | /1000k/boundary/park /1000k/boundary/mpark 58 | /1000k/boundary/rtc /1000k/boundary/mrtc 59 | 60 | /1000k/boundary/info/border /1000k/boundary/info/mborder 61 | /1000k/boundary/info/codist /1000k/boundary/info/mcodist 62 | /1000k/boundary/info/fntt /1000k/boundary/info/mfntt 63 | /1000k/boundary/info/gma /1000k/boundary/info/mgma 64 | /1000k/boundary/info/oa /1000k/boundary/info/moa 65 | /1000k/boundary/info/park /1000k/boundary/info/mpark 66 | /1000k/boundary/info/rtc /1000k/boundary/info/mrtc 67 | 68 | "rr1000\.coast "base\ 1000k\.coast 69 | "rr1000\.water "base\ 1000k\.water 70 | "rr1000\.river "base\ 1000k\.river 71 | "rr1000\.ice "base\ 1000k\.ice 72 | "rr1000\.contour "base\ 1000k\.contour 73 | "rr1000\.hypsometry "base\ 1000k\.hypsometry 74 | "rr1000\.access "base\ 1000k\.access 75 | "rr1000\.places "base\ 1000k\.places 76 | "rr1000\.ocean "base\ 1000k\.ocean 77 | 78 | "rr250 "rr250-old 79 | "rr50 "rr50-old 80 | 81 | z:/arcdata/250k/base z:/arcdata_old/250k/base 82 | z:/arcdata/50k/base z:/arcdata_old/50k/base 83 | -------------------------------------------------------------------------------- /gis/recursive_apr_update/replace.vim: -------------------------------------------------------------------------------- 1 | :" 2 | :" % = current file 3 | :" s = substitute 4 | :" no = no 'magic' pattern matching 5 | :" trailing '/e' turns off 'pattern not found' messages 6 | :" w = write file 7 | :" 8 | :%sno/d:\/rrgis\/250k\/q/z:\/arcdata\/250k\/boundary\/q/e 9 | :%sno/d:\/rrgis\/250k\/info\/q/z:\/arcdata\/250k\/boundary\/info\/q/e 10 | :%sno/d:\/rrgis\/250k\/boundary/z:\/arcdata\/250k\/boundary/e 11 | :%sno/d:\/rrgis\/250k\/theme/z:\/arcdata\/250k\/theme/e 12 | :%sno/d:\/rrgis\/50k\/theme/z:\/arcdata\/50k\/theme/e 13 | :%sno/d:\/rrgis\/1000k/z:\/arcdata\/1000k/e 14 | :%sno/d:\/rrgis/z:\/arcdata_old/e 15 | :%sno/z:\/arcdata\/lib250/z:\/arcdata_old\/250k/e 16 | :%sno/z:\/arcdata\/arcdata/z:\/arcdata/e 17 | :%sno/z:\/arcdata_old\/arcdata/z:\/arcdata_old/e 18 | :" %sno/z:\/arcdata_old\/1000k/z:\arcdata\/1000k/e 19 | :" %sno/\/1000k\/boundary\/border/\/1000k\/boundary\/mborder/e 20 | :" %sno/\/1000k\/boundary\/codist/\/1000k\/boundary\/mcodist/e 21 | :" %sno/\/1000k\/boundary\/fntt/\/1000k\/boundary\/mfntt/e 22 | :" %sno/\/1000k\/boundary\/gma/\/1000k\/boundary\/mgma/e 23 | :" %sno/\/1000k\/boundary\/oa/\/1000k\/boundary\/moa/e 24 | :" %sno/\/1000k\/boundary\/park/\/1000k\/boundary\/mpark/e 25 | :" %sno/\/1000k\/boundary\/rtc/\/1000k\/boundary\/mrtc/e 26 | :" %sno/\/1000k\/boundary\/info\/border/\/1000k\/boundary\/info\/mborder/e 27 | :" %sno/\/1000k\/boundary\/info\/codist/\/1000k\/boundary\/info\/mcodist/e 28 | :" %sno/\/1000k\/boundary\/info\/fntt/\/1000k\/boundary\/info\/mfntt/e 29 | :" %sno/\/1000k\/boundary\/info\/gma/\/1000k\/boundary\/info\/mgma/e 30 | :" %sno/\/1000k\/boundary\/info\/oa/\/1000k\/boundary\/info\/moa/e 31 | :" %sno/\/1000k\/boundary\/info\/park/\/1000k\/boundary\/info\/mpark/e 32 | :" %sno/\/1000k\/boundary\/info\/rtc/\/1000k\/boundary\/info\/mrtc/e 33 | :%sno/"Forest\ Inventory\ 250"/"Forest\ Inventory\ 50k"/e 34 | :%sno/"rr50\.forest"/"Forest\ Inventory\ 50k\.forest_cover"/e 35 | :%sno/"Forest\ Inventory\ 250.forest_cover"/"Forest\ Inventory\ 50k\.forest_cover"/e 36 | :%sno/"forest\ inventory.forest_cover"/"Forest\ Inventory\ 50k\.forest_cover"/e 37 | :%sno/"forest\ inventory\ 250.forest_cover"/"Forest\ Inventory\ 50k\.forest_cover"/e 38 | :%sno/250k\/theme\/forestry/50k\/theme\/forestry/e 39 | :%sno/"rr250\./"rr250-old\./e 40 | :%sno/"rr50\./"rr50-old\./e 41 | :%sno/"rr1000\.coast/"base\ 1000k\.coast/e 42 | :%sno/"rr1000\.water/"base\ 1000k\.water/e 43 | :%sno/"rr1000\.river/"base\ 1000k\.river/e 44 | :%sno/"rr1000\.ice/"base\ 1000k\.ice/e 45 | :%sno/"rr1000\.contour/"base\ 1000k\.contour/e 46 | :%sno/"rr1000\.hypsometry/"base\ 1000k\.hypsometry/e 47 | :%sno/"rr1000\.access/"base\ 1000k\.access/e 48 | :%sno/"rr1000\.places/"base\ 1000k\.places/e 49 | :%sno/"rr1000\.ocean/"base\ 1000k\.ocean/e 50 | :%sno/z:\/arcdata\/250k\/base/z:\/arcdata_old\/250k\/base/e 51 | :%sno/z:\/arcdata\/50k\/base/z:\/arcdata_old\/50k\/base/e 52 | :%sno/z:\/arcdata\/1000k\/boundary/z:\/arcdata_old\/1000k\/boundary/e 53 | :%sno/z:\/arcdata\/250k\/boundary/z:\/arcdata_old\/250k\/boundary/e 54 | :%sno/z:\/arcdata\/50k\/boundary/z:\/arcdata_old\/50k\/boundary/e 55 | :%sno/z:\/arcdata_old\/1000k\/base/z:\/arcdata\/1000k\/base/e 56 | :%sno/\/lims\//\/base\//e 57 | :%sno/"rr250-old\.-lims/"rr250-old\./e 58 | :%sno/old\.old\./old\./e 59 | :%sno/z:\/b1000k\//z:\/arcdata\/1000k\//e 60 | :w 61 | -------------------------------------------------------------------------------- /gis/recursive_apr_update/rgn_update.tws: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/recursive_apr_update/rgn_update.tws -------------------------------------------------------------------------------- /gis/recursive_apr_update/set-vim.bat: -------------------------------------------------------------------------------- 1 | set root=x: 2 | set VIMRUNTIME=%root%/vim/vim57 3 | set VIM=%root%/vim 4 | path=%path%;%root%\vim\vim57 5 | -------------------------------------------------------------------------------- /gis/recursive_apr_update/upgrade-all.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/recursive_apr_update/upgrade-all.bat -------------------------------------------------------------------------------- /gis/recursive_apr_update/vim/vim57/_put_vim_runtime_here_: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/recursive_apr_update/vim/vim57/_put_vim_runtime_here_ -------------------------------------------------------------------------------- /gis/recursive_apr_update/vim/vimrc: -------------------------------------------------------------------------------- 1 | " An example for a vimrc file. 2 | " 3 | " Maintainer: Bram Moolenaar 4 | " Last change: 2000 Mar 29 5 | " 6 | " To use it, copy it to 7 | " for Unix and OS/2: ~/.vimrc 8 | " for Amiga: s:.vimrc 9 | " for MS-DOS and Win32: $VIM\_vimrc 10 | " for OpenVMS: sys$login:.vimrc 11 | " Changes for Cygwin-Environment by Michael Ring (Michael-Ring@T-Online.de) 12 | " 13 | " Use Vim settings, rather then Vi settings (much better!). 14 | " This must be first, because it changes other options as a side effect. 15 | set nocompatible 16 | 17 | set bs=2 " allow backspacing over everything in insert mode 18 | if has("vms") 19 | set nobackup " do not keep a backup file, use versions instead 20 | else 21 | set backup " keep a backup file 22 | endif 23 | set viminfo='20,\"50 " read/write a .viminfo file, don't store more 24 | " than 50 lines of registers 25 | set history=50 " keep 50 lines of command line history 26 | set ruler " show the cursor position all the time 27 | 28 | if &term == "cygwin" 29 | set background=dark 30 | endif 31 | 32 | " Switch syntax highlighting on, when the terminal has colors 33 | " Also switch on highlighting the last used search pattern. 34 | if &t_Co > 2 || has("gui_running") 35 | syntax on 36 | set hlsearch 37 | endif 38 | 39 | set vi='20,\"50,nx:/viminfo 40 | 41 | set nobackup 42 | -------------------------------------------------------------------------------- /gis/xx-set-alias.py: -------------------------------------------------------------------------------- 1 | # Update feature class alias 2 | import arcgisscripting 3 | gp = arcgisscripting.create(9.3) 4 | 5 | gdbTable = 'd:/s/gdb.gdb/wka' 6 | desc = gp.describe(gdbTable) 7 | 8 | # Print GDB Table properties 9 | # 10 | print "AliasName: %s" % desc.AliasName 11 | print "DefaultSubtypeCode: %s" % desc.DefaultSubtypeCode 12 | print "GlobalIDFieldName: %s" % desc.GlobalIDFieldName 13 | print "ModelName: %s" % desc.ModelName 14 | print "RasterFieldName: %s" % desc.RasterFieldName 15 | print "RelationshipClassNames: %s" % desc.RelationshipClassNames 16 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/50k_dem.tws: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/yt30m_dem/50kdem/50k_dem.tws -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/50k_dem_anudem.tws: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/yt30m_dem/50kdem/50k_dem_anudem.tws -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/_ReadMe.aml: -------------------------------------------------------------------------------- 1 | &return this aml is meant to be read not executed 2 | &ty -------------------------------------------------------------------------- 3 | &ty 50k DEM from LIMS dataset * mhwilkie * 02-August-2k 4 | &ty -------------------------------------------------------------------------- 5 | 6 | *** 13-Dec-2k *** This document is still mostly correct, but please keep in mind it is slightly outdated. The order of the steps is a little mishmashed in places. 7 | 8 | \\killerbee2\lims50kdem Projectdir for the 50k maps we didn't have data for during round one. 9 | 10 | .\scripts\50k_dem_lims.txt exported query from Arcview: select where Old_Map.Elev = NotPresent and New_Map.Elev = Present 11 | 12 | .\scripts\job.list.txt pared the above down to Index-ID, Tile-name, and Location (179 records) 13 | 14 | 15 | adopted same procedure as with the 250k_dem project: the Index-IDs for the LIMS dataset do not match our old Index-IDs. Therefore tiles are manipulated by their NTS Name. 16 | 17 | [Step 1] 18 | Create the directory framework ...\115a\115a15 for all tiles 19 | AML: make_tilestruct 20 | 21 | [Step 2] 22 | Grab neatlines and make buffers for each tile 23 | AML: make_buffers 24 | 25 | [Step 3] 26 | identify and save source library paths of all tiles which intersect the 2km buffer 27 | AML: find_paths 28 | FILES: %tile%\overlap.tiles, overlap.path 29 | 30 | [Step 4] 31 | clip lake contour'd border to 2k buffer 32 | AML: clip_lakes 33 | 34 | [Step 5] 35 | Build Large 300m dem for flipping stream arcs 36 | AML: make_flipgrid 37 | 38 | Notes: some tiles have contours which are too dense, resulting in a "Too Many Critical Points" error. The workaround is to append the overlapping coverages to a local copy and then clip to the 2k buffer (ie: the original method). ANUDEM does not have this problem, or it has a higher tolerance. 39 | 40 | Tiles manually processed using: 41 | 42 | &wo %.home%\106f\106f06 43 | &sys sed 's/$/\\fctr/' overlap.path.bare > append.txt ; 44 | &sys echo end >> append.txt ; 45 | &sys arc append fctr link < append.txt ; 46 | clip fctr buf_2k fctr-clip link ; 47 | kill fctr all ; 48 | rename fctr-clip fctr 49 | 50 | The flipping grid shows many tiles which with elevations coded in feet and attempting to pass themselves off as meters. Fix is to manually change the FNEAT.AAT 'Z_units' to 'PIEDS' and then run add_zmetric.aml (z:\arcdata\50k\lims\scripts) 51 | Lather, rinse, repeat as necessary. 52 | 53 | [Step 6]: 54 | Append overlapping watercourse coverages into single cover and clip to 1km buffer. 55 | AML: append_h2o 56 | 57 | [Step 7]: 58 | Stream flipping (finally!) 59 | AML: flip_streams 60 | 61 | [Step 8] build 30m dems 62 | FILES: %tile%\dem 63 | AML: MAKE_DEMS 64 | 65 | [Step 8.5] flatten lakes 66 | FILES: %tile%\dem, .lake_elev = x:\water\final\nov15-poly 67 | AML: FLAT_LAKES 68 | 69 | [Step 9] make hillshade relief models 70 | FILES: %tile%\dem_hs 71 | AML: MAKE_SHADE 72 | 73 | [Step 10] clip verified (final) dems and hillshades to 100m buffer in preparations for mosaicing and insertion into repository. 74 | FILES: %tile%\dem %tile%\dem_hs 75 | AML: CLIP_100M 76 | 77 | [Step 11] Build & Package 250k DEMs for public distribution<<<<< CURRENT >>>>> 78 | FILES: %quad%\dem_90m, shade_90m 79 | AML: MOSAIC_250k, PKG_250k 80 | 81 | 82 | 83 | /*============================================================================ 84 | /* Stageless 85 | /*============================================================================ 86 | kill_locks.aml: walk directory tree and remove lockfiles. Use this when amls 87 | don't finish properly and lockfiles are not removed. 88 | 89 | grid2catalog.aml: walk dir tree and create an image catalog for specified grids -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/_TODO.txt: -------------------------------------------------------------------------------- 1 | These tiles did not have a FDEM grid: (z:\arcdata\50k\base) 2 | 094o\094o14 095f\ 095l\ 104p\104p14 106m\ 106n\ 115b\115b05 117d\117d12-new 3 | 4 | 5 | /* 2001-March-21 */ 6 | /* tiles affected by the acquisition of new BC and AK dem data: 7 | 115C10 115C09 115B12 115B11 115C07 115C08 115B05 115B06 095B03 095B04 095C01 095C02 095C03 115B03 095C04 115B02 095D01 095D02 095D03 094O14 095D04 105A01 115A02 094O13 105A02 115A01 105A03 105D04 094N16 105A04 105D03 105B01 105D02 105B02 105D01 105B03 105C04 105C03 094N15 105C01 105C02 094N14 094N13 114O15 094M16 094M15 094M14 094M13 104P16 114P15 104P15 114P16 104P14 104M13 104P13 104M14 104O16 104M15 104O15 104M16 104O14 104N13 104N14 104N16 104N15 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/_readme-anudem.txt: -------------------------------------------------------------------------------- 1 | 2001 November 30 * matt.wilkie@gov.yk.ca 2 | 3 | The central "brain" script is out2anudem.aml. It is an "all-in-one" synthesis of the other ANUDEM scripts. 4 | 5 | Conceptual Model, For each tile do: (- done, + todo) 6 | 7 | - export contours, streams, boundary poly, etc. to ungenerate files 8 | - calc stats (min/max elev, bounds) [optimal tolerances?] 9 | - write anudem.cmd file 10 | - run anudem 11 | + convert anudem outputs (dem and diagnostic files) to Arc 12 | + delete intermediate files(?) 13 | 14 | 15 | | * out2anudem * | all in one script | 16 | | cover2generate | convert Arc coverage to generate file | 17 | | build_cmd | build ANUDEM command file | 18 | | build_dem | calculate the dem | 19 | | adem2grid | convert ANUDEM dem to Arc Grid | 20 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/_template.aml: -------------------------------------------------------------------------------- 1 | /*=========================================================================== 2 | /* Template for Yukon 50k_dem AMLs (from updated LIMS dataset) 3 | /*=========================================================================== 4 | &severity &error &routine bail 5 | /* if there are commandline arguments, make them the TODO list 6 | &args quad tile:REST 7 | &ty -------------------------------------------------------------------------- 8 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 18-Sept-2k 9 | &ty ::Step #:: (see scripts\__ReadMe.aml) 10 | &ty 11 | &ty - what this script does 12 | &ty * warnings go here 13 | &ty 14 | &ty Autorun: &r %aml$file% {quad} {tile(s)} 15 | &ty -------------------------------------------------------------------------- 16 | &ty 17 | &ty Current commandline: &r %aml$file% %quad% %tile% 18 | &ty 19 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 20 | 21 | &if [null %quad%] &then &do 22 | &s pause [response ' to continue, something else to abort'] 23 | &if not [null %pause%] &then &return %aml$file% exited by user request. 24 | &end 25 | 26 | &workspace %.home% 27 | 28 | /* put header variables and other semi-global code here 29 | 30 | /* follow ...\\\ (...\115h\115h12\) pattern 31 | /* check for quad placeholder (allows "&r aml_prog . 105d11 105d12 105d13") 32 | &if %quad% = . &then &set quad = [listfile * -directory] 33 | /* check for quad commandline args 34 | &if [null %quad%] &then &set quad = [listfile * -directory] 35 | /* check for tile argument 36 | &if not [null %tile%] &then &set tile_arg = yes 37 | 38 | &do quad &list [unquote %quad%] 39 | &workspace %quad%; &type ...entering %quad% 40 | /* check for TODO list on the command line, else TODO = existing workspaces 41 | &if [null %tile%] &then &set tile = [listfile * -workspace] 42 | 43 | &do tile &list [unquote %tile%] 44 | &call main 45 | &end 46 | 47 | /* if tile arg is autogenerated, null out else it won't be generated anew for next loop 48 | &if not [variable tile_arg] &then &set tile = 49 | 50 | &workspace .. 51 | &end 52 | 53 | &RETURN ...[upcase %aml$fullfile%] finished normally. 54 | 55 | /*============================================================================ 56 | &ROUTINE MAIN 57 | /*-------mark workspace busy---------------------- 58 | &if [exists %tile%\lock -file] &then &return 59 | &set lockfile = [OPEN %tile%\lock openstat -write] 60 | &if %openstat% = 0 &then &type ...workspace %tile% locked 61 | &else &return Error %openstat% opening lockfile 62 | /*------------------------------------------------ 63 | &workspace %tile% 64 | 65 | 66 | ...code goes here... 67 | 68 | 69 | &workspace .. 70 | /*-------mark workspace not busy----------------- 71 | &if [close %lockfile%] = 0 &then 72 | &type ...workspace %tile% unlocked 73 | &else &return Error closing lockfile 74 | &if [delete %tile%\lock -file] <> 0 &then 75 | &return &error ...Error removing %tile%\lock 76 | /*----------------------------------------------- 77 | &RETURN 78 | /*--------------------------------------------------------------------------- 79 | /* other routines go here 80 | 81 | &routine bail 82 | &if not [variable str] &then &s str Bailing out of %aml$file%... 83 | &return; &return &warning %str% 84 | /*=========================================================================== 85 | /* End Of Template 86 | /*=========================================================================== -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/adem2grid.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* ------------------------------------------------------------------------ 3 | &args out-dem dem 4 | /* out-dem = Anudem created dem dem = name for output Arcinfo grid 5 | /* ------------------------------------------------------------------------ 6 | &if [null %out-dem%] | [null %dem%] &then 7 | &return ...USAGE: &r %aml$file% {anudem-dem} {arcinfo-dem} 8 | 9 | &type ...converting Anudem %out-dem% to Arc %dem% 10 | &if [exists %dem% -grid] &then &return ...[upcase %dem%] already exists! 11 | 12 | floatgrid %out-dem% %dem% 13 | 14 | projectdefine grid %dem% 15 | Projection ALBERS 16 | Datum NAD83 17 | Zunits NO 18 | Units METERS 19 | Spheroid GRS1980 20 | Xshift 0.0000000000 21 | Yshift 0.0000000000 22 | Parameters 23 | 61 40 0.000 /* 1st standard parallel 24 | 68 0 0.000 /* 2nd standard parallel 25 | -132 30 0.000 /* central meridian 26 | 59 0 0.000 /* latitude of projection's origin 27 | 500000.00000 /* false easting (meters) 28 | 500000.00000 /* false northing (meters) 29 | 30 | &RETURN ...[upcase %aml$fullfile%] finished normally. 31 | /* ------------------------------------------------------------------------ 32 | &routine bail 33 | &if not [variable str] &then &s str Bailing out of %aml$file%... 34 | &return; &return &warning %str% 35 | /*=========================================================================== 36 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/border-tiles.txt: -------------------------------------------------------------------------------- 1 | 117C09 117C08 117C01 117B16 117B09 117B08 117B01 116N15 116N10 116N07 116N02 116K15 116K10 116K07 116K02 116F15 116F10 116F07 116F02 116C15 116C10 116C07 116C02 115N15 115N10 115N07 115N02 115K15 115K10 115K07 115K02 115F15 115F10 115F07 115F02 115C15 115C10 115C07 2 | 3 | /* tiles which border alaska -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/clip_lakes.aml: -------------------------------------------------------------------------------- 1 | /*=========================================================================== 2 | &severity &error &routine bail 3 | /* if there are commandline arguments, make them the TODO list 4 | &args quad tile:REST 5 | &ty -------------------------------------------------------------------------- 6 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 02-Aug-2k 7 | &ty ::Step 4:: (see scripts\__ReadMe.aml) 8 | &ty 9 | &ty - clip lake contour'd border to 2k buffer 10 | &ty -------------------------------------------------------------------------- 11 | &if [null %quad%] &then &do 12 | &s pause [response ' to continue, something else to abort'] 13 | &if not [null %pause%] &then &return %aml$file% exited by user request. 14 | &end 15 | 16 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 17 | &workspace %.home% 18 | 19 | /* put header variables and other semi-global code here 20 | &setvar biglake = x:\water\final\lakes_final 21 | /*&setvar biglake = x:\water\final\wat11-06-00 /* ocean coeastline 22 | 23 | /* follow ...\\\ (...\115h\115h12\) pattern 24 | /* check for quad placeholder (allows "&r aml_prog . 105d11 105d12 105d13") 25 | &if %quad% = . &then &set quad = [listfile * -directory] 26 | /* check for quad commandline args 27 | &if [null %quad%] &then &set quad = [listfile * -directory] 28 | /* check for tile argument 29 | &if not [null %tile%] &then &set tile_arg = yes 30 | 31 | &do quad &list [unquote %quad%] 32 | &workspace %quad%; &type ...entering %quad% 33 | /* check for TODO list on the command line, else TODO = existing workspaces 34 | &if [null %tile%] &then &set tile = [listfile * -workspace] 35 | 36 | &do tile &list [unquote %tile%] 37 | &workspace %tile% 38 | &call main 39 | &workspace .. 40 | &end 41 | 42 | /* if tile arg is autogenerated, null out else it won't be generated anew for next loop 43 | &if not [variable tile_arg] &then &set tile = 44 | 45 | &workspace .. 46 | &end 47 | 48 | &RETURN ...[upcase %aml$fullfile%] finished normally. 49 | 50 | /*============================================================================ 51 | &ROUTINE MAIN 52 | &if [exists lake_ctr -cover] OR [exists clip_lakes.done -file] &then &return 53 | /*-------mark workspace busy---------------------- 54 | &if [exists lock -file] &then &return 55 | &set lockfile = [OPEN lock openstat -write] 56 | &if %openstat% = 0 &then &type ...workspace %tile% locked 57 | &else &return Error %openstat% opening lockfile 58 | /*------------------------------------------------ 59 | &type ...Killing off Round I mistakes 60 | &if [exist lake_ctr -cover] &then kill lake_ctr all 61 | &if [exist lake_ctr1 -cover] &then kill lake_ctr1 all 62 | &if [exist lake_ctr2 -cover] &then kill lake_ctr2 all 63 | 64 | 65 | &severity &error &ignore 66 | &type ...Making Round II mistakes 67 | /* clip {type} {tolerance} 68 | clip %biglake% buf_2k lake_ctr LINE 0.0000001 69 | &severity &error &routine bail 70 | 71 | &describe lake_ctr 72 | &if %dsc$arcs% = 0 &then &do 73 | &type %tile% lake_ctr coverage is empty, nuking 74 | kill lake_ctr all 75 | &sys echo No lakes in this tile!>clip_lakes.done 76 | &end 77 | 78 | &label Fini 79 | /*-------mark workspace not busy----------------- 80 | &if [close %lockfile%] = 0 &then 81 | &type ...workspace %tile% unlocked 82 | &else &return Error closing lockfile 83 | &sys del lock 84 | /*----------------------------------------------- 85 | &RETURN 86 | /*============================================================================ 87 | &routine bail 88 | &if not [variable str] &then &s str Bailing out of %aml$file%... 89 | &return; &return &warning %str% 90 | /*=========================================================================== 91 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/cover2generate.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* ------------------------------------------------------------------------- 3 | &args feature elev cover_list:rest 4 | /* ------------------------------------------------------------------------- 5 | &if [null %feature%] | [null %elev%] | [null %cover_list%] &then 6 | &return /&...USAGE: &r %aml$file% {feature_type} {Z_field} {cover1} {cover2} .../& 7 | 8 | &type ...converting [quote %cover_list%] to ungenerate files. 9 | 10 | &do cover &list [unquote %cover_list%] 11 | &if not [exists %cover% -cover] &then &goto End_c2g 12 | &if [exists %cover%.gen.gz -file] &then &goto End_c2g 13 | &if [exists %cover%.gen -file] &then &goto do_gzip 14 | &set edit-cov = [scratchname] 15 | copy %cover% %edit-cov% 16 | 17 | /* if the elevation field doesn't exist, go straight to ungenerate 18 | &if [iteminfo %cover%.aat -info %elev% -exists] &then 19 | &do ; ArcEdit 20 | /* thanks to CSIRO, Australia for this AE tip (http://www.ffp.csiro.au/nfm/mdp/softqaa.htm#ar1) 21 | edit %edit-cov% %feature% 22 | select all 23 | calculate $id = %elev% 24 | save 25 | quit ; &end 26 | 27 | ungenerate %feature% %edit-cov% %cover%.gen # fixed 28 | kill %edit-cov% all 29 | /* compress ungenerate file to save disk space; using Start sends the task to background so we can carry on without waiting 30 | &label do_gzip 31 | &sys gzip %cover%.gen 32 | &type ...gzipped %cover% 33 | &label End_c2g 34 | &end 35 | 36 | 37 | &RETURN ...[upcase %aml$fullfile%] finished normally. 38 | /* ------------------------------------------------------------------------ 39 | &routine bail 40 | &if not [variable str] &then &s str Bailing out of %aml$file%... 41 | &return; &return &warning %str% 42 | /*=========================================================================== 43 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/flip_streams.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* if there are commandline arguments, make them the TODO list 3 | &args quad tile:REST 4 | &ty -------------------------------------------------------------------------- 5 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 04-Oct-2k 6 | &ty ::Step 7:: (see scripts\__ReadMe.aml) 7 | &ty 8 | &ty - Flip drainage arcs such that all streams run downhill 9 | &ty 10 | &ty Autorun: &r %aml$file% {quad} {tile(s)} 11 | &ty -------------------------------------------------------------------------- 12 | &if [null %quad%] &then &do 13 | &s pause [response ' to continue, something else to abort'] 14 | &if not [null %pause%] &then &return %aml$file% exited by user request. 15 | &end 16 | 17 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 18 | &workspace %.home% 19 | 20 | /* put header variables and other semi-global code here 21 | &set dem = flip_grd 22 | &set draincov = fwtc 23 | 24 | /* follow ...\\\ (...\115h\115h12\) pattern 25 | /* check for quad placeholder (allows "&r aml_prog . 105d11 105d12 105d13") 26 | &if %quad% = . &then &set quad = [listfile * -directory] 27 | /* check for quad commandline args 28 | &if [null %quad%] &then &set quad = [listfile * -directory] 29 | /* check for tile argument, if yes make a note of it 30 | &if not [null %tile%] &then &set tile_arg = yes 31 | 32 | &do quad &list [unquote %quad%] 33 | &workspace %quad%; &type ...entering %quad% 34 | /* check for TODO list on the command line, else TODO = existing workspaces 35 | &if not [variable tile_arg] &then &set tile = [listfile * -workspace] 36 | 37 | &do tile &list [unquote %tile%] 38 | &call main 39 | &end 40 | 41 | /* if tile arg is autogenerated, null out else it won't be generated anew for next loop 42 | &if not [variable tile_arg] &then &set tile = 43 | 44 | &workspace .. 45 | &end 46 | 47 | &RETURN ...[upcase %aml$fullfile%] finished normally. 48 | 49 | /*============================================================================ 50 | &ROUTINE MAIN 51 | /* we use a done marker because if no streams need to be flipped, drain_directions deletes the flipped cover. 52 | &if [exists %tile%\flip_streams.done -file] &then &return 53 | /*-------mark workspace busy---------------------- 54 | &if [exists %tile%\lock -file] &then &return 55 | &set lockfile = [OPEN %tile%\lock openstat -write] 56 | &if %openstat% = 0 &then &type ...workspace %tile% locked 57 | &else &return Error %openstat% opening lockfile 58 | /*------------------------------------------------ 59 | &workspace %tile% 60 | 61 | /* drain_direction.aml is usually located in the global aml directory 62 | /* Usage: &run drain_direction.aml 63 | &run drain_direction.aml %dem% %draincov% 64 | 65 | &if [exists %draincov%_f -cover] &then &do 66 | &type ...setting done marker 67 | &sys echo All done! > flip_streams.done 68 | &end 69 | 70 | &type ... [date -vfull] * Minutes since last: [calc [extract 2 [show &pt all]] / 60] 71 | /*&pause /* debug breakpoint 72 | 73 | &workspace .. 74 | /*-------mark workspace not busy----------------- 75 | &if [close %lockfile%] = 0 &then 76 | &type ...workspace %tile% unlocked 77 | &else &return Error closing lockfile 78 | &sys del %tile%\lock 79 | /*----------------------------------------------- 80 | &RETURN 81 | /*--------------------------------------------------------------------------- 82 | /* other routines go here 83 | 84 | &routine bail 85 | &if not [variable str] &then &s str Bailing out of %aml$file%... 86 | &return; &return &warning %str% 87 | /*=========================================================================== 88 | /* End Of Flip_Streams.aml 89 | /*=========================================================================== -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/float2int.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* if there are commandline arguments, make them the TODO list 3 | &args quad tile:REST 4 | &ty -------------------------------------------------------------------------- 5 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 18-Sept-2k 6 | &ty ::Step #:: (see scripts\__ReadMe.aml) 7 | &ty 8 | &ty - convert all floating point grids to integer format (saves disk space) 9 | &ty 10 | &ty * only run if there are no grids which you want to keep floating point * 11 | &ty 12 | &ty Autorun: &r %aml$file% {quad} {tile(s)} 13 | &ty -------------------------------------------------------------------------- 14 | &if [null %quad%] &then &do 15 | &s pause [response ' to continue, something else to abort'] 16 | &if not [null %pause%] &then &return %aml$file% exited by user request. 17 | &end 18 | 19 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 20 | &workspace %.home% 21 | 22 | /* put header variables and other semi-global code here 23 | &if [locase[show program]] <> grid &then GRID /* we must be in GRID to work 24 | 25 | /* follow ...\\\ (...\115h\115h12\) pattern 26 | /* check for quad placeholder (allows "&r aml_prog . 105d11 105d12 105d13") 27 | &if %quad% = . &then &set quad = [listfile * -directory] 28 | /* check for quad commandline args 29 | &if [null %quad%] &then &set quad = [listfile * -directory] 30 | /* check for tile argument 31 | &if not [null %tile%] &then &set tile_arg = yes 32 | 33 | &do quad &list [unquote %quad%] 34 | &workspace %.home%\%quad%; &type ...entering %quad% 35 | /* check for TODO list on the command line, else TODO = existing workspaces 36 | &if [null %tile%] &then &set tile = [listfile * -workspace] 37 | 38 | &do for_each &list [unquote %tile%] 39 | &call main 40 | &end 41 | 42 | /* if tile arg is autogenerated, null out else it won't be generated anew for next loop 43 | &if not [variable tile_arg] &then &set tile = 44 | 45 | &workspace .. 46 | &end 47 | 48 | &if [locase[show program]] = grid &then QUIT /* exit GRID 49 | &RETURN ...[upcase %aml$fullfile%] finished normally. 50 | 51 | /*============================================================================ 52 | &ROUTINE MAIN 53 | &workspace %.home%\%quad%\%for_each% 54 | /*-------mark workspace busy---------------------- 55 | &if [exists lock -file] &then &return 56 | &set lockfile = [OPEN lock openstat -write] 57 | &if %openstat% = 0 &then &type ...workspace %for_each% locked 58 | &else &return Error %openstat% opening lockfile 59 | /*------------------------------------------------ 60 | 61 | &do grids &list [listfile * -grid] /* generate grid list 62 | &if [null %grids%] &then &goto end_int /* skip if no grids 63 | &describe %grids% /* skip if already integer 64 | &if %grd$type% = 1 &then &goto end_int 65 | &s scratch = [scratchname] /* generate temp grid name 66 | 67 | %scratch% = INT(%grids%) /* convert to integer 68 | kill %grids% all /* kill original grid 69 | rename %scratch% %grids% /* rename temp to original 70 | &type renamed %scratch% to %grids% 71 | 72 | &label end_int /* re-entry point from "if already integer" 73 | /* &stop /* debug break point 74 | &end 75 | 76 | /*-------mark workspace not busy----------------- 77 | &if [close %lockfile%] = 0 &then 78 | &type ...workspace %for_each% unlocked 79 | &else &return Error closing lockfile 80 | &sys del lock 81 | /*----------------------------------------------- 82 | &workspace .. 83 | &RETURN 84 | /*--------------------------------------------------------------------------- 85 | /* other routines go here 86 | 87 | &routine bail 88 | &if not [variable str] &then &s str Bailing out of %aml$file%... 89 | &return; &return &warning %str% 90 | /*=========================================================================== 91 | /* End Of float2int.aml 92 | /*=========================================================================== 93 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/flowdirect.aml: -------------------------------------------------------------------------------- 1 | /***********************************************************************/ 2 | /* FlowDirector.aml */ 3 | /* Programmer: Gord Nevin Jan 5 2001 - Yukon Geology Program */ 4 | /* Identifies watershed boundaries using a GRID DEM file. */ 5 | /* Performs the same operation on a number of grids in one workspace. */ 6 | /* Remember to navigate to the proper workspace first. */ 7 | /* requires GRID ; can be modified, but retain this header */ 8 | /* WARNING: All files must reside on the local drive, not a server */ 9 | /* Run from the ARC PROMPT */ 10 | /* */ 11 | /* modified by Matt.Wilkie@gov.yk.ca * 09-Jan-2001 - RRGIS */ 12 | /***********************************************************************/ 13 | 14 | /* 15 | &if [locase[show program]] <> grid &then GRID 16 | 17 | /*&sv thecovers = [listfile * -grid] 18 | &sv thecovers = dem 19 | &sv dest = d:\tmp 20 | /* 21 | 22 | &do cov &list %thecovers% 23 | /*&sv Sheet = [after %cov% dem] 24 | &set sheet = dem 25 | flo%sheet% = flowdirection (%cov%) ; bas%sheet% = basin (flo%sheet%) 26 | buildsta bas%sheet% ; buildvat bas%sheet% 27 | py%sheet% = gridpoly (bas%sheet%) 28 | /* 29 | /*copy py%sheet% d:\dem\50k\grid\basins\py%sheet% 30 | copy py%sheet% %dest%\py%sheet% 31 | /* 32 | kill flo%sheet% all ; kill bas%sheet% all ; kill py%sheet% all 33 | &end 34 | &ty Program complete! ; quit 35 | &return -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/grid2catalog.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* if there are commandline arguments, make them the TODO list 3 | &args item catalog quad:REST /* tile:REST 4 | &ty -------------------------------------------------------------------------- 5 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 03-Aug-2k 6 | &ty ::Step *:: (see scripts\__ReadMe.aml) 7 | &ty 8 | &ty - Walks directory tree and adds specified grids to a new image catalog 9 | &ty 10 | &ty Usage: &run %aml$file% 11 | &ty 12 | &ty If run with no arguments %aml$file% defaults to interactive mode. 13 | &ty -------------------------------------------------------------------------- 14 | &ty 15 | &ty Current commandline: &r %aml$file% %item% %catalog% %quad% 16 | &ty 17 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 18 | 19 | &if [null %item%] &then &s item = [response 'Name of grids to add'] 20 | &if [null %catalog%] &then &s catalog = ~ 21 | [response 'Name of image catalog to create (%item%_cat)' %item%_cat] 22 | 23 | &s missing = 24 | &s exit_str = 25 | 26 | &if not [exists %catalog% -info] &then CREATECATALOG %catalog% 27 | 28 | &if %quad% = . &then &set quad = [listfile * -directory] 29 | &if [null %quad%] &then &set quad = [listfile * -directory] 30 | 31 | &severity &error &routine too_long 32 | 33 | /*&call 250k /* temporary hack 34 | 35 | &do quad &list [unquote %quad%] 36 | &do tile &list [listfile %quad%\* -workspace] 37 | &if [exists %quad%\%tile%\%item% -grid] &then 38 | ADDIMAGE %quad%\%tile%\%item% %catalog% 39 | &else 40 | &s missing = %missing% %quad%\%tile% 41 | /*&end 42 | &end 43 | &end 44 | 45 | &if not [null %missing%] &then 46 | &do 47 | &type These tiles did not have a [upcase %item%] grid: 48 | &type %missing% 49 | &end 50 | &type ...%exit_str% 51 | 52 | &return ...[upcase %aml$file%] finished normally. 53 | /* ------------------------------------------------------------------------ 54 | &routine too_long 55 | &s exit_str = 'Too many items to include in a variable. The missing list is incomplete' 56 | &return 57 | /* ------------------------------------------------------------------------ 58 | &routine 250k 59 | 60 | &do quad &list [unquote %quad%] 61 | &if [exists %quad%\%item% -grid] &then &do 62 | ADDIMAGE %quad%\%item% %catalog% 63 | &else 64 | &s missing = %missing% %quad% 65 | /*&end 66 | &end 67 | &end 68 | 69 | &stop 70 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/kill_flipgrids.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* if there are commandline arguments, make them the TODO list 3 | &args quad tile:REST 4 | &ty -------------------------------------------------------------------------- 5 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 18-Sept-2k 6 | &ty ::Step #:: (see scripts\__ReadMe.aml) 7 | &ty 8 | &ty *INDISCRIMINATELY* kills off all flipping grids and associated files 9 | &ty 10 | &ty 11 | &ty Autorun: &r %aml$file% {quad} {tile(s)} 12 | &ty -------------------------------------------------------------------------- 13 | &s pause [response ' to continue, something else to abort'] 14 | &if not [null %pause%] &then &return %aml$file% exited by user request. 15 | 16 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 17 | &workspace %.home% 18 | 19 | /* put header variables and other semi-global code here 20 | 21 | /* follow ...\\\ (...\115h\115h12\) pattern 22 | /* check for quad placeholder (allows "&r aml_prog . 105d11 105d12 105d13") 23 | &if %quad% = . &then &set quad = [listfile * -directory] 24 | /* check for quad commandline args 25 | &if [null %quad%] &then &set quad = [listfile * -directory] 26 | /* check for tile argument 27 | &if not [null %tile%] &then &set tile_arg = yes 28 | 29 | &do quad &list [unquote %quad%] 30 | &workspace %quad%; &type ...entering %quad% 31 | /* check for TODO list on the command line, else TODO = existing workspaces 32 | &if [null %tile%] &then &set tile = [listfile * -workspace] 33 | 34 | &do tile &list [unquote %tile%] 35 | &call main 36 | &end 37 | 38 | /* if tile arg is autogenerated, null out else it won't be generated anew for next loop 39 | &if not [variable tile_arg] &then &set tile = 40 | 41 | &workspace .. 42 | &end 43 | 44 | &RETURN ...[upcase %aml$fullfile%] finished normally. 45 | 46 | /*============================================================================ 47 | &ROUTINE MAIN 48 | /*-------mark workspace busy---------------------- 49 | &if [exists %tile%\lock -file] &then &return 50 | &set lockfile = [OPEN %tile%\lock openstat -write] 51 | &if %openstat% = 0 &then &type ...workspace %tile% locked 52 | &else &return Error %openstat% opening lockfile 53 | /*------------------------------------------------ 54 | &workspace %tile% 55 | 56 | &type ...killing off flip_grd and friends 57 | &if [exist flip_grd -grid] &then kill flip_grd all 58 | &if [exist flip_sink -cover] &then kill flip_sink all 59 | &if [exist flip_drain -cover] &then kill flip_drain all 60 | &sys if exist flip_diag del flip_diag 61 | 62 | &workspace .. 63 | /*-------mark workspace not busy----------------- 64 | &if [close %lockfile%] = 0 &then 65 | &type ...workspace %tile% unlocked 66 | &else &return Error closing lockfile 67 | &sys del %tile%\lock 68 | /*----------------------------------------------- 69 | &RETURN 70 | /*--------------------------------------------------------------------------- 71 | /* other routines go here 72 | 73 | &routine bail 74 | &if not [variable str] &then &s str Bailing out of %aml$file%... 75 | &return; &return &warning %str% 76 | /*=========================================================================== 77 | /* End Of KILL_FLIPGRIDS.aml 78 | /*=========================================================================== 79 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/kill_locks.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | &args quad tile:REST 3 | &ty -------------------------------------------------------------------------- 4 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 02-Aug-2k 5 | &ty ::Step *:: (see scripts\__ReadMe.aml) 6 | &ty 7 | &ty - Walk directory tree and remove all lock files from workspaces... 8 | &ty (lockfiles which are marked open are skipped quietly) 9 | &ty -------------------------------------------------------------------------- 10 | &if [null %quad%] &then &do 11 | &s pause [response ' to continue, something else to abort'] 12 | &if not [null %pause%] &then &return %aml$file% exited by user request. 13 | &end 14 | 15 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 16 | &workspace %.home% 17 | 18 | /* put header variables and other semi-global code here 19 | 20 | /* follow ...\\\ (...\115h\115h12\) pattern 21 | /* check for quad placeholder (allows "&r aml_prog . 105d11 105d12 105d13") 22 | &if %quad% = . &then &set quad = [listfile * -directory] 23 | /* check for quad commandline args 24 | &if [null %quad%] &then &set quad = [listfile * -directory] 25 | /* check for tile argument 26 | &if not [null %tile%] &then &set tile_arg = yes 27 | 28 | &do quad &list [unquote %quad%] 29 | &workspace %quad%; &type ...entering %quad% 30 | 31 | &do tile &list [listfile * -workspace] 32 | &call main 33 | &end 34 | 35 | &workspace .. 36 | &end 37 | 38 | &RETURN ...[upcase %aml$fullfile%] finished normally. 39 | 40 | /* ============================================================================ 41 | &ROUTINE MAIN 42 | &severity &error &ignore /* so it won't stop when it encounters an active session 43 | 44 | &if [exists %tile%\lock -file] &then &type ...deleting %tile%\lock 45 | &if [exists %tile%\lock -file] &then &sys del %tile%\lock 46 | &RETURN 47 | 48 | &routine bail 49 | &if not [variable str] &then &s str Bailing out of %aml$file%... 50 | &return; &return &warning %str% 51 | /*=========================================================================== 52 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/make_buffers.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* if there are commandline arguments, make them the TODO list 3 | &args quad tile:REST 4 | &ty ----------------------------------------------------------------------- 5 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 02-Aug-2k 6 | &ty ::Step 2:: (see scripts\__ReadMe.aml) 7 | &ty 8 | &ty - grab neatlines and create 2km and 100m buffers for each tile 9 | &ty 10 | &ty ----------------------------------------------------------------------- 11 | &if [null %quad%] &then &do 12 | &s pause [response ' to continue, something else to abort'] 13 | &if not [null %pause%] &then &return %aml$file% exited by user request. 14 | &end 15 | 16 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 17 | &workspace %.home% 18 | 19 | /* follow ...\\\ (...\115h\115h12\) pattern 20 | /* check for quad placeholder (allows "&r aml_prog . 105d11 105d12 105d13") 21 | &if %quad% = . &then &set quad = [listfile * -directory] 22 | /* check for quad commandline args 23 | &if [null %quad%] &then &set quad = [listfile * -directory] 24 | /* check for tile argument 25 | &if not [null %tile%] &then &set tile_arg = yes 26 | 27 | &do quad &list [unquote %quad%] 28 | &workspace %quad% ; &type ...entering %quad% 29 | /* check for TODO list on the command line, else TODO = existing workspaces 30 | &if [null %tile%] &then &set tile = [listfile * -workspace] 31 | 32 | &do tile &list [unquote %tile%] 33 | &workspace %tile% 34 | &call main 35 | &workspace .. 36 | &end 37 | 38 | /* if tile arg is autogenerated, null out else it won't be generated anew for next loop 39 | &if not [variable tile_arg] &then &set tile = 40 | 41 | &workspace .. 42 | &end 43 | 44 | &RETURN ...[upcase %aml$fullfile%] finished normally. 45 | 46 | 47 | /* ------------------------------------------------------------------------ 48 | &ROUTINE MAIN 49 | &if [exists buf_1k -cover] &then &return 50 | /*-------mark workspace busy---------------------- 51 | &if [exists lock -file] &then &return 52 | &set lockfile = [OPEN lock openstat -write] 53 | &if %openstat% = 0 &then &type ...workspace %tile% locked 54 | &else &return Error %openstat% opening lockfile 55 | /*------------------------------------------------ 56 | &describe %.library%\%quad%\%tile%\fneat 57 | &if %dsc$polygons% = 0 &then build %.library%\%quad%\%tile%\fneat poly 58 | 59 | &type -----{ Making 100m, 1km and 2km buffers for %tile% }----- 60 | &do bufcov &list buf_2k buf_1k buf_100m 61 | &if not [exists %bufcov% -cover] &then &do 62 | &if %bufcov% = buf_2k &then &set bsize = 2000 63 | &if %bufcov% = buf_1k &then &set bsize = 1000 64 | &if %bufcov% = buf_100m &then &set bsize = 100 65 | buffer %.library%\%quad%\%tile%\fneat buf%bsize% # # %bsize% # poly 66 | rename buf%bsize% %bufcov% 67 | &end 68 | &end 69 | 70 | /*-------mark workspace not busy----------------- 71 | &if [close %lockfile%] = 0 &then 72 | &type ...workspace %tile% unlocked 73 | &else &return Error closing lockfile 74 | &sys del lock 75 | /*----------------------------------------------- 76 | &RETURN 77 | /* ------------------------------------------------------------------------ 78 | &routine bail 79 | &if not [variable str] &then &s str Bailing out of %aml$file%... 80 | &return; &return &warning %str% 81 | /*=========================================================================== 82 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/make_shade.aml: -------------------------------------------------------------------------------- 1 | /*=========================================================================== 2 | &severity &error &routine bail 3 | /* if there are commandline arguments, make them the TODO list 4 | &args dem shaded quad tile:REST 5 | &ty -------------------------------------------------------------------------- 6 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 18-Sept-2k 7 | &ty ::Step 9:: (see scripts\__ReadMe.aml) 8 | &ty 9 | &ty - generate shaded relief grids from existing DEMs 10 | &ty 11 | &ty Autorun: &r %aml$file% {source_grid} {output_grid} {quad} {tile(s)} 12 | &ty -------------------------------------------------------------------------- 13 | &if [null %quad%] &then &do 14 | &s pause [response ' to continue, something else to abort'] 15 | &if not [null %pause%] &then &return %aml$file% exited by user request. 16 | &end 17 | 18 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 19 | &workspace %.home% 20 | 21 | /* put header variables and other semi-global code here 22 | &if [null %dem%] &then ~ 23 | &set dem = [response 'Enter name of source grid (dem)' dem] 24 | &if [null %shaded%] &then ~ 25 | &set shaded = [response 'Enter name of output grid (%dem%_hs)' %dem%_hs] 26 | 27 | /* follow ...\\\ (...\115h\115h12\) pattern 28 | /* check for quad placeholder (allows "&r aml_prog . 105d11 105d12 105d13") 29 | &if %quad% = . &then &set quad = [listfile * -directory] 30 | /* check for quad commandline args 31 | &if [null %quad%] &then &set quad = [listfile * -directory] 32 | /* check for tile argument 33 | &if not [null %tile%] &then &set tile_arg = yes 34 | 35 | 36 | &do quad &list [unquote %quad%] 37 | &workspace %quad%; &type ...entering %quad% 38 | /* check for TODO list on the command line, else TODO = existing workspaces 39 | &if [null %tile%] &then &set tile_list = [listfile * -workspace] 40 | &else &set tile_list = [unquote %tile%] 41 | 42 | &do tile &list [unquote %tile_list%] 43 | &call main 44 | &end 45 | 46 | /* if tile arg is autogenerated, null out else it won't be generated anew for next loop 47 | &if not [variable tile_arg] &then &set tile = 48 | 49 | &workspace %.home% 50 | &end 51 | 52 | &RETURN ...[upcase %aml$fullfile%] finished normally. 53 | 54 | /*============================================================================ 55 | &ROUTINE MAIN 56 | &if not [exists %tile%\%dem% -grid] &then &return 57 | &workspace %tile% 58 | /*-------mark workspace busy---------------------- 59 | &if [exists lock -file] &then &return 60 | &set lockfile = [OPEN lock openstat -write] 61 | &if %openstat% = 0 &then &type ...workspace %tile% locked 62 | &else &return Error %openstat% opening lockfile 63 | /*------------------------------------------------ 64 | 65 | /* uncomment to overwrite existing shaded relief images 66 | /*&if [exists %shaded% -grid] &then kill %shaded% all 67 | 68 | /* use flattened lake dem if it exists 69 | &if [exists %dem%_flak -grid] &then &do 70 | &set save-dem = %dem% ; &set dem = %dem%_flak ; &end 71 | 72 | &if not [exists %shaded% -grid] &then hillshade %dem% %shaded% 315 70 73 | 74 | &if [variable save-dem] &then &do 75 | &set dem = %save-dem% ; &delvar save-dem ; &end 76 | 77 | /*-------mark workspace not busy----------------- 78 | &if [close %lockfile%] = 0 &then 79 | &type ...workspace %tile% unlocked 80 | &else &return Error closing lockfile 81 | &sys del lock 82 | /*----------------------------------------------- 83 | &workspace .. 84 | &RETURN 85 | /*--------------------------------------------------------------------------- 86 | /* other routines go here 87 | 88 | &routine bail 89 | &if not [variable str] &then &s str Bailing out of %aml$file%... 90 | &return; &return &warning %str% 91 | /*=========================================================================== 92 | /* End Of Template 93 | /*=========================================================================== 94 | 95 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/make_tilestruct.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* if there are commandline arguments, make them the TODO list 3 | &args quad tiles:REST 4 | &ty ----------------------------------------------------------------------- 5 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 12-Dec-2k 6 | &ty ::Step 1:: (see scripts\__ReadMe.aml) 7 | &ty 8 | &ty - creates a directory framework in the '%.home%' directory based on 9 | &ty which tiles in the repository contain data: 10 | &ty 11 | &ty ...\\\ ...\115A\115a16\ 12 | &ty 13 | &ty - To only process specified tiles, use: 14 | &ty 15 | &ty "&run %aml$file% . {tile1} {tile2} {tile3} ..." 16 | &ty 17 | &ty ----------------------------------------------------------------------- 18 | &if %quad% <> . &then &do 19 | &s pause [response ' to continue, something else to abort'] 20 | &if not [null %pause%] &then &return %aml$file% exited by user request. 21 | &end 22 | 23 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 24 | &workspace %.home% 25 | 26 | /* put header variables and other semi-global code here 27 | &set testcov = fneat 28 | &set root = %.library% /* eg: z:\arcdata\50k\base 29 | 30 | &if not [null %tiles%] &then &call commandline 31 | &if [null %tiles%] &then &call MAIN 32 | 33 | &RETURN ...[upcase %aml$fullfile%] finished normally. 34 | 35 | /*============================================================================ 36 | &ROUTINE MAIN 37 | /*for each quad which exists in repository do... 38 | &do quad &list [listfile %root%\0* -directory] [listfile %root%\1* -directory] 39 | &type ...checking %quad% 40 | /* for each tile which exists in repository do ... 41 | &do tile &list [listfile %root%\%quad%\* -workspace] 42 | /*&type %tile% 43 | /* if neatline cover exists then... 44 | &if [exists %root%\%quad%\%tile%\%testcov% -cover] &then &do 45 | /* create development quad workspace 46 | &if not [exists %quad% -workspace] &then createworkspace %quad% 47 | /* create dev tile ws 48 | &if not [exists %quad%\%tile% -workspace] &then &do 49 | cw %quad%\%tile% 50 | &type created %quad%\%tile% 51 | &end 52 | /*end if-exists-neatline test 53 | &end 54 | /*end for-each-tile 55 | &end 56 | /*end for-each-quad 57 | &end 58 | &RETURN 59 | /*--------------------------------------------------------------------------- 60 | /* other routines go here 61 | 62 | &routine commandline 63 | /* for each tile do... 64 | &do tile &list [unquote %tiles%] 65 | /* the 1st four characters are the major nts name (quad) 66 | /* [substring {num_chars}] 67 | &set quad = [substr %tile% 1 4] 68 | /*&type ...checking %quad%\%tile% 69 | /* if neatline cover exists in repsoitory then... 70 | &if [exists %root%\%quad%\%tile%\%testcov% -cover] &then &do 71 | /* create development quad workspace 72 | &if not [exists %quad% -workspace] &then createworkspace %quad% 73 | /* create dev tile ws 74 | &if not [exists %quad%\%tile% -workspace] &then &do 75 | cw %quad%\%tile% 76 | &type created %quad%\%tile% 77 | &end 78 | /*end if-exists-neatline test 79 | &end 80 | /*end for-each-tile do 81 | &end 82 | &return ...[upcase %aml$fullfile%] finished commandline mode normally. 83 | 84 | &routine bail 85 | &if not [variable str] &then &s str Bailing out of %aml$file%... 86 | &return; &return &warning %str% 87 | /*=========================================================================== 88 | /* End Of MAKE_TILESTRUCT.aml 89 | /*=========================================================================== 90 | 91 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/mosaic_250k.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* if there are commandline arguments, make them the TODO list 3 | &args quad:REST 4 | &ty -------------------------------------------------------------------------- 5 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 06-Nov-2k 6 | &ty ::Step 11:: (see scripts\__ReadMe.aml) 7 | &ty 8 | &ty - mosaic NTS tiles into NTS Quads (50k => 250k) 9 | &ty - resample to 90m pixels 10 | &ty * make sure the tiles have been clipped to 100m buffer first! * 11 | &ty 12 | &ty Autorun: &r %aml$file% {quad(s)} 13 | &ty -------------------------------------------------------------------------- 14 | &if [null %quad%] &then &do 15 | &s pause [response ' to continue, something else to abort'] 16 | &if not [null %pause%] &then &return %aml$file% exited by user request. 17 | &end 18 | 19 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 20 | &workspace %.home% 21 | 22 | /* put header variables and other semi-global code here 23 | &set cellsize = 90 24 | 25 | /* make sure we are in GRID 26 | &if [locase[show program]] <> grid &then GRID 27 | 28 | /* check for quad commandline args 29 | &if [null %quad%] &then &set quad = [listfile * -directory] 30 | 31 | &do quad &list [unquote %quad%] 32 | &workspace %quad%; &type ...entering %quad% 33 | 34 | &set tile_list = [listfile * -workspace] 35 | &CALL MAIN 36 | 37 | &workspace .. 38 | &end 39 | 40 | &if [locase[show program]] = grid &then QUIT /* exit GRID 41 | 42 | &RETURN ...[upcase %aml$fullfile%] finished normally. 43 | 44 | /*============================================================================ 45 | &ROUTINE MAIN 46 | /*-------mark workspace busy---------------------- 47 | &if [exists lock -file] &then &return 48 | &set lockfile = [OPEN lock openstat -write] 49 | &if %openstat% = 0 &then &type ...workspace %quad% locked 50 | &else &return Error %openstat% opening lockfile 51 | /*------------------------------------------------ 52 | /* dems 53 | &s tiles = 54 | &if not [exists dem_30m -grid] &then &do 55 | /* if flat lake dem exists, use that, else use the regular dem 56 | &do grd &list [unquote %tile_list%] 57 | &if not [exists %grd%\dem_flak -grid] &then 58 | &s tiles = %grd%\dem,%tiles% 59 | &else &s tiles = %grd%\dem_flak,%tiles% 60 | &end 61 | &s tiles = [trim %tiles% -right ,] /* strip trailing comma 62 | 63 | &type ...mosaicking "%tiles%" into [upcase "%quad%\dem_30m"] 64 | dem_30m = mosaic(%tiles%) 65 | &end 66 | 67 | &if not [exists dem_%cellsize%m -grid] &then &do 68 | &type ...resampling to %cellsize% meter pixels 69 | dem_%cellsize%m = resample(dem_30m,%cellsize%,bilinear) 70 | &end 71 | 72 | /* hillshades 73 | &if not [exists shade_30m -grid] &then &do 74 | &type ...building 30 meter hillshade 75 | shade_%cellsize%m = hillshade(dem_%cellsize%m,315,70) 76 | &end 77 | 78 | &if not [exists shade_%cellsize%m -grid] &then &do 79 | &type ...building %cellsize% meter hillshade 80 | shade_%cellsize%m = hillshade(dem_%cellsize%m,315,70) 81 | &end 82 | 83 | /*-------mark workspace not busy----------------- 84 | &if [close %lockfile%] = 0 &then 85 | &type ...workspace %quad% unlocked 86 | &else &return Error closing lockfile 87 | &sys del lock 88 | /*----------------------------------------------- 89 | &RETURN 90 | /*--------------------------------------------------------------------------- 91 | /* other routines go here 92 | 93 | &routine bail 94 | &if not [variable str] &then &s str Bailing out of %aml$file%... 95 | &return; &return &warning %str% 96 | /*=========================================================================== 97 | /* End Of MOASIAC_250K.aml 98 | /*=========================================================================== 99 | 100 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/nuke.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /*---------------------------------------------------------------------------- 3 | &args featr cover tiles:REST 4 | 5 | &if [null %tiles%] &then &return &error /& ~ 6 | ...Usage: &r %aml$file% {cover|grid|file} {cover_name} {tile1} {tile2} {tile3} ... /& 7 | 8 | &type /& 9 | &set warning = ...Kill [upcase %cover%] from %tiles%? (N,y) 10 | &if not [getchar [quote %warning%] n] = y ~ 11 | &then &return ...Exiting by user request. 12 | 13 | 14 | &do tile &list [unquote %tiles%] 15 | &s quad = [substr %tile% 1 4] 16 | &if [exists %quad%\%tile%\%cover% -%featr%] &then 17 | &do 18 | &if %featr% = file &then &do 19 | &sys del %quad%\%tile%\%cover% 20 | &type ...nuked %quad%\%tile%\%cover% ; &end 21 | &else kill %quad%\%tile%\%cover% all 22 | &end 23 | &end 24 | 25 | 26 | &return /&...[upcase %aml$file%] finished normally. 27 | 28 | 29 | &routine bail 30 | &if not [variable str] &then &s str Bailing out of %aml$file%... 31 | &return; &return &warning %str% 32 | /*=========================================================================== 33 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/rinse.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* if there are commandline arguments, make them the TODO list 3 | &args quad tile:REST 4 | &ty -------------------------------------------------------------------------- 5 | &ty * [upcase %aml$file%] * Project: Updated LIMS 50k DEM * mhw * 18-Sept-2k 6 | &ty * (Rinse, Lather, Repeat) * 7 | &ty ::Step #:: (see scripts\__ReadMe.aml) 8 | &ty 9 | &ty - kill dems and all associated marker files in prep for regenerating 10 | &ty 11 | &ty Autorun: &r %aml$file% {quad} {tile(s)} 12 | &ty -------------------------------------------------------------------------- 13 | &ty 14 | &ty Current commandline: &r %aml$file% %quad% %tile% 15 | &ty 16 | &if not [variable .library] &then &return &error Project Environment is not setup. Look for ./scripts/setenv.aml 17 | 18 | &if [null %quad%] &then &do 19 | &s pause [response ' to continue, something else to abort'] 20 | &if not [null %pause%] &then &return %aml$file% exited by user request. 21 | &end 22 | 23 | &workspace %.home% 24 | 25 | /* put header variables and other semi-global code here 26 | &set dem = dem 27 | &set shade = dem_hs 28 | 29 | /* follow ...\\\ (...\115h\115h12\) pattern 30 | /* check for quad placeholder (allows "&r aml_prog . 105d11 105d12 105d13") 31 | &if %quad% = . &then &set quad = [listfile * -directory] 32 | /* check for quad commandline args 33 | &if [null %quad%] &then &set quad = [listfile * -directory] 34 | /* check for tile argument 35 | &if not [null %tile%] &then &set tile_arg = yes 36 | 37 | &do quad &list [unquote %quad%] 38 | &workspace %quad%; &type ...entering %quad% 39 | /* check for TODO list on the command line, else TODO = existing workspaces 40 | &if [null %tile%] &then &set tile = [listfile * -workspace] 41 | 42 | &do tile &list [unquote %tile%] 43 | &do fer_grid &list %dem%_90m %dem%_30m shade_90m shade_30m 44 | &if [exists %fer_grid% -grid] &then kill %fer_grid% all 45 | &end 46 | &call main 47 | &end 48 | 49 | /* if tile arg is autogenerated, null out else it won't be generated anew for next loop 50 | &if not [variable tile_arg] &then &set tile = 51 | 52 | &workspace .. 53 | &end 54 | 55 | &RETURN ...[upcase %aml$fullfile%] finished normally. 56 | 57 | /*============================================================================ 58 | &ROUTINE MAIN 59 | /*-------mark workspace busy---------------------- 60 | &if [exists %tile%\lock -file] &then &return 61 | &set lockfile = [OPEN %tile%\lock openstat -write] 62 | &if %openstat% = 0 &then &type ...workspace %tile% locked 63 | &else &return Error %openstat% opening lockfile 64 | /*------------------------------------------------ 65 | &workspace %tile% 66 | 67 | 68 | &do fer_cover &list %dem%_sink %dem%_drain 69 | &if [exists %fer_cover% -cover] &then kill %fer_cover% all 70 | &end 71 | 72 | &do fer_grid &list %dem%_flak %shade% %dem% 73 | &if [exists %fer_grid% -grid] &then kill %fer_grid% all 74 | &end 75 | 76 | &do fer_file &list %dem%_is_100m %shade%_is_100m flake.done %dem%_diag dem_flak_is_100m 77 | &if [exists %fer_file% -file] &then &sys del %fer_file% 78 | &end 79 | 80 | 81 | &workspace .. 82 | /*-------mark workspace not busy----------------- 83 | &if [close %lockfile%] = 0 &then 84 | &type ...workspace %tile% unlocked 85 | &else &return Error closing lockfile 86 | &if [delete %tile%\lock -file] <> 0 &then 87 | &return &error ...Error removing %tile%\lock 88 | /*----------------------------------------------- 89 | &RETURN 90 | /*--------------------------------------------------------------------------- 91 | /* other routines go here 92 | 93 | &routine bail 94 | &if not [variable str] &then &s str Bailing out of %aml$file%... 95 | &return; &return &warning %str% 96 | /*=========================================================================== 97 | /* End Of Rinse, Lather, Repeat 98 | /*=========================================================================== 99 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/run_anudem.aml: -------------------------------------------------------------------------------- 1 | &severity &error &routine bail 2 | /* ------------------------------------------------------------------------ 3 | &args out-dem cmdfile logfile overwrite tile 4 | /* ------------------------------------------------------------------------ 5 | &if [null %cmdfile%] | [null %logfile%] &then 6 | &return ...USAGE: &r %aml$file% {out-dem} {cmdfile} {logfile} {overwrite} 7 | 8 | &set anudem = x:\anudem\bin\anudemc.exe 9 | 10 | &if %overwrite% = overwrite &then &do 11 | &sys del %out-dem% >nul 12 | &sys del %tile%.hdr >nul 13 | &sys attrib +r %tile%-dem.cmd >nul 14 | &sys del %tile%-dem.* >nul 15 | &sys attrib -r %tile%-dem.cmd >nul 16 | &end 17 | 18 | &if [exists %out-dem% -file] &then &return ...%out-dem% already exists. 19 | 20 | &type ...building ANUDEM dem 21 | &do arced &list [listfile *.gz -file] 22 | &sys gunzip %arced% 23 | &end 24 | &if not [null %logfile%] &then ~ 25 | &sys %anudem% <%cmdfile% 1>%logfile% 26 | &else &sys %anudem% <%cmdfile% 27 | &sys cat %logfile% >>%.home%\global-%logfile% 28 | &sys tail -23 %logfile% 29 | &sys gzip *.gen 30 | &return 31 | /* ------------------------------------------------------------------------ 32 | &routine bail 33 | &if not [variable str] &then &s str Bailing out of %aml$file%... 34 | &return; &return &warning %str% 35 | /*=========================================================================== 36 | -------------------------------------------------------------------------------- /gis/yt30m_dem/50kdem/sed.txt: -------------------------------------------------------------------------------- 1 | &sys sed 's/$/\\fctr/' overlap.path.bare > append.txt ; &sys echo end >> append.txt ; &sys arc append fctr link < append.txt ; clip fctr buf_2k fctr-clip link ; kill fctr all ; rename fctr-clip fctr 2 | -------------------------------------------------------------------------------- /gis/yt30m_dem/depends/UNIX2DOS.EXE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/yt30m_dem/depends/UNIX2DOS.EXE -------------------------------------------------------------------------------- /gis/yt30m_dem/depends/cygwin1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/yt30m_dem/depends/cygwin1.dll -------------------------------------------------------------------------------- /gis/yt30m_dem/depends/gunzip.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/yt30m_dem/depends/gunzip.exe -------------------------------------------------------------------------------- /gis/yt30m_dem/depends/gzip.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/yt30m_dem/depends/gzip.exe -------------------------------------------------------------------------------- /gis/yt30m_dem/depends/sed.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/yt30m_dem/depends/sed.exe -------------------------------------------------------------------------------- /gis/yt30m_dem/readme.txt: -------------------------------------------------------------------------------- 1 | 13:13 2001-05-11 * Matt.wilkie@gov.yk.ca * Yukon Renewable Resources 2 | 3 | Yukon 30 meter Digital Elevation Model 4 | Support Scripts 5 | 6 | You can have all the AMLs I wrote to make this happen but be forewarned, 7 | I am not a programmer and have no training. Before starting this project 8 | I had not written any AML scripts. So they are messy, not well thought 9 | out, of greatly varying quality and stability, and unlikely to be very 10 | portable. If they blow up your computer or nuke your data, it's not my 11 | fault. All the same if they will help you, you are welcome to them. 12 | 13 | Read .\resources\Overview.txt for a general idea of how I proceeded, 14 | then .\50kdem\_ReadMe.aml for a more detailed, and out of date, description. 15 | Finally, if your insurance is paid and all your data is backed up, 16 | .\50kdem\whole_hog.aml is the master do-everything-at-once wrapper script. 17 | 18 | 19 | This package and it's contents are (c) 1999-2001 by Yukon Renewable 20 | Resources and published under the GNU Public License, v2 or later at 21 | your discretion. You may do whatever you wish with it inclcuding 22 | modification and redistribution provided you do not attempt to restrict 23 | others from doing the same. See the file LICENSE.TXT for the full text of 24 | the GPL. 25 | 26 | Why go through the bother of copyrighting and licensing this stuff 27 | rather than just placing it in the public domain? 28 | 29 | Because in the course of the 30m DEM project I ended up corresponding 30 | with and learning from many people through the newsgroups and mailing 31 | lists. I could not have done it with out them. One of those I corresponded 32 | with was an ArcInfo oldtimer from wayback who used to write and publish 33 | all his scripts for anybody to use. He stopped doing that when he 34 | discovered some of his scripts, almost completely unaltered, in the 35 | next release of ArcInfo without even a mention of the original author 36 | and copyrighted by ESRI. Because his scripts were public domain ESRI 37 | were completely within their legal rights to do that. Because of this I 38 | was deprived of the benefit of this oldtimer's experience. This will 39 | not happen with my works. 40 | 41 | -matt 42 | 43 | 44 | -------------------------------------------------------------------------------- /gis/yt30m_dem/resources/FW geomorphometry DEM creation from digitized map (Summary of Replies).txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/gis/yt30m_dem/resources/FW geomorphometry DEM creation from digitized map (Summary of Replies).txt -------------------------------------------------------------------------------- /gis/yt30m_dem/setenv_50kdem.aml: -------------------------------------------------------------------------------- 1 | &ty 2 | &ty * [upcase %aml$file%] * mhwilkie * 12-December-2k 3 | &ty 4 | &ty Setting Environment for generating 50kDEMS 5 | &ty 6 | 7 | &set .home = W:\lims50kdem 8 | &set .library = z:\arcdata\50k\base 9 | &set .index = %.library%\database\index 10 | &amlpath z:\arcutils\aml\50kdem,[show &amlpath] 11 | 12 | &listglobal 13 | &ty AML Search Path: [show &amlpath] 14 | -------------------------------------------------------------------------------- /other/OpenWithNotepad.reg: -------------------------------------------------------------------------------- 1 | Windows Registry Editor Version 5.00 2 | 3 | [HKEY_CLASSES_ROOT\*\shell\Open with Notepad] 4 | 5 | [HKEY_CLASSES_ROOT\*\shell\Open with Notepad\command] 6 | @="notepad.exe %1" 7 | 8 | -------------------------------------------------------------------------------- /other/RelaunchElevated.cmd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/other/RelaunchElevated.cmd -------------------------------------------------------------------------------- /other/RelaunchElevated_EmbeddedScripts.cmd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/other/RelaunchElevated_EmbeddedScripts.cmd -------------------------------------------------------------------------------- /other/RemoveOpenWithNotepad.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/other/RemoveOpenWithNotepad.reg -------------------------------------------------------------------------------- /other/add2shims.bat: -------------------------------------------------------------------------------- 1 | @Echo off 2 | :: Install a wrapper around program, so we don't have add whole 3 | :: new folder to PATH. 4 | :: Using a batch file because I can never remember exeproxy's 5 | :: parameters. 6 | setlocal 7 | set src=%~dpnx1 8 | set shim=%~nx1 9 | 10 | if not exist "%src%" goto :Usage 11 | 12 | exeproxy.exe exeproxy-copy "C:\Shims\%shim%" "%src%" 13 | dir "c:\Shims\%shim%" | findstr "%shim%" 14 | 15 | endlocal 16 | goto :eof 17 | 18 | :Usage 19 | echo. 20 | echo. %~n0 [path to exe to mirror in Shim folder] 21 | echo. 22 | goto :eof 23 | -------------------------------------------------------------------------------- /other/args.py: -------------------------------------------------------------------------------- 1 | """yet another argparse learning snippet""" 2 | import argparse 3 | 4 | # create the top level parser 5 | parser = argparse.ArgumentParser(description='Command line package manager for Osgeo4w') 6 | ##parser.add_argument('action', type=str, help='install, update, setup', 7 | ## choices='install update setup'.split()) 8 | subparsers = parser.add_subparsers() 9 | 10 | ##parser.parse_args('install'.split(' ')) 11 | ##parser.add_argument('package', type=str, nargs='+', help='list of packages') 12 | 13 | # global options 14 | parser.add_argument('--ini') 15 | parser.add_argument('--mirror') 16 | parser.add_argument('--download-only') 17 | 18 | # install 19 | parser_ins = subparsers.add_parser('install', help='install new packages') 20 | parser_ins.add_argument('package', nargs='+', help='list of packages') 21 | 22 | # remove 23 | parser_rem = subparsers.add_parser('remove', help='remove installed packages') 24 | parser_rem.add_argument('package', nargs='+', help='list of packages') 25 | 26 | # update 27 | parser_rem = subparsers.add_parser('update', 28 | help='get latest available package listing from mirror') 29 | parser_rem.add_argument('None') 30 | 31 | # setup 32 | parser_rem = subparsers.add_parser('setup', 33 | help='initialize new Osgeo4W environment') 34 | parser_rem.add_argument('path', help='path to use for Osgeo4W root') 35 | 36 | 37 | 38 | args = parser.parse_args() 39 | ##print args.accumulate(args.action) 40 | -------------------------------------------------------------------------------- /other/assoc-py.cmd: -------------------------------------------------------------------------------- 1 | assoc .py=Python.File 2 | -------------------------------------------------------------------------------- /other/bats/chrome-me-um.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: Chrome-me-um - start Chrome browser with speficified user profile 3 | :: Matt Wilkie, 2008-sept-26. 4 | :: 2013-Jan-06 + add FindChromeExe 5 | :: this script is public domain 6 | if [%1]==[] goto :Usage 7 | 8 | setlocal 9 | set _user=%1 10 | set _root=%homedrive%%homepath%\Local Settings\Application Data\Google\Chrome 11 | set _profile="%_root%\User Data\%_user%" 12 | if not exist %_profile% set _opt=-first-run 13 | call :FindChromeExe 14 | 15 | if defined _chrome ( 16 | start /b "%0" %_chrome% --user-data-dir=%_profile% %_opt%) 17 | 18 | goto :eof 19 | rem ---------- End ---------- 20 | 21 | :FindChromeExe 22 | if exist "%_root%\Application\chrome.exe" ( 23 | set _chrome="%_root%\Application\chrome.exe") 24 | 25 | if exist "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" ( 26 | set _chrome="%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe") 27 | 28 | if exist "%ProgramFiles%Google\Chrome\Application\chrome.exe" ( 29 | set _chrome="%ProgramFiles%Google\Chrome\Application\chrome.exe") 30 | 31 | if not defined _chrome echo. *** Error, couldn't locate chrome.exe 32 | goto :eof 33 | 34 | :Usage 35 | echo. 36 | echo. Start Google Chrome browser with a profile. Example: 37 | echo. 38 | echo. %~n0 Noah_Body 39 | echo. 40 | goto :eof -------------------------------------------------------------------------------- /other/bats/dupe-search.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: dupe-search - Search PATH for duplicates of executables in specified directory 3 | :: 4 | :: (c) 2008 Yukon Department of Environment 5 | :: License: MIT - http://www.opensource.org/licenses/mit-license.php 6 | :: 7 | :: Initial version Matt.wilkie@gov.yk.ca, (mhw) 2008-Oct-10 8 | :: http://code.google.com/p/maphew/source/browse/trunk/other/bats/dupe-search.bat 9 | :: 10 | :: 2008-Oct-14 mhw - report location of dupe 11 | :: 12 | if [%1]==[] goto Usage 13 | set srcDir=%1 14 | if not exist %srcDir% goto :NotFound 15 | 16 | set dupes=%temp%\dupes.txt 17 | if exist %dupes% del %dupes% 18 | 19 | call :EditPath 20 | call :Search 21 | goto :End 22 | :: --------------------------------------------------------------------------- 23 | 24 | :EditPath 25 | :: Make sure our search directory is not in PATH 26 | :: Adapted from http://www.ss64.com/nt/syntax-substring.html 27 | :: 28 | :: Note - the User path can be edited, but the System path remains 29 | :: read-only for most users. This is pretty quirky so change with care. For 30 | :: instance a leading semi-colon in PATH means the script will *always* 31 | :: report dupes, even if there are none. 32 | pushd %srcDir% 33 | :: Strip current dir 34 | call set PATH=%%PATH:%cd%=%% 35 | :: Replace double path delimiters with single 36 | call set PATH=%%PATH:;;=;%% 37 | :: strip leading delimeter 38 | set _1=%PATH:~0,1% 39 | if "%_1%"==";" call set PATH=%%PATH:~1%% 40 | popd 41 | goto :eof 42 | 43 | :Search 44 | pushd %srcDir% 45 | echo. 46 | echo --- Searching PATH for duplicates of %cd%\* 47 | for %%f in (*) do if not "%%~dp$PATH:f" =="" call :FoundDupe %%f 48 | if exist %dupes% (call :Report) else ( 49 | echo. 50 | echo. No dupes found :^) 51 | ) 52 | popd 53 | goto :eof 54 | 55 | :FoundDupe 56 | :: Parse PATH, adapted from http://www.ss64.com/nt/path.html 57 | for %%p in ("%path:;=" "%") do ( 58 | if exist %%p\%1 dir /s/b %%p\%1 >> %dupes% 59 | ) 60 | goto :eof 61 | 62 | :Report 63 | echo. 64 | echo. Duplicates: 65 | echo. 66 | type %dupes% 67 | echo. 68 | echo. List saved in %dupes% 69 | goto :eof 70 | 71 | :Usage 72 | echo. 73 | echo. Usage: %~nx0 [dir to use search template] 74 | echo. 75 | echo. %~n0 c:\osgeo4w\bin 76 | echo. 77 | goto :eof 78 | 79 | :NotFound 80 | echo. 81 | echo. Error, "%srcDir%" does not exist. 82 | echo. 83 | goto :eof 84 | 85 | :End 86 | echo. 87 | echo --- %~n0 finished. 88 | -------------------------------------------------------------------------------- /other/bats/enable-remote-desktop.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | @setlocal 3 | call :Main %1 %2 %3 %4 %5 4 | goto :eof 5 | 6 | 7 | :Main 8 | set .h=\\%1 9 | psexec %.h% %2 %3 %4 %5 reg add "hklm\system\currentcontrolset\control\terminal server" ^ 10 | /f /v fDenyTSConnections /t REG_DWORD /d 0 11 | psexec %.h% %2 %3 %4 %5 netsh advfirewall firewall set rule group="remote admin" new enable=Yes 12 | psexec %.h% %2 %3 %4 %5 netsh advfirewall firewall set rule group="remote desktop" new enable=Yes 13 | endlocal 14 | goto :EOF 15 | 16 | 17 | REM Remotely enable Remote Desktop (RDP) 18 | REM https://yukonnect.gov.yk.ca/collab/env-c1/GIS/_layouts/OneNote.aspx?id=%2Fcollab%2Fenv-c1%2FGIS%2FSiteAssets%2FENV%20GIS%20Unit%20notebook&wd=target%28Tips%20and%20Tricks.one%7CC3C1DDDC-F07F-4B44-AB2E-81D0EDB0A9EF%2FRemotely%20enable%20Remote%20Desktop%20%28RDP%5C%29%7C3673B622-8C9E-4B07-9294-06261CD27DC3%2F%29 19 | -------------------------------------------------------------------------------- /other/bats/make-bat-for-py.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | for %%g in (*.py) do ( 3 | @echo @python "%%~dpnxg" %%* 4 | if not exist %%~ng.bat echo @python "%%~dpnxg" %%* > %%~ng.bat 5 | ) 6 | -------------------------------------------------------------------------------- /other/bats/paint.bat: -------------------------------------------------------------------------------- 1 | @rem http://superuser.com/questions/342024/set-different-image-editor-as-destination 2 | @start /b "Paint" "c:\Program Files\Paint.NET\PaintDotNet.exe" %2 3 | -------------------------------------------------------------------------------- /other/bats/search-path.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM @+leo-ver=5-thin 3 | REM @+node:maphew.20101020152902.3710: * @file search-path.bat 4 | REM @@first 5 | REM @@language batch 6 | :: 7 | :: Search PATH for specified filename(s) 8 | :: 9 | REM @+<> 10 | REM @+node:maphew.20101020152902.3714: ** <> 11 | :: 12 | :: adapted from http://ss64.com/nt/path.html 13 | :: this script is public domain 14 | :: 15 | :: 2010-Oct-21, Matt Wilkie 16 | :: 17 | REM @-<> 18 | 19 | setlocal 20 | set _home=%CD% 21 | set _targets=%* 22 | 23 | echo. 24 | echo -- Searching PATH for "%_targets%" -- 25 | echo. 26 | 27 | :Main 28 | for %%g in ("%path:;=" "%") do ( 29 | if not exist %%g (call :invalid_path %%g) else ( 30 | pushd %%g 31 | call :lookfor %_targets% 32 | popd 33 | ) 34 | ) 35 | 36 | REM One final check in the current directory before we finish 37 | call :lookfor %_targets% 38 | 39 | goto :End 40 | 41 | REM @+others 42 | REM @+node:maphew.20101020152902.3711: ** :invalid_path 43 | :invalid_path 44 | set _msgs=%_msgs%; ** This directory is in PATH but does not exist: %1 45 | goto :eof 46 | 47 | REM @+node:maphew.20101020152902.3713: ** :lookfor 48 | :lookfor 49 | for %%h in (%*) do ( 50 | if exist "%%h" ( 51 | set /a _count=%_count% + 1 52 | echo. 53 | rem Report full path, size, and time stamp 54 | echo %%~dpnxh ^| %%~zh ^| %%~th 55 | ) 56 | ) 57 | goto :eof 58 | 59 | REM @+node:maphew.20101020152902.3712: ** :End 60 | :End 61 | if defined _msgs ( 62 | echo. 63 | echo %_msgs% 64 | ) 65 | 66 | if defined _count ( 67 | echo. 68 | echo. %_count% occurences found. 69 | echo. 70 | ) else ( 71 | echo. 72 | echo. No occurences found. 73 | ) 74 | 75 | endlocal 76 | 77 | REM @-others 78 | REM @-leo 79 | -------------------------------------------------------------------------------- /other/cmdline.bat: -------------------------------------------------------------------------------- 1 | @python %~dp0\cmdline.py %* -------------------------------------------------------------------------------- /other/cmdline.py: -------------------------------------------------------------------------------- 1 | ''' exploring argparse for handling commandline parameters ''' 2 | # http://www.doughellmann.com/PyMOTW/argparse/ 3 | # http://stackoverflow.com/questions/9642692/argparse-help-without-duplicate-allcaps 4 | # http://stackoverflow.com/questions/5462873/control-formatting-of-the-argparse-help-argument-list 5 | # http://stackoverflow.com/questions/3853722/python-argparse-how-to-insert-newline-the-help-text 6 | # http://stackoverflow.com/questions/4042452/display-help-message-with-python-argparse-when-script-is-called-without-any-argu 7 | # http://stackoverflow.com/questions/9653250/argparse-usage-reporting-for-individual-choices-of-a-positional-argument 8 | 9 | import sys,argparse 10 | from argparse import RawTextHelpFormatter 11 | 12 | def subs(): 13 | p = argparse.ArgumentParser() 14 | subp = p.add_subparsers(help='commands') 15 | 16 | p_install = subp.add_parser('install', help="download and install packages, including dependencies") 17 | p_install.add_argument('install', help="install packages") 18 | 19 | p_update = subp.add_parser('update', help="fetch current setup.ini") 20 | p_update.add_argument('update', help="fetch current setup.ini from mirror") 21 | 22 | p_remove = subp.add_parser('remove', help="uninstall packages") 23 | p_remove.add_argument('remove', help="uninstall named packages (note: doesn't process dependencies)") 24 | 25 | p_setup = subp.add_parser('setup', help="create skeleton folder structure & install database") 26 | p_setup.add_argument('setup', help="create skeleton folder structure & install database") 27 | 28 | print '\n', p.parse_args() 29 | 30 | def args(): 31 | ''' stub for developing Apt command line argument parser ''' 32 | ''' apt [update, install, remove, setup] [list of packages] ''' 33 | p = argparse.ArgumentParser( 34 | description='Apt - a commandline package installer for Osgeo4w', 35 | usage="%(prog)s {options} [command] [package(s)]", 36 | formatter_class=argparse.RawTextHelpFormatter 37 | ## formatter_class=lambda prog: 38 | ## argparse.HelpFormatter(prog,max_help_position=30) 39 | ) 40 | 41 | actions = "install update remove setup".split() 42 | p.add_argument('action', choices=actions, 43 | help=""" 44 | install - named packages 45 | remove - named packages 46 | update - download latest setup.ini file 47 | setup - create skeleton file structure 48 | """) 49 | 50 | p.add_argument('package', action="append", nargs="*", 51 | help="list of packages to operate on") 52 | p.add_argument('-i', '--ini', 53 | help="full path or url to alternate setup.ini") 54 | p.add_argument('-d', '--download', action="store_true", default=False, 55 | help="download only, don't install") 56 | p.add_argument('-m', '--mirror', metavar="MIRROR", 57 | default="http://download.osgeo.org/osgeo4w", 58 | help="url of package mirror to download from") 59 | p.add_argument('-s', '--start-menu', metavar="NAME", 60 | default="OSGeo4W", 61 | help="StartMenu folder name to use") 62 | p.add_argument('-r', '--root', 63 | default="C:/OSGeo4W", 64 | help="use this as root directory", metavar="PATH") 65 | p.add_argument('-x', '--ignore-deps', action="store_true", 66 | default=False, 67 | help="ignore dependencies") 68 | p.add_argument('-v','--version', action='version', version='%(prog)s 0.1') 69 | print '\n', p.parse_args() 70 | 71 | if __name__ == '__main__': 72 | ## args() 73 | subs() 74 | 75 | -------------------------------------------------------------------------------- /other/create-leobat.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: A batch file which generates other batch files to run the Leo Editor, 3 | :: adapted for the local machine. Optionally, it will also set the Windows 4 | :: filetype and association so .leo files can be opened from Explorer. 5 | :: 6 | :: It needs to live in the same folder as "launchLeo.py" 7 | :: 8 | :: Open Source X/MIT License 9 | :: initial version * 2012-Dec-13 * matt wilkie 10 | 11 | if "%1"=="" goto :Usage 12 | 13 | call :pyCheck %1 14 | call :main %1 15 | if "%2"=="register" call :register %1 16 | goto :eof 17 | 18 | :main 19 | :: %1 is the path to folder containing python .exe's 20 | set pyexe=%~dp1\python.exe 21 | set pywexe=%~dp1\pythonw.exe 22 | echo. 23 | echo. Generating... 24 | echo. 25 | echo. Leo.bat - run leo in Windows mode 26 | echo. Leoc.bat - run leo and keep console window open 27 | echo. 28 | echo. These can be placed anywhere in PATH. 29 | echo. 30 | echo @"%pyexe%" "%~dp0\launchLeo.py" %%* > leoc.bat 31 | echo @start /b "Leo" "%pywexe%" "%~dp0\launchLeo.py" %%* > leo.bat 32 | goto :eof 33 | 34 | :register 35 | :: perms check courtesy of http://stackoverflow.com/questions/4051883 36 | :: batch-script-how-to-check-for-admin-rights 37 | net session >nul 2>&1 38 | if %errorlevel% == 0 ( 39 | echo. 40 | echo. Setting .leo filetype and registering association with Windows 41 | echo. 42 | assoc .leo=Leo.File 43 | ftype Leo.File=%pywexe% "%~dp0\launchLeo.py" %%* 44 | ) else ( 45 | echo. Error: Can't set filetype and register association. 46 | echo. Please run from elevated shell to do that. 47 | echo. 48 | ) 49 | goto :eof 50 | 51 | :pyCheck 52 | if not exist "%1" goto :Usage 53 | goto :eof 54 | 55 | :usage 56 | echo. 57 | echo. -=[%~nx0]=- 58 | echo. 59 | echo. Create batch files to launch Leo Editor that can be 60 | echo. placed and run from anywhere on this machine. 61 | echo. 62 | echo. and optionally register filetype with windows 63 | echo. 64 | echo. Usage: 65 | echo. %~n0 "c:\path\to\python.exe" 66 | echo. %~n0 "c:\path\to\python.exe" register 67 | echo. 68 | goto :eof 69 | -------------------------------------------------------------------------------- /other/dezoomify.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # Dezoomify. See README.markdown. 3 | # By Henrik Nyh 2009-02-06 under the MIT License. 4 | 5 | require 'open-uri' 6 | require 'rubygems' 7 | require 'nokogiri' 8 | 9 | 10 | ARGV.each_with_index do |page_url, page_url_index| 11 | puts "#{page_url_index}. Visiting #{page_url}" 12 | 13 | page = Nokogiri::HTML(open(page_url)) 14 | #mhw: paths = page.search('param[name="FlashVars"]').map {|var| var[:value][/zoomifyImagePath=([^"'&]+)/, 1] } 15 | # note - openzoom uses lower case 'flashvars' and 'source=' instead of 'zoomifyImagePath=' 16 | paths ="Sheep-Goat-Panorama_img/ImageProperties.xml" 17 | 18 | paths.each_with_index do |path, path_index| 19 | #mhw: full_path = URI.join(page_url, path+'/') 20 | full_path = "/mnt/hgfs/X/Share/Sheep-Goat-Panorama_img/" 21 | puts " #{page_url_index}.#{path_index} Found image path #{full_path}" 22 | 23 | 24 | # 25 | #mhw: xml_url = URI.join(full_path.to_s, 'ImageProperties.xml') 26 | xml_url = '/mnt/hgfs/X/Share/Sheep-Goat-Panorama_img/ImageProperties.xml' 27 | doc = Nokogiri::XML(open(xml_url)) 28 | props = doc.at('IMAGE_PROPERTIES') 29 | 30 | width = props[:WIDTH].to_i 31 | height = props[:HEIGHT].to_i 32 | tilesize = props[:TILESIZE].to_f 33 | 34 | tiles_wide = (width/tilesize).ceil 35 | tiles_high = (height/tilesize).ceil 36 | 37 | # Determine max zoom level. 38 | # Also determine tile_counts per zoom level, used to determine tile group. 39 | # With thanks to http://trac.openlayers.org/attachment/ticket/1285/zoomify.patch. 40 | zoom = 0 41 | w = width 42 | h = height 43 | tile_counts = [] 44 | while w > tilesize || h > tilesize 45 | zoom += 1 46 | 47 | t_wide = (w / tilesize).ceil 48 | t_high = (h / tilesize).ceil 49 | tile_counts.unshift t_wide*t_high 50 | 51 | w = (w / 2.0).floor 52 | h = (h / 2.0).floor 53 | end 54 | tile_counts.unshift 1 # Zoom level 0 has a single tile. 55 | tile_count_before_level = tile_counts[0..-2].inject(0) {|sum, num| sum + num } 56 | 57 | files_by_row = [] 58 | tiles_high.times do |y| 59 | row = [] 60 | tiles_wide.times do |x| 61 | filename = '%s-%s-%s.jpg' % [zoom, x, y] 62 | local_filepath = "/tmp/zoomify-#{filename}" 63 | row << local_filepath 64 | 65 | tile_group = ((x + y * tiles_wide + tile_count_before_level) / tilesize).floor 66 | #mhw: tile_url = URI.join(full_path.to_s, "TileGroup#{tile_group}/#{filename}") 67 | tile_url = full_path.to_s, "TileGroup#{tile_group}/#{filename}" 68 | #mhw: url = URI.join(tile_url.to_s, filename) 69 | url = tile_url.to_s 70 | puts " Getting #{url}..." 71 | #mhw: 72 | url = File.open(url, 'rb') 73 | File.open(local_filepath, 'wb') {|f| f.print url.read } 74 | end 75 | files_by_row << row 76 | end 77 | 78 | 79 | # `montage` is ImageMagick. 80 | # We first stitch together the tiles of each row, then stitch all rows. 81 | # Stitching the full image all at once can get extremely inefficient for large images. 82 | 83 | puts " Stitching #{tiles_wide} x #{tiles_high} = #{tiles_wide*tiles_high} tiles..." 84 | 85 | row_files = [] 86 | files_by_row.each_with_index do |row, index| 87 | filename = "/tmp/zoomify-row-#{index}.jpg" 88 | `montage #{row.join(' ')} -geometry +0+0 -tile #{tiles_wide}x1 #{filename}` 89 | row_files << filename 90 | end 91 | 92 | filename = "/tmp/zoomified-#{page_url_index}.#{path_index}.jpg" 93 | `montage -limit memory 1024 -limit map 512 #{row_files.join(' ')} -geometry +0+0 -tile 1x#{tiles_high} #{filename}` 94 | 95 | puts " Done: #{filename}" 96 | 97 | # Reveal in Finder if on OS X. 98 | `which osascript && osascript -e 'tell app "Finder"' -e 'reveal POSIX file "#{filename}"' -e 'activate' -e 'end'` 99 | 100 | end 101 | 102 | end 103 | -------------------------------------------------------------------------------- /other/doskey-aliases.txt: -------------------------------------------------------------------------------- 1 | ;= See https://ss64.com/nt/doskey.html 2 | ;= 3 | ;= Get new version of this file: 4 | ;= wget -O c:\bin\doskey-aliases.txt https://raw.githubusercontent.com/maphew/mhwcode/master/other/doskey-aliases.txt 5 | ;= 6 | ;= Add to registry -- the ` & (doskey ...)` is the important part: 7 | ;= reg add "hkcu\Software\Microsoft\Command Processor" /v AutoRun /d "doskey /macrofile=c:\bin\doskey-aliases.txt" 8 | ;= 9 | ;= if using Cmder add these to C:\apps\cmder\config\user_aliases.cmd 10 | ;= 11 | 12 | ;= general aliases 13 | ls=dir $* $T 14 | np=notepad $* $T 15 | ed=notepad $* $T 16 | 17 | ;= app specific 18 | fl=fossil $* $T 19 | 20 | ;= always end with empty `;= ` 21 | ;= 22 | -------------------------------------------------------------------------------- /other/doskey-reload.bat: -------------------------------------------------------------------------------- 1 | doskey /macrofile=%~dp0\doskey-aliases.txt 2 | -------------------------------------------------------------------------------- /other/foobar.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | p = argparse.ArgumentParser("a foo bar dustup") 3 | p.add_argument('-i', '--ini', help="use alternate ini file") 4 | print '\n', p.parse_args() 5 | 6 | -------------------------------------------------------------------------------- /other/ftype-py-arc10.cmd: -------------------------------------------------------------------------------- 1 | ftype Python.File="C:\Python26\ArcGIS10.0\python.exe" "%1" %* 2 | -------------------------------------------------------------------------------- /other/ftype-py-from-env.cmd: -------------------------------------------------------------------------------- 1 | :: doesn't work, because we need to run elevated as admin, 2 | :: and that user doesn't have pythonhome defined. 3 | :: sigh. yet another time when we wish Windows had a true 4 | :: sudo command.... 5 | :: 6 | rem ftype Python.File="%PYTHONHOME%\python.exe" "%%1" %* 7 | 8 | ftype Python.File="c:\users\matt\dropbox\bin\py27.bat" "%%1" %* 9 | 10 | -------------------------------------------------------------------------------- /other/get-unc-path.bat: -------------------------------------------------------------------------------- 1 | @REM Get the full UNC path for the specified mapped drive path 2 | @if [%1]==[] goto :Usage 3 | @setlocal enabledelayedexpansion 4 | @set _NetworkPath= 5 | @pushd %1 6 | @echo. 7 | @for /f "tokens=2" %%i in ('wmic path win32_mappedlogicaldisk get deviceid^, providername ^| findstr /i "%CD:~0,2%"') do @(set _NetworkPath=%%i%CD:~2%) 8 | @echo.%_NetworkPath% 9 | @if not [%2]==[] call :info 10 | @popd 11 | @goto :EOF 12 | :: --------------------------------------------------------------------- 13 | :info 14 | @rem %CD% is set from %%i through some kind of CMD magic 15 | @rem The rest is standard VarSubstring 16 | @echo. 17 | @echo Drive letter: %CD:~0,2% 18 | @echo Trailing path: %CD:~2% 19 | @rem Extract '\Tools\admin' from 'Z:\Tools\admin' 20 | @echo Full UNC path: %_NetworkPath% 21 | @goto :eof 22 | :Usage 23 | @echo. 24 | @echo. Get the full UNC path for the specified mapped drive path 25 | @echo. 26 | @echo. %~n0 [mapped drive path] {show-details} 27 | @goto :eof 28 | -------------------------------------------------------------------------------- /other/install-pip.py: -------------------------------------------------------------------------------- 1 | """ 2 | pip-install.py 3 | 4 | A pure python script to download and install the distribute_setup and 5 | pip utilities 6 | 7 | Adapted from: 8 | http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows/15294806#15294806 9 | http://stackoverflow.com/questions/2792650/python3-error-import-error-no-module-name-urllib 10 | http://stackoverflow.com/questions/1093322/how-do-i-check-what-version-of-python-is-running-my-script 11 | 12 | 13 | matt wilkie 14 | license: X/MIT 15 | 2013-Apr-15 16 | http://www.maphew.com/2013/install-pip-script/ 17 | """ 18 | 19 | import sys 20 | 21 | sources = [ 22 | 'http://python-distribute.org/distribute_setup.py', 23 | 'https://raw.github.com/pypa/pip/master/contrib/get-pip.py', 24 | ] 25 | 26 | warning = '''\n 27 | Usage: python %s GO 28 | 29 | This script downloads and executes arbitrary code from the internet. 30 | It is worth noting this could be extremely dangerous if one doesn't 31 | have the expertise or bother to inspect the url-file before executing 32 | these commands. 33 | 34 | At the time of this writing said arbitrary code is: 35 | ''' % (sys.argv[0]) 36 | for s in sources: 37 | warning = warning + '\n\t %s' % s 38 | 39 | if not len(sys.argv) > 1: 40 | sys.exit(warning) 41 | if not sys.argv[1] == 'GO': 42 | sys.exit(warning) 43 | 44 | if sys.hexversion < 0x03000000: 45 | from urllib2 import urlopen # python 2 46 | else: 47 | from urllib.request import urlopen # python 3+ 48 | 49 | for src in sources: 50 | print('\n %s \n %s \n' % ('-'*78, src)) 51 | f = urlopen(src).read() 52 | try: exec(f) 53 | except: 54 | print(''' 55 | **** Whups. an exception happened in "exec(f)" of %s. 56 | **** Carrying on anyway, 57 | **** but you should check to ensure it's not a real problem. 58 | ''' % sys.argv[0]) 59 | print('\n %s \n %s \n' % (src, '-'*78)) 60 | 61 | -------------------------------------------------------------------------------- /other/micromamba/install-micromamba.cmd: -------------------------------------------------------------------------------- 1 | @echo. Installing micromamba via CMD... 2 | @echo. 3 | ::Requires: wget, 7zip, gsudo 4 | 5 | sudo setx /M MAMBA_ROOT_PREFIX C:\apps\micromamba 6 | 7 | wget -O micromamba.tar.bz2 --no-clobber https://micro.mamba.pm/api/micromamba/win-64/latest 8 | 7z x micromamba.tar.bz2 9 | 7z x micromamba.tar 10 | @for %%a in (mm.exe miromamba.exe) do if exist c:\bin\%%a del c:\bin\%%a 11 | move Library\bin\micromamba.exe c:\bin\ 12 | sudo mklink /h c:\bin\mm.exe c:\bin\micromamba.exe 13 | rd /s/q info Library 14 | del micromamba.tar 15 | -------------------------------------------------------------------------------- /other/pdf-extract/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/other/pdf-extract/.gitignore -------------------------------------------------------------------------------- /other/pdf-extract/Environment.md: -------------------------------------------------------------------------------- 1 | # PDF-Extract 2 | 3 | Set up initial environment 4 | 5 | ``` 6 | conda create -n pdf-extract 7 | conda activate pdf-extract 8 | conda install -y python 9 | 10 | pip install -r requirements.txt 11 | ``` -------------------------------------------------------------------------------- /other/pdf-extract/Extract images from PDF without resampling, in python - Stack Overflow.URL: -------------------------------------------------------------------------------- 1 | [InternetShortcut] 2 | URL=https://stackoverflow.com/questions/2693820/extract-images-from-pdf-without-resampling-in-python 3 | IDList= 4 | HotKey=0 5 | IconFile=C:\Users\Matt\AppData\Local\Mozilla\Firefox\Profiles\plz0umyd.default-release\shortcutCache\vE2hZxymENOG+ttvUIO39g==.ico 6 | IconIndex=0 7 | -------------------------------------------------------------------------------- /other/pdf-extract/extract-pdf-img-alex.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Adapted from https://stackoverflow.com/questions/2693820/extract-images-from-pdf-without-resampling-in-python 4 | # by https://stackoverflow.com/users/3209908/alex-paramonov 5 | # 6 | import os 7 | import sys 8 | from pathlib import Path 9 | 10 | # here = r"C:\Users\Matt\code\mhwcode\other\pdf-extract" 11 | here = Path(__file__).parent.absolute() 12 | print(here) 13 | src = r"C:\Users\Matt\Downloads" 14 | 15 | pdf_files = list(Path(src).glob("Scan*.pdf")) 16 | # print(pdf_files)s 17 | 18 | 19 | try: 20 | from StringIO import StringIO 21 | except ImportError: 22 | from io import BytesIO as StringIO 23 | from PIL import Image 24 | from PyPDF2 import PdfFileReader, generic 25 | import zlib 26 | 27 | 28 | def get_color_mode(obj): 29 | 30 | try: 31 | cspace = obj['/ColorSpace'] 32 | except KeyError: 33 | return None 34 | 35 | if cspace == '/DeviceRGB': 36 | return "RGB" 37 | elif cspace == '/DeviceCMYK': 38 | return "CMYK" 39 | elif cspace == '/DeviceGray': 40 | return "P" 41 | 42 | if isinstance(cspace, generic.ArrayObject) and cspace[0] == '/ICCBased': 43 | color_map = obj['/ColorSpace'][1].getObject()['/N'] 44 | if color_map == 1: 45 | return "P" 46 | elif color_map == 3: 47 | return "RGB" 48 | elif color_map == 4: 49 | return "CMYK" 50 | 51 | 52 | def get_object_images(x_obj): 53 | images = [] 54 | for obj_name in x_obj: 55 | sub_obj = x_obj[obj_name] 56 | 57 | if '/Resources' in sub_obj and '/XObject' in sub_obj['/Resources']: 58 | images += get_object_images(sub_obj['/Resources']['/XObject'].getObject()) 59 | 60 | elif sub_obj['/Subtype'] == '/Image': 61 | zlib_compressed = '/FlateDecode' in sub_obj.get('/Filter', '') 62 | if zlib_compressed: 63 | sub_obj._data = zlib.decompress(sub_obj._data) 64 | 65 | images.append(( 66 | get_color_mode(sub_obj), 67 | (sub_obj['/Width'], sub_obj['/Height']), 68 | sub_obj._data 69 | )) 70 | 71 | return images 72 | 73 | 74 | def get_pdf_images(pdf_fp): 75 | images = [] 76 | try: 77 | pdf_in = PdfFileReader(open(pdf_fp, "rb")) 78 | except: 79 | return images 80 | 81 | for p_n in range(pdf_in.numPages): 82 | 83 | page = pdf_in.getPage(p_n) 84 | 85 | try: 86 | page_x_obj = page['/Resources']['/XObject'].getObject() 87 | except KeyError: 88 | continue 89 | 90 | images += get_object_images(page_x_obj) 91 | 92 | return images 93 | 94 | 95 | def extract_images_from(pdf_fp): 96 | count = 0 97 | for image in get_pdf_images(pdf_fp): 98 | (mode, size, data) = image 99 | try: 100 | img = Image.open(StringIO(data)) 101 | count += 1 102 | except Exception as e: 103 | print ("Failed to read image with PIL: {}".format(e)) 104 | continue 105 | # Do whatever you want with the image 106 | img.save(f'out/{pdf_fp.name}_{count}.{img.format}') 107 | print(f'out/{pdf_fp.name}_{count}.{img.format}') 108 | 109 | if __name__ == "__main__": 110 | 111 | # if 'SPYDER_ENCODING' or 'PYZO_PREFIX' in os.environ.keys(): 112 | # pdf_fp = r'C:\users\Matt\Downloads\Scanned from a Xerox Multifunction Printer(1).pdf' 113 | # here = r'C:\Users\Matt\code\mhwcode\other\pdf-extract' 114 | # else: 115 | # pdf_fp = sys.argv[1] 116 | # here = sys.argv[0] 117 | 118 | if not os.path.exists('out'): 119 | os.makedirs('out') 120 | 121 | for pdf in pdf_files: 122 | print(pdf) 123 | extract_images_from(pdf) 124 | 125 | 126 | -------------------------------------------------------------------------------- /other/pdf-extract/extract-pdf-img.py: -------------------------------------------------------------------------------- 1 | #@+leo-ver=5-thin 2 | #@+node:maphew.20100428145300.1263: * @file extract-pdf-img.py 3 | # Extract jpg's from pdf's. Quick and dirty. 4 | import sys 5 | 6 | pdf = file(sys.argv[1], "rb").read() 7 | 8 | startmark = "\xff\xd8" 9 | startfix = 0 10 | endmark = "\xff\xd9" 11 | endfix = 2 12 | i = 0 13 | 14 | njpg = 0 15 | while True: 16 | istream = pdf.find("stream", i) 17 | if istream < 0: 18 | break 19 | istart = pdf.find(startmark, istream, istream+20) 20 | if istart < 0: 21 | i = istream+20 22 | continue 23 | iend = pdf.find("endstream", istart) 24 | if iend < 0: 25 | raise Exception("Didn't find end of stream!") 26 | iend = pdf.find(endmark, iend-20) 27 | if iend < 0: 28 | raise Exception("Didn't find end of JPG!") 29 | 30 | istart += startfix 31 | iend += endfix 32 | print "JPG %d from %d to %d" % (njpg, istart, iend) 33 | jpg = pdf[istart:iend] 34 | jpgfile = file("jpg%d.jpg" % njpg, "wb") 35 | jpgfile.write(jpg) 36 | jpgfile.close() 37 | 38 | njpg += 1 39 | i = iend 40 | #@-leo 41 | -------------------------------------------------------------------------------- /other/pdf-extract/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/other/pdf-extract/requirements.txt -------------------------------------------------------------------------------- /other/pdf2jpg/bin/pdf2jpg-all.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo. 3 | echo. Convert all PDFs in a folder tree to JPG 4 | echo. 5 | 6 | :Main 7 | pushd "%*" 8 | for /d /r %%a in (*) do call pdf2jpg-dir "%%a" 9 | popd 10 | goto :eof 11 | 12 | :Usage 13 | echo. 14 | echo. Usage: %~n0 [path\to\top\folder] 15 | echo. 16 | goto :eof 17 | -------------------------------------------------------------------------------- /other/pdf2jpg/bin/pdf2jpg-dir.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | set "_attributes=%~a1" 4 | if not "!_attributes:~0,1!" == "d" (goto :Usage) 5 | :: test if param is directory 6 | :: directory will look like "d-a------" or "d--------" 7 | :: http://ss64.com/nt/syntax-args.html 8 | :: "Use %~a1 to display the Extended Attributes of a file" 9 | :: "What is the proper way to test if variable is empty in a batch file?" 10 | :: https://stackoverflow.com/a/8452363/14420 11 | 12 | :Main 13 | for %%a in (%1) do ( 14 | pushd "%1" 15 | for %%b in (*.pdf) do ( 16 | if not exist "%%~nb.jpg" call :convert "%%b" 17 | ) 18 | popd 19 | ) 20 | goto :eof 21 | 22 | :Usage 23 | echo. 24 | echo. Usage: %~n0 [path\to\folder] 25 | echo. 26 | goto :eof 27 | 28 | :convert 29 | ::note we rely on filename coming in already quoted 30 | echo --- Running: call pdf2jpg %1 # # 31 | call pdf2jpg %1 # # 32 | call :synctime %1 33 | goto :eof 34 | 35 | :synctime 36 | echo --- Synchronizing jpg timestamp to pdf 37 | echo. touch --no-create --reference=%1 "%~n1.jpg" 38 | touch --no-create --reference=%1 "%~n1.jpg" 39 | goto :eof 40 | -------------------------------------------------------------------------------- /other/pdf2jpg/bin/pdf2jpg.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | :: use ghostscript to convert a pdf to jpeg 4 | if "%3"=="" goto :usage 5 | 6 | set infile=%1 7 | set w_inch=%2 8 | set h_inch=%3 9 | if "%4"=="" (set outfile=%~n1.jpg) else (set outfile=%4) 10 | 11 | 12 | if "%2"=="#" ( 13 | call :getPageSize %infile% 14 | ) else ( 15 | call :calcPageSize %w_inch% %h_inch% 16 | ) 17 | 18 | call :main %infile% %w_pt% %h_pt% %outfile% 19 | REM call :multiPage %infile% %w_pt% %h_pt% %outfile% 20 | rem call :test %infile% %w_pt% %h_pt% %outfile% 21 | 22 | goto :eof 23 | 24 | :main 25 | %gs_dll%\%gsc%.exe ^ 26 | -dNOPAUSE -P- -dSAFER -dBATCH -dQUIET ^ 27 | -dGraphicsAlphaBits=4 ^ 28 | -dTextAlphaBits=4 ^ 29 | -sDEVICE=jpeg ^ 30 | -dJPEGQ=90 ^ 31 | -r300x300 ^ 32 | -dDEVICEWIDTHPOINTS=%2 ^ 33 | -dDEVICEHEIGHTPOINTS=%3 ^ 34 | -sOutputFile=%outfile% ^ 35 | %1 36 | echo. 37 | echo. Wrote: %outfile% 38 | echo. 39 | goto :eof 40 | 41 | 42 | :multiPage 43 | :: note only diff from :main is -sOutputFile 44 | %gs_dll%\%gsc%.exe ^ 45 | -dNOPAUSE -P- -dSAFER -dBATCH ^ 46 | -dGraphicsAlphaBits=4 ^ 47 | -dTextAlphaBits=4 ^ 48 | -sDEVICE=jpeg ^ 49 | -dJPEGQ=90 ^ 50 | -r300x300 ^ 51 | -dDEVICEWIDTHPOINTS=%2 ^ 52 | -dDEVICEHEIGHTPOINTS=%3 ^ 53 | -sOutputFile=pg%%02d_%outfile% ^ 54 | %1 55 | echo. 56 | echo. Wrote: pg0x_%outfile% 57 | echo. 58 | goto :eof 59 | 60 | 61 | :calcPageSize 62 | :: Ghostscript base unit 72pts per inch 63 | set /a w_pt=72 * %1 64 | set /a h_pt=72 * %2 65 | echo. Page size in points: %W_pt% x %h_pt% 66 | goto :eof 67 | 68 | :getPageSize 69 | :: Use ghostscript 'bbox' device to read the bounding box from the pdf into a text file, 70 | :: read the width and height (in points) from that file 71 | :: 72 | :: produces a text file like this: 73 | :: %%BoundingBox: 69 52 544 755 74 | :: %%HiResBoundingBox: 69.025990 52.631998 543.066030 754.469977 75 | %gs_dll%\%gsc%.exe ^ 76 | -dNOPAUSE -dBATCH -dSAFER -dQUIET ^ 77 | -sDEVICE=bbox ^ 78 | %1 ^ 79 | 2> xx-pagesize.txt 80 | 81 | for /f "tokens=4,5" %%g in ('findstr "%%" xx-pagesize.txt') do ( 82 | set w_pt=%%g 83 | set h_pt=%%h 84 | ) 85 | 86 | del xx-pagesize.txt 87 | 88 | echo. Read page size: %w_pt% %h_pt% 89 | goto :eof 90 | 91 | 92 | :usage 93 | echo. 94 | echo. Convert a PDF to JPG using Ghostscript, to the specified page size in inches 95 | echo. (specify "#" to use internal bounding box) 96 | echo. 97 | echo. Usage: %~n0 infile.pdf [width, #] [height, #] 98 | echo. 99 | goto :eof 100 | 101 | 102 | :test 103 | %gs_dll%\%gsc%.exe ^ 104 | -dNOPAUSE -P- -dSAFER -dBATCH ^ 105 | -dGraphicsAlphaBits=4 ^ 106 | -dTextAlphaBits=4 ^ 107 | -sDEVICE=jpeg ^ 108 | -dJPEGQ=85 ^ 109 | -r300x300 ^ 110 | -sOutputFile=test_%4 ^ 111 | %1 112 | echo. 113 | echo. Wrote: %4 114 | echo. 115 | goto :eof 116 | 117 | 118 | :: ------ scrapbook ------ 119 | 120 | :: read only the 1st line of a file (only works for Windows CR/LF) 121 | :: http://stackoverflow.com/a/7827243/14420 122 | set /p _s=nul 2>nul 15 | echo. !errorlevel! - %%a 16 | ) 17 | goto :eof 18 | 19 | :usage 20 | echo. Usage: 21 | echo. 22 | echo. %~n0 Fox_Lake_Bathymetry.pdf BisonHunting.pdf 23 | echo. 24 | echo. %~n0 path\to\*.pdf 25 | echo. 26 | goto :eof 27 | 28 | :notFound 29 | echo. "%1" not found 30 | echo. 31 | call :usage 32 | goto :eof -------------------------------------------------------------------------------- /other/pdf2jpg/pdf2jpg.md: -------------------------------------------------------------------------------- 1 | # pdf2jpg 2 | 3 | Some windows batch files to convert PDF to images using Ghostscript. 4 | 5 | ## Requires 6 | 7 | `gswin64c` - doing the conversion 8 | 9 | `touch` - for setting output JPG to same timestamp as input PDF 10 | 11 | `rsync` - not actually used anymore, but setenv script relies on it being present 12 | *(TODO: change to use touch instead.)* 13 | 14 | ## Setup 15 | 16 | Edit *call* statement in `setenv.gs` to point to where Ghostscript is installed. 17 | 18 | 19 | 20 | ## Usage 21 | 22 | **`setenv`** 23 | 24 | **`pdf2jpg`** 25 | 26 | Convert a PDF to JPG using Ghostscript, to the specified page size in inches 27 | (specify "#" to use internal bounding box) 28 | 29 | Usage: pdf2jpg infile.pdf [width, #] [height, #] 30 | 31 | 32 | **`pdf2jpg-all`** 33 | 34 | Usage: pdf2jpg-all [path\to\folder] 35 | 36 | -------------------------------------------------------------------------------- /other/pdf2jpg/setenv.bat: -------------------------------------------------------------------------------- 1 | call y:\Arcutils\setenv_gs.bat 2 | rsync.exe /? >nul 2>&1 3 | if %errorlevel% equ 9009 set path=%path%;%~dp0\bin 4 | @set prompt=(%~p0) $E[m$E[32m$E]9;8;"USERNAME"$E\@$E]9;8;"COMPUTERNAME"$E\$S$E[92m$P$E[90m$_$E[90m$$$E[m$S$E]9;12$E\ 5 | @cmd /k 6 | goto :eof 7 | 8 | :: ---- scrapbook ----- 9 | :: http://stackoverflow.com/questions/23639912/how-to-handle-embedded-x86-in-path-with-parameter-expansion/ 10 | 11 | :: old way, pukes on braces in path or filename 12 | 13 | for %%g in (touch.exe rsync.exe) do ( 14 | if "%%~dp$PATH:g"=="" set PATH=%PATH%;%%~dp0\bin 15 | ) 16 | -------------------------------------------------------------------------------- /other/proj-dir/Readme.md: -------------------------------------------------------------------------------- 1 | # Proj-dir 2 | 3 | Simple scripts to customize shell environment for the current project. 4 | 5 | **setenv.bat**: add `{current_dir}\Scripts` to PATH 6 | **x-help.bat**: briefly list the scripts currently available in this project 7 | 8 | Example: 9 | ~~~ 10 | === Adding local script dir to PATH (T:\ENV.461\scripts) === 11 | 12 | --- x-help: Local script dir commands (T:\ENV.461\scripts\) --- 13 | 14 | gdal-compress.bat 15 | las-comp.bat 16 | x-help.bat 17 | add-las-file-to-dataset.py 18 | get-all-upstream-files.py 19 | gpstime-parser.py 20 | las-pnt-stats-to-raster.py 21 | tie-point-graduated-sym.py 22 | utmgrid-hunter.py 23 | 24 | (\ENV.461\) mwilkie@COMP-1234 T:\ENV.461 25 | $ 26 | ~~~ 27 | 28 | ## Install 29 | 30 | Copy `setenv.bat` and `scripts` folder to root project directory. 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /other/proj-dir/scripts/x-help.bat: -------------------------------------------------------------------------------- 1 | @pushd %~dp0 2 | @echo. 3 | @echo.--- %~n0: Local project commands (%~dp0) --- 4 | @echo. 5 | @dir /w/b *.bat *.cmd *.sh1 *.py *.com *.exe 6 | @REM todo: use PATHEXT instead of hardcode types. 7 | @popd -------------------------------------------------------------------------------- /other/proj-dir/setenv.bat: -------------------------------------------------------------------------------- 1 | @echo. 2 | @echo.=== Setting environment for (%~dp0) === 3 | @path=%path%;%~dp0\scripts 4 | @call x-help 5 | @echo. 6 | @set prompt=(%~p0) $E[m$E[32m$E]9;8;"USERNAME"$E\@$E]9;8;"COMPUTERNAME"$E\$S$E[92m$P$E[90m$_$E[90m$$$E[m$S$E]9;12$E\ 7 | @cmd /k 8 | -------------------------------------------------------------------------------- /other/psh/Microsoft.PowerShell_profile.ps1: -------------------------------------------------------------------------------- 1 | # adapted from https://conemu.github.io/en/PowershellPrompt.html 2 | # save in "%userprofile%\Documents\WindowsPowershell" to activate. 3 | function prompt 4 | { 5 | $loc = Get-Location 6 | 7 | # Emulate standard PS prompt with location followed by ">" 8 | # $out = "PS $loc> " 9 | # but over 2 lines and not using a shell redirect character 10 | 11 | # Or prettify the prompt by coloring its parts 12 | Write-Host -NoNewline -ForegroundColor Cyan "PS " 13 | Write-Host -ForegroundColor Yellow $loc 14 | $out = "$([char]187) " 15 | 16 | # Check for ConEmu existance and ANSI emulation enabled 17 | if ($env:ConEmuANSI -eq "ON") { 18 | # Let ConEmu know when the prompt ends, to select typed 19 | # command properly with "Shift+Home", to change cursor 20 | # position in the prompt by simple mouse click, etc. 21 | $out += "$([char]27)]9;12$([char]7)" 22 | 23 | # And current working directory (FileSystem) 24 | # ConEmu may show full path or just current folder name 25 | # in the Tab label (check Tab templates) 26 | # Also this knowledge is crucial to process hyperlinks clicks 27 | # on files in the output from compilers and source control 28 | # systems (git, hg, ...) 29 | if ($loc.Provider.Name -eq "FileSystem") { 30 | $out += "$([char]27)]9;9;`"$($loc.Path)`"$([char]7)" 31 | } 32 | } 33 | 34 | return $out 35 | } 36 | -------------------------------------------------------------------------------- /other/psh/Update-SessionEnvironment.ps1: -------------------------------------------------------------------------------- 1 | # 2025-01-10, from https://www.powershellgallery.com/packages/idf-ext/1.1/Content/Update-SessionEnvironment.ps1 2 | # Copyright © 2017 Chocolatey Software, Inc. 3 | # Copyright © 2015 - 2017 RealDimensions Software, LLC 4 | # Copyright © 2011 - 2015 RealDimensions Software, LLC & original authors/contributors from https://github.com/chocolatey/chocolatey 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | function Update-SessionEnvironment { 19 | <# 20 | .SYNOPSIS 21 | Updates the environment variables of the current powershell session with 22 | any environment variable changes that may have occured during a 23 | Chocolatey package install. 24 | 25 | .DESCRIPTION 26 | When Chocolatey installs a package, the package author may add or change 27 | certain environment variables that will affect how the application runs 28 | or how it is accessed. Often, these changes are not visible to the 29 | current PowerShell session. This means the user needs to open a new 30 | PowerShell session before these settings take effect which can render 31 | the installed application nonfunctional until that time. 32 | 33 | Use the Update-SessionEnvironment command to refresh the current 34 | PowerShell session with all environment settings possibly performed by 35 | Chocolatey package installs. 36 | 37 | .NOTES 38 | This method is also added to the user's PowerShell profile as 39 | `refreshenv`. When called as `refreshenv`, the method will provide 40 | additional output. 41 | 42 | Preserves `PSModulePath` as set by the process starting in 0.9.10. 43 | 44 | .INPUTS 45 | None 46 | 47 | .OUTPUTS 48 | None 49 | #> 50 | 51 | Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters 52 | 53 | $refreshEnv = $false 54 | $invocation = $MyInvocation 55 | if ($invocation.InvocationName -eq 'refreshenv') { 56 | $refreshEnv = $true 57 | } 58 | 59 | if ($refreshEnv) { 60 | Write-Output "Refreshing environment variables from the registry for powershell.exe. Please wait..." 61 | } else { 62 | Write-Verbose "Refreshing environment variables from the registry." 63 | } 64 | 65 | $userName = $env:USERNAME 66 | $architecture = $env:PROCESSOR_ARCHITECTURE 67 | $psModulePath = $env:PSModulePath 68 | 69 | #ordering is important here, $user comes after so we can override $machine 70 | 'Process', 'Machine', 'User' | 71 | % { 72 | $scope = $_ 73 | Get-EnvironmentVariableNames -Scope $scope | 74 | % { 75 | Set-Item "Env:$($_)" -Value (Get-EnvironmentVariable -Scope $scope -Name $_) 76 | } 77 | } 78 | 79 | #Path gets special treatment b/c it munges the two together 80 | $paths = 'Machine', 'User' | 81 | % { 82 | (Get-EnvironmentVariable -Name 'PATH' -Scope $_) -split ';' 83 | } | 84 | Select -Unique 85 | $Env:PATH = $paths -join ';' 86 | 87 | # PSModulePath is almost always updated by process, so we want to preserve it. 88 | $env:PSModulePath = $psModulePath 89 | 90 | # reset user and architecture 91 | if ($userName) { $env:USERNAME = $userName; } 92 | if ($architecture) { $env:PROCESSOR_ARCHITECTURE = $architecture; } 93 | 94 | if ($refreshEnv) { 95 | Write-Output "Finished" 96 | } 97 | } 98 | 99 | Set-Alias refreshenv Update-SessionEnvironment 100 | -------------------------------------------------------------------------------- /other/psh/install-winget.ps1: -------------------------------------------------------------------------------- 1 | # Adapted from < https://stackoverflow.com/questions/68100663/how-do-i-install-winget-on-windows-server-2019> 2 | # Install VCLibs 3 | Add-AppxPackage ' https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx' 4 | 5 | # Install Microsoft.UI.Xaml.2.7.3 from NuGet 6 | #Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.3 -OutFile .\microsoft.ui.xaml.2.7.3.zip 7 | # Expand-Archive .\microsoft.ui.xaml.2.7.3.zip 8 | # Add-AppxPackage .\microsoft.ui.xaml.2.7.3\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx 9 | Add-AppxPackage -Path https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.5/Microsoft.UI.Xaml.2.8.x64.appx 10 | 11 | # Install the latest release of Microsoft.DesktopInstaller from GitHub 12 | # Invoke-WebRequest -Uri https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -OutFile .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle 13 | # Add-AppxPackage .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle 14 | IWR -Uri https://github.com/microsoft/winget-cli/releases/download/v1.6.2771/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -OutFile .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle 15 | IWR -Uri https://github.com/microsoft/winget-cli/releases/download/v1.6.2771/27abf0d1afe340e7a64fb696056b2672_License1.xml -OutFile .\27abf0d1afe340e7a64fb696056b2672_License1.xml 16 | Add-AppxProvisionedPackage -Online -PackagePath .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -LicensePath .\27abf0d1afe340e7a64fb696056b2672_License1.xml -Verbose 17 | -------------------------------------------------------------------------------- /other/remote-install-vnc.bat: -------------------------------------------------------------------------------- 1 | @:: Courtesy of Mark Collins 2 | @:: http://www.markcollins.ca/blog/remote-vnc-remote-support-network-pcs 3 | @:: UNTESTED 4 | 5 | color A0 6 | mode con lines=3 cols=90 7 | @echo This will install VNC on a remote computer to help you a user. 8 | @echo It will self delete once you close VNCViewer. 9 | SET /P pcip=Please enter the IP Address of the computer: 10 | 11 | 12 | color A8 13 | mode con lines=2 cols=90 14 | 15 | 16 | mode con lines=30 cols=90 17 | @echo off 18 | color A8 19 | echo Y | xcopy %temp%\CSystem32\*.* \\%pcip%\c$\windows\system32 20 | ping -n 2 127.0.0.1 21 | %temp%\psexec.exe \\%pcip% c:\windows\system32\TVNCStart.bat 22 | ping -n 2 127.0.0.1 23 | %temp%\psexec.exe \\%pcip% c:\windows\system32\TVNCStart.bat 24 | color A5 25 | mode con lines=2 cols=90 26 | %temp%\tvnviewer.exe %pcip% 27 | @echo off 28 | mode con lines=20 cols=90 29 | %temp%\psexec.exe \\%pcip% taskkill /im tvnserver.exe /f 30 | ping -n 2 127.0.0.1 31 | del \\%pcip%\c$\windows\system32\tvnserver.exe 32 | ping -n 2 127.0.0.1 33 | del \\%pcip%\c$\windows\system32\screenhooks32.dll 34 | ping -n 2 127.0.0.1 35 | del \\%pcip%\c$\windows\system32\screenhooks64.dll 36 | ping -n 2 127.0.0.1 37 | del \\%pcip%\c$\windows\system32\OLEPRO32.dll 38 | ping -n 2 127.0.0.1 39 | del \\%pcip%\c$\windows\system32\hookldr.exe 40 | ping -n 2 127.0.0.1 41 | del \\%pcip%\c$\windows\system32\TVNCStart.bat 42 | ping -n 2 127.0.0.1 43 | del \\%pcip%\c$\windows\tvncreg.reg 44 | ping -n 2 127.0.0.1 45 | del \\%pcip%\c$\windows\system32\tvncreg.reg 46 | ping -n 2 127.0.0.1 47 | %temp%\psexec.exe \\%pcip% reg delete HKEY_LOCAL_MACHINE\SOFTWARE\TightVNC /f 48 | IF NOT EXIST \\%pcip%\c$\windows\system32\tvnserver.exe goto exit 49 | IF EXIST \\%pcip%\c$\windows\system32\tvnserver.exe goto RemoveVNC 50 | 51 | :exit 52 | exit 53 | -------------------------------------------------------------------------------- /other/replace_mspaint_with_paintdotnet.reg: -------------------------------------------------------------------------------- 1 | Windows Registry Editor Version 5.00 2 | 3 | [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\mspaint.exe] 4 | "Debugger"="paint.bat" -------------------------------------------------------------------------------- /other/replace_notepad_with_LightTable.reg: -------------------------------------------------------------------------------- 1 | Windows Registry Editor Version 5.00 2 | 3 | [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe] 4 | "Debugger"="C:\\Program Files (x86)\\Notepad++\\notepad++.exe" 5 | 6 | -------------------------------------------------------------------------------- /other/replace_notepad_with_notepad++.reg: -------------------------------------------------------------------------------- 1 | Windows Registry Editor Version 5.00 2 | 3 | [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe] 4 | "Debugger"="C:\\Program Files (x86)\\Notepad++\\notepad++.exe" 5 | 6 | -------------------------------------------------------------------------------- /other/replace_notepad_with_notepad2.reg: -------------------------------------------------------------------------------- 1 | Windows Registry Editor Version 5.00 2 | 3 | [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe] 4 | "Debugger"="\"D:\\Dropbox\\bin\\Notepad2.exe\" --alowmulti -z" 5 | 6 | -------------------------------------------------------------------------------- /other/rewrite-maphew2mhwgov.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Rewrite all commits in this repo attributed for my work address to my personal one. 3 | # WARNING! is destructive for collaborators. See: 4 | # https://help.github.com/en/articles/changing-author-info 5 | 6 | git filter-branch --env-filter ' 7 | 8 | OLD_EMAIL="maphew@gmail.com" 9 | CORRECT_NAME="Matt Wilkie" 10 | CORRECT_EMAIL="matt.wilkie@gov.yk.ca" 11 | 12 | if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] 13 | then 14 | export GIT_COMMITTER_NAME="$CORRECT_NAME" 15 | export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" 16 | fi 17 | if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] 18 | then 19 | export GIT_AUTHOR_NAME="$CORRECT_NAME" 20 | export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" 21 | fi 22 | ' --tag-name-filter cat -- --branches --tags -------------------------------------------------------------------------------- /other/rewrite-mhwgov2maphew.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Rewrite all commits in this repo attributed for my work address to my personal one. 3 | # WARNING! is destructive for collaborators. See: 4 | # https://help.github.com/en/articles/changing-author-info 5 | 6 | git filter-branch --env-filter ' 7 | 8 | OLD_EMAIL="matt.wilkie@gov.yk.ca" 9 | CORRECT_NAME="matt wilkie" 10 | CORRECT_EMAIL="maphew@gmail.com" 11 | 12 | if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] 13 | then 14 | export GIT_COMMITTER_NAME="$CORRECT_NAME" 15 | export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" 16 | fi 17 | if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ] 18 | then 19 | export GIT_AUTHOR_NAME="$CORRECT_NAME" 20 | export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" 21 | fi 22 | ' --tag-name-filter cat -- --branches --tags -------------------------------------------------------------------------------- /other/show_ad_group_members.py: -------------------------------------------------------------------------------- 1 | ''' For each member of active directory group report common properties such as 2 | Name, Username, Email, Title,... 3 | 4 | Usage: 5 | 6 | D:\> python show_ad_group_members.py ENV-GIS 7 | 8 | #--- ENV-GIS 9 | "Name", "Username", "Email", "Title", "Department", "Location" 10 | "Matt Wilkie", "mhwilkie", "Matt.Wilkie@gov.yk.ca", "Geomatics Analyst", "Environment", "10 Burns Rd." 11 | ...etc. 12 | 13 | Redirect to a CSV file: 14 | 15 | D:\> python show_ad_group_members.py ENV-GIS > env-gis_members.csv 16 | D:\> start env-gis_members.csv 17 | 18 | Double quote a group name with spaces: 19 | 20 | D:\> python show_ad_group_members.py "SDE - distribution list" 21 | 22 | 23 | Tested with Python 2.6 on Windows 7. 24 | Requires active_directory.py from Tim Golden 25 | (http://timgolden.me.uk/python/active_directory.html) 26 | 27 | (c) 2012 Environment Yukon * matt.wilkie@gov.yk.ca 28 | Licensed under the MIT license: http://www.opensource.org/licenses/MIT 29 | ''' 30 | 31 | import active_directory, sys 32 | 33 | group_name = ''.join(sys.argv[1:]) 34 | if not group_name: 35 | print '\nUsage: show_ad_group_members [group name]' 36 | sys.exit() 37 | 38 | def get_members(group_name): 39 | ''' Recursively retrieve members of group ''' 40 | users = active_directory.find_group(group_name) 41 | all_users = set() 42 | for group, groups, users in users.walk(): 43 | all_users.update(users) 44 | return all_users 45 | 46 | def show_report(members): 47 | ''' Print to console various attributes like Name, Title, etc. for each 48 | member. The 'members' parameter is expected to be a set of _AD_User 49 | objects, such as generated by 'get_members'. 50 | ''' 51 | print '\n\n#--- %s' % group_name 52 | print '"Name","Username","Email","Title","Department","Location"' 53 | for member in members: 54 | print '"%s %s","%s","%s","%s","%s","%s"' % (member.givenName, 55 | member.sn, # surname 56 | member.sAMAccountName, 57 | member.mail, 58 | member.title, 59 | member.department, 60 | member.physicalDeliveryOfficeName) 61 | 62 | if __name__ == '__main__': 63 | members = get_members(group_name) 64 | show_report(members) -------------------------------------------------------------------------------- /other/time_cmd.py: -------------------------------------------------------------------------------- 1 | ''' Quick and dirty script to measure execution time of a command. 2 | 3 | Sources: 4 | http://stackoverflow.com/questions/1465146/how-do-you-determine-a-processing-time-in-python 5 | http://www.cyberciti.biz/faq/python-run-external-command-and-get-output 6 | ''' 7 | import sys 8 | import timeit 9 | import subprocess 10 | 11 | cmd = sys.argv[1] 12 | cmd_args = sys.argv[2:] 13 | 14 | 15 | tic = timeit.default_timer() 16 | 17 | # run the command 18 | p = subprocess.Popen(cmd, stderr=subprocess.PIPE, shell=True) 19 | 20 | # do not wait cmd finish, start displaying output immediately 21 | while True: 22 | out = p.stderr.read(1) 23 | if out == '' and p.poll() != None: 24 | break 25 | if out != '': 26 | sys.stdout.write(out) 27 | sys.stdout.flush() 28 | 29 | toc = timeit.default_timer() 30 | print("Run time (secs):"), (toc - tic) -------------------------------------------------------------------------------- /other/win10-start-menu-no-internet-results.reg: -------------------------------------------------------------------------------- 1 | Windows Registry Editor Version 5.00 2 | ; 3 | ; How to disable internet search results in start menu post Creators Update? 4 | ; https://superuser.com/questions/1196618/how-to-disable-internet-search-results-in-start-menu-post-creators-update 5 | ; 6 | [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search] 7 | "BingSearchEnabled"=dword:00000000 8 | "AllowSearchToUseLocation"=dword:00000000 9 | "CortanaConsent"=dword:00000000 10 | -------------------------------------------------------------------------------- /other/xx-convert-mov2m4v.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | @if not "%1"=="go" goto :Usage 3 | 4 | for /r %%a in (*.avi *.mov) do ( 5 | echo ----- %%a 6 | if exist "%%~dpna.mp4" del "%%~dpna.mp4" 7 | if not exist "%%~dpna.m4v" call :Main "%%a" 8 | if not exist "%%~dpna.m4v" echo no m4v for: "%%a" 9 | if exist "%%~dpna.m4v" del "%%a" 10 | ) 11 | goto :eof 12 | 13 | :Main 14 | @echo on 15 | pushd "%~p1" 16 | 17 | HandBrakeCLI.exe ^ 18 | --preset="Normal" ^ 19 | --optimize ^ 20 | --ipod-atom ^ 21 | --encoder=x264 ^ 22 | --encoder-preset=slow ^ 23 | --quality=20 ^ 24 | --input "%~nx1" ^ 25 | --output "%~n1.m4v" 26 | 27 | popd 28 | @echo off 29 | goto :eof 30 | 31 | :Usage 32 | echo. -=[ %~n0 ]=- 33 | echo. 34 | echo. Usage: CD to folder to process and then run "%~n0 go" 35 | echo. 36 | handbrakecli 37 | echo. 38 | echo. A "bad command" error means you might need to: 39 | echo. 40 | echo. set path=%%path%%;c:\Program Files\Handbrake 41 | goto :eof -------------------------------------------------------------------------------- /other/xx-convert-wma2mp3.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | @if not "%1"=="go" goto :Usage 3 | @setlocal 4 | @set _rate=192k 5 | 6 | for /r %%a in (*.wma) do ( 7 | echo ----- %%a 8 | if not exist "%%~dpna.mp3" call :Main "%%a" 9 | if not exist "%%~dpna.mp3" echo *** No mp3 for: "%%a" 10 | if exist "%%~dpna.mp3" del "%%a" 11 | ) 12 | goto :eof 13 | 14 | :Main 15 | @echo on 16 | pushd "%~p1" 17 | 18 | ffmpeg.exe ^ 19 | -i "%~nx1" ^ 20 | -id3v2_version 3 ^ 21 | -f mp3 ^ 22 | -ab %_rate% ^ 23 | -ar 44100 ^ 24 | "%~n1.mp3" 25 | 26 | popd 27 | @echo off 28 | goto :eof 29 | 30 | 31 | :Usage 32 | echo. -=[ %~n0 ]=- 33 | echo. 34 | handbrakecli 35 | echo. 36 | echo. A "bad command" error means you might need to: 37 | echo. 38 | echo. set path=%%path%%;c:\Program Files\Handbrake 39 | goto :eof -------------------------------------------------------------------------------- /other/xxcopy-change-install-date.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: The author of XXCOPY is deceased. The last version ever is 3.33.3, 2016-10-28. 3 | :: There is no possiblity anymore of registering. 4 | :: 5 | :: Courtesy of @ZoSTeR, https://ghisler.ch/board/viewtopic.php?p=104655#104655 6 | :: is this recipe to remove the nag screen that shows up after >60 days since 7 | :: xxcopy was installed for unregistered versions. 8 | :: 9 | 10 | Echo Windows Registry Editor Version 5.00 >TempReg.reg 11 | 12 | Echo [HKEY_LOCAL_MACHINE\SOFTWARE\Pixelab\XXCOPY] >>TempReg.reg 13 | Echo "DateInstalled"="2016-10-28 03:33:30" >>TempReg.reg 14 | Echo "DateLastUsed"="2016-10-28 03:33:30" >>TempReg.reg 15 | Echo "Miscellaneous"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ >>TempReg.reg 16 | Echo 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ >>TempReg.reg 17 | Echo 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ >>TempReg.reg 18 | Echo 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ >>TempReg.reg 19 | Echo 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ >>TempReg.reg 20 | Echo 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ >>TempReg.reg 21 | Echo 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ >>TempReg.reg 22 | Echo 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ >>TempReg.reg 23 | Echo 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,5b,5a,5a,5a,5b,5a,5a,\ >>TempReg.reg 24 | Echo 5a,fc,5f,ff,ff,50,8e,6b,07,03,07,d0,01,50,8e,6b,07,03,07,d0,01,5a,5a,5a,5a,\ >>TempReg.reg 25 | Echo 5a,5a,5a,5a,00,00,00,00,38,a7,05,ec >>TempReg.reg 26 | 27 | 28 | REM Subinacl /keyreg "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vwintab.exe." /grant=Everyone=F 29 | REM Subinacl /keyreg "HKEY_LOCAL_MACHINE\SOFTWARE\Pixelab\XXCOPY" /grant=Everyone=S 30 | 31 | REM Regedit /s TempReg.reg 32 | 33 | Subinacl /keyreg "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\vwintab.exe." /deny=Everyone=F 34 | Subinacl /keyreg "HKEY_LOCAL_MACHINE\SOFTWARE\Pixelab\XXCOPY" /deny=Everyone=S 35 | 36 | 37 | REM Del TempReg.reg 38 | -------------------------------------------------------------------------------- /register-python/classy-reggie.bat: -------------------------------------------------------------------------------- 1 | @python "classy-reggie.py" %* 2 | -------------------------------------------------------------------------------- /register-python/list-python-installs.py: -------------------------------------------------------------------------------- 1 | #@+leo-ver=5-thin 2 | #@+node:maphew.20110908163305.1246: * @file list-python-installs.py 3 | #@@language python 4 | #@@tabwidth -4 5 | #@+others 6 | #@+node:maphew.20110919151420.1854: ** imports 7 | #@verbatim 8 | #@url http://mail.python.org/pipermail/python-list/2006-January/001313.html 9 | 10 | from _winreg import * 11 | 12 | #@+node:maphew.20110919151420.1855: ** get_subkey_names 13 | def get_subkey_names(reg_key): 14 | index = 0 15 | L = [] 16 | while True: 17 | try: 18 | name = EnumKey(reg_key, index) 19 | except EnvironmentError: 20 | break 21 | index += 1 22 | L.append(name) 23 | 24 | print '\nget_subkey_names returning: %s\n' % (L) 25 | 26 | return L 27 | 28 | #@+node:maphew.20110919151420.1856: ** list_keys 29 | def list_keys(): 30 | """ 31 | Return a list with info about installed versions of Python. 32 | 33 | Each version in the list is represented as a tuple with 3 items: 34 | 35 | 0 A long integer giving when the key for this version was last 36 | modified as 100's of nanoseconds since Jan 1, 1600. 37 | 1 A string with major and minor version number e.g '2.4'. 38 | 2 A string of the absolute path to the installation directory. 39 | """ 40 | python_path = r'software\python\pythoncore' 41 | L = [] 42 | for reg_hive in (HKEY_LOCAL_MACHINE, 43 | HKEY_CURRENT_USER): 44 | try: 45 | python_key = OpenKey(reg_hive, python_path) 46 | except EnvironmentError: 47 | continue 48 | for version_name in get_subkey_names(python_key): 49 | 50 | print 'version_name:', version_name 51 | 52 | key = OpenKey(python_key, version_name) 53 | modification_date = QueryInfoKey(key)[2] 54 | 55 | print key, modification_date 56 | 57 | install_path = QueryValue(key, version_name + '\\installpath') 58 | # on Win7x64-pro fails with "WindowsError: [Error 2] The system cannot find the file specified" 59 | # because should be opening wow6432 instead?? 60 | # to read: @url http://docs.python.org/library/_winreg.html#bit-specific 61 | print install_path 62 | 63 | L.append((modification_date, version_name, install_path)) 64 | return L 65 | 66 | #@-others 67 | list_keys() 68 | #@-leo 69 | -------------------------------------------------------------------------------- /register-python/list-registry.py: -------------------------------------------------------------------------------- 1 | # File: winreg-example-1.py 2 | from _winreg import * 3 | 4 | explorer = OpenKey( 5 | HKEY_CURRENT_USER, 6 | "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer" 7 | ) 8 | 9 | # list values owned by this registry key 10 | try: 11 | i = 0 12 | while 1: 13 | name, value, type = EnumValue(explorer, i) 14 | print repr(name), 15 | i += 1 16 | except WindowsError: 17 | print 18 | 19 | value, type = QueryValueEx(explorer, "Logon User Name") 20 | 21 | print 22 | print "user is", repr(value) 23 | 24 | -------------------------------------------------------------------------------- /register-python/register-python.bat: -------------------------------------------------------------------------------- 1 | @python register-python.py %* -------------------------------------------------------------------------------- /register-python/samples/hkcu_py-reg_d-drive.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/register-python/samples/hkcu_py-reg_d-drive.reg -------------------------------------------------------------------------------- /register-python/samples/hklm_o4wpy-reg_23.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/register-python/samples/hklm_o4wpy-reg_23.reg -------------------------------------------------------------------------------- /register-python/samples/hklm_o4wpy-reg_d-drive.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/register-python/samples/hklm_o4wpy-reg_d-drive.reg -------------------------------------------------------------------------------- /register-python/samples/hklm_x64_default_install.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/register-python/samples/hklm_x64_default_install.reg -------------------------------------------------------------------------------- /register-python/samples/hklm_x64_py27.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/register-python/samples/hklm_x64_py27.reg -------------------------------------------------------------------------------- /register-python/samples/hklm_x64_pyqt4_py27.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/register-python/samples/hklm_x64_pyqt4_py27.reg -------------------------------------------------------------------------------- /register-python/samples/py25_x32_default_install.reg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maphew/mhwcode/5dadd78280fd20b5280727017624a269c80aeac3/register-python/samples/py25_x32_default_install.reg -------------------------------------------------------------------------------- /register-python/switch-python.py: -------------------------------------------------------------------------------- 1 | #@+leo-ver=5-thin 2 | #@+node:maphew.20110928212851.1387: * @file switch-python.py 3 | #@verbatim 4 | #@url http://nedbatchelder.com/blog/200810/switching_python_versions_on_windows.html 5 | #url http://stackoverflow.com/questions/1845650/python-windowserror-when-editing-registry-values-using-winreg-on-windows-7 6 | """ Change the .py file extension to point to a different 7 | Python installation. 8 | """ 9 | import _winreg as reg 10 | import sys 11 | 12 | pydir = sys.argv[1] 13 | 14 | todo = [ 15 | ('Applications\python.exe\shell\open\command', 16 | '"PYDIR\\python.exe" "%1" %*'), 17 | ('Applications\pythonw.exe\shell\open\command', 18 | '"PYDIR\\pythonw.exe" "%1" %*'), 19 | ('Python.CompiledFile\DefaultIcon', 20 | 'PYDIR\\pyc.ico'), 21 | ('Python.CompiledFile\shell\open\command', 22 | '"PYDIR\\python.exe" "%1" %*'), 23 | ('Python.File\DefaultIcon', 24 | 'PYDIR\\py.ico'), 25 | ('Python.File\shell\open\command', 26 | '"PYDIR\\python.exe" "%1" %*'), 27 | ('Python.NoConFile\DefaultIcon', 28 | 'PYDIR\\py.ico'), 29 | ('Python.NoConFile\shell\open\command', 30 | '"PYDIR\\pythonw.exe" "%1" %*'), 31 | ] 32 | 33 | classes_root = reg.OpenKey(reg.HKEY_CLASSES_ROOT, "") 34 | for path, value in todo: 35 | key = reg.OpenKey(classes_root, path, 0, reg.KEY_SET_VALUE) 36 | reg.SetValue(key, '', reg.REG_SZ, value.replace('PYDIR', pydir)) 37 | #@-leo 38 | -------------------------------------------------------------------------------- /register-python/walk-registry.py: -------------------------------------------------------------------------------- 1 | #http://timgolden.me.uk/python-on-windows/programming-areas/registry/walk-the-registry.html 2 | 3 | import _winreg 4 | 5 | def walk (top, writeable=False): 6 | """walk the registry starting from the key represented by 7 | top in the form HIVE\\key\\subkey\\..\\subkey and generating 8 | (key_name, key), subkey_names, values at each level. 9 | 10 | subkey_names are simply names of the subkeys of that key 11 | values are 3-tuples containing (name, data, data-type). 12 | See the documentation for _winreg.EnumValue for more details. 13 | """ 14 | keymode = _winreg.KEY_READ 15 | if writeable: 16 | keymode |= _winreg.KEY_SET_VALUE 17 | if "\\" not in top: top += "\\" 18 | root, subkey = top.split ("\\", 1) 19 | key = _winreg.OpenKey (getattr (_winreg, root), subkey, 0, keymode) 20 | 21 | subkeys = [] 22 | i = 0 23 | while True: 24 | try: 25 | subkeys.append (_winreg.EnumKey (key, i)) 26 | i += 1 27 | except EnvironmentError: 28 | break 29 | 30 | values = [] 31 | i = 0 32 | while True: 33 | try: 34 | values.append (_winreg.EnumValue (key, i)) 35 | i += 1 36 | except EnvironmentError: 37 | break 38 | 39 | yield (top, key), subkeys, values 40 | for subkey in subkeys: 41 | for result in walk (top.rstrip ("\\") + "\\" + subkey, writeable): 42 | yield result 43 | 44 | 45 | 46 | if __name__ == '__main__': 47 | keypath = r"HKEY_CURRENT_USER\Software\Python" 48 | for (key_name, key), subkey_names, values in walk (keypath): 49 | level = key_name.count ("\\") 50 | print " " * level, key_name 51 | for name, data, datatype in values: 52 | print " ", " " * level, name, "=>", data 53 | print 54 | 55 | -------------------------------------------------------------------------------- /register-python/win-specialfolders.py: -------------------------------------------------------------------------------- 1 | ''' Get windows special folders without pythonwin 2 | Example: 3 | import win-specialfolders 4 | start_programs = win-specialfolders.get(win-specialfolders.PROGRAMS) 5 | 6 | Code is public domain, do with it what you will. 7 | 8 | Luke Pinner - Environment.gov.au, 2010 February 10 9 | ''' 10 | 11 | #Imports use _syntax to mask them from autocomplete IDE's 12 | import ctypes as _ctypes 13 | from ctypes.wintypes import HWND as _HWND, HANDLE as _HANDLE,DWORD as _DWORD,LPCWSTR as _LPCWSTR,MAX_PATH as _MAX_PATH, create_unicode_buffer as _cub 14 | _SHGetFolderPath = _ctypes.windll.shell32.SHGetFolderPathW 15 | 16 | #public special folder constants 17 | DESKTOP= 0 18 | PROGRAMS= 2 19 | MYDOCUMENTS= 5 20 | FAVORITES= 6 21 | STARTUP= 7 22 | RECENT= 8 23 | SENDTO= 9 24 | STARTMENU= 11 25 | MYMUSIC= 13 26 | MYVIDEOS= 14 27 | NETHOOD= 19 28 | FONTS= 20 29 | TEMPLATES= 21 30 | ALLUSERSSTARTMENU= 22 31 | ALLUSERSPROGRAMS= 23 32 | ALLUSERSSTARTUP= 24 33 | ALLUSERSDESKTOP= 25 34 | APPLICATIONDATA= 26 35 | PRINTHOOD= 27 36 | LOCALSETTINGSAPPLICATIONDATA= 28 37 | ALLUSERSFAVORITES= 31 38 | LOCALSETTINGSTEMPORARYINTERNETFILES=32 39 | COOKIES= 33 40 | LOCALSETTINGSHISTORY= 34 41 | ALLUSERSAPPLICATIONDATA= 35 42 | 43 | def get(intFolder): 44 | _SHGetFolderPath.argtypes = [_HWND, _ctypes.c_int, _HANDLE, _DWORD, _LPCWSTR] 45 | auPathBuffer = _cub(_MAX_PATH) 46 | exit_code=_SHGetFolderPath(0, intFolder, 0, 0, auPathBuffer) 47 | return auPathBuffer.value 48 | -------------------------------------------------------------------------------- /register-python/xx-parse.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: latin-1 -*-# 3 | #@+leo-ver=5-thin 4 | #@+node:maphew.20110914213235.1222: * @file xx-parse.py 5 | #@@first 6 | #@@first 7 | #@@language python 8 | #@@tabwidth -4 9 | #@+others 10 | #@+node:maphew.20110914213235.1221: ** parse command line 11 | #@verbatim 12 | #@url http://www.doughellmann.com/PyMOTW/argparse/ 13 | import argparse, sys 14 | 15 | # @url http://stackoverflow.com/questions/4042452/display-help-message-with-python-argparse-when-script-is-called-without-any-argum 16 | # display the usage message when it is called with no arguments 17 | class MyParser(argparse.ArgumentParser): 18 | def error(self, message): 19 | sys.stderr.write('error: %s\n' % message) 20 | self.print_help() 21 | sys.exit(2) 22 | 23 | parser=MyParser() 24 | parser.add_argument('action', help='one of "install" or "remove" ') 25 | args = vars(parser.parse_args()) 26 | 27 | #@-others 28 | #@-leo 29 | -------------------------------------------------------------------------------- /scrapbook/tag2semver.py: -------------------------------------------------------------------------------- 1 | '''Something I wrote while trying to figure out how use Leo-Editor's git tags for PEP440 valid release names to upload to PyPi. 2 | Implemented in Leo round about here https://github.com/leo-editor/leo-editor/commit/c8835d9aa4a609cba2f7f40b6393e44764684d7f 3 | ''' 4 | import semantic_version 5 | print('=== Extracting semantic version from git tags ===') 6 | 7 | # captured from `git tags > git-tags.txt` 8 | tags='''4-11-a2 5.3 5.4 5.4-b1 5.4.1 5.5 5.5b1 5.6 5.6b1 5.7b1 Bug-135 Bug-149-stage-0-complete Fixed-bug-149 Leo-4-4-8-b1 Leo-4-5-b1 Leo-4-5-b2 Leo-4-5-b3 Leo-5.0-a1 Leo-5.0-a2 Leo-5.0-b1 Leo-5.0-b2 Leo-5.0-final Leo-5.1-b1 Leo-5.1-b2 Leo-5.1-final before-moving-parents-to-vnode before-open-with-work before-until-4-7-final before_unicode_mass_update breaks-auto-completer broke-abbrev last-good-commit last-good-vim last_working_recursive_import leo-4-10-b1 leo-4-10-final leo-4-11-a1 leo-4-11-b1 leo-4-11-final leo-4-4-8-b2 leo-4-4-8-b3 leo-4-4-8-final leo-4-4-8-rc1 leo-4-4-8-rc1-a leo-4-5-1-august-14-2008 leo-4-5-1-final leo-4-5-b4 leo-4-5-final leo-4-5-rc1 leo-4-5-rc2 leo-4-6-1-final-released leo-4-6-2 leo-4-6-b1 leo-4-6-b2 leo-4-6-rc1 leo-4-7-1-final leo-4-7-b1 leo-4-7-b2 leo-4-7-b2-as-released leo-4-7-b3 leo-4-7-final leo-4-7-rc1 leo-4-7-rc1-a leo-4-7-rc1-b leo-4-8-a1 leo-4-8-b1 leo-4-8-final leo-4-8-rc1 leo-4-9-b1 leo-4-9-b2 leo-4-9-b4 leo-4-9-final leo-4-9-rc1 leo-4-9-rc1-a leo-5.0-a1 old-rst-code-last-rev v5.2 v5.3'''.split() 9 | 10 | valid = {} 11 | skipped = [] 12 | for t in tags: 13 | try: 14 | tc = t 15 | if t.lower().startswith('leo-'): tc = t[4:] 16 | if t.lower().startswith('v'): tc = t[1:] 17 | v = semantic_version.Version.coerce(tc, partial=True) 18 | valid[t] = tc 19 | except ValueError: 20 | skipped.append(t) 21 | 22 | print('\n--- PARSED ---\n') 23 | longest = len(max(valid.keys(), key=len)) # length of longest element in list 24 | for k,v in valid.items(): 25 | print('{0:<{1}} -->\t{2}'.format(k,longest,v)) 26 | 27 | print('\n--- SKIPPED ---\n') 28 | [print(x) for x in skipped] 29 | 30 | def thankyou(): 31 | print('''Thank you to: 32 | @Paolo_Bergantino, longest item in list: 33 | https://stackoverflow.com/questions/873327/pythons-most-efficient-way-to-choose-longest-string-in-list 34 | @EbraHim, use variable in format string: 35 | https://stackoverflow.com/questions/36962995/format-in-python-by-variable-length 36 | ''') 37 | # (c) 2018 Matt Wilkie, maphew@gmail.com 38 | # License: X/MIT Open Source 39 | -------------------------------------------------------------------------------- /tools/Readme.md: -------------------------------------------------------------------------------- 1 | # Tools 2 | 3 | Ready to run scripts that do something. 4 | 5 | Typical usage: 6 | 7 | uv run foobar.py ... 8 | 9 | -------------------------------------------------------------------------------- /win-remote-reboot.ps1: -------------------------------------------------------------------------------- 1 | # Installs everything needed to reboot a remote machine and then reboots the 2 | # machine. 3 | # ugly and inelegant. they should be completely separate activities. Maybe 4 | # I'll rewrite properly later. 5 | param( 6 | $machine 7 | ) 8 | 9 | if (!$machine) { 10 | Write-Host "`n-={ Reboot remote machine }=- Read inline comments for more info. Usage: `n`n$($MyInvocation.MyCommand.Name) [machine-name]`n" 11 | exit 12 | } 13 | # Might need to set this policy before running the script for the rest to work: 14 | # Set-ExecutionPolicy RemoteSigned -Scope CurrentUser 15 | irm get.scoop.sh | iex 16 | scoop install git 17 | git config --global credential.helper manager-core 18 | %USERPROFILE%\scoop\apps\7zip\current\install-context.reg 19 | Scoop bucket add extras 20 | Scoop install sysinternals 21 | 22 | $env:remote = $machine 23 | 24 | Psinfo \\$env:remote 25 | 26 | Psshutdown -rf \\$env:remote 27 | 28 | Ping -t $env:remote 29 | --------------------------------------------------------------------------------