├── Doc ├── InstallDoc.docx ├── InstallDoc.pdf ├── README.md └── images │ ├── image001.png │ ├── image003.png │ ├── image005.png │ ├── image007.png │ └── image009.png ├── R Tools.tbx ├── R-toolbox-image.png ├── README.md ├── Scripts ├── LogitWithR.py ├── LogitWithR.r ├── PointClusters.py ├── PointClusters.r ├── RenderClusters.lyr ├── arcpyWithR.py └── clust.R ├── ToolData ├── InputPoint.dbf ├── InputPoint.prj ├── InputPoint.sbn ├── InputPoint.sbx ├── InputPoint.shp ├── InputPoint.shp.xml ├── InputPoint.shx ├── Votepoints.dbf ├── Votepoints.prj ├── Votepoints.shp ├── Votepoints.shp.xml └── Votepoints.shx └── license.txt /Doc/InstallDoc.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/Doc/InstallDoc.docx -------------------------------------------------------------------------------- /Doc/InstallDoc.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/Doc/InstallDoc.pdf -------------------------------------------------------------------------------- /Doc/README.md: -------------------------------------------------------------------------------- 1 | Installing R for use with ArcGIS Toolboxes and Scripts 2 | ====================================================== 3 | 4 | 5 | 1. Make sure that you have installed ArcGIS 10.0 or later and Python 6 | 1. Note that Python should be installed by default when you install 7 | ArcGIS. 8 | 9 | 2. Check for the location of several important directories, which 10 | are installed to `C:\\Program Files` or `C:\\Program Files (x86)` depending 11 | on your operating system.  The directories you should be able to locate 12 | include: 13 | - `...\ArcGIS\Desktop10.x\bin` 14 | - `...\ArcGIS\Desktop10.x\arcpy` 15 | - `...\ArcGIS\Desktop\ArcToolbox\Scripts` 16 | - `..\Python26\ArcGIS10.0` or `..\Python27\ArcGIS10.1` or `..\Python\ArcGIS10.2` 17 | 18 | 3. When you install ArcGIS and Python the above directories should be added automatically to your Python 19 | Path (an environment variable, which you will learn how to set in the next set of steps) 20 | - To make sure that these directories were added to your Path environment variable automatically, 21 | open ArcMap, open the Python Window (from the Geoprocessing Dropdown), and type the following: 22 | 23 | ``` 24 | >>> import sys 25 | >>> import sys.path 26 | ``` 27 | 28 | - The output should include the following (the exact output will be different, but should include the pathnames listed above) 29 | ![arcgis-python-path](./images/image001.png) 30 | - If you do not see the directories listed (which is unlikely), add them in Step XX below 31 | - Close ArcMap 32 | 33 | 2. Install R 34 | 35 | 1. Go to the R homepage ([http://www.r-project.org](http://www.r-project.org)) and download the most recent version 36 | by clicking the "Download R" link in the Getting Started section, and then choosing the location that is closest to you 37 | - Choose to Download and Install R (NOT the Source Code for all Platforms), choose the appropriate operating system, choose to download the Base install, and then choose to Download R (this will be the most recent version of R) 38 | 2. Follow the standard steps for installation 39 | - IMPORTANT: Take note of the directory where you choose to install R and write it here (or on a separate piece of paper so that you don't forget... you will need it to add the directory to the Path environment variable)
R installation path: 40 | 41 | - Accept all of the defaults, and run the installation 42 | 43 | 3. Install the necessary R Libraries (maptools, clustTool, SM, and Design/rms) 44 | 45 | 1. For R versions < 2.14, you will need the Design module. For R >= 2.14 this package was renamed rms. The R script should be robust to which ever you have on your system. 46 | 2. Open R, either from the desktop shortcut that was created (if you chose to create one), or from the Start menu 47 | 3. Go to the Packages menu, then choose to Install Packages, then choose the location closest to you for download 48 | 4. Find clustTool, maptools, SM, and Design in the list of packages and select them both (you can select multiple packages using the Ctrl key), and click OK 49 | 5. Close R, without saving the workspace image 50 | 6. You are now ready to run the ArcGIS Sample R Scripts in ArcMap (which can be found in the Geoprocessing Resource Center in the Model and Script tool gallery here) 51 | 52 | 4. Add the R Tools toolbox and start using it 53 | 54 | 1. Open ArcMap 55 | 2. Open ArcToolbox: from the Geoprocessing Window select ArcToolbox 56 | 3. Right click inside of ArcToolbox, and choose Add Toolbox 57 | 4. Navigate to the location where you saved the Using R in ArcGIS 10 zip file and unzipped everything, and choose R Tools.tbx 58 | 5. Double-click on the Point Clustering tool, and fill out of the necessary parameters 59 | - This tool can only take Shapefiles as inputs, and can only output Shapefiles 60 | 6. Run the tool 61 | - Ignore the R windows that may pop open, that is just part of the way that the tool functions 62 | 63 | Modifying the Path Environment Variable 64 | --------------------------------------- 65 | 66 | Current versions of this script automatically detect and set the correct path for your R installation. However, if the scripts are unable to find your installation of R, these steps allow you to directly set the location of your R installation. You can follow these same steps to add ArcGIS directories to your path if they did not appear in step 1.3. 67 | 68 | 1. Navigate to the location of the R install on your computer (that you wrote on the line above) and open the folder labeled Bin 69 | 2. Copy the full path location of the bin folder (by default it would install here: `C:\Program Files (x86)\R\R-2.11.1\bin`) 70 | 3. Go to your Start Menu, find the My Computer icon (or just Computer icon, depending on what operating system you are using), right click on it, and choose the Properties option 71 | 72 | ![properties-start-menu](./images/image003.png) 73 | 74 | 4. For both Windows Vista and Windows 7, this will open a dialog where you will then click the Advanced System Settings link on the left side (highlighted in red). For Windows XP, this will open the System Properties dialog box, from which you will choose the Advanced tab (highlighted in red in) 75 | ![properties-menus](./images/image005.png) 76 | 77 | 5. The next window will have a button on the bottom that says Environment Variables, click it and the following dialog will appear 78 | 79 | ![environment-variables](./images/image007.png) 80 | 81 | 6. Find the environment variable called Path (or PATH). This may be in the User Variables, and it may be in the System Variables. If you are the only person that uses your machine, this distinction should not matter. If your machine is shared, and you use the Path variable that is a user variable, then you will be the only person impacted by the change. If you want your changes to be shared by all users, make sure to use the System Variable. 82 | 83 | 7. Select the Path Variable, and click Edit 84 | 85 | ![environment-variables](./images/image009.png) 86 | 87 | 7. At the end of the list of directories, add a semi-colon (;) with NO space after it, and then paste in the R Bin directory that you copied earlier (should look something like this: `C:\Program Files (x86)\R\R-2.11.1\bin`) 88 | 89 | 8. Click OK 90 | 91 | 9. Your R Bin directory should be successfully added to your Path environment variable 92 | -------------------------------------------------------------------------------- /Doc/images/image001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/Doc/images/image001.png -------------------------------------------------------------------------------- /Doc/images/image003.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/Doc/images/image003.png -------------------------------------------------------------------------------- /Doc/images/image005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/Doc/images/image005.png -------------------------------------------------------------------------------- /Doc/images/image007.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/Doc/images/image007.png -------------------------------------------------------------------------------- /Doc/images/image009.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/Doc/images/image009.png -------------------------------------------------------------------------------- /R Tools.tbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/R Tools.tbx -------------------------------------------------------------------------------- /R-toolbox-image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/R-toolbox-image.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NOTE: This repository is deprecated, Esri has created an project to directly [link ArcGIS and R](http://blogs.esri.com/esri/esri-insider/2015/07/20/building-a-bridge-to-the-r-community/), see: [https://r-arcgis.github.io](https://r-arcgis.github.io) 2 | 3 | # R-toolbox-py 4 | 5 | This toolbox contains a framework for using R (The R Project for Statistical 6 | Computing) in ArcGIS 10 and 10.1. This is the third version of the toolbox. 7 | This release improves the IO hook between Python and R, allowing for R message 8 | output in the ArcGIS Results Window. This version also solves an issue with a 9 | name change in regards to the R module that computes Logistic Regression. 10 | Lastly, it is very important that you follow the guidelines in the 11 | INSTALLDOC.doc. 12 | 13 | Learn more 14 | [here](http://www.arcgis.com/home/item.html?id=a5736544d97a4544aa47d06baf910f6d). 15 | 16 | [View it 17 | live](http://video.esri.com/watch/1925/integrating-open_dash_source-statistical-packages-with-arcgis) 18 | 19 | ![App](https://raw.github.com/Esri/R-toolbox-py/master/R-toolbox-image.png) 20 | 21 | ## Features 22 | * Toolbox with Python Script Tools - Runs R code within ArcGIS Environment 23 | 24 | ## Instructions 25 | 26 | 1. Fork and then clone the repo. 27 | 2. Run and try the samples. 28 | 29 | ## Requirements 30 | 31 | * ArcGIS 10.0+ 32 | * R 33 | 34 | ## Resources 35 | 36 | ## Issues 37 | 38 | Find a bug or want to request a new feature? Please let us know by submitting 39 | an issue. 40 | 41 | ## Contributing 42 | 43 | Anyone and everyone is welcome to contribute. 44 | 45 | ## Licensing Copyright 2013 Esri 46 | 47 | Licensed under the Apache License, Version 2.0 (the "License"); you may not 48 | use this file except in compliance with the License. You may obtain a copy of 49 | the License at 50 | 51 | http://www.apache.org/licenses/LICENSE-2.0 52 | 53 | Unless required by applicable law or agreed to in writing, software 54 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 55 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 56 | License for the specific language governing permissions and limitations under 57 | the License. 58 | 59 | A copy of the license is available in the repository's [license.txt]( 60 | https://raw.github.com/Esri/R-toolbox-py/master/license.txt) file. 61 | 62 | [](Esri Tags: ArcGIS Python R Analysis Geoprocessing Statistics Tools) 63 | [](Esri Language: Python) 64 | 65 | -------------------------------------------------------------------------------- /Scripts/LogitWithR.py: -------------------------------------------------------------------------------- 1 | import arcpy as ARCPY 2 | import arcpy.management as DM 3 | import SSDataObject as SSDO 4 | import SSUtilities as UTILS 5 | import arcpyWithR as RARC 6 | import numpy as NUM 7 | import ErrorUtils as ERROR 8 | import subprocess as SUB 9 | import os as OS 10 | import sys as SYS 11 | import locale as LOCALE 12 | LOCALE.setlocale(LOCALE.LC_ALL, '') 13 | 14 | def setupLogit(): 15 | #### Get User Provided Inputs #### 16 | inputFC = ARCPY.GetParameterAsText(0) 17 | outputFC = ARCPY.GetParameterAsText(1) 18 | depVarName = str(ARCPY.GetParameterAsText(2)) 19 | indVarNames = ARCPY.GetParameterAsText(3) 20 | indVarNames = [ str(i) for i in indVarNames.split(";") ] 21 | indVarNames = ";".join(indVarNames) 22 | usePenalty = ARCPY.GetParameterAsText(4) 23 | if usePenalty == 'true': 24 | usePenalty = "1" 25 | else: 26 | usePenalty = "0" 27 | 28 | coefTableIn = ARCPY.GetParameterAsText(5) 29 | coefTable, dbf = UTILS.returnTableName(coefTableIn) 30 | 31 | diagTableIn = ARCPY.GetParameterAsText(6) 32 | diagTable, dbf = UTILS.returnTableName(diagTableIn) 33 | 34 | #### Create R Command #### 35 | pyScript = SYS.argv[0] 36 | toolDir = OS.path.dirname(pyScript) 37 | rScript = OS.path.join(toolDir, "logitWithR.r") 38 | ARCPY.SetProgressor("default", "Executing R Script...") 39 | args = [RARC.findRExecutable(), "--slave", "--vanilla", "--args", 40 | inputFC, outputFC, depVarName, indVarNames, 41 | usePenalty, coefTable, diagTable] 42 | 43 | #### Uncomment Next Two Lines to Print/Create Command Line Args #### 44 | #cmd = RARC.createRCommand(args, rScript) 45 | #ARCPY.AddWarning(cmd) 46 | 47 | #### Execute Command #### 48 | scriptSource = open(rScript, 'rb') 49 | rCommand = SUB.Popen(args, 50 | stdin = scriptSource, 51 | stdout = SUB.PIPE, 52 | stderr = SUB.PIPE, 53 | shell=True) 54 | 55 | #### Print Result #### 56 | resString, errString = rCommand.communicate() 57 | 58 | #### Push Output to Message Window #### 59 | if errString and "Calculations Complete..." not in resString: 60 | ARCPY.AddError(errString) 61 | else: 62 | resOutString = RARC.printRMessages(resString) 63 | ARCPY.AddMessage(resOutString) 64 | 65 | #### Project the Data #### 66 | DM.DefineProjection(outputFC, inputFC) 67 | 68 | #### Create SSDO #### 69 | ssdo = SSDO.SSDataObject(outputFC) 70 | 71 | #### Display Symbology #### 72 | params = ARCPY.gp.GetParameterInfo() 73 | try: 74 | renderType = UTILS.renderType[ssdo.shapeType.upper()] 75 | if renderType == 0: 76 | renderLayerFile = "StdResidPoints.lyr" 77 | elif renderType == 1: 78 | renderLayerFile = "StdResidPolylines.lyr" 79 | else: 80 | renderLayerFile = "StdResidPolygons.lyr" 81 | fullRLF = OS.path.join(ARCPY.GetInstallInfo()['InstallDir'], 82 | "ArcToolbox", "Templates", "Layers", 83 | renderLayerFile) 84 | params[1].Symbology = fullRLF 85 | except: 86 | ARCPY.AddIDMessage("WARNING", 973) 87 | 88 | #### Print Coef Output Table #### 89 | try: 90 | rows = ARCPY.SearchCursor(coefTable) 91 | except: 92 | ARCPY.AddIDMessage("ERROR", 204) 93 | raise ERROR.ScriptError() 94 | 95 | labels = ["Variable", "Coef", "StdError", "Wald", "Prob"] 96 | header = "Logistic Regression Coefficient Table" 97 | res = [ labels ] 98 | for row in rows: 99 | rowRes = [] 100 | for i, val in enumerate(labels): 101 | if i == 0: 102 | rowRes.append(row.getValue(val)) 103 | else: 104 | rowRes.append(LOCALE.format("%0.6f", row.getValue(val))) 105 | res.append(rowRes) 106 | del rows 107 | 108 | coefTextTab = UTILS.outputTextTable(res, header = header) 109 | ARCPY.AddMessage("\n") 110 | ARCPY.AddMessage(coefTextTab) 111 | 112 | #### Add to TOC #### 113 | ARCPY.SetParameterAsText(5, coefTable) 114 | 115 | #### Print Diag Table (In Two Parts) #### 116 | try: 117 | rows = ARCPY.SearchCursor(diagTable) 118 | except: 119 | ARCPY.AddIDMessage("ERROR", 204) 120 | raise ERROR.ScriptError() 121 | 122 | labels = ["Diag_Name", "Diag_Value"] 123 | header = "Logistic Regression Diagnostic Table" 124 | resLab1 = [] 125 | resVal1 = [] 126 | resLab2 = [] 127 | resVal2 = [] 128 | c = 0 129 | for row in rows: 130 | for i, val in enumerate(labels): 131 | if i == 0: 132 | cellVal = row.getValue(val) 133 | if c <= 6: 134 | resLab1.append(cellVal) 135 | else: 136 | resLab2.append(cellVal) 137 | else: 138 | cellVal = LOCALE.format("%0.6f", row.getValue(val)) 139 | if c <= 6: 140 | resVal1.append(cellVal) 141 | else: 142 | resVal2.append(cellVal) 143 | c += 1 144 | del rows 145 | 146 | diagTextTab1 = UTILS.outputTextTable([resLab1, resVal1], header = header) 147 | ARCPY.AddMessage("\n") 148 | ARCPY.AddMessage(diagTextTab1) 149 | ARCPY.AddMessage("\n") 150 | diagTextTab2 = UTILS.outputTextTable([resLab2, resVal2]) 151 | ARCPY.AddMessage(diagTextTab2) 152 | ARCPY.AddMessage("\n") 153 | 154 | #### Add to TOC #### 155 | ARCPY.SetParameterAsText(6, diagTable) 156 | 157 | if __name__ == '__main__': 158 | test = setupLogit() 159 | -------------------------------------------------------------------------------- /Scripts/LogitWithR.r: -------------------------------------------------------------------------------- 1 | #### Load Libraries #### 2 | print("Loading Libraries....") 3 | library(maptools) 4 | library(sm) 5 | 6 | #### Check Version for Required "lrm" Package #### 7 | checkRVersion = function(checkMajor, checkMinor){ 8 | majorBool = as.numeric(R.version$major) >= checkMajor 9 | minorBool = as.numeric(R.version$minor) >= checkMinor 10 | majorBool & minorBool 11 | } 12 | 13 | versionBool = checkRVersion(2, 14) 14 | if (versionBool){ 15 | library(rms) 16 | }else{ 17 | require(Design) 18 | } 19 | 20 | #### Get Arguments #### 21 | Args = commandArgs() 22 | inputFC = sub(".shp", "", Args[5], ignore.case = TRUE) 23 | outputFC = sub(".shp", "", Args[6], ignore.case = TRUE) 24 | dependentVar = Args[7] 25 | independentVarString = Args[8] 26 | usePenalty = as.integer(Args[9]) 27 | usePenalty = usePenalty == 1 28 | coefTable = sub(".dbf", "", Args[10], ignore.case = TRUE) 29 | diagTable = sub(".dbf", "", Args[11], ignore.case = TRUE) 30 | print(paste(commandArgs(), collapse=" ")) 31 | 32 | #### Get Ind Var Names #### 33 | independentVars = strsplit(independentVarString, ";") 34 | independentVars = c(unlist(independentVars)) 35 | 36 | ### Make Formula #### 37 | form = as.formula(paste(dependentVar, paste(independentVars, collapse='+'), sep='~')) 38 | 39 | print("Begin Calculations....") 40 | ### Using Maptools #### 41 | shp = readShapeSpatial(inputFC) 42 | 43 | ### Do Logit #### 44 | print("Logit....") 45 | #fit = lrm(form, shp) 46 | fit = lrm(form, shp, x = TRUE, y = TRUE) 47 | 48 | print("Adjustment....") 49 | ### AIC Alternative Measure of Model Performance #### 50 | bf = pentrace(fit, seq(.2,1,by=.05)) 51 | if (usePenalty) { 52 | pen = bf$penalty 53 | } else { 54 | pen = 0.0 55 | } 56 | 57 | allPens = bf$results.all[,1] 58 | allAICs = bf$results.all[,3] 59 | for (i in 1:length(allPens)){ 60 | penValue = allPens[i] 61 | if (penValue == pen){ 62 | aic = allAICs[i] 63 | } 64 | } 65 | 66 | if (usePenalty){ 67 | fit = update(fit, penalty = bf$penalty) 68 | } 69 | 70 | ### Residuals #### 71 | res = residuals.lrm(fit) 72 | resOut = c(res) 73 | resSTD = (resOut - mean(resOut)) / sqrt(var(resOut)) 74 | 75 | ### Create Output Shape File #### 76 | print("Writing Output....") 77 | shp$Residual = resOut 78 | shp$StdResid = resSTD 79 | writeSpatialShape(shp, outputFC) 80 | 81 | ### Write Coefficient DBF Table #### 82 | allIndVars = c("Intercept") 83 | allIndVars = append(allIndVars, independentVars) 84 | k = length(allIndVars) 85 | d = matrix(0, k, 4) 86 | d[,1] = fit$coefficients 87 | d[,2] = sqrt(diag(fit$var)) 88 | d[,3] = d[,1] / d[,2] 89 | d[,4] = pnorm(abs(d[,3]), lower.tail = FALSE) * 2.0 90 | coefList = list("Variable" = allIndVars, "Coef" = d[,1], 91 | "StdError" = d[,2], "Wald" = d[,3], 92 | "Prob" = d[,4]) 93 | coefFrame = data.frame(coefList) 94 | write.dbf(coefFrame, coefTable) 95 | 96 | ### Write Diagnostic DBF Table #### 97 | diagNames = names(fit$stats) 98 | allStats = c(as.vector(fit$stats), pen, aic) 99 | diagValues = matrix(allStats, length(diagNames), 1) 100 | diagList = list("Diag_Name" = diagNames, "Diag_Value" = diagValues) 101 | diagFrame = data.frame(diagList) 102 | write.dbf(diagFrame, diagTable) 103 | 104 | print("Calculations Complete...") 105 | -------------------------------------------------------------------------------- /Scripts/PointClusters.py: -------------------------------------------------------------------------------- 1 | import arcpy as ARCPY 2 | import arcpy.management as DM 3 | import os as OS 4 | import sys as SYS 5 | import subprocess as SUB 6 | import arcpyWithR as RARC 7 | 8 | #### Parameter Dictionaries #### 9 | clusterDict = {"KMEANS_HARTIGAN": "kmeansHartigan", "CLARA": "clara", 10 | "B_CLUST": "bclust", "M_CLUST": "Mclust", 11 | "KCCA_KMEANS": "kccaKmeans", 12 | "CMEANS": "cmeans"} 13 | 14 | def PointClusters(): 15 | #### Get User Provided Inputs #### 16 | inputFC = ARCPY.GetParameterAsText(0) 17 | outputFC = ARCPY.GetParameterAsText(1) 18 | numClusters = ARCPY.GetParameterAsText(2) 19 | clusterMethod = ARCPY.GetParameterAsText(3) 20 | clusterMethodStr = clusterDict[clusterMethod] 21 | varNames = ARCPY.GetParameterAsText(4) 22 | varNames = [ str(i) for i in varNames.split(";") ] 23 | varNames = ";".join(varNames) 24 | if varNames == '': 25 | varNames = "NA" 26 | useLocation = ARCPY.GetParameterAsText(5) 27 | if useLocation == 'true': 28 | useLocation = "1" 29 | else: 30 | useLocation = "0" 31 | 32 | #### Create R Command #### 33 | pyScript = SYS.argv[0] 34 | toolDir = OS.path.dirname(pyScript) 35 | rScript = OS.path.join(toolDir, "PointClusters.r") 36 | ARCPY.SetProgressor("default", "Executing R Script...") 37 | args = [RARC.findRExecutable(), "--slave", "--vanilla", "--args", 38 | inputFC, outputFC, numClusters, clusterMethodStr, 39 | varNames, useLocation, toolDir] 40 | 41 | #### Uncomment Next Two Lines to Print/Create Command Line Args #### 42 | #cmd = RARC.createRCommand(args, rScript) 43 | #ARCPY.AddWarning(cmd) 44 | 45 | #### Execute Command #### 46 | scriptSource = open(rScript, 'rb') 47 | rCommand = SUB.Popen(args, 48 | stdin = scriptSource, 49 | stdout = SUB.PIPE, 50 | stderr = SUB.PIPE, 51 | shell=True) 52 | 53 | #### Print Result #### 54 | resString, errString = rCommand.communicate() 55 | 56 | #### Push Output to Message Window #### 57 | if errString and "Calculations Complete..." not in resString: 58 | ARCPY.AddError(errString) 59 | else: 60 | resOutString = RARC.printRMessages(resString) 61 | ARCPY.AddMessage(resOutString) 62 | 63 | #### Project the Data #### 64 | DM.DefineProjection(outputFC, inputFC) 65 | 66 | #### Render the Results #### 67 | params = ARCPY.gp.GetParameterInfo() 68 | renderFile = OS.path.join(toolDir, "RenderClusters.lyr") 69 | params[1].Symbology = renderFile 70 | 71 | if __name__ == '__main__': 72 | 73 | test = PointClusters() 74 | -------------------------------------------------------------------------------- /Scripts/PointClusters.r: -------------------------------------------------------------------------------- 1 | normalize = function(x){ 2 | normX = (x - mean(x)) / sqrt(var(x)) 3 | } 4 | 5 | #### Get/Parse Arguments #### 6 | Args = commandArgs() 7 | inputFC = sub(".shp", "", Args[5], ignore.case = TRUE) 8 | outputFC = sub(".shp", "", Args[6], ignore.case = TRUE) 9 | numClusters = as.integer(Args[7]) 10 | clusterMethod = Args[8] 11 | fields = Args[9] 12 | useLocation = as.integer(Args[10]) 13 | scriptDir = Args[11] 14 | useFields = FALSE 15 | 16 | #### Create Field Names is Applicable #### 17 | if (fields != "NA"){ 18 | varNames = strsplit(fields, ";") 19 | varNames = c(unlist(varNames)) 20 | useFields = TRUE 21 | } 22 | 23 | #### Import the Cluster Library #### 24 | print("Loading Libraries....") 25 | # include the core clust function from clustTools 26 | clust.include <- paste(sep="/", scriptDir, "clust.R") 27 | source(clust.include) 28 | 29 | #### Using Maptools For Shapefiles #### 30 | library(maptools) 31 | 32 | print("Begin Calculations....") 33 | shp = readShapePoints(inputFC) 34 | centroids = coordinates(shp) 35 | 36 | #### Create Boolean For Using Location #### 37 | #### Set to True: if useLocation requested or no fields provided #### 38 | noFields = (useFields == FALSE) 39 | addLocation = (useLocation | noFields) 40 | 41 | #### Add Locations #### 42 | if (addLocation){ 43 | XCOO = normalize(centroids[,1]) 44 | YCOO = normalize(centroids[,2]) 45 | allVars = cbind(XCOO, YCOO) 46 | } else { 47 | allVars = NULL 48 | } 49 | 50 | #### Add Fields #### 51 | if (useFields){ 52 | for (i in 1:length(varNames)){ 53 | allVars = cbind(allVars, normalize(shp[[varNames[i]]])) 54 | } 55 | } 56 | 57 | #### Create Data Frame for Analysis #### 58 | new = data.frame(allVars) 59 | 60 | #### Run Algorithm #### 61 | newCL = clust(new, k = numClusters, method = clusterMethod) 62 | 63 | #### Write Output to New FC #### 64 | shp$CLUSTER = newCL$cluster 65 | writeSpatialShape(shp, outputFC) 66 | 67 | #### Print Output Summary #### 68 | print(newCL) 69 | delim = paste(rep('-', 55), collapse = "") 70 | print(delim) 71 | print(names(newCL)) 72 | print(delim) 73 | print(delim) 74 | print("Centers") 75 | print(newCL$centers) 76 | print(delim) 77 | print(delim) 78 | print(newCL$valMeasures) 79 | print(delim) 80 | 81 | print("Calculations Complete...") 82 | -------------------------------------------------------------------------------- /Scripts/RenderClusters.lyr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/Scripts/RenderClusters.lyr -------------------------------------------------------------------------------- /Scripts/arcpyWithR.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def findRExecutable(): 4 | try: 5 | import _winreg 6 | except ImportError: # Non-windows builds 7 | return "R" 8 | 9 | handle = None 10 | try: 11 | handle =_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 12 | r"SOFTWARE\R-Core\R") 13 | i = 0 14 | while True: 15 | key, value, _ = _winreg.EnumValue(handle, i) 16 | if key.lower() == "installpath": 17 | r_executable_path = os.path.join(value, "bin", "R.exe") 18 | return r_executable_path 19 | i += 1 20 | except: 21 | return "R" 22 | finally: 23 | if handle is not None: 24 | _winreg.CloseKey(handle) 25 | # Fall back to default (hope it's on the %PATH%) 26 | return "R" 27 | 28 | def printRMessages(resString): 29 | initLine = '[1] "Loading Libraries...."' 30 | outInitLine = "Loading Libraries...." 31 | resString = resString.replace(initLine, outInitLine) 32 | resString = resString.replace("\n[1] ", "\n") 33 | resString = resString.replace('"\n', "\n") 34 | return resString.replace('\n"', "\n") 35 | 36 | def createRCommand(args, rScript): 37 | argString = args + ["<", rScript] 38 | return " ".join(argString) 39 | 40 | -------------------------------------------------------------------------------- /Scripts/clust.R: -------------------------------------------------------------------------------- 1 | # clust.R from clustTools, which isn't supported in more recent releases of R 2 | # and hasn't been updated in 3 years. 3 | # Author: Matthias Templ 4 | # Licence: GPL 2 5 | 6 | "clust" <- 7 | function( x=Cassini$x, k=3, method="kmeansHartigan", 8 | seed=set.seed(123), distMethod="euclidean", 9 | qtclustsize=0.7, iter.max=100, eps=0.1, 10 | vals = TRUE, alt = NULL, coord=NULL, bic=NULL){ 11 | 12 | ############### 13 | 14 | ### utility function from fpc package: 15 | cluster.stats <- function(d,clustering,alt.clustering=NULL, 16 | silhouette=TRUE,G2=FALSE,G3=FALSE, 17 | compareonly=FALSE){ 18 | cn <- max(clustering) 19 | n <- length(clustering) 20 | diameter <- average.distance <- median.distance <- separation <- 21 | average.toother <- 22 | cluster.size <- within.dist <- between.dist <- numeric(0) 23 | for (i in 1:cn) 24 | cluster.size[i] <- sum(clustering==i) 25 | pk1 <- cluster.size/n 26 | pk10 <- pk1[pk1>0] 27 | h1 <- -sum(pk10*log(pk10)) 28 | corrected.rand <- vi <- NULL 29 | if (!is.null(alt.clustering)){ 30 | choose2 <- function(v){ 31 | out <- numeric(0) 32 | for (i in 1:length(v)) 33 | out[i] <- ifelse(v[i]>=2,choose(v[i],2),0) 34 | out 35 | } 36 | cn2 <- max(alt.clustering) 37 | nij <- table(clustering,alt.clustering) 38 | dsum <- sum(choose2(nij)) 39 | cs2 <- numeric(0) 40 | for (i in 1:cn2) 41 | cs2[i] <- sum(alt.clustering==i) 42 | sum1 <- sum(choose2(cluster.size)) 43 | sum2 <- sum(choose2(cs2)) 44 | pk2 <- cs2/n 45 | pk12 <- nij/n 46 | corrected.rand <- (dsum-sum1*sum2/choose2(n))/ 47 | ((sum1+sum2)/2-sum1*sum2/choose2(n)) 48 | pk20 <- pk2[pk2>0] 49 | h2 <- -sum(pk20*log(pk20)) 50 | icc <- 0 51 | for (i in 1:cn) 52 | for (j in 1:cn2) 53 | if (pk12[i,j]>0) 54 | icc <- icc+pk12[i,j]*log(pk12[i,j]/(pk1[i]*pk2[j])) 55 | # print(icc) 56 | vi <- h1+h2-2*icc 57 | } 58 | if (compareonly){ 59 | out <- list(corrected.rand=corrected.rand,vi=vi) 60 | } 61 | else{ 62 | if (silhouette) require(cluster) 63 | dmat <- as.matrix(d) 64 | within.cluster.ss <- 0 65 | separation.matrix <- matrix(0,ncol=cn,nrow=cn) 66 | di <- list() 67 | for (i in 1:cn){ 68 | cluster.size[i] <- sum(clustering==i) 69 | di <- as.dist(dmat[clustering==i,clustering==i]) 70 | within.cluster.ss <- within.cluster.ss+sum(di^2)/cluster.size[i] 71 | within.dist <- c(within.dist,di) 72 | if (sum(clustering==i)>1) 73 | diameter[i] <- max(di) 74 | else 75 | diameter[i] <- 0 76 | average.distance[i] <- mean(di) 77 | median.distance[i] <- median(di) 78 | bv <- numeric(0) 79 | for (j in 1:cn){ 80 | if (j!=i){ 81 | sij <- dmat[clustering==i,clustering==j] 82 | bv <- c(bv,sij) 83 | if (ibetween.dist) 108 | } 109 | g2 <- (splus - sminus)/(splus + sminus) 110 | } 111 | if (G3){ 112 | sdist <- sort(c(within.dist,between.dist)) 113 | sr <- nwithin+nbetween 114 | dmin <- sum(sdist[1:nwithin]) 115 | dmax <- sum(sdist[(sr-nwithin+1):sr]) 116 | g3 <- (sum(within.dist)-dmin)/(dmax-dmin) 117 | } 118 | hubertgamma <- cor(c(within.dist,between.dist),c(rep(0,nwithin), 119 | rep(1,nbetween))) 120 | dunn <- min(separation)/max(diameter) 121 | out <- list(n=n, 122 | cluster.number=cn, 123 | cluster.size=cluster.size, # vector of cluster sizes 124 | diameter=diameter, # vector of cluster diameters 125 | average.distance=average.distance, 126 | # vector of within cl. av. dist. 127 | median.distance=median.distance, 128 | # vector of within cl. median dist. 129 | separation=separation, # vector of min. clusterwise between dist. 130 | average.toother=average.toother, 131 | # vector of mean clusterwise between dist. 132 | separation.matrix=separation.matrix, 133 | # clusterwise matrix of min. between dist. 134 | average.between=average.between, # mean between cl. distance 135 | average.within=average.within, # mean within cl. distance 136 | n.between=nbetween, # number of between cl. distances 137 | n.within=nwithin, # number of within cl. distances 138 | within.cluster.ss=within.cluster.ss, 139 | clus.avg.silwidths=clus.avg.widths, 140 | # vector of cluster avg. silhouette widths 141 | avg.silwidth=avg.width, # average silhouette width 142 | g2=g2, # Goodman and Kruskal coefficient, see Gordon p. 62 143 | g3=g3, # G3 index, see Gordon p. 62 144 | hubertgamma=hubertgamma, # Correlation between distances and 145 | # 0-1-vector same/different cluster 146 | dunn=dunn, # Dunn index, see Halkidi et al. (2002) 147 | # Min. sepatation / max. diameter 148 | entropy=h1, 149 | wb.ratio=average.within/average.between, 150 | corrected.rand=corrected.rand, vi=vi) # Corrected rand index between 151 | # clustering and alt.clustering 152 | # class(out) <- "cluster.stats" 153 | } 154 | out 155 | } 156 | 157 | 158 | 159 | ############## 160 | 161 | 162 | 163 | 164 | 165 | 166 | if( method == "fixmahal" && vals == TRUE ){ 167 | stop("vals are not available with method fixmahal") 168 | } 169 | 170 | seed 171 | vp <- FALSE # varplot information 172 | if( distMethod == "rf" ){ 173 | cat("\n *** calculating random forest proximity measure...\n") 174 | flush.console() 175 | d <- sqrt( 1 - randomForest(x, proximity=TRUE)$proximity) 176 | } 177 | if( distMethod == "correlation" ){ 178 | d <- 1 - abs(cor(t(x))) 179 | } 180 | if( distMethod == "robustCorrelation" ){ 181 | d <- 1 - abs(covMcd(t(x), cor=TRUE)$cor) 182 | } 183 | cosadistCalc <- function(x, method){ 184 | ##cosadist part: 185 | platform="windows" 186 | cosadir="E:/matthias/R/cosa/" 187 | source("E:\\matthias\\R\\cosa\\r_cosa.q") 188 | if( any( method == c("hclustSingle", "hclustComplete", "hclustAverage", 189 | "hclustWard", "hclustMcquitty", "hclustMedian", 190 | "hclustcentroid" ) ) ){ d <- cosadist(x,niter=70) } else { 191 | d <- cosadist(x,niter=80) 192 | N <- dim(x)[1] 193 | m <- matrix(0, ncol=N, nrow=N) 194 | ind=0 195 | f2 <- function(){ 196 | for( i in 1:N ){ 197 | if( i + 1 <= N ){ 198 | for( j in (i+1):N ){ 199 | ind <- ind + 1 200 | m[i,j] <- m[j,i] <- d[ind] 201 | 202 | } 203 | } 204 | } 205 | return(m) 206 | } 207 | d <- f2() 208 | } 209 | d 210 | } 211 | ## end cosadist part 212 | if( distMethod == "cosadist" ) d <- cosadistCalc(x=x, method=method) 213 | if( any(distMethod == c("gower", "bray", "kulczynski", "chord")) ) d <- gdist(x, method = distMethod) 214 | if( any(distMethod == c("morisita", "horn", "mountford")) ) d <- vegdist(x, method = distMethod) 215 | menge1 <- c("gower", "bray", "kulczynski", "chord") 216 | menge2 <- c("morisita", "horn", "mountford") 217 | ##menge2 <- c(menge1, "euclidean", "rf", "cosadist") 218 | menge3 <- c("maximum", "canberra") 219 | 220 | findCenter <- function(x, clustering, k){ 221 | a1 <- matrix(nrow=k, ncol=ncol(x)) 222 | for( i in 1:k ){ 223 | a1[i,] <- apply(x[ which( clustering == i ), , drop=FALSE ], 2, mean) 224 | } 225 | a1 226 | } 227 | 228 | clust <- list() 229 | seed 230 | cat(paste("\n *** running", method, "cluster algorithm...\n")) 231 | flush.console() 232 | if( method == "kmeansHartigan" ) { 233 | if( distMethod == "euclidean" ) { 234 | d <- x 235 | vp <- TRUE 236 | } 237 | ##if( distMethod != "euclidean" && distMethod != "rf" && distMethod != "cosadist") d <- dist(x, method = distMethod ) 238 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 239 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 240 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 241 | a <- kmeans(d, k, algorithm="Hartigan-Wong", iter.max=iter.max, nstart=5 ) 242 | clust$cluster <- a$cluster 243 | clust$centers <- a$centers 244 | clust$size <- a$size 245 | ### Achtung: mit eigener Distanzmatrix falsches Ergebnis!!! 246 | } 247 | if( method == "kmeansLloyd" ) { 248 | if( distMethod == "euclidean" ){ 249 | d <- x 250 | vp <- TRUE 251 | } 252 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 253 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 254 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 255 | a <- kmeans(d, k, algorithm="Lloyd", iter.max=iter.max, nstart=5 ) 256 | clust$cluster <- a$cluster 257 | clust$centers <- a$centers 258 | clust$size <- a$size 259 | } 260 | if( method == "kmeansForgy" ) { 261 | if( distMethod == "euclidean" ){ 262 | d <- x 263 | vp <- TRUE 264 | } 265 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 266 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 267 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 268 | a <- kmeans(d, k, algorithm="Forgy", iter.max=iter.max, nstart=5 ) 269 | clust$cluster <- a$cluster 270 | clust$centers <- a$centers 271 | clust$size <- a$size 272 | } 273 | if( method == "kmeansMacQueen" ) { 274 | if( distMethod == "euclidean" ){ 275 | d <- x 276 | vp <- TRUE 277 | } 278 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 279 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 280 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 281 | a <- kmeans(d, k, algorithm="MacQueen", iter.max=iter.max, nstart=5 ) 282 | clust$cluster <- a$cluster 283 | clust$centers <- a$centers 284 | clust$size <- a$size 285 | } 286 | if( method == "cmeansUfcl" ){ 287 | if( any(distMethod == c("euclidean", "manhattan")) ){ 288 | d <- x 289 | vp <- TRUE 290 | } 291 | ##if( all(distMethod != c("euclidean", "manhattan", "rf","cosadist")) ) d <- dist(x, method = distMethod ) 292 | if( any(distMethod == menge3) ) d <- dist(x, method = distMethod ) 293 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 294 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 295 | a <- cmeans(d, k, method="ufcl") 296 | clust$cluster <- a$cluster 297 | clust$centers <- a$centers 298 | clust$size <- a$size 299 | clust$membership <- a$membership 300 | } 301 | if( method == "pam" || method == "clara" ){ 302 | if( any(distMethod == c("euclidean", "manhattan")) ){ 303 | d <- x; vp <- TRUE; a <- get(method)(d, k, metric=distMethod) 304 | } 305 | if( any(distMethod == menge1) ) gdist(x, method=distMethod) 306 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 307 | ##if( all(distMethod != c("euclidean", "manhattan", "rf","cosadist")) ) { 308 | if( any(distMethod == menge3 ) ){ 309 | d <- dist(x, distMethod ) 310 | a <- get(method)(d, k) 311 | } 312 | if( distMethod == "rf" ){ 313 | a <- get(method)(d, k) 314 | } 315 | if( distMethod == "correlation" ){ 316 | a <- get(method)(d, k) 317 | } 318 | if( distMethod == "cosadist" ){ 319 | a <- get(method)(d, k) 320 | } 321 | if( any(distMethod == c(menge1,menge2)) ) a <- get(method)(d,k) 322 | clust$cluster <- a$cluster 323 | clust$center <- a$med 324 | clust$size <- a$clusinfo[,1] 325 | } 326 | if( method == "fanny" ){ 327 | if( any(distMethod == c("euclidean", "manhattan")) ){ 328 | d <- x 329 | vp <- TRUE 330 | } 331 | if( any(distMethod == menge3) ) d <- dist(x, method = distMethod ) 332 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 333 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 334 | a <- fanny(d, k) 335 | clust$cluster <- a$cluster 336 | clust$center <- a$med 337 | clust$size <- a$clusinfo[,1] 338 | clust$membership <- a$mem 339 | } 340 | if( method == "bclust" ){ 341 | if( distMethod == "euclidean" ){ 342 | d <- x 343 | vp <- TRUE 344 | } 345 | if( any(distMethod == c("manhattan",menge3)) ) d <- dist(x, method = distMethod ) 346 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 347 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 348 | a <- bclust(d, k) 349 | clust$cluster <- a$cluster 350 | clust$center <- a$centers 351 | clust$size <- table(a$cluster) 352 | } 353 | if( method == "cmeans" || method == "cshell" ){ 354 | if( any(distMethod == c("euclidean", "manhattan")) ){ 355 | d <- x 356 | vp <- TRUE 357 | } 358 | if( any(distMethod == menge3) ) d <- dist(x, method = distMethod ) 359 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 360 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 361 | a <- get(method)(d, k) 362 | clust$cluster <- a$cluster 363 | clust$centers <- a$centers 364 | clust$size <- a$size 365 | clust$membership <- a$membership 366 | } 367 | if( method == "Mclust" ){ 368 | vp <- TRUE 369 | a <- Mclust(x, G=k) 370 | clust$cluster <- a$classification 371 | clust$center <- aggregate(x, list(a$classification), mean)[,-1] 372 | #clust$center <- t(a$mu) 373 | clust$size <- table(a$classification) 374 | #clust$bic <- a$bic 375 | clust$BIC <- a$bic 376 | clust$model <- a$model 377 | } 378 | if( method == "kccaKmeans" ){ 379 | cat("\n --------- \n Note: \n If an error message (detach(package:kernlab) is printed,") 380 | cat("\n ignore the error, please.") 381 | cat("\n Package kernlab *must* be detached, before running the algorithm!\n") 382 | flush.console() 383 | try(detach(package:kernlab)) 384 | cat("\n --------- \n") 385 | flush.console() 386 | if( distMethod == "euclidean" ){ a <- kcca(x, k, family=kccaFamily("kmeans")) 387 | vp <- TRUE 388 | } 389 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 390 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 391 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 392 | if( distMethod != "euclidean" ){ 393 | a <- kcca(as.matrix(d), k, family=kccaFamily("kmeans")) 394 | } 395 | clust$cluster <- a@cluster 396 | clust$center <- a@centers 397 | clust$size <- table(a@cluster) 398 | } 399 | if( method == "kccaKmedians" ){ 400 | cat("\n --------- \n Note: \n If an error message (detach(package:kernlab) is printed,") 401 | cat("\n ignore the error, please.") 402 | cat("\n Package kernlab *must* be detached, before running the algorithm!\n") 403 | flush.console() 404 | try(detach(package:kernlab)) 405 | cat("\n --------- \n") 406 | flush.console() 407 | if( distMethod == "manhattan" ){ a <- kcca(x, k, family=kccaFamily("kmedians")) 408 | vp <- TRUE 409 | } 410 | if( any(distMethod == c("euclidean", menge3)) ) d <- dist(x, method = distMethod ) 411 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 412 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 413 | if( distMethod != "manhattan" ){ 414 | a <- kcca(as.matrix(d), k, family=kccaFamily("kmedians")) 415 | } 416 | clust$cluster <- a@cluster 417 | clust$center <- a@centers 418 | clust$size <- table(a@cluster) 419 | } 420 | if( method == "kccaAngle" ){ 421 | cat("\n --------- \n Note: \n If an error message (detach(package:kernlab) is printed,") 422 | cat("\n ignore the error, please.") 423 | cat("\n Package kernlab *must* be detached, before running the algorithm!\n") 424 | flush.console() 425 | try(detach(package:kernlab)) 426 | cat("\n --------- \n") 427 | flush.console() 428 | if( distMethod == "euclidean" ){ a <- kcca(x, k, family=kccaFamily("angle")) 429 | vp <- TRUE 430 | } 431 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 432 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 433 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 434 | if( distMethod != "euclidean" ){ 435 | a <- kcca(as.matrix(d), k, family=kccaFamily("angle")) 436 | } 437 | clust$cluster <- a@cluster 438 | clust$center <- a@centers 439 | clust$size <- table(a@cluster) 440 | } 441 | if( method == "kccaJaccard" ){ 442 | cat("\n --------- \n Note: \n If an error message (detach(package:kernlab) is printed,") 443 | cat("\n ignore the error, please.") 444 | cat("\n Package kernlab *must* be detached, before running the algorithm!\n") 445 | flush.console() 446 | try(detach(package:kernlab)) 447 | cat("\n --------- \n") 448 | flush.console() 449 | if( distMethod == "euclidean" ){ a <- kcca(x, k, family=kccaFamily("jaccard")) 450 | vp <- TRUE 451 | } 452 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 453 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 454 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 455 | if( distMethod != "euclidean" ){ 456 | a <- kcca(as.matrix(d), k, family=kccaFamily("jaccard")) 457 | } 458 | clust$cluster <- a@cluster 459 | clust$center <- a@centers 460 | clust$size <- table(a@cluster) 461 | } 462 | if( method == "kccaEjaccard" ){ 463 | cat("\n --------- \n Note: \n If an error message (detach(package:kernlab) is printed,") 464 | cat("\n ignore the error, please.") 465 | cat("\n Package kernlab *must* be detached, before running the algorithm!\n") 466 | flush.console() 467 | try(detach(package:kernlab)) 468 | cat("\n --------- \n") 469 | flush.console() 470 | if( distMethod == "euclidean" ){ a <- kcca(x, k, family=kccaFamily("ejaccard")) 471 | vp <- TRUE 472 | } 473 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 474 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 475 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 476 | if( distMethod != "euclidean" ){ 477 | a <- kcca(as.matrix(d), k, family=kccaFamily("ejaccard")) 478 | } 479 | clust$cluster <- a@cluster 480 | clust$center <- a@centers 481 | clust$size <- table(a@cluster) 482 | } 483 | if( method == "cclustKmeans" ){ 484 | if( any( distMethod == c("euclidean","manhattan") ) ){ d <- x 485 | vp <- TRUE 486 | a <- cclust(x, k, method="kmeans", dist=distMethod) 487 | } 488 | ##if( any(distMethod == menge3) ) d <- dist(x, method = distMethod ) 489 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 490 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 491 | a <- cclust(x, k, method="kmeans") 492 | clust$cluster <- a@cluster 493 | clust$center <- a@centers 494 | clust$size <- table(a@cluster) 495 | } 496 | if( method == "cclustHardcl" ){ 497 | if( any( distMethod == c("euclidean","manhattan") )){ d <- x 498 | vp <- TRUE 499 | a <- cclust(x, k, method="hardcl", dist=distMethod) 500 | } 501 | ##if( any(distMethod == menge3) ) d <- dist(x, method = distMethod ) 502 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 503 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 504 | a <- cclust(x, k, method="hardcl") 505 | clust$cluster <- a@cluster 506 | clust$center <- a@centers 507 | clust$size <- table(a@cluster) 508 | } 509 | if( method == "cclustNeuralgas" ){ 510 | if( any( distMethod == c("euclidean","manhattan") )){ d <- x 511 | vp <- TRUE 512 | a <- cclust(x, k, method="neuralgas", dist=distMethod) 513 | } 514 | ##if( any(distMethod == menge3) ) d <- dist(x, method = distMethod ) 515 | if( any(distMethod == menge1) ){ d <- gdist(x, method=distMethod) 516 | stop("cclust can only deal with euclidean or manhattan distances") 517 | } 518 | if( any(distMethod == menge2) ){ d <- vegdist(x, method=distMethod) 519 | stop("cclust can only deal with euclidean or manhattan distances") 520 | } 521 | ##a <- cclust(as.matrix(d), k, method="neuralgas") 522 | clust$cluster <- a@cluster 523 | clust$center <- a@centers 524 | clust$size <- table(a@cluster) 525 | } 526 | if( method == "qtclustKmeans" ){ 527 | if( distMethod == "euclidean" ){ 528 | d <- x 529 | vp <- TRUE 530 | } 531 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 532 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 533 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 534 | a <- qtclust(x, qtclustsize, family=kccaFamily("kmeans")) 535 | clust$cluster <- a@cluster 536 | clust$center <- a@centers 537 | clust$size <- a@size 538 | } 539 | if( method == "qtclustKmedian" ){ 540 | if( distMethod == "euclidean" ){ 541 | d <- x 542 | vp <- TRUE 543 | } 544 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 545 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 546 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 547 | a <- qtclust(x, qtclustsize, family=kccaFamily("kmedian")) 548 | clust$cluster <- a@cluster 549 | clust$center <- a@centers 550 | clust$size <- a@size 551 | } 552 | if( method == "qtclustAngle" ){ 553 | if( distMethod == "euclidean" ){ 554 | d <- x 555 | vp <- TRUE 556 | } 557 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 558 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 559 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 560 | a <- qtclust(x, qtclustsize, family=kccaFamily("angle")) 561 | clust$cluster <- a@cluster 562 | clust$center <- a@centers 563 | clust$size <- a@size 564 | } 565 | if( method == "qtclustJaccard" ){ 566 | if( distMethod == "euclidean" ){ 567 | d <- x 568 | vp <- TRUE 569 | } 570 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 571 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 572 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 573 | a <- qtclust(x, qtclustsize, family=kccaFamily("jaccard")) 574 | clust$cluster <- a@cluster 575 | clust$center <- a@centers 576 | clust$size <- a@size 577 | } 578 | if( method == "qtclustEjaccard" ){ 579 | if( distMethod == "euclidean" ){ 580 | d <- x 581 | vp <- TRUE 582 | } 583 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 584 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 585 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 586 | a <- qtclust(x, qtclustsize, family=kccaFamily("ejaccard")) 587 | clust$cluster <- a@cluster 588 | clust$center <- a@centers 589 | clust$size <- a@size 590 | } 591 | if( method == "dbscan" ){ 592 | if( distMethod == "euclidean" ){ 593 | d <- x 594 | vp <- TRUE 595 | } 596 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 597 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 598 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 599 | a <- dbscan(x, eps=eps) 600 | clust$cluster <- a$classification 601 | clust$center <- "none" 602 | clust$size <- table(a$classification) 603 | } 604 | if( method == "speccRbfdot" ){ 605 | library(kernlab) 606 | if( distMethod == "euclidean" ){ 607 | d <- x 608 | vp <- TRUE 609 | } 610 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 611 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 612 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 613 | a <- specc(as.matrix(d),centers=k) 614 | clust$cluster <- a@.Data 615 | clust$center <- a@centers 616 | clust$size <- a@size 617 | } 618 | if( method == "speccPolydot" ){ 619 | library(kernlab) 620 | if( distMethod == "euclidean" ){ 621 | d <- x 622 | vp <- TRUE 623 | } 624 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 625 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 626 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod ) 627 | a <- specc(as.matrix(d),centers=k, kernel="polydot") 628 | clust$cluster <- a@.Data 629 | clust$center <- a@centers 630 | clust$size <- a@size 631 | } # vanilladot tanhdot laplacedot besseldot anovadot splinedot 632 | if( method == "speccVanilladot" ){ 633 | library(kernlab) 634 | if( distMethod == "euclidean" ){ 635 | d <- x 636 | vp <- TRUE 637 | } 638 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 639 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 640 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 641 | a <- specc(as.matrix(x),centers=k, kernel="vanilladot") 642 | clust$cluster <- a@.Data 643 | clust$center <- a@centers 644 | clust$size <- a@size 645 | } 646 | if( method == "speccTanhdot" ){ 647 | library(kernlab) 648 | if( distMethod == "euclidean" ){ 649 | d <- x 650 | vp <- TRUE 651 | } 652 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 653 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 654 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 655 | a <- specc(as.matrix(x),centers=k, kernel="tanhdot") 656 | clust$cluster <- a@.Data 657 | clust$center <- a@centers 658 | clust$size <- a@size 659 | } 660 | if( method == "speccLaplacedot" ){ 661 | library(kernlab) 662 | if( distMethod == "euclidean" ){ 663 | d <- x 664 | vp <- TRUE 665 | } 666 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 667 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 668 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 669 | a <- specc(as.matrix(x),centers=k, kernel="laplacedot") 670 | clust$cluster <- a@.Data 671 | clust$center <- a@centers 672 | clust$size <- a@size 673 | } 674 | if( method == "speccBesseldot" ){ 675 | library(kernlab) 676 | if( distMethod == "euclidean" ){ 677 | d <- x 678 | vp <- TRUE 679 | } 680 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 681 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 682 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 683 | a <- specc(as.matrix(x),centers=k, kernel="besseldot") 684 | clust$cluster <- a@.Data 685 | clust$center <- a@centers 686 | clust$size <- a@size 687 | } 688 | if( method == "speccAnovadot" ){ 689 | library(kernlab) 690 | if( distMethod == "euclidean" ){ 691 | d <- x 692 | vp <- TRUE 693 | } 694 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 695 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 696 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 697 | a <- specc(as.matrix(x),centers=k, kernel="anovadot") 698 | clust$cluster <- a@.Data 699 | clust$center <- a@centers 700 | clust$size <- a@size 701 | } 702 | if( method == "speccSplinedot" ){ 703 | library(kernlab) 704 | if( distMethod == "euclidean" ){ 705 | d <- x 706 | vp <- TRUE 707 | } 708 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 709 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 710 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 711 | a <- specc(as.matrix(x),centers=k, kernel="splinedot") 712 | clust$cluster <- a@.Data 713 | clust$center <- a@centers 714 | clust$size <- a@size 715 | } 716 | if( method == "fixmahal" ){ 717 | if( distMethod == "euclidean" ){ 718 | d <- x 719 | vp <- TRUE 720 | } 721 | if( any(distMethod == c("manhattan", menge3)) ) d <- dist(x, method = distMethod ) 722 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 723 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 724 | f <- try(fixmahal(x)) 725 | f2 <- try(fpclusters(f)) 726 | clust$cluster <- f2 727 | clust$center <- "none" 728 | clust$size <- "none" 729 | clust$fixmahl <- TRUE 730 | } 731 | if( method == "hclustSingle" ){ 732 | ##if( method != "rf" && distMethod != "cosadist") d <- dist(x, method = distMethod) 733 | if( any(distMethod == c("euclidean", "manhattan", menge3) ) ) d <- dist(x, method = distMethod ) 734 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 735 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 736 | a <- cutree(hclust(d, method="single"), k) 737 | clust$cluster <- as.numeric(a) 738 | clust$center <- as.numeric(findCenter(x, a, k)) 739 | clust$size <- table(a) 740 | } 741 | if( method == "hclustComplete" ){ 742 | if( any(distMethod == c("euclidean", "manhattan", menge3) ) ) d <- dist(x, method = distMethod ) 743 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 744 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 745 | a <- cutree(hclust(d, method="complete"), k) 746 | clust$cluster <- as.numeric(a) 747 | clust$center <- findCenter(x, a, k) 748 | clust$size <- table(a) 749 | } 750 | if( method == "hclustAverage" ){ 751 | if( any(distMethod == c("euclidean", "manhattan", menge3) )) d <- dist(x, method = distMethod ) 752 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 753 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 754 | a <- cutree(hclust(d, method="average"), k) 755 | clust$cluster <- as.numeric(a) 756 | clust$center <- findCenter(x, a, k) 757 | clust$size <- table(a) 758 | } 759 | if( method == "hclustWard" ){ 760 | if( any(distMethod == c("euclidean", "manhattan", menge3) )) d <- dist(x, method = distMethod ) 761 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 762 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 763 | a <- cutree(hclust(d, method="ward"), k) 764 | clust$cluster <- as.numeric(a) 765 | clust$center <- findCenter(x, a, k) 766 | clust$size <- table(a) 767 | } 768 | if( method == "hclustMcquitty" ){ 769 | if( any(distMethod == c("euclidean", "manhattan", menge3) )) d <- dist(x, method = distMethod ) 770 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 771 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 772 | a <- cutree(hclust(d, method="mcquitty"), k) 773 | clust$cluster <- as.numeric(a) 774 | clust$center <- findCenter(x, a, k) 775 | clust$size <- table(a) 776 | } 777 | if( method == "hclustMedian" ){ 778 | if( any(distMethod == c("euclidean", "manhattan", menge3) )) d <- dist(x, method = distMethod ) 779 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 780 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 781 | a <- cutree(hclust(d, method="median"), k) 782 | clust$cluster <- as.numeric(a) 783 | clust$center <- findCenter(x, a, k) 784 | clust$size <- table(a) 785 | } 786 | if( method == "hclustcentroid" ){ 787 | if( any(distMethod == c("euclidean", "manhattan", menge3) )) d <- dist(x, method = distMethod ) 788 | if( any(distMethod == menge1) ) d <- gdist(x, method=distMethod) 789 | if( any(distMethod == menge2) ) d <- vegdist(x, method=distMethod) 790 | a <- cutree(hclust(d, method="centroid"), k) 791 | clust$cluster <- as.numeric(a) 792 | clust$center <- findCenter(x, a, k) 793 | clust$size <- table(a) 794 | } 795 | ### validity: --------------------------------------------------------------- 796 | cat("\n *** calculating validity measure... \n") 797 | flush.console() 798 | if( vals == FALSE ) clust.val <- m <- NA 799 | if( vals == TRUE && length(alt) > 1){ 800 | if( length(coord) == 0 ){ 801 | clust.val <- cluster.stats(dist(x), clust$cluster, as.numeric(alt)) 802 | } else { clust.val <- cluster.stats(dist(coord), clust$cluster, as.numeric(alt)) } 803 | 804 | m <- data.frame( average.between = round(clust.val$average.between, 3), 805 | average.within = round(clust.val$average.within, 3), 806 | avg.silwidth = round(clust.val$avg.silwidth, 3), 807 | hubertgamma = round(clust.val$hubertgamma, 3), 808 | dunn = round(clust.val$dunn, 3), 809 | wb.ratio = round(clust.val$wb.ratio, 3), 810 | corrected.rand = round(clust.val$corrected.rand, 3), 811 | row.names = paste(method, "-", distMethod, sep="")) 812 | 813 | } 814 | if( vals == TRUE && length(alt) == 0){ 815 | if( length(coord) == 0 ){ 816 | clust.val <- cluster.stats(dist(x), clust$cluster) 817 | } else { clust.val <- cluster.stats(dist(coord), clust$cluster) } 818 | m <- data.frame( average.between = round(clust.val$average.between, 3), 819 | average.within = round(clust.val$average.within, 3), 820 | avg.silwidth = round(clust.val$avg.silwidth, 3), 821 | hubertgamma = round(clust.val$hubertgamma, 3), 822 | dunn = round(clust.val$dunn, 3), 823 | wb.ratio = round(clust.val$wb.ratio, 3), 824 | corrected.rand = NA, 825 | row.names = paste(method, "-", distMethod, sep="")) 826 | } 827 | if( length(bic) > 0 ){ 828 | cl <- Mclust(x,G=k) 829 | bics <- vector() 830 | for(i in 1:k ){ 831 | bics[i] <- min(EMclust(x[cl$class==i,], 1), na.rm=TRUE) 832 | } 833 | ##m <- cbind(m,bics) 834 | clust$bic <- bics 835 | } 836 | clust$xdata <- x 837 | clust$method <- method 838 | clust$distMethod <- distMethod 839 | clust$k <- k 840 | clust$valTF <- vals 841 | clust$valMeasures <- m 842 | clust$silwidths <- clust.val$clus.avg.silwidths 843 | clust$separation <- clust.val$separation 844 | clust$diameter <- clust.val$diameter 845 | clust$average.distance <- clust.val$average.distance 846 | clust$median.distance <- clust.val$median.distance 847 | clust$average.toother <- clust.val$average.toother 848 | #clust$bics <- clust$bics 849 | clust$vp <- vp 850 | class(clust) <- "clust" 851 | if( vp == TRUE ){ colnames(clust$center) <- colnames(x)} 852 | class(clust) <- "clust" 853 | invisible(clust) 854 | } 855 | 856 | -------------------------------------------------------------------------------- /ToolData/InputPoint.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/ToolData/InputPoint.dbf -------------------------------------------------------------------------------- /ToolData/InputPoint.prj: -------------------------------------------------------------------------------- 1 | PROJCS["NAD_1983_StatePlane_Oregon_North_FIPS_3601_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",8202083.333333332],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-120.5],PARAMETER["Standard_Parallel_1",44.33333333333334],PARAMETER["Standard_Parallel_2",46.0],PARAMETER["Latitude_Of_Origin",43.66666666666666],UNIT["Foot_US",0.3048006096012192]] -------------------------------------------------------------------------------- /ToolData/InputPoint.sbn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/ToolData/InputPoint.sbn -------------------------------------------------------------------------------- /ToolData/InputPoint.sbx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/ToolData/InputPoint.sbx -------------------------------------------------------------------------------- /ToolData/InputPoint.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/ToolData/InputPoint.shp -------------------------------------------------------------------------------- /ToolData/InputPoint.shp.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | {6780E660-1607-4154-9E08-B9135A52854A}2007112714503800FALSECreateFeatureclass C:\Backup\TechTransfer\Data\Data911.mdb WtdCalls POINT # DISABLED DISABLED "PROJCS['NAD_1983_StatePlane_Oregon_North_FIPS_3601_Feet',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Lambert_Conformal_Conic'],PARAMETER['False_Easting',8202083.333333332],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',-120.5],PARAMETER['Standard_Parallel_1',44.33333333333334],PARAMETER['Standard_Parallel_2',46.0],PARAMETER['Latitude_Of_Origin',43.66666666666666],UNIT['Foot_US',0.3048006096012192]];7590118.31134761 649951.374293621 57990.4352909029;#;#;3.44884460681699E-05;#;#;IsLowPrecision" # 0 0 0 C:\Backup\TechTransfer\Data\Data911.mdb\WtdCallsAddField C:\Backup\TechTransfer\Data\Data911.mdb\WtdCalls ICOUNT LONG # # # # NULLABLE NON_REQUIRED # C:\Backup\TechTransfer\Data\Data911.mdb\WtdCallsCollectEvents C:\Backup\TechTransfer\Data\Data911.mdb\a911Calls C:\Backup\TechTransfer\Data\Data911.mdb\WtdCalls ICOUNT 25AddField C:\Backup\TechTransfer\Data\Data911.mdb\WtdCalls UniqID LONG # # # # NULLABLE NON_REQUIRED # C:\Backup\TechTransfer\Data\Data911.mdb\WtdCallsCalculateField C:\Backup\TechTransfer\Data\Data911.mdb\WtdCalls UniqID [OBJECTID] VB # C:\Backup\TechTransfer\Data\Data911.mdb\WtdCallsFeatureClassToFeatureClass C:\1Shitij\Examples\Users\Lauren\Data\Data911.mdb\WtdCalls C:\Temp\RTools\ToolData InputPoint.shp # "ICOUNT "ICOUNT" true true false 4 Long 0 0 ,First,#,C:\1Shitij\Examples\Users\Lauren\Data\Data911.mdb\WtdCalls,ICOUNT,-1,-1;UniqID "UniqID" true true false 4 Long 0 0 ,First,#,C:\1Shitij\Examples\Users\Lauren\Data\Data911.mdb\WtdCalls,UniqID,-1,-1" #InputPoint0020.000file://\\SMEHTA\Temp\RTools\ToolData\InputPoint.shpLocal Area NetworkProjectedGCS_North_American_1983NAD_1983_StatePlane_Oregon_North_FIPS_3601_Feet<ProjectedCoordinateSystem xsi:type='typens:ProjectedCoordinateSystem' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:typens='http://www.esri.com/schemas/ArcGIS/10.0'><WKT>PROJCS[&quot;NAD_1983_StatePlane_Oregon_North_FIPS_3601_Feet&quot;,GEOGCS[&quot;GCS_North_American_1983&quot;,DATUM[&quot;D_North_American_1983&quot;,SPHEROID[&quot;GRS_1980&quot;,6378137.0,298.257222101]],PRIMEM[&quot;Greenwich&quot;,0.0],UNIT[&quot;Degree&quot;,0.0174532925199433]],PROJECTION[&quot;Lambert_Conformal_Conic&quot;],PARAMETER[&quot;False_Easting&quot;,8202083.333333332],PARAMETER[&quot;False_Northing&quot;,0.0],PARAMETER[&quot;Central_Meridian&quot;,-120.5],PARAMETER[&quot;Standard_Parallel_1&quot;,44.33333333333334],PARAMETER[&quot;Standard_Parallel_2&quot;,46.0],PARAMETER[&quot;Latitude_Of_Origin&quot;,43.66666666666666],UNIT[&quot;Foot_US&quot;,0.3048006096012192],AUTHORITY[&quot;ESRI&quot;,102726]]</WKT><XOrigin>-111333400</XOrigin><YOrigin>-98152300</YOrigin><XYScale>37675833.767964289</XYScale><ZOrigin>-100000</ZOrigin><ZScale>10000</ZScale><MOrigin>-100000</MOrigin><MScale>10000</MScale><XYTolerance>0.0032808333333333335</XYTolerance><ZTolerance>0.001</ZTolerance><MTolerance>0.001</MTolerance><HighPrecision>true</HighPrecision><WKID>102726</WKID></ProjectedCoordinateSystem>20100325100218002010032510021800Microsoft Windows XP Version 5.1 (Build 2600) Service Pack 2; ESRI ArcGIS 10.0.0.2356InputPoint002Shapefile0.000datasetESRI10.0.0Simple1FALSE0FALSEFALSE0InputPointFeature Class0FIDFIDOID400Internal feature number.ESRISequential unique whole numbers that are automatically generated.ShapeShapeGeometry000Feature geometry.ESRICoordinates defining the features.ICOUNTICOUNTInteger990UniqIDUniqIDInteger99020100325 4 | -------------------------------------------------------------------------------- /ToolData/InputPoint.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/ToolData/InputPoint.shx -------------------------------------------------------------------------------- /ToolData/Votepoints.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/ToolData/Votepoints.dbf -------------------------------------------------------------------------------- /ToolData/Votepoints.prj: -------------------------------------------------------------------------------- 1 | PROJCS["NAD_1983_StatePlane_Oregon_North_FIPS_3601_Feet",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["False_Easting",8202083.333333332],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-120.5],PARAMETER["Standard_Parallel_1",44.33333333333334],PARAMETER["Standard_Parallel_2",46.0],PARAMETER["Latitude_Of_Origin",43.66666666666666],UNIT["Foot_US",0.3048006096012192]] -------------------------------------------------------------------------------- /ToolData/Votepoints.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/ToolData/Votepoints.shp -------------------------------------------------------------------------------- /ToolData/Votepoints.shp.xml: -------------------------------------------------------------------------------- 1 | 2 | 20100709150711001.0TRUECreateRandomPoints C:\Users\laur357\Documents\Tools\AdditionalTools\RTools\ToolData Votepoints C:\Users\laur357\Documents\Tools\AdditionalTools\RTools\ToolData\InputPoint.shp "0 0 250 250" 906 "1 Feet" POINT 0CalculateField Votepoints CID "[CID] +1" VB #CalculateField Votepoints CID "[FID] +1" VB # 3 | -------------------------------------------------------------------------------- /ToolData/Votepoints.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Esri/R-toolbox-py/5412c165fb1943031b85557c6a7de34ac58f2ae2/ToolData/Votepoints.shx -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Apache License - 2.0 2 | 3 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 4 | 5 | 6 | 1. Definitions. 7 | 8 | "License" shall mean the terms and conditions for use, reproduction, and 9 | distribution as defined by Sections 1 through 9 of this document. 10 | 11 | "Licensor" shall mean the copyright owner or entity authorized by the 12 | copyright owner that is granting the License. 13 | 14 | "Legal Entity" shall mean the union of the acting entity and all other 15 | entities that control, are controlled by, or are under common control with 16 | that entity. For the purposes of this definition, "control" means (i) the 17 | power, direct or indirect, to cause the direction or management of such 18 | entity, whether by contract or otherwise, or (ii) ownership of fifty percent 19 | (50%) or more of the outstanding shares, or (iii) beneficial ownership of such 20 | entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, 26 | including but not limited to software source code, documentation source, and 27 | configuration files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object 31 | code, generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, 34 | made available under the License, as indicated by a copyright notice that is 35 | included in or attached to the work (an example is provided in the Appendix 36 | below). 37 | 38 | "Derivative Works" shall mean any work, whether in Source or Object form, that 39 | is based on (or derived from) the Work and for which the editorial revisions, 40 | annotations, elaborations, or other modifications represent, as a whole, an 41 | original work of authorship. For the purposes of this License, Derivative 42 | Works shall not include works that remain separable from, or merely link (or 43 | bind by name) to the interfaces of, the Work and Derivative Works thereof. 44 | 45 | "Contribution" shall mean any work of authorship, including the original 46 | version of the Work and any modifications or additions to that Work or 47 | Derivative Works thereof, that is intentionally submitted to Licensor for 48 | inclusion in the Work by the copyright owner or by an individual or Legal 49 | Entity authorized to submit on behalf of the copyright owner. For the purposes 50 | of this definition, "submitted" means any form of electronic, verbal, or 51 | written communication sent to the Licensor or its representatives, including 52 | but not limited to communication on electronic mailing lists, source code 53 | control systems, and issue tracking systems that are managed by, or on behalf 54 | of, the Licensor for the purpose of discussing and improving the Work, but 55 | excluding communication that is conspicuously marked or otherwise designated 56 | in writing by the copyright owner as "Not a Contribution." 57 | 58 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 59 | of whom a Contribution has been received by Licensor and subsequently 60 | incorporated within the Work. 61 | 62 | 2. Grant of Copyright License. Subject to the terms and conditions of this 63 | License, each Contributor hereby grants to You a perpetual, worldwide, 64 | non-exclusive, no-charge, royalty-free, irrevocable copyright license to 65 | reproduce, prepare Derivative Works of, publicly display, publicly perform, 66 | sublicense, and distribute the Work and such Derivative Works in Source or 67 | Object form. 68 | 69 | 3. Grant of Patent License. Subject to the terms and conditions of this 70 | License, each Contributor hereby grants to You a perpetual, worldwide, 71 | non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this 72 | section) patent license to make, have made, use, offer to sell, sell, import, 73 | and otherwise transfer the Work, where such license applies only to those 74 | patent claims licensable by such Contributor that are necessarily infringed by 75 | their Contribution(s) alone or by combination of their Contribution(s) with 76 | the Work to which such Contribution(s) was submitted. If You institute patent 77 | litigation against any entity (including a cross-claim or counterclaim in a 78 | lawsuit) alleging that the Work or a Contribution incorporated within the Work 79 | constitutes direct or contributory patent infringement, then any patent 80 | licenses granted to You under this License for that Work shall terminate as of 81 | the date such litigation is filed. 82 | 83 | 4. Redistribution. You may reproduce and distribute copies of the Work or 84 | Derivative Works thereof in any medium, with or without modifications, and in 85 | Source or Object form, provided that You meet the following conditions: 86 | 87 | 1. You must give any other recipients of the Work or Derivative Works a 88 | copy of this License; and 89 | 90 | 2. You must cause any modified files to carry prominent notices stating 91 | that You changed the files; and 92 | 93 | 3. You must retain, in the Source form of any Derivative Works that You 94 | distribute, all copyright, patent, trademark, and attribution notices from 95 | the Source form of the Work, excluding those notices that do not pertain 96 | to any part of the Derivative Works; and 97 | 98 | 4. If the Work includes a "NOTICE" text file as part of its distribution, 99 | then any Derivative Works that You distribute must include a readable copy 100 | of the attribution notices contained within such NOTICE file, excluding 101 | those notices that do not pertain to any part of the Derivative Works, in 102 | at least one of the following places: within a NOTICE text file 103 | distributed as part of the Derivative Works; within the Source form or 104 | documentation, if provided along with the Derivative Works; or, within a 105 | display generated by the Derivative Works, if and wherever such 106 | third-party notices normally appear. The contents of the NOTICE file are 107 | for informational purposes only and do not modify the License. You may 108 | add Your own attribution notices within Derivative Works that You 109 | distribute, alongside or as an addendum to the NOTICE text from the Work, 110 | provided that such additional attribution notices cannot be construed as 111 | modifying the License. You may add Your own copyright statement to Your 112 | modifications and may provide additional or different license terms and 113 | conditions for use, reproduction, or distribution of Your modifications, 114 | or for any such Derivative Works as a whole, provided Your use, 115 | reproduction, and distribution of the Work otherwise complies with the 116 | conditions stated in this License. 117 | 118 | 5. Submission of Contributions. Unless You explicitly state otherwise, any 119 | Contribution intentionally submitted for inclusion in the Work by You to the 120 | Licensor shall be under the terms and conditions of this License, without any 121 | additional terms or conditions. Notwithstanding the above, nothing herein 122 | shall supersede or modify the terms of any separate license agreement you may 123 | have executed with Licensor regarding such Contributions. 124 | 125 | 6. Trademarks. This License does not grant permission to use the trade names, 126 | trademarks, service marks, or product names of the Licensor, except as 127 | required for reasonable and customary use in describing the origin of the Work 128 | and reproducing the content of the NOTICE file. 129 | 130 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in 131 | writing, Licensor provides the Work (and each Contributor provides its 132 | Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 133 | KIND, either express or implied, including, without limitation, any warranties 134 | or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 135 | PARTICULAR PURPOSE. You are solely responsible for determining the 136 | appropriateness of using or redistributing the Work and assume any risks 137 | associated with Your exercise of permissions under this License. 138 | 139 | 8. Limitation of Liability. In no event and under no legal theory, whether in 140 | tort (including negligence), contract, or otherwise, unless required by 141 | applicable law (such as deliberate and grossly negligent acts) or agreed to in 142 | writing, shall any Contributor be liable to You for damages, including any 143 | direct, indirect, special, incidental, or consequential damages of any 144 | character arising as a result of this License or out of the use or inability 145 | to use the Work (including but not limited to damages for loss of goodwill, 146 | work stoppage, computer failure or malfunction, or any and all other 147 | commercial damages or losses), even if such Contributor has been advised of 148 | the possibility of such damages. 149 | 150 | 9. Accepting Warranty or Additional Liability. While redistributing the Work 151 | or Derivative Works thereof, You may choose to offer, and charge a fee for, 152 | acceptance of support, warranty, indemnity, or other liability obligations 153 | and/or rights consistent with this License. However, in accepting such 154 | obligations, You may act only on Your own behalf and on Your sole 155 | responsibility, not on behalf of any other Contributor, and only if You agree 156 | to indemnify, defend, and hold each Contributor harmless for any liability 157 | incurred by, or claims asserted against, such Contributor by reason of your 158 | accepting any such warranty or additional liability. 159 | 160 | END OF TERMS AND CONDITIONS 161 | 162 | --------------------------------------------------------------------------------