From d18b03aa00c01ded121f2a5220d555f2b707629d Mon Sep 17 00:00:00 2001 From: Tom Russo Date: Wed, 8 Nov 2017 15:03:57 -0700 Subject: [PATCH 1/8] Updates SQL where statement-Line 74 Updates SQL where statement for acquiring Lead Agency information --- Tools/Scripts/IGT4SAR_MissingPersonForm.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Tools/Scripts/IGT4SAR_MissingPersonForm.py b/Tools/Scripts/IGT4SAR_MissingPersonForm.py index cd33752..f60ecb5 100644 --- a/Tools/Scripts/IGT4SAR_MissingPersonForm.py +++ b/Tools/Scripts/IGT4SAR_MissingPersonForm.py @@ -33,6 +33,7 @@ import IGT4SAR_fdf def checkNoneType(variable, varName): + arcpy.AddMessage("variable Name: {}".format(variable)) if type(variable) is NoneType: arcpy.AddWarning(varName + " is not defined") result = " " @@ -63,21 +64,18 @@ def checkNoneType(variable, varName): k+=1 if type(row.getValue("Lead_Agency")) is NoneType: LeadAgency = " " + Phone=" " + email=" " else: LeadAgency = row.getValue("Lead_Agency") - where2 = '"Lead_Agency" = ' + "'" + LeadAgency + "'" - rows2 = arcpy.SearchCursor(fc2, where2) - row2 = rows2.next() - - while row2: - # you need to insert correct field names in your getvalue function + where2="".join(['"Lead_Agency"=', "'", LeadAgency, "'"]) + arcpy.AddMessage(where2) + rows2 = arcpy.SearchCursor(fc2,where2) + for row2 in rows2: Phone = checkNoneType(row2.getValue("Lead_Phone"), '"Reporting Phone Number"') email = checkNoneType(row2.getValue("E_Mail"), '"Reporting e-mail"') - row2 = rows2.next() - del rows2 - del row2 - Callback = "If you have information please call: " + str(LeadAgency) + " at phone: " + str(Phone) + " or e-mail:" + str(email) + Callback = ("If you have information please call: {} at phone: {} or e-mail: {}".format(str(LeadAgency), str(Phone), str(email))) row = rows.next() del rows del row @@ -187,4 +185,4 @@ def checkNoneType(variable, varName): row = rows.next() del rows del row - #arcpy.DeleteFeatures_management(fc3) \ No newline at end of file + #arcpy.DeleteFeatures_management(fc3) From 5edc3ba4ede54a59b6fad23ddcad86e1ba10d6fb Mon Sep 17 00:00:00 2001 From: Tom Russo Date: Wed, 8 Nov 2017 15:13:57 -0700 Subject: [PATCH 2/8] updated for 10.6 updated install / uninstall for 10.5 and 10.6 --- ~LoadMapSAREXTools.bat | 2 ++ ~UninstallMapSAREXTools.bat | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/~LoadMapSAREXTools.bat b/~LoadMapSAREXTools.bat index 2dc2d1e..b2bfb07 100644 --- a/~LoadMapSAREXTools.bat +++ b/~LoadMapSAREXTools.bat @@ -36,6 +36,8 @@ IF EXIST "%_programs%\ArcGIS\Desktop10.1\License" CALL :install "%_programs%\Arc IF EXIST "%_programs%\ArcGIS\Desktop10.2\License" CALL :install "%_programs%\ArcGIS\Desktop10.2" IF EXIST "%_programs%\ArcGIS\Desktop10.3\License" CALL :install "%_programs%\ArcGIS\Desktop10.3" IF EXIST "%_programs%\ArcGIS\Desktop10.4\License" CALL :install "%_programs%\ArcGIS\Desktop10.4" +IF EXIST "%_programs%\ArcGIS\Desktop10.5\License" CALL :install "%_programs%\ArcGIS\Desktop10.5" +IF EXIST "%_programs%\ArcGIS\Desktop10.6\License" CALL :install "%_programs%\ArcGIS\Desktop10.6" set _config="%APPDATA%\ArcGIS4LocalGovernment\ConfigFiles" IF NOT EXIST %_config% ( diff --git a/~UninstallMapSAREXTools.bat b/~UninstallMapSAREXTools.bat index d45fc8a..f4450b9 100644 --- a/~UninstallMapSAREXTools.bat +++ b/~UninstallMapSAREXTools.bat @@ -33,7 +33,9 @@ IF EXIST "%_programs%\ArcGIS\Desktop10.0\License" CALL :remove "%_programs%\ArcG IF EXIST "%_programs%\ArcGIS\Desktop10.1\License" CALL :remove "%_programs%\ArcGIS\Desktop10.1" IF EXIST "%_programs%\ArcGIS\Desktop10.2\License" CALL :remove "%_programs%\ArcGIS\Desktop10.2" IF EXIST "%_programs%\ArcGIS\Desktop10.3\License" CALL :remove "%_programs%\ArcGIS\Desktop10.3" -IF EXIST "%_programs%\ArcGIS\Desktop10.1\License" CALL :remove "%_programs%\ArcGIS\Desktop10.4" +IF EXIST "%_programs%\ArcGIS\Desktop10.4\License" CALL :remove "%_programs%\ArcGIS\Desktop10.4" +IF EXIST "%_programs%\ArcGIS\Desktop10.5\License" CALL :remove "%_programs%\ArcGIS\Desktop10.5" +IF EXIST "%_programs%\ArcGIS\Desktop10.6\License" CALL :remove "%_programs%\ArcGIS\Desktop10.6" del "%APPDATA%\ArcGIS4LocalGovernment\ConfigFiles\loaded.config" From 683598f9557ca1c38024f71a1a6ece300a9c2e2d Mon Sep 17 00:00:00 2001 From: Tom Russo Date: Wed, 8 Nov 2017 15:17:31 -0700 Subject: [PATCH 3/8] updated typos --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e92766..5a98da5 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ http://www.youtube.com/channel/UCrWNjhnpNOiEAATDzNw3lFg Installation ============ -The installation process for IGT4SAR doe snot include an edit to the registry that would let Windows know where the folders are located. Becuase some of the scripts include with IGT4SAR rely on knowing where IGT4SAR has been installed, you must install IGT4SAR in the following folder: "C:\MapSAR_Ex". +The installation process for IGT4SAR does not include an edit to the registry that would let Windows know where the folders are located. Becuase some of the scripts include with IGT4SAR rely on knowing where IGT4SAR has been installed, you must install IGT4SAR in the following folder: "C:\MapSAR_Ex". When downloading the zip from GitHub the zip file is name "MapSAR_Ex-master.zip. This creates a problem when unzipping the file as it will create a folder called "MapSAR_Ex-master" as opposed to the required "MapSAR_Ex". To correct this problem, merely rename the unzipped folder MapSAR_Ex and place it in your root directory. Once properly installed you should have the following: From 56d8720f555b313c790e0dc3dfb620410c296391 Mon Sep 17 00:00:00 2001 From: Tom Russo Date: Wed, 8 Nov 2017 15:18:30 -0700 Subject: [PATCH 4/8] Updated mapbook tool Added error checking in case text objects were missing or replaced on the template layout. --- Tools/Scripts/IGT4SAR_Mapbook.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Tools/Scripts/IGT4SAR_Mapbook.py b/Tools/Scripts/IGT4SAR_Mapbook.py index e40ee39..a316292 100644 --- a/Tools/Scripts/IGT4SAR_Mapbook.py +++ b/Tools/Scripts/IGT4SAR_Mapbook.py @@ -150,10 +150,6 @@ def CreatingMap(fcOut, gRids, mxd, df, mapScale, output): except: pass - UTMZn=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "UTMZone")[0] - USNGZn=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "USNGZone")[0] - MagDeclin=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MagDecl")[0] - mkLyr=arcpy.mapping.ListLayers(mxd, fcOut,df)[0] for llyr in arcpy.mapping.ListLayers(mxd, "*",df): if str(llyr.name) == "MRGS_UTM_USNG": @@ -172,16 +168,27 @@ def CreatingMap(fcOut, gRids, mxd, df, mapScale, output): rows7=arcpy.SearchCursor(mapLyr) row7 = rows7.next() + try: + UTMZn=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "UTMZone")[0] UTMZn.text = row7.getValue("GRID1MIL") + except: + pass + try: + USNGZn=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "USNGZone")[0] UtmZone=UTMZn.text USNGZn.text = row7.getValue("GRID100K") UsngGrid = USNGZn.text except: - arcpy.AddMessage("No update to UTM Zone or USNG Grid") + pass + except: pass MapName.text = key + try: + MagDeclin=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MagDecl")[0] MagDeclin.text = gRids[key][2] + except: + pass ##arcpy.AddMessage("UTM Zone is " + UTMZn.text + " and USNG Grid is " + USNGZn.text) From 1aaba95de23a6f43746f5a5d289ba34a0fdca018 Mon Sep 17 00:00:00 2001 From: Tom Russo Date: Wed, 8 Nov 2017 15:41:03 -0700 Subject: [PATCH 5/8] Revert "Updated mapbook tool" This reverts commit 6d604d8bb26a41c79fa3c87284b8b22cf47fdb23. --- Tools/Scripts/IGT4SAR_Mapbook.py | 779 +++++++++++++++---------------- 1 file changed, 386 insertions(+), 393 deletions(-) diff --git a/Tools/Scripts/IGT4SAR_Mapbook.py b/Tools/Scripts/IGT4SAR_Mapbook.py index 8f8ed03..e40ee39 100644 --- a/Tools/Scripts/IGT4SAR_Mapbook.py +++ b/Tools/Scripts/IGT4SAR_Mapbook.py @@ -1,394 +1,387 @@ -#------------------------------------------------------------------------------- -# Name: IGT4SAR_MapBook.py -# Purpose: Create Task Assignment Forms from selected rows in the -# Assignments data layer. New TAFs are stored by Task ID in the -# Assignments folder -# -# Author: Don Ferguson -# -# Created: 02/15/2015 -# Copyright: (c) Don Ferguson 2015 -# Licence: -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# The GNU General Public License can be found at -# . -#------------------------------------------------------------------------------- -try: - arcpy -except NameError: - import arcpy -try: - sys -except NameError: - import sys -import geomag -from types import * - -# Environment variables -wrkspc=arcpy.env.workspace -arcpy.env.overwriteOutput = "True" -arcpy.env.extent = "MAXOF" - - -def getDataframe(): - """ get current mxd and dataframe returns mxd, frame""" - try: - mxd = arcpy.mapping.MapDocument('CURRENT');df = arcpy.mapping.ListDataFrames(mxd,"*")[0] - - return(mxd,df) - - except SystemExit as err: - pass - -def checkNoneType(variable): - if type(variable) is NoneType: - result = "" - else: - result = variable - return result - -def checkFields(fc, fldName, fldType): - desc=arcpy.Describe(fc) - # Get a list of field names from the feature - fieldsList = desc.fields - field_names=[f.name for f in fieldsList] - if fldName not in field_names: - arcpy.AddField_management (fc, fldName, fldType) - return - -def gNorth_Check(fc, fldName, fldType,unProjCoordSys): - - checkFields(fc, fldName, fldType) - arcpy.CalculateGridConvergenceAngle_cartography(fc,fldName, "GEOGRAPHIC") - - rows0 = arcpy.SearchCursor(fc, '', unProjCoordSys) - k = 0.0 - gridNorth = 0.0 - for row0 in rows0: - gridN = row0.getValue(fld_gNorth) - arcpy.AddMessage('Grid North: {0}'.format(gridN)) - gridNorth += float(gridN) - k+=1.0 - - gridN = round((gridNorth / k),2) - del row0 - del rows0 - del k - # Remove field - dropField=[fld_gNorth] - arcpy.DeleteField_management(fc, dropField) - - if gridN > 0: - gCard ="W" - else: - gCard ="E" - return(str(abs(gridN)) + " " + gCard) - -def MagDeclin(gLat, gLong): - declin = geomag.declination(gLat,gLong) - MagDeclinlination = round(declin,2) - if MagDeclinlination < 0: - Cardinal ="W" - else: - Cardinal ="E" - MagDecTxt = str(abs(MagDeclinlination)) + " " + Cardinal - return(MagDecTxt) - - -def GetXY(inputFC, poly_Height, poly_Width, lenConv, sCale, nCol, nRow): - desc = arcpy.Describe(inputFC) - shpType = desc.shapeType ## Determine if the input Feature is Polygon, Polyline or Point - shapefieldname = desc.ShapeFieldName - nAme=desc.name - - centreX = [] - centreY = [] - cursor = arcpy.SearchCursor(inputFC) - for row in cursor: - feat = row.getValue(shapefieldname) - if shpType.upper()=='POINT': - centroid = feat.getPart() - elif (shpType.upper() =="POLYGON") or (shpType.upper() == "POLYLINE"): - centroid = feat.trueCentroid - centreX.append(centroid.X) - centreY.append(centroid.Y) - - meanX = int(float(sum(centreX))/len(centreX)) if len(centreX) > 0 else float('nan') - meanY = int(float(sum(centreY))/len(centreY)) if len(centreY) > 0 else float('nan') - - arcpy.AddMessage("Check: {0}".format(str(sCale/lenConv*nRow/2.0))) - - - xMin = meanX - (poly_Width/lenConv)*sCale*nCol/2.0 - yMin = meanY - (poly_Height/lenConv)*sCale*nRow/2.0 - - return(xMin, yMin) - -def CreatingMap(fcOut, gRids, mxd, df, mapScale, output): - ## Get a list of PageNames - try: - PlanNum=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "PlanNum")[0] - PlanNum.text = " " - except: - pass - try: - AssignNum=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "AssignNum")[0] - AssignNum.text = " " - except: - pass - try: - MapName=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapName")[0] - except: - pass - - mkLyr=arcpy.mapping.ListLayers(mxd, fcOut,df)[0] - for llyr in arcpy.mapping.ListLayers(mxd, "*",df): - if str(llyr.name) == "MRGS_UTM_USNG": - mapLyr=arcpy.mapping.ListLayers(mxd, "MRGS_UTM_USNG",df)[0] - elif str(llyr.name) == "MRGSZones_World": - mapLyr=arcpy.mapping.ListLayers(mxd, "MGRSZones_World",df)[0] - - - for key in gRids: - where4 = ('"PageName" = ' + "'" + key + "'") - arcpy.AddMessage("{0}, MagDec = {1}".format(where4, gRids[key][2])) - arcpy.SelectLayerByAttribute_management (mkLyr, "NEW_SELECTION", where4) - df.zoomToSelectedFeatures() - try: - arcpy.SelectLayerByLocation_management(mapLyr,"INTERSECT",mkLyr) - - rows7=arcpy.SearchCursor(mapLyr) - row7 = rows7.next() - try: - UTMZn=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "UTMZone")[0] - UTMZn.text = row7.getValue("GRID1MIL") - except: - pass - try: - USNGZn=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "USNGZone")[0] - UtmZone=UTMZn.text - USNGZn.text = row7.getValue("GRID100K") - UsngGrid = USNGZn.text - except: - pass - except: - pass - - MapName.text = key - try: - MagDeclin=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MagDecl")[0] - MagDeclin.text = gRids[key][2] - except: - pass - - ##arcpy.AddMessage("UTM Zone is " + UTMZn.text + " and USNG Grid is " + USNGZn.text) - - arcpy.SelectLayerByAttribute_management (mapLyr, "CLEAR_SELECTION") - - - arcpy.SelectLayerByAttribute_management (mkLyr, "CLEAR_SELECTION") - - mxd.activeView='PAGE_LAYOUT' - - if mapScale > 0: - pScaler = mapScale - df.scale = pScaler*1.0 - else: - df.scale = 24000.0 - mkLyr.visible = False - arcpy.RefreshActiveView() - outFile = output + "/" + str(key) + "_MAP.pdf" - mkLyr.visible = True - - - try: - arcpy.mapping.ExportToPDF(mxd, outFile) - except: - arcpy.AddWarning(" ") - arcpy.AddWarning("Unable to produce map for Assignment: " + str(key)) - arcpy.AddWarning("Problem with ExportToPDF") - arcpy.AddWarning(" ") - - arcpy.SelectLayerByAttribute_management (mkLyr, "CLEAR_SELECTION") - return - - - -if __name__ == '__main__': - ####### - #Automate map production - July 27, 2012 - mxd, df = getDataframe() - - ## Input parameters - ## inputFC - This is the feature you wish to build the mapbook around. Preferrably this could be the PLS or LKP. If the desired feature class contains mulitple features than you must - ## select a single feature otherwise mapbooks will be created around each feature. Can be points, lines, polygons, or rasters. - ## sCale = Scale must be specified in real world inches (e.g 24000 for 1:24000) - ## - ## nRow = Number of rows to create in the y direction from the point of origin. - ## nCol = Number of columns to create in the x direction from the point of origin. - ## - - inputFC = arcpy.GetParameterAsText(0) - sCale = float(arcpy.GetParameterAsText(1)) - nRow = float(arcpy.GetParameterAsText(2)) - nCol = float(arcpy.GetParameterAsText(3)) - output = arcpy.GetParameterAsText(4) - output = output.replace("'\'","/") - - ## First we need to build the grid - dfSpatial_Type = df.spatialReference.type - if dfSpatial_Type.upper() != 'PROJECTED': - arcpy.AddError('Must have a projected coordinate system') - sys.exit(1) - - ## Check to see if the layer exists...if so delete it - - - poly_Width= df.elementWidth - poly_Height = df.elementHeight - - mapUnits = df.mapUnits - lenConv=1.0 - if mapUnits == 'Meters': - lenConv = 39.37 #inches to meters - elif mapUnits == 'Feet': - lenConv = 12.0 #inches to feet - elif mapUnits == 'Inches': - lenConv = 1.0 #inches to inches - else: - sys.exit(0) - - - xMin, yMin = GetXY(inputFC, poly_Height, poly_Width, lenConv, int(sCale), nCol, nRow) - - originCoord = "{0} {1}".format(str(xMin), str(yMin)) - arcpy.AddMessage("SW coordinates are: {0}".format(originCoord)) - desc=arcpy.Describe(inputFC) - nAme = desc.name - fcOut = "GRID_{0}_{1}".format(nAme, str(int(sCale))) - - arcpy.GridIndexFeatures_cartography (fcOut, "", "", "USEPAGEUNIT", sCale, "", "", originCoord, nRow, nCol) - - unProjCoordSys = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]" - - #First determine the grid north value - fld_gNorth = "gNORTH" - field_type = "FLOAT" - gNorthTxt=gNorth_Check(inputFC, fld_gNorth, field_type, unProjCoordSys) - try: - df.rotation = 0.0 - if arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "gNorth"): - gridNorth=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "gNorth")[0] - gridNorth.text = gNorthTxt - except: - pass - - layerOn=False - - if arcpy.Exists(fcOut): - arcpy.MakeFeatureLayer_management(fcOut,fcOut) - mkLyr = arcpy.mapping.Layer(fcOut) - mkLyr.name=fcOut - arcpy.mapping.RemoveLayer(df,mkLyr) - arcpy.mapping.AddLayer(df,mkLyr,"TOP") - - try: - lyr = arcpy.mapping.ListLayers(mxd, mkLyr.name, df)[0] - symbologyLayer = r"C:\MapSAR_Ex\Tools\Layers Files - Local\Layer Groups\MapBookGrid.lyr" - refGroupLayerA = "Grids" - if refGroupLayerA in arcpy.mapping.ListLayers(mxd,"",df)[0].name: - arcpy.mapping.AddLayerToGroup(df,refGroupLayerA,lyr,'TOP') - arcpy.ApplySymbologyFromLayer_management(lyr, symbologyLayer) - ext=lyr.getExtent() - df.extent = ext - outFile = output + "/" + "MapBookGrid.pdf" - if lyr.supports("LABELCLASSES"): - for lblclass in lyr.labelClasses: - lblclass.showClassLabels = True - lblclass.expression = '"%s" & [PageName] & "%s"' % ("", "") - layerOn=True - lyr.visible = True - lyr.showLabels = True - if arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapName"): - MapName=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapName")[0] - MapName.text = "Mapbook Index" - arcpy.RefreshActiveView() - try: - arcpy.mapping.ExportToPDF(mxd, outFile) - except: - pass - lyr.visible = False - lyr.showLabels = False - except: - pass - - - #Get the Lat / Long, magDeclination for each GRID - desc = arcpy.Describe(fcOut) - shapefieldname = desc.ShapeFieldName - gRids={} - cGrid=arcpy.GetCount_management(fcOut) - if int(cGrid.getOutput(0)) > 0: - cursor1 = arcpy.SearchCursor(fcOut, '', unProjCoordSys) - for row1 in cursor1: - gName = row1.getValue("PageName") - feat = row1.getValue(shapefieldname) - centroid = feat.trueCentroid - gLat = centroid.Y - gLong = centroid.X - magDec = MagDeclin(gLat, gLong) - gRids[gName]=[gLat, gLong, magDec] - arcpy.AddMessage("{0}, magDec = {1}".format(gName, magDec)) - - - - ############################## - # Print Maps for each grid - ############################## -## Need to do some major re-work. Need to determine the MagDec and UTM details for each -## grid square within the GRID. Once the GRID is created, get a list of coordinates for the centroid -## of each grid. Run the Mag Dec (see IGT4SAR_updateLayout.py) for each and create the following dictionary: -## GRID[PageName]={magDec, UTM Zone, USNG Zone, Incident Name, Incident Number} -## Send this info to module for printing map - - CreatingMap(fcOut, gRids, mxd, df, int(sCale), output) - - try: - PlanNum=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "PlanNum")[0] - PlanNum.text = " " - except: - pass - try: - AssignNum=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "AssignNum")[0] - AssignNum.text = " " - except: - pass - try: - MapName=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapName")[0] - MapName.text=" " - except: - pass - - - if layerOn==True: - lyr.visible = True - lyr.showLabels = True - - -## Zom to the extent of the Fishnet and create index map - - - - - - +#------------------------------------------------------------------------------- +# Name: IGT4SAR_MapBook.py +# Purpose: Create Task Assignment Forms from selected rows in the +# Assignments data layer. New TAFs are stored by Task ID in the +# Assignments folder +# +# Author: Don Ferguson +# +# Created: 02/15/2015 +# Copyright: (c) Don Ferguson 2015 +# Licence: +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# The GNU General Public License can be found at +# . +#------------------------------------------------------------------------------- +try: + arcpy +except NameError: + import arcpy +try: + sys +except NameError: + import sys +import geomag +from types import * + +# Environment variables +wrkspc=arcpy.env.workspace +arcpy.env.overwriteOutput = "True" +arcpy.env.extent = "MAXOF" + + +def getDataframe(): + """ get current mxd and dataframe returns mxd, frame""" + try: + mxd = arcpy.mapping.MapDocument('CURRENT');df = arcpy.mapping.ListDataFrames(mxd,"*")[0] + + return(mxd,df) + + except SystemExit as err: + pass + +def checkNoneType(variable): + if type(variable) is NoneType: + result = "" + else: + result = variable + return result + +def checkFields(fc, fldName, fldType): + desc=arcpy.Describe(fc) + # Get a list of field names from the feature + fieldsList = desc.fields + field_names=[f.name for f in fieldsList] + if fldName not in field_names: + arcpy.AddField_management (fc, fldName, fldType) + return + +def gNorth_Check(fc, fldName, fldType,unProjCoordSys): + + checkFields(fc, fldName, fldType) + arcpy.CalculateGridConvergenceAngle_cartography(fc,fldName, "GEOGRAPHIC") + + rows0 = arcpy.SearchCursor(fc, '', unProjCoordSys) + k = 0.0 + gridNorth = 0.0 + for row0 in rows0: + gridN = row0.getValue(fld_gNorth) + arcpy.AddMessage('Grid North: {0}'.format(gridN)) + gridNorth += float(gridN) + k+=1.0 + + gridN = round((gridNorth / k),2) + del row0 + del rows0 + del k + # Remove field + dropField=[fld_gNorth] + arcpy.DeleteField_management(fc, dropField) + + if gridN > 0: + gCard ="W" + else: + gCard ="E" + return(str(abs(gridN)) + " " + gCard) + +def MagDeclin(gLat, gLong): + declin = geomag.declination(gLat,gLong) + MagDeclinlination = round(declin,2) + if MagDeclinlination < 0: + Cardinal ="W" + else: + Cardinal ="E" + MagDecTxt = str(abs(MagDeclinlination)) + " " + Cardinal + return(MagDecTxt) + + +def GetXY(inputFC, poly_Height, poly_Width, lenConv, sCale, nCol, nRow): + desc = arcpy.Describe(inputFC) + shpType = desc.shapeType ## Determine if the input Feature is Polygon, Polyline or Point + shapefieldname = desc.ShapeFieldName + nAme=desc.name + + centreX = [] + centreY = [] + cursor = arcpy.SearchCursor(inputFC) + for row in cursor: + feat = row.getValue(shapefieldname) + if shpType.upper()=='POINT': + centroid = feat.getPart() + elif (shpType.upper() =="POLYGON") or (shpType.upper() == "POLYLINE"): + centroid = feat.trueCentroid + centreX.append(centroid.X) + centreY.append(centroid.Y) + + meanX = int(float(sum(centreX))/len(centreX)) if len(centreX) > 0 else float('nan') + meanY = int(float(sum(centreY))/len(centreY)) if len(centreY) > 0 else float('nan') + + arcpy.AddMessage("Check: {0}".format(str(sCale/lenConv*nRow/2.0))) + + + xMin = meanX - (poly_Width/lenConv)*sCale*nCol/2.0 + yMin = meanY - (poly_Height/lenConv)*sCale*nRow/2.0 + + return(xMin, yMin) + +def CreatingMap(fcOut, gRids, mxd, df, mapScale, output): + ## Get a list of PageNames + try: + PlanNum=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "PlanNum")[0] + PlanNum.text = " " + except: + pass + try: + AssignNum=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "AssignNum")[0] + AssignNum.text = " " + except: + pass + try: + MapName=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapName")[0] + except: + pass + + UTMZn=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "UTMZone")[0] + USNGZn=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "USNGZone")[0] + MagDeclin=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MagDecl")[0] + + mkLyr=arcpy.mapping.ListLayers(mxd, fcOut,df)[0] + for llyr in arcpy.mapping.ListLayers(mxd, "*",df): + if str(llyr.name) == "MRGS_UTM_USNG": + mapLyr=arcpy.mapping.ListLayers(mxd, "MRGS_UTM_USNG",df)[0] + elif str(llyr.name) == "MRGSZones_World": + mapLyr=arcpy.mapping.ListLayers(mxd, "MGRSZones_World",df)[0] + + + for key in gRids: + where4 = ('"PageName" = ' + "'" + key + "'") + arcpy.AddMessage("{0}, MagDec = {1}".format(where4, gRids[key][2])) + arcpy.SelectLayerByAttribute_management (mkLyr, "NEW_SELECTION", where4) + df.zoomToSelectedFeatures() + try: + arcpy.SelectLayerByLocation_management(mapLyr,"INTERSECT",mkLyr) + + rows7=arcpy.SearchCursor(mapLyr) + row7 = rows7.next() + UTMZn.text = row7.getValue("GRID1MIL") + UtmZone=UTMZn.text + USNGZn.text = row7.getValue("GRID100K") + UsngGrid = USNGZn.text + except: + arcpy.AddMessage("No update to UTM Zone or USNG Grid") + pass + + MapName.text = key + MagDeclin.text = gRids[key][2] + + ##arcpy.AddMessage("UTM Zone is " + UTMZn.text + " and USNG Grid is " + USNGZn.text) + + arcpy.SelectLayerByAttribute_management (mapLyr, "CLEAR_SELECTION") + + + arcpy.SelectLayerByAttribute_management (mkLyr, "CLEAR_SELECTION") + + mxd.activeView='PAGE_LAYOUT' + + if mapScale > 0: + pScaler = mapScale + df.scale = pScaler*1.0 + else: + df.scale = 24000.0 + mkLyr.visible = False + arcpy.RefreshActiveView() + outFile = output + "/" + str(key) + "_MAP.pdf" + mkLyr.visible = True + + + try: + arcpy.mapping.ExportToPDF(mxd, outFile) + except: + arcpy.AddWarning(" ") + arcpy.AddWarning("Unable to produce map for Assignment: " + str(key)) + arcpy.AddWarning("Problem with ExportToPDF") + arcpy.AddWarning(" ") + + arcpy.SelectLayerByAttribute_management (mkLyr, "CLEAR_SELECTION") + return + + + +if __name__ == '__main__': + ####### + #Automate map production - July 27, 2012 + mxd, df = getDataframe() + + ## Input parameters + ## inputFC - This is the feature you wish to build the mapbook around. Preferrably this could be the PLS or LKP. If the desired feature class contains mulitple features than you must + ## select a single feature otherwise mapbooks will be created around each feature. Can be points, lines, polygons, or rasters. + ## sCale = Scale must be specified in real world inches (e.g 24000 for 1:24000) + ## + ## nRow = Number of rows to create in the y direction from the point of origin. + ## nCol = Number of columns to create in the x direction from the point of origin. + ## + + inputFC = arcpy.GetParameterAsText(0) + sCale = float(arcpy.GetParameterAsText(1)) + nRow = float(arcpy.GetParameterAsText(2)) + nCol = float(arcpy.GetParameterAsText(3)) + output = arcpy.GetParameterAsText(4) + output = output.replace("'\'","/") + + ## First we need to build the grid + dfSpatial_Type = df.spatialReference.type + if dfSpatial_Type.upper() != 'PROJECTED': + arcpy.AddError('Must have a projected coordinate system') + sys.exit(1) + + ## Check to see if the layer exists...if so delete it + + + poly_Width= df.elementWidth + poly_Height = df.elementHeight + + mapUnits = df.mapUnits + lenConv=1.0 + if mapUnits == 'Meters': + lenConv = 39.37 #inches to meters + elif mapUnits == 'Feet': + lenConv = 12.0 #inches to feet + elif mapUnits == 'Inches': + lenConv = 1.0 #inches to inches + else: + sys.exit(0) + + + xMin, yMin = GetXY(inputFC, poly_Height, poly_Width, lenConv, int(sCale), nCol, nRow) + + originCoord = "{0} {1}".format(str(xMin), str(yMin)) + arcpy.AddMessage("SW coordinates are: {0}".format(originCoord)) + desc=arcpy.Describe(inputFC) + nAme = desc.name + fcOut = "GRID_{0}_{1}".format(nAme, str(int(sCale))) + + arcpy.GridIndexFeatures_cartography (fcOut, "", "", "USEPAGEUNIT", sCale, "", "", originCoord, nRow, nCol) + + unProjCoordSys = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]]" + + #First determine the grid north value + fld_gNorth = "gNORTH" + field_type = "FLOAT" + gNorthTxt=gNorth_Check(inputFC, fld_gNorth, field_type, unProjCoordSys) + try: + df.rotation = 0.0 + if arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "gNorth"): + gridNorth=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "gNorth")[0] + gridNorth.text = gNorthTxt + except: + pass + + layerOn=False + + if arcpy.Exists(fcOut): + arcpy.MakeFeatureLayer_management(fcOut,fcOut) + mkLyr = arcpy.mapping.Layer(fcOut) + mkLyr.name=fcOut + arcpy.mapping.RemoveLayer(df,mkLyr) + arcpy.mapping.AddLayer(df,mkLyr,"TOP") + + try: + lyr = arcpy.mapping.ListLayers(mxd, mkLyr.name, df)[0] + symbologyLayer = r"C:\MapSAR_Ex\Tools\Layers Files - Local\Layer Groups\MapBookGrid.lyr" + refGroupLayerA = "Grids" + if refGroupLayerA in arcpy.mapping.ListLayers(mxd,"",df)[0].name: + arcpy.mapping.AddLayerToGroup(df,refGroupLayerA,lyr,'TOP') + arcpy.ApplySymbologyFromLayer_management(lyr, symbologyLayer) + ext=lyr.getExtent() + df.extent = ext + outFile = output + "/" + "MapBookGrid.pdf" + if lyr.supports("LABELCLASSES"): + for lblclass in lyr.labelClasses: + lblclass.showClassLabels = True + lblclass.expression = '"%s" & [PageName] & "%s"' % ("", "") + layerOn=True + lyr.visible = True + lyr.showLabels = True + if arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapName"): + MapName=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapName")[0] + MapName.text = "Mapbook Index" + arcpy.RefreshActiveView() + try: + arcpy.mapping.ExportToPDF(mxd, outFile) + except: + pass + lyr.visible = False + lyr.showLabels = False + except: + pass + + + #Get the Lat / Long, magDeclination for each GRID + desc = arcpy.Describe(fcOut) + shapefieldname = desc.ShapeFieldName + gRids={} + cGrid=arcpy.GetCount_management(fcOut) + if int(cGrid.getOutput(0)) > 0: + cursor1 = arcpy.SearchCursor(fcOut, '', unProjCoordSys) + for row1 in cursor1: + gName = row1.getValue("PageName") + feat = row1.getValue(shapefieldname) + centroid = feat.trueCentroid + gLat = centroid.Y + gLong = centroid.X + magDec = MagDeclin(gLat, gLong) + gRids[gName]=[gLat, gLong, magDec] + arcpy.AddMessage("{0}, magDec = {1}".format(gName, magDec)) + + + + ############################## + # Print Maps for each grid + ############################## +## Need to do some major re-work. Need to determine the MagDec and UTM details for each +## grid square within the GRID. Once the GRID is created, get a list of coordinates for the centroid +## of each grid. Run the Mag Dec (see IGT4SAR_updateLayout.py) for each and create the following dictionary: +## GRID[PageName]={magDec, UTM Zone, USNG Zone, Incident Name, Incident Number} +## Send this info to module for printing map + + CreatingMap(fcOut, gRids, mxd, df, int(sCale), output) + + try: + PlanNum=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "PlanNum")[0] + PlanNum.text = " " + except: + pass + try: + AssignNum=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "AssignNum")[0] + AssignNum.text = " " + except: + pass + try: + MapName=arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "MapName")[0] + MapName.text=" " + except: + pass + + + if layerOn==True: + lyr.visible = True + lyr.showLabels = True + + +## Zom to the extent of the Fishnet and create index map + + + + + + ## Print Index map \ No newline at end of file From 0d52cee8edc20c1ed7779a4421afec4f5359af10 Mon Sep 17 00:00:00 2001 From: Tom Russo Date: Wed, 8 Nov 2017 15:41:05 -0700 Subject: [PATCH 6/8] Revert "updated typos" This reverts commit 4cf2daee16e551006d87cd9b24f04215154bfe76. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a98da5..2e92766 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ http://www.youtube.com/channel/UCrWNjhnpNOiEAATDzNw3lFg Installation ============ -The installation process for IGT4SAR does not include an edit to the registry that would let Windows know where the folders are located. Becuase some of the scripts include with IGT4SAR rely on knowing where IGT4SAR has been installed, you must install IGT4SAR in the following folder: "C:\MapSAR_Ex". +The installation process for IGT4SAR doe snot include an edit to the registry that would let Windows know where the folders are located. Becuase some of the scripts include with IGT4SAR rely on knowing where IGT4SAR has been installed, you must install IGT4SAR in the following folder: "C:\MapSAR_Ex". When downloading the zip from GitHub the zip file is name "MapSAR_Ex-master.zip. This creates a problem when unzipping the file as it will create a folder called "MapSAR_Ex-master" as opposed to the required "MapSAR_Ex". To correct this problem, merely rename the unzipped folder MapSAR_Ex and place it in your root directory. Once properly installed you should have the following: From 031d5bd0a3e2b6cc207da23508c925f59cda6bb7 Mon Sep 17 00:00:00 2001 From: Tom Russo Date: Wed, 8 Nov 2017 15:41:06 -0700 Subject: [PATCH 7/8] Revert "updated for 10.6" This reverts commit 13c156024ad8db344912c046524134b01c89b7d1. --- ~LoadMapSAREXTools.bat | 116 +++++++++++++++++------------------ ~UninstallMapSAREXTools.bat | 118 ++++++++++++++++++------------------ 2 files changed, 115 insertions(+), 119 deletions(-) diff --git a/~LoadMapSAREXTools.bat b/~LoadMapSAREXTools.bat index 6cc0936..2dc2d1e 100644 --- a/~LoadMapSAREXTools.bat +++ b/~LoadMapSAREXTools.bat @@ -1,59 +1,57 @@ -@echo off - -REM Get admin privileges -REM from https://sites.google.com/site/eneerge/scripts/batchgotadmin - -REM --> Check for permissions ->nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" - -REM --> If error flag set, we do not have admin. -if '%errorlevel%' NEQ '0' ( - echo Requesting administrative privileges... - goto UACPrompt -) else ( goto gotAdmin ) - -:UACPrompt - echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" - echo UAC.ShellExecute "%~0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" - - "%temp%\getadmin.vbs" - exit /B - -:gotAdmin - if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) - -@echo on - -If DEFINED ProgramFiles(x86) Set _programs=%ProgramFiles(x86)% -If Not DEFINED ProgramFiles(x86) Set _programs=%ProgramFiles% - -ECHO %_programs% - -set _igtpath=%~dp0 - -IF EXIST "%_programs%\ArcGIS\Desktop10.0\License" CALL :install "%_programs%\ArcGIS\Desktop10.0" -IF EXIST "%_programs%\ArcGIS\Desktop10.1\License" CALL :install "%_programs%\ArcGIS\Desktop10.1" -IF EXIST "%_programs%\ArcGIS\Desktop10.2\License" CALL :install "%_programs%\ArcGIS\Desktop10.2" -IF EXIST "%_programs%\ArcGIS\Desktop10.3\License" CALL :install "%_programs%\ArcGIS\Desktop10.3" -IF EXIST "%_programs%\ArcGIS\Desktop10.4\License" CALL :install "%_programs%\ArcGIS\Desktop10.4" -IF EXIST "%_programs%\ArcGIS\Desktop10.5\License" CALL :install "%_programs%\ArcGIS\Desktop10.5" -IF EXIST "%_programs%\ArcGIS\Desktop10.6\License" CALL :install "%_programs%\ArcGIS\Desktop10.6" - -set _config="%APPDATA%\ArcGIS4LocalGovernment\ConfigFiles" -IF NOT EXIST %_config% ( - MKDIR %_config% -) -copy "%_igtpath%tools\aaloaded.config" %_config%\loaded.config /y - -set _regasmdir="%_programs%\Common Files\ArcGIS\bin\" -start "Register Measure Angle Addin" /D%_regasmdir% /W %_regasmdir%\ESRIRegAsm /p:Desktop "%_igtpath%Tools\AddIns\MeasureAngle.dll" - -GOTO :eof - - -:install - - xcopy "%_igtpath%tools\addins\*.esriaddin" "%~1\bin\Addins\" - xcopy "%_igtpath%tools\SAR_Toolbox100.tbx" "%~1\ArcToolbox\Toolboxes\" - -ENDLOCAL +@echo off + +REM Get admin privileges +REM from https://sites.google.com/site/eneerge/scripts/batchgotadmin + +REM --> Check for permissions +>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" + +REM --> If error flag set, we do not have admin. +if '%errorlevel%' NEQ '0' ( + echo Requesting administrative privileges... + goto UACPrompt +) else ( goto gotAdmin ) + +:UACPrompt + echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" + echo UAC.ShellExecute "%~0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" + + "%temp%\getadmin.vbs" + exit /B + +:gotAdmin + if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) + +@echo on + +If DEFINED ProgramFiles(x86) Set _programs=%ProgramFiles(x86)% +If Not DEFINED ProgramFiles(x86) Set _programs=%ProgramFiles% + +ECHO %_programs% + +set _igtpath=%~dp0 + +IF EXIST "%_programs%\ArcGIS\Desktop10.0\License" CALL :install "%_programs%\ArcGIS\Desktop10.0" +IF EXIST "%_programs%\ArcGIS\Desktop10.1\License" CALL :install "%_programs%\ArcGIS\Desktop10.1" +IF EXIST "%_programs%\ArcGIS\Desktop10.2\License" CALL :install "%_programs%\ArcGIS\Desktop10.2" +IF EXIST "%_programs%\ArcGIS\Desktop10.3\License" CALL :install "%_programs%\ArcGIS\Desktop10.3" +IF EXIST "%_programs%\ArcGIS\Desktop10.4\License" CALL :install "%_programs%\ArcGIS\Desktop10.4" + +set _config="%APPDATA%\ArcGIS4LocalGovernment\ConfigFiles" +IF NOT EXIST %_config% ( + MKDIR %_config% +) +copy "%_igtpath%tools\aaloaded.config" %_config%\loaded.config /y + +set _regasmdir="%_programs%\Common Files\ArcGIS\bin\" +start "Register Measure Angle Addin" /D%_regasmdir% /W %_regasmdir%\ESRIRegAsm /p:Desktop "%_igtpath%Tools\AddIns\MeasureAngle.dll" + +GOTO :eof + + +:install + + xcopy "%_igtpath%tools\addins\*.esriaddin" "%~1\bin\Addins\" + xcopy "%_igtpath%tools\SAR_Toolbox100.tbx" "%~1\ArcToolbox\Toolboxes\" + +ENDLOCAL diff --git a/~UninstallMapSAREXTools.bat b/~UninstallMapSAREXTools.bat index 3088a54..d45fc8a 100644 --- a/~UninstallMapSAREXTools.bat +++ b/~UninstallMapSAREXTools.bat @@ -1,60 +1,58 @@ -@echo off - -REM Get admin privileges -REM from https://sites.google.com/site/eneerge/scripts/batchgotadmin - -REM --> Check for permissions ->nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" - -REM --> If error flag set, we do not have admin. -if '%errorlevel%' NEQ '0' ( - echo Requesting administrative privileges... - goto UACPrompt -) else ( goto gotAdmin ) - -:UACPrompt - echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" - echo UAC.ShellExecute "%~0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" - - "%temp%\getadmin.vbs" - exit /B - -:gotAdmin - if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) - -@echo on - -If DEFINED ProgramFiles(x86) Set _programs=%ProgramFiles(x86)% -If Not DEFINED ProgramFiles(x86) Set _programs=%ProgramFiles% - -ECHO %_programs% - -IF EXIST "%_programs%\ArcGIS\Desktop10.0\License" CALL :remove "%_programs%\ArcGIS\Desktop10.0" -IF EXIST "%_programs%\ArcGIS\Desktop10.1\License" CALL :remove "%_programs%\ArcGIS\Desktop10.1" -IF EXIST "%_programs%\ArcGIS\Desktop10.2\License" CALL :remove "%_programs%\ArcGIS\Desktop10.2" -IF EXIST "%_programs%\ArcGIS\Desktop10.3\License" CALL :remove "%_programs%\ArcGIS\Desktop10.3" -IF EXIST "%_programs%\ArcGIS\Desktop10.4\License" CALL :remove "%_programs%\ArcGIS\Desktop10.4" -IF EXIST "%_programs%\ArcGIS\Desktop10.5\License" CALL :remove "%_programs%\ArcGIS\Desktop10.5" -IF EXIST "%_programs%\ArcGIS\Desktop10.6\License" CALL :remove "%_programs%\ArcGIS\Desktop10.6" - -del "%APPDATA%\ArcGIS4LocalGovernment\ConfigFiles\loaded.config" - -set _igtpath=%~dp0 -set _regasmdir="%_programs%\Common Files\ArcGIS\bin\" -start "Unregister Measure Angle Addin" /D%_regasmdir% /W %_regasmdir%\ESRIRegAsm /p:Desktop /u "%_igtpath%Tools\AddIns\MeasureAngle.dll" - -goto :eof - - -:remove - - del "%~1\bin\Addins\Search_Editor.esriAddIn" - del "%~1\bin\Addins\MapSAREX_Config.esriAddIn" - del "%~1\bin\Addins\GPX.esriAddIn" - del "%~1\bin\Addins\Get_Map_Point_Addin_Tool.esriAddIn" - del "%~1\bin\Addins\ConstructwithBuffer.esriAddIn" - del "%~1\bin\Addins\AttributeAssistant.esriAddIn" - - del "%~1\ArcToolbox\Toolboxes\SAR_Toolbox100.tbx" - -ENDLOCAL +@echo off + +REM Get admin privileges +REM from https://sites.google.com/site/eneerge/scripts/batchgotadmin + +REM --> Check for permissions +>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" + +REM --> If error flag set, we do not have admin. +if '%errorlevel%' NEQ '0' ( + echo Requesting administrative privileges... + goto UACPrompt +) else ( goto gotAdmin ) + +:UACPrompt + echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" + echo UAC.ShellExecute "%~0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" + + "%temp%\getadmin.vbs" + exit /B + +:gotAdmin + if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) + +@echo on + +If DEFINED ProgramFiles(x86) Set _programs=%ProgramFiles(x86)% +If Not DEFINED ProgramFiles(x86) Set _programs=%ProgramFiles% + +ECHO %_programs% + +IF EXIST "%_programs%\ArcGIS\Desktop10.0\License" CALL :remove "%_programs%\ArcGIS\Desktop10.0" +IF EXIST "%_programs%\ArcGIS\Desktop10.1\License" CALL :remove "%_programs%\ArcGIS\Desktop10.1" +IF EXIST "%_programs%\ArcGIS\Desktop10.2\License" CALL :remove "%_programs%\ArcGIS\Desktop10.2" +IF EXIST "%_programs%\ArcGIS\Desktop10.3\License" CALL :remove "%_programs%\ArcGIS\Desktop10.3" +IF EXIST "%_programs%\ArcGIS\Desktop10.1\License" CALL :remove "%_programs%\ArcGIS\Desktop10.4" + +del "%APPDATA%\ArcGIS4LocalGovernment\ConfigFiles\loaded.config" + +set _igtpath=%~dp0 +set _regasmdir="%_programs%\Common Files\ArcGIS\bin\" +start "Unregister Measure Angle Addin" /D%_regasmdir% /W %_regasmdir%\ESRIRegAsm /p:Desktop /u "%_igtpath%Tools\AddIns\MeasureAngle.dll" + +goto :eof + + +:remove + + del "%~1\bin\Addins\Search_Editor.esriAddIn" + del "%~1\bin\Addins\MapSAREX_Config.esriAddIn" + del "%~1\bin\Addins\GPX.esriAddIn" + del "%~1\bin\Addins\Get_Map_Point_Addin_Tool.esriAddIn" + del "%~1\bin\Addins\ConstructwithBuffer.esriAddIn" + del "%~1\bin\Addins\AttributeAssistant.esriAddIn" + + del "%~1\ArcToolbox\Toolboxes\SAR_Toolbox100.tbx" + +ENDLOCAL From 3e563c002c30c766e7dd0921582e619d0315e81f Mon Sep 17 00:00:00 2001 From: Tom Russo Date: Wed, 8 Nov 2017 15:41:07 -0700 Subject: [PATCH 8/8] Revert "Updates SQL where statement-Line 74" This reverts commit 3b9a37d7ba5e749d953213c7b15c0c295a1a6ee1. --- Tools/Scripts/IGT4SAR_MissingPersonForm.py | 376 +++++++++++---------- 1 file changed, 189 insertions(+), 187 deletions(-) diff --git a/Tools/Scripts/IGT4SAR_MissingPersonForm.py b/Tools/Scripts/IGT4SAR_MissingPersonForm.py index 2998133..cd33752 100644 --- a/Tools/Scripts/IGT4SAR_MissingPersonForm.py +++ b/Tools/Scripts/IGT4SAR_MissingPersonForm.py @@ -1,188 +1,190 @@ -#------------------------------------------------------------------------------- -# Name: MissingPersomForm.py -# -# Purpose: Create Missing Person Flyer from data stored in the Subject -# Information data layer within MapSAR -# -# Author: Don Ferguson -# -# Created: 12/12/2011 -# Copyright: (c) Don Ferguson 2011 -# Licence: -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# The GNU General Public License can be found at -# . -#------------------------------------------------------------------------------- -#!/usr/bin/env python -try: - arcpy -except NameError: - import arcpy -import png, pyqrcode -from types import * -from datetime import datetime -import IGT4SAR_fdf - -def checkNoneType(variable, varName): - arcpy.AddMessage("variable Name: {}".format(variable)) - if type(variable) is NoneType: - arcpy.AddWarning(varName + " is not defined") - result = " " - else: - result = variable - return result - -if __name__ == '__main__': - - #workspc = arcpy.GetParameterAsText(0) - output = arcpy.GetParameterAsText(0) - addInfo = arcpy.GetParameterAsText(1) - - #arcpy.env.workspace = workspc - arcpy.env.overwriteOutput = "True" - - output = output.replace("'\'","/") - - fc3="Incident_Information" - fc2="Lead Agency" - - rows = arcpy.SearchCursor(fc3) - row = rows.next() - arcpy.AddMessage("Get Incident Info") - k=0 - while row: - # you need to insert correct field names in your getvalue function - k+=1 - if type(row.getValue("Lead_Agency")) is NoneType: - LeadAgency = " " - Phone=" " - email=" " - else: - LeadAgency = row.getValue("Lead_Agency") - where2="".join(['"Lead_Agency"=', "'", LeadAgency, "'"]) - arcpy.AddMessage(where2) - rows2 = arcpy.SearchCursor(fc2,where2) - for row2 in rows2: - Phone = checkNoneType(row2.getValue("Lead_Phone"), '"Reporting Phone Number"') - email = checkNoneType(row2.getValue("E_Mail"), '"Reporting e-mail"') - - Callback = ("If you have information please call: {} at phone: {} or e-mail: {}".format(str(LeadAgency), str(Phone), str(email))) - row = rows.next() - del rows - del row - - if k==0: - arcpy.AddWarning('"Reporting Information (Lead Agency: call in phone # or e-mail)" is not defined') - Callback =" " - - arcpy.AddMessage("\nSubject Information") - - fc1="Subject_Information" - rows = arcpy.SearchCursor(fc1) - row = rows.next() - while row: - # you need to insert correct field names in your getvalue function - Subject_Name = checkNoneType(row.getValue("Name"),"Subject Name") - Subject_Name = row.getValue("Name") - if Subject_Name is not None: - - arcpy.AddMessage("Subject Name: {0}".format(Subject_Name)) - else: - arcpy.AddWarning('Need to provide a Subject Name ~ "Subject" was used') - Subject_Name="Subject" - - if type(row.getValue("Date_Seen")) is NoneType: - arcpy.AddWarning('"Date last seen" is not defined') - Date_Seen = " " - else: - fDate = row.getValue("Date_Seen") - Date_Seen = fDate.strftime("%m/%d/%Y") - - fTime = checkNoneType(row.getValue("Time_Seen"), '"Time Last Seen"') - - Where_Last = checkNoneType(row.getValue("WhereLastSeen"), '"Where Last Seen"') - Age = checkNoneType(row.getValue("Age"), "Subject Age") - Gender = checkNoneType(row.getValue("Gender"), "Subject Gender") - Race = checkNoneType(row.getValue("Race"), "Subject Race") - - Height2 =checkNoneType(row.getValue("Height"), "Subject Height") - ## Bug fix...object type "int" has not length, so changed "if len(Height)>1" to if "Height2>1" - if len(str(Height2))>1: - Height1 = Height2/12.0 - feet = int(Height1) - inches = int((Height1 - feet)*12.0) - fInches = "%1.0f" %inches - Height = str(feet) + " ft " + fInches +" in" - else: - Height = " " - - Weight = checkNoneType(row.getValue("Weight"), '"Subject Weight"') - Build = checkNoneType(row.getValue("Build"), '"Subject Build"') - Complex =checkNoneType(row.getValue("Complexion"), '"Subject Complexion"') - Hair = checkNoneType(row.getValue("Hair"), '"Subject Hair"') - Eyes = checkNoneType(row.getValue("Eyes"), '"Subject Eye Color"') - Other = checkNoneType(row.getValue("Other"), '"Other Clothing Information"') - Shirt = checkNoneType(row.getValue("Shirt"), '"Subject Shirt"') - Pants = checkNoneType(row.getValue("Pants"), '"Subject Pants"') - Jacket = checkNoneType(row.getValue("Jacket"), '"Subject Jacket"') - Hat = checkNoneType(row.getValue("Hat"), '"Subject Hat"') - Footwear = checkNoneType(row.getValue("Footwear"), '"Subject Footwear"') - if addInfo.upper()=="TRUE": - Info = checkNoneType(row.getValue("Info"), '"Additonal Information"') - else: - Info = checkNoneType("", '"Additonal Information"') - - qrCode = row.getValue("QRCode") - if qrCode is not None: - url=pyqrcode.create(qrCode) - qrFile = output + "/" + str(Subject_Name) + "_QRcode.png" - url.png(qrFile, scale=8) - else: - qrFile=" " - - #QRCode = checkNoneType(row.getValue("QRCode"), '"QRCode"') - - fdfFields = { - 'MPF_Name':Subject_Name, - 'MPFAge':Age, - 'MPFSex':Gender, - 'MPF_Location':Where_Last, - 'MPF_TimeMissing':fTime, - 'MPF_DateMissing':Date_Seen, - 'MPF_Race':Race, - 'MPF_Height':Height, - 'MPF_Weight':Weight, - 'MPF_Build':Build, - 'MPF_Complex':Complex, - 'MPF_HairColor':Hair, - 'MPF_EyeColor':Eyes, - 'MPF_OtherPhy':Other, - #'MPF_OtherPhy':Incident_Name, - 'MPF_ShirtClothing':Shirt, - 'MPF_PantsClothing':Pants, - 'MPF_JacketClothing':Jacket, - 'MPF_HatClothing':Hat, - 'MPF_FootClothing':Footwear, - 'MPF_OtherInfo':Info, - 'MPF_CallNumber':Callback - } - - formName = 'MissingPersonForm.pdf' - fName = "Missing_{0}.fdf".format(str(Subject_Name)) - - # Create .fdf - IGT4SAR_fdf.create_fdf3(output, fName, formName, fdfFields, conCat=False) - - row = rows.next() - del rows - del row +#------------------------------------------------------------------------------- +# Name: MissingPersomForm.py +# +# Purpose: Create Missing Person Flyer from data stored in the Subject +# Information data layer within MapSAR +# +# Author: Don Ferguson +# +# Created: 12/12/2011 +# Copyright: (c) Don Ferguson 2011 +# Licence: +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# The GNU General Public License can be found at +# . +#------------------------------------------------------------------------------- +#!/usr/bin/env python +try: + arcpy +except NameError: + import arcpy +import png, pyqrcode +from types import * +from datetime import datetime +import IGT4SAR_fdf + +def checkNoneType(variable, varName): + if type(variable) is NoneType: + arcpy.AddWarning(varName + " is not defined") + result = " " + else: + result = variable + return result + +if __name__ == '__main__': + + #workspc = arcpy.GetParameterAsText(0) + output = arcpy.GetParameterAsText(0) + addInfo = arcpy.GetParameterAsText(1) + + #arcpy.env.workspace = workspc + arcpy.env.overwriteOutput = "True" + + output = output.replace("'\'","/") + + fc3="Incident_Information" + fc2="Lead Agency" + + rows = arcpy.SearchCursor(fc3) + row = rows.next() + arcpy.AddMessage("Get Incident Info") + k=0 + while row: + # you need to insert correct field names in your getvalue function + k+=1 + if type(row.getValue("Lead_Agency")) is NoneType: + LeadAgency = " " + else: + LeadAgency = row.getValue("Lead_Agency") + where2 = '"Lead_Agency" = ' + "'" + LeadAgency + "'" + rows2 = arcpy.SearchCursor(fc2, where2) + row2 = rows2.next() + + while row2: + # you need to insert correct field names in your getvalue function + Phone = checkNoneType(row2.getValue("Lead_Phone"), '"Reporting Phone Number"') + email = checkNoneType(row2.getValue("E_Mail"), '"Reporting e-mail"') + row2 = rows2.next() + del rows2 + del row2 + Callback = "If you have information please call: " + str(LeadAgency) + " at phone: " + str(Phone) + " or e-mail:" + str(email) + + row = rows.next() + del rows + del row + + if k==0: + arcpy.AddWarning('"Reporting Information (Lead Agency: call in phone # or e-mail)" is not defined') + Callback =" " + + arcpy.AddMessage("\nSubject Information") + + fc1="Subject_Information" + rows = arcpy.SearchCursor(fc1) + row = rows.next() + while row: + # you need to insert correct field names in your getvalue function + Subject_Name = checkNoneType(row.getValue("Name"),"Subject Name") + Subject_Name = row.getValue("Name") + if Subject_Name is not None: + + arcpy.AddMessage("Subject Name: {0}".format(Subject_Name)) + else: + arcpy.AddWarning('Need to provide a Subject Name ~ "Subject" was used') + Subject_Name="Subject" + + if type(row.getValue("Date_Seen")) is NoneType: + arcpy.AddWarning('"Date last seen" is not defined') + Date_Seen = " " + else: + fDate = row.getValue("Date_Seen") + Date_Seen = fDate.strftime("%m/%d/%Y") + + fTime = checkNoneType(row.getValue("Time_Seen"), '"Time Last Seen"') + + Where_Last = checkNoneType(row.getValue("WhereLastSeen"), '"Where Last Seen"') + Age = checkNoneType(row.getValue("Age"), "Subject Age") + Gender = checkNoneType(row.getValue("Gender"), "Subject Gender") + Race = checkNoneType(row.getValue("Race"), "Subject Race") + + Height2 =checkNoneType(row.getValue("Height"), "Subject Height") + ## Bug fix...object type "int" has not length, so changed "if len(Height)>1" to if "Height2>1" + if len(str(Height2))>1: + Height1 = Height2/12.0 + feet = int(Height1) + inches = int((Height1 - feet)*12.0) + fInches = "%1.0f" %inches + Height = str(feet) + " ft " + fInches +" in" + else: + Height = " " + + Weight = checkNoneType(row.getValue("Weight"), '"Subject Weight"') + Build = checkNoneType(row.getValue("Build"), '"Subject Build"') + Complex =checkNoneType(row.getValue("Complexion"), '"Subject Complexion"') + Hair = checkNoneType(row.getValue("Hair"), '"Subject Hair"') + Eyes = checkNoneType(row.getValue("Eyes"), '"Subject Eye Color"') + Other = checkNoneType(row.getValue("Other"), '"Other Clothing Information"') + Shirt = checkNoneType(row.getValue("Shirt"), '"Subject Shirt"') + Pants = checkNoneType(row.getValue("Pants"), '"Subject Pants"') + Jacket = checkNoneType(row.getValue("Jacket"), '"Subject Jacket"') + Hat = checkNoneType(row.getValue("Hat"), '"Subject Hat"') + Footwear = checkNoneType(row.getValue("Footwear"), '"Subject Footwear"') + if addInfo.upper()=="TRUE": + Info = checkNoneType(row.getValue("Info"), '"Additonal Information"') + else: + Info = checkNoneType("", '"Additonal Information"') + + qrCode = row.getValue("QRCode") + if qrCode is not None: + url=pyqrcode.create(qrCode) + qrFile = output + "/" + str(Subject_Name) + "_QRcode.png" + url.png(qrFile, scale=8) + else: + qrFile=" " + + #QRCode = checkNoneType(row.getValue("QRCode"), '"QRCode"') + + fdfFields = { + 'MPF_Name':Subject_Name, + 'MPFAge':Age, + 'MPFSex':Gender, + 'MPF_Location':Where_Last, + 'MPF_TimeMissing':fTime, + 'MPF_DateMissing':Date_Seen, + 'MPF_Race':Race, + 'MPF_Height':Height, + 'MPF_Weight':Weight, + 'MPF_Build':Build, + 'MPF_Complex':Complex, + 'MPF_HairColor':Hair, + 'MPF_EyeColor':Eyes, + 'MPF_OtherPhy':Other, + #'MPF_OtherPhy':Incident_Name, + 'MPF_ShirtClothing':Shirt, + 'MPF_PantsClothing':Pants, + 'MPF_JacketClothing':Jacket, + 'MPF_HatClothing':Hat, + 'MPF_FootClothing':Footwear, + 'MPF_OtherInfo':Info, + 'MPF_CallNumber':Callback + } + + formName = 'MissingPersonForm.pdf' + fName = "Missing_{0}.fdf".format(str(Subject_Name)) + + # Create .fdf + IGT4SAR_fdf.create_fdf3(output, fName, formName, fdfFields, conCat=False) + + row = rows.next() + del rows + del row #arcpy.DeleteFeatures_management(fc3) \ No newline at end of file