├── .gitignore ├── LICENSE ├── README.md ├── docs ├── Example_Model.png ├── Example_Model.py ├── Example_Script.py ├── agd.png ├── importing_data.png ├── importing_ok.png ├── install01.png ├── install2.png ├── install3.png ├── model_result.png └── screenshot.png ├── gkudos ├── __init__.py ├── cartodb_utils.py ├── esri │ └── toolboxes │ │ └── CartoDBToolbox.pyt └── esri_scripts.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | requests.egg-info/ 3 | .project 4 | .pydevproject 5 | *.pyc 6 | *.swp 7 | *.egg 8 | *.pyt.xml 9 | env/ 10 | .workon 11 | dist 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/LICENSE -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | #CartoDBToolbox 3 | 4 | CartoDB Toolbox for Arcgis Desktop. It allows you to upload data from Arcgis Desktop to a CartoDB account. 5 | 6 | (**Note:** This project is under development, and I am interested in getting feedback. If you have specific ArcGIS-to-CartoDB needs not met by the current codebase, please email me at ) 7 | 8 | ## Features 9 | 10 | * Upload data from Arcgis Desktop to CartoDB 11 | * (For ArcGis Server / Online layers you can use the [Arcgis Connector](http://docs.cartodb.com/cartodb-platform/import-api.html#the-arcgis-connector) ) 12 | 13 | ## Supported Versions 14 | 15 | * Arcgis Desktop 10.3 16 | 17 | ## Install 18 | 19 | ### Prerequisites : Requests Library 20 | 21 | [Requests](http://docs.python-requests.org/en/latest/) 22 | [Install Guide](http://docs.python-requests.org/en/latest/user/install/) 23 | 24 | or... 25 | 26 | Add the python that arcgis use to your system path. ( i.e. *c:\Python27\Arcgis10.3\* ) 27 | * See [ How to set the path and environment variables in Windows](http://www.computerhope.com/issues/ch000549.htm) 28 | 29 | Download the zipball from https://github.com/kennethreitz/requests/zipball/master 30 | 31 | Unzip it. 32 | 33 | Use the command Prompt to install the package: 34 | 35 | ''' 36 | cd kennethreitz-requests-ab1f493 37 | python setup.py install 38 | ''' 39 | 40 | ### Toolbox 41 | 42 | Download the installer from https://github.com/gkudos/cartodb-toolbox/releases/download/1.0/CartoDB.Toolbox.For.Arcgis-1.0.win32.exe 43 | 44 | Run the installer 45 | 46 | 47 | ![Installer](docs/install01.png?raw=true "Installer") 48 | 49 | ![Installer](docs/install2.png?raw=true "Installer") 50 | 51 | Once installed, CartoDB toolbox must appear on ArcToolbox 52 | 53 | ![Installer](docs/install3.png?raw=true "Installer") 54 | 55 | 56 | ## Basic Usage 57 | 58 | You can use the import tool to CartoDB like any other toolbox. 59 | 60 | Parameters: 61 | * CartoDB User Name 62 | * [Your Api Key](http://docs.cartodb.com/cartodb-editor.html#your-account) 63 | * Features to be uploaded 64 | 65 | ![CartoDB Toolbox](docs/screenshot.png?raw=true "CartoDB Toolbox") 66 | 67 | ![CartoDB Toolbox](docs/importing_data.png?raw=true "CartoDB Toolbox") 68 | 69 | And Voila! Your data is now available on CartoDB 70 | 71 | ![CartoDB Toolbox](docs/importing_ok.png?raw=true "CartoDB Toolbox") 72 | 73 | 74 | ## "Advanced" Usage 75 | 76 | ### ArcPy 77 | 78 | * [Uploading Geodatabases to CartoDB Using Python and Arcpy](http://gkudos.com/blog/2016/01/11/uploading-geodatabases-to-cartodb-using-python-and-arcpy/) 79 | 80 | 81 | 82 | ### Model Builder 83 | 84 | You can also use *CartoDB Toolbox* in model builder. 85 | 86 | For example, this model clips features using a buffer. The geoprocessing results are automatically uploaded to CartoDB. 87 | 88 | ![CartoDB Toolbox](docs/Example_Model.png?raw=true "CartoDB Toolbox") 89 | 90 | - Original data: 91 | 92 | ![CartoDB Toolbox](docs/agd.png?raw=true "CartoDB Toolbox") 93 | 94 | - Clipped features uploaded to CartoDB: 95 | 96 | ![CartoDB Toolbox](docs/model_result.png?raw=true "CartoDB Toolbox") 97 | 98 | 99 | # Contributors 100 | 101 | - Juan Méndez ( [@dersteppen](https://twitter.com/dersteppen) ) 102 | 103 | 104 | # 3rd Party Scripts 105 | 106 | - [cartodb-utils.py](https://gist.github.com/andrewxhill/093c89fa45e5f657fec7) by Andrew W. Hill ( [@andrewxhill](https://twitter.com/andrewxhill) ) 107 | - [Zip (compress) Python script by Esri](http://arcg.is/1HsK0P0) 108 | 109 | 110 | -------------------------------------------------------------------------------- /docs/Example_Model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/docs/Example_Model.png -------------------------------------------------------------------------------- /docs/Example_Model.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # --------------------------------------------------------------------------- 3 | # Example_Model.py 4 | # Created on: 2015-05-15 11:06:35.00000 5 | # (generated by ArcGIS/ModelBuilder) 6 | # Usage: Example_Model 7 | # Description: 8 | # --------------------------------------------------------------------------- 9 | 10 | # Import arcpy module 11 | import arcpy 12 | 13 | # Script arguments 14 | Distance__value_or_field_ = arcpy.GetParameterAsText(0) 15 | if Distance__value_or_field_ == '#' or not Distance__value_or_field_: 16 | Distance__value_or_field_ = "500 Meters" # provide a default value if unspecified 17 | 18 | # Local variables: 19 | Cuerpo_de_agua = "Cuerpo de agua" 20 | CAgu_Buffer = Distance__value_or_field_ 21 | CAgu_Buffer_Clip = CAgu_Buffer 22 | Results = CAgu_Buffer_Clip 23 | Manzana = "Manzana" 24 | 25 | # Process: Buffer 26 | arcpy.Buffer_analysis(Cuerpo_de_agua, CAgu_Buffer, Distance__value_or_field_, "FULL", "ROUND", "NONE", "", "PLANAR") 27 | 28 | # Process: Clip 29 | arcpy.Clip_analysis(Manzana, CAgu_Buffer, CAgu_Buffer_Clip, "") 30 | 31 | # Process: Import Data 32 | arcpy.CartoDBImportToolbox_CartoDB( "your_user", "your_key", "F:\\data\\your_Data.gdb\\yourFeature") 33 | 34 | -------------------------------------------------------------------------------- /docs/Example_Script.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Import arcpy module 4 | import arcpy 5 | 6 | # Process: Import Data 7 | arcpy.CartoDBImportToolbox_CartoDB( "your_user", "your_key", "F:\\data\\your_Data.gdb\\yourFeature") 8 | 9 | -------------------------------------------------------------------------------- /docs/agd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/docs/agd.png -------------------------------------------------------------------------------- /docs/importing_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/docs/importing_data.png -------------------------------------------------------------------------------- /docs/importing_ok.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/docs/importing_ok.png -------------------------------------------------------------------------------- /docs/install01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/docs/install01.png -------------------------------------------------------------------------------- /docs/install2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/docs/install2.png -------------------------------------------------------------------------------- /docs/install3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/docs/install3.png -------------------------------------------------------------------------------- /docs/model_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/docs/model_result.png -------------------------------------------------------------------------------- /docs/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/docs/screenshot.png -------------------------------------------------------------------------------- /gkudos/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gkudos/cartodb-toolbox/22bc7aac039df69168acb53470b447271682d2f7/gkudos/__init__.py -------------------------------------------------------------------------------- /gkudos/cartodb_utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | import urllib 3 | import urllib2 4 | import base64 5 | import json 6 | import sys 7 | import argparse 8 | import arcpy 9 | 10 | 11 | try: 12 | import requests 13 | except ImportError: 14 | print 'The requests package is required: http://docs.python-requests.org/en/latest/user/install/#install' 15 | sys.exit() 16 | 17 | ''' 18 | Source: 19 | https://gist.github.com/andrewxhill/093c89fa45e5f657fec7 20 | 21 | ''' 22 | class CartoDB: 23 | def __init__(self, options): 24 | # do stuff 25 | self.options = options 26 | self.api_url = "https://%s.cartodb.com/api/v2/sql" % (self.options['u']) 27 | self.import_url = "https://%s.cartodb.com/api/v1/imports/?api_key=%s" % (self.options['u'], self.options['k']) 28 | self.new_tables = [] 29 | self.internal_columns = ['created_at', 'updated_at', 'the_geom', 'the_geom_webmercator', 'cartodb_id'] 30 | self.type_map = {'string':'text', 'boolean': 'boolean', 'date': 'timestamp', 'number':'numeric'} 31 | def _log(self, message): 32 | if self.options['verbose'] == True: 33 | print message 34 | arcpy.AddMessage(message) 35 | def _error(self, error): 36 | print error 37 | sys.exit() 38 | def sql_api(self, sql): 39 | # execute sql request over API 40 | params = { 41 | 'api_key' : self.options["k"], 42 | 'q' : sql 43 | } 44 | r = requests.get(self.api_url, params=params) 45 | return r.json() 46 | def upload(self): 47 | # import a file 48 | # see https://gist.github.com/lbosque/5876697 49 | # returns new table name 50 | r = requests.post(self.import_url, files={'file': open(self.options['f'], 'rb')}) 51 | data = r.json() 52 | if data['success']!=True: 53 | self._error("Upload failed") 54 | complete = False 55 | last_state = '' 56 | while not complete: 57 | import_status_url = "https://%s.cartodb.com/api/v1/imports/%s?api_key=%s" % (self.options['u'], data['item_queue_id'], self.options['k']) 58 | req = urllib2.Request(import_status_url) 59 | response = urllib2.urlopen(req) 60 | d = json.loads(str(response.read())) 61 | if last_state!=d['state']: 62 | last_state=d['state'] 63 | if d['state']=='uploading': 64 | self._log('Uploading file...') 65 | elif d['state']=='importing': 66 | self._log('Importing data...') 67 | elif d['state']=='complete': 68 | complete = True 69 | self._log('Table "%s" created' % d['table_name']) 70 | if d['state']=='failure': 71 | self._error(d['get_error_text']['what_about']) 72 | self.new_tables.append(d['table_name']) 73 | return d['table_name'] 74 | 75 | def columns(self, table): 76 | sql = "SELECT * FROM %s LIMIT 0" % table 77 | data = self.sql_api(sql) 78 | return data['fields'] 79 | 80 | def add_column(self, table, name, coltype): 81 | sql = "ALTER TABLE %s ADD COLUMN %s %s" % (table, name, coltype) 82 | data = self.sql_api(sql) 83 | return True 84 | 85 | def overwrite(self, append=False): 86 | # upload new data 87 | new_table = self.upload() 88 | source_columns = self.columns(new_table) 89 | target_columns = self.columns(self.options['t']) 90 | insert_cols = {} 91 | alter_cols = [] 92 | for c in source_columns.keys(): 93 | if c in self.internal_columns: 94 | source_columns.pop(c, None) 95 | else: 96 | if c not in target_columns.keys(): 97 | insert_cols[c] = self.type_map[source_columns[c]['type']] 98 | alter_cols.append(c) 99 | else: 100 | insert_cols[c] = self.type_map[target_columns[c]['type']] 101 | for c in alter_cols: 102 | self.add_column(self.options['t'], c, insert_cols[c]) 103 | select_list = [] 104 | for c,t in insert_cols.items(): 105 | select_list.append( "%s::%s" % (c,t)) 106 | sql = "INSERT INTO %s (the_geom, %s) " % (self.options['t'], ','.join(insert_cols.keys())) 107 | sql += "SELECT the_geom, %s FROM %s; " % (','.join(select_list), new_table) 108 | sql += "DROP TABLE %s" % new_table 109 | self._log("Writing data to %s and droppping %s" % (self.options['t'],new_table)) 110 | if append==False: 111 | sql = "DELETE FROM %s; %s " % (self.options['t'], sql) 112 | data = self.sql_api(sql) 113 | if 'error' in data.keys(): 114 | self._log('Overwrite failed, cleaning-up') 115 | sql = "DROP TABLE %s" % new_table 116 | self.sql_api(sql) 117 | return False 118 | else: 119 | return True 120 | 121 | def drop_table(self): 122 | # drop a table ' 123 | self._log("Dropping table %s" % self.options['t']) 124 | sql = "DROP TABLE %s" % self.options['t'] 125 | data = self.sql_api(sql) 126 | if 'error' in data.keys(): 127 | self._error(data['error']) 128 | return True 129 | 130 | def clear_rows(self): 131 | # clear all rows from a table 132 | self._log("Deleting all rows") 133 | sql = "DELETE FROM %s" % self.options['t'] 134 | data = self.sql_api(sql) 135 | if 'error' in data.keys(): 136 | self._error(data['error']) 137 | return True 138 | 139 | def export_table(self): 140 | self._log("Exporting new %s" % self.options['m']) 141 | params = {"format": self.options['m'], "api_key": self.options["k"],"q": "SELECT * FROM %s" % self.options["t"]} 142 | r = requests.get(self.api_url, params=params, stream=True) 143 | with open(self.options['l'], 'wb') as fd: 144 | for chunk in r.iter_content(10): 145 | fd.write(chunk) 146 | return True 147 | def clean_table(self): 148 | # clean up table for speed 149 | self._log("Cleaning up unused space") 150 | sql = "VACUUM FULL %s" % self.options['t'] 151 | data = self.sql_api(sql) 152 | if 'error' in data.keys(): 153 | self._error(data['error']) 154 | self._log("Optimizing existing indexes") 155 | sql = "ANALYZE %s" % self.options['t'] 156 | data = self.sql_api(sql) 157 | if 'error' in data.keys(): 158 | self._error(data['error']) 159 | return True 160 | 161 | ''' 162 | if __name__ == "__main__": 163 | 164 | SUPPORTED_METHODS = { 165 | 'import' : { 166 | "description": "Import a file to create a new table", 167 | "requirements": ["f","k","u"], 168 | "example": "python cartodb-utils.py import -f myfile.csv -k myapikey -u myusername" 169 | }, 170 | 'overwrite' : { 171 | "description": "Overwrite an existing table with data from a file", 172 | "requirements": ["f","k","u","t"], 173 | "example": "python cartodb-utils.py overwrite -f myfile.csv -t some_existing_table -k myapikey -u myusername" 174 | }, 175 | 'append' : { 176 | "description": "Append rows to an existing table from a file", 177 | "requirements": ["f","k","u","t"], 178 | "example": "python cartodb-utils.py append -f myfile.csv -t some_existing_table -k myapikey -u myusername" 179 | }, 180 | 'clear' : { 181 | "description": "Clear all rows from an existing table", 182 | "requirements": ["k","u","t"], 183 | "example": "python cartodb-utils.py clear -t some_existing_table -k myapikey -u myusername" 184 | }, 185 | 'drop' : { 186 | "description": "Completely drop an existing table", 187 | "requirements": ["k","u","t"], 188 | "example": "python cartodb-utils.py drop -t some_existing_table -k myapikey -u myusername" 189 | }, 190 | 'export' :{ 191 | "description": "Export an existing table to a local file (default GeoJSON)", 192 | "requirements": ["k","u","t","l"], 193 | "example": "python cartodb-utils.py export -t some_existing_table -m CSV -l local_file.csv -k myapikey -u myusername" 194 | }, 195 | 'clean' : { 196 | "description": "Vacuum and analyze a table for speed", 197 | "requirements": ["k","u","t"], 198 | "example": "python cartodb-utils.py clean -t some_existing_table -k myapikey -u myusername" 199 | } 200 | } 201 | parser = argparse.ArgumentParser(description="CartoDB Python Utility") 202 | 203 | parser.add_argument('method', nargs="?", help='e.g. %s' % ','.join(SUPPORTED_METHODS.keys())) 204 | 205 | parser.add_argument('-f', '--file', dest='f', help='Source file') 206 | parser.add_argument('-l', '--local', dest='l', help='Local file') 207 | parser.add_argument('-m', '--format', default="GeoJSON", dest='m', help='Export file format') 208 | parser.add_argument('-u', '--user', dest='u', help='CartoDB username') 209 | parser.add_argument('-k', '--key', dest='k', help='CartoDB account API Key') 210 | parser.add_argument('-t', '--target', dest='t', help='Target table') 211 | parser.add_argument('-v', '--verbose', dest='verbose', default=False, action="store_true", help='Verbose output if included') 212 | 213 | args = parser.parse_args() 214 | options = vars(args) 215 | 216 | def success(message): 217 | print 'SUCCESS', message 218 | def failure(message): 219 | print 'FAILURE', message 220 | m = args.method.lower() 221 | if m in SUPPORTED_METHODS.keys(): 222 | for d in SUPPORTED_METHODS[m]["requirements"]: 223 | if options[d] is None: 224 | print "Arguement -%s is required\n\n%s\n\ndescription:\t%s\nrequired args:\t%s\nexample:\t%s" % (d,m,SUPPORTED_METHODS[m]['description'],SUPPORTED_METHODS[m]['requirements'],SUPPORTED_METHODS[m]['example']) 225 | sys.exit() 226 | 227 | cartodb = CartoDB(options) 228 | if args.method.lower() == 'import': 229 | new_table = cartodb.upload() 230 | success(new_table) 231 | if args.method.lower() == 'overwrite': 232 | status = cartodb.overwrite() 233 | if status == True: 234 | success('Table data replaced') 235 | if args.method.lower() == 'append': 236 | status = cartodb.overwrite(True) 237 | if status == True: 238 | success('Data appended to table') 239 | if args.method.lower() == 'clean': 240 | status = cartodb.clean_table() 241 | if status == True: 242 | success('Cleaned table') 243 | if args.method.lower() == 'drop': 244 | status = cartodb.drop_table() 245 | if status == True: 246 | success('Dropped table') 247 | if args.method.lower() == 'clear': 248 | status = cartodb.clear_rows() 249 | if status == True: 250 | success('Cleared all rows from table') 251 | if args.method.lower() == 'export': 252 | status = cartodb.export_table() 253 | if status == True: 254 | success('Exported table to %s' % options['l']) 255 | ''' -------------------------------------------------------------------------------- /gkudos/esri/toolboxes/CartoDBToolbox.pyt: -------------------------------------------------------------------------------- 1 | import arcpy 2 | import os, tempfile 3 | import gkudos 4 | 5 | from gkudos.esri_scripts import create_zip 6 | from gkudos.cartodb_utils import CartoDB 7 | 8 | class Toolbox(object): 9 | def __init__(self): 10 | """Define the toolbox (the name of the toolbox is the name of the 11 | .pyt file).""" 12 | self.label = "CartoDB" 13 | self.alias = "CartoDB" 14 | 15 | # List of tool classes associated with this toolbox 16 | self.tools = [CartoDBImportToolbox] 17 | 18 | 19 | class CartoDBImportToolbox(object): 20 | def __init__(self): 21 | """Define the tool (tool name is the name of the class).""" 22 | self.label = "Upload data to CartoDB" 23 | self.description = "Upload data to CartoDB" 24 | self.canRunInBackground = False 25 | 26 | def getParameterInfo(self): 27 | """Define parameter definitions""" 28 | # El parametro definido como respuesta siempre va en la primera posicion ("Estandar" Programacion SNC) 29 | results = arcpy.Parameter( 30 | displayName="Results", 31 | name="results", 32 | datatype="GPString", 33 | parameterType="Derived", 34 | direction="Output") 35 | 36 | param0 = arcpy.Parameter( 37 | displayName="Cartodb User Name", 38 | name="cdb_user_name", 39 | datatype="GPString", 40 | parameterType="Required", 41 | direction="Input") 42 | 43 | param1 = arcpy.Parameter( 44 | displayName="Api Key", 45 | name="cdb_key", 46 | datatype="GPString", 47 | parameterType="Required", 48 | direction="Input") 49 | 50 | param2 = arcpy.Parameter( 51 | displayName="Feature Class", 52 | name="feature_class", 53 | datatype="GPFeatureLayer", 54 | parameterType="Required", 55 | direction="Input", 56 | multiValue=True) 57 | 58 | params = [results, param0, param1, param2] 59 | return params 60 | 61 | def isLicensed(self): 62 | """Set whether tool is licensed to execute.""" 63 | return True 64 | 65 | def updateParameters(self, parameters): 66 | """Modify the values and properties of parameters before internal 67 | validation is performed. This method is called whenever a parameter 68 | has been changed.""" 69 | return 70 | 71 | def updateMessages(self, parameters): 72 | """Modify the messages created by internal validation for each tool 73 | parameter. This method is called after internal validation.""" 74 | return 75 | 76 | def execute(self, parameters, messages): 77 | """The source code of the tool.""" 78 | cdb_user_name = parameters[1].valueAsText.strip() 79 | cdb_key = parameters[2].valueAsText.strip() 80 | features = parameters[3].values 81 | 82 | temp_folder = tempfile.mkdtemp() 83 | 84 | arcpy.SetProgressor("step", "Uploading data to CartoDB...", 0, len(features), 1) 85 | 86 | #messages.addMessage("cdb_user_name : " + cdb_user_name ) 87 | #messages.addMessage("cdb_key : " + cdb_key ) 88 | #messages.addMessage("temp_folder : " + temp_folder ) 89 | new_tables = [] 90 | feature_counter = 0 91 | for feature in features: 92 | desc = arcpy.Describe(feature) 93 | feature_name = None 94 | try: 95 | feature_name = desc.name 96 | except Exception as e: 97 | feature_name = "feature_"+str(feature_counter) 98 | 99 | messages.addMessage("feature_name : " + feature_name ) 100 | arcpy.SetProgressorLabel("Loading {0}...".format(feature_name)) 101 | 102 | outputFolder = temp_folder+"\\"+feature_name 103 | os.makedirs(outputFolder) 104 | 105 | # Trim the '.shp' extension 106 | #fc = os.path.splitext(shp)[0] 107 | #feature_name = 108 | # Update the progressor label for current shapefile 109 | 110 | arcpy.FeatureClassToShapefile_conversion([feature], outputFolder) 111 | 112 | output_file = temp_folder+"\\"+feature_name+".zip" 113 | create_zip(outputFolder, output_file ) 114 | 115 | messages.addMessage("Zip File : " + output_file ) 116 | 117 | options = {} 118 | options["f"] = output_file 119 | options["k"] = cdb_key 120 | options["u"] = cdb_user_name 121 | options["verbose"] = True 122 | 123 | 124 | cartodb = CartoDB(options) 125 | new_table = cartodb.upload() 126 | messages.addMessage("New Table : " + new_table ) 127 | new_tables.append(new_table) 128 | 129 | # Update the progressor position 130 | arcpy.SetProgressorPosition() 131 | feature_counter += 1 132 | 133 | #os.removedirs(temp_folder) 134 | arcpy.SetParameter(0, new_tables) 135 | messages.AddMessage("Data import completed.") 136 | return -------------------------------------------------------------------------------- /gkudos/esri_scripts.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Created on 14/05/2015 3 | 4 | http://desktop.arcgis.com/en/desktop/latest/analyze/sharing-workflows/h-zip-python-script.htm 5 | 6 | @author: arcgis 7 | ''' 8 | 9 | import sys, zipfile, arcpy, os, traceback 10 | 11 | # Function for zipping files. If keep is true, the folder, along with 12 | # all its contents, will be written to the zip file. If false, only 13 | # the contents of the input folder will be written to the zip file - 14 | # the input folder name will not appear in the zip file. 15 | # 16 | def zipws(path, zip, keep): 17 | path = os.path.normpath(path) 18 | # os.walk visits every subdirectory, returning a 3-tuple 19 | # of directory name, subdirectories in it, and file names 20 | # in it. 21 | # 22 | for (dirpath, dirnames, filenames) in os.walk(path): 23 | # Iterate over every file name 24 | # 25 | for file in filenames: 26 | # Ignore .lock files 27 | # 28 | if not file.endswith('.lock'): 29 | #arcpy.AddMessage("Adding %s..." % os.path.join(path, dirpath, file)) 30 | try: 31 | if keep: 32 | zip.write(os.path.join(dirpath, file), 33 | os.path.join(os.path.basename(path), os.path.join(dirpath, file)[len(path)+len(os.sep):])) 34 | else: 35 | zip.write(os.path.join(dirpath, file), 36 | os.path.join(dirpath[len(path):], file)) 37 | 38 | except Exception, e: 39 | arcpy.AddWarning(" Error adding %s: %s" % (file, e)) 40 | 41 | return None 42 | 43 | ''' 44 | 45 | ''' 46 | def create_zip(infolder, outfile): 47 | # Create the zip file for writing compressed data. In some rare 48 | # instances, the ZIP_DEFLATED constant may be unavailable and 49 | # the ZIP_STORED constant is used instead. When ZIP_STORED is 50 | # used, the zip file does not contain compressed data, resulting 51 | # in large zip files. 52 | try: 53 | arcpy.AddMessage("Creating Zip file...") 54 | zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_DEFLATED) 55 | zipws(infolder, zip, True) 56 | zip.close() 57 | except RuntimeError: 58 | # Delete zip file if it exists 59 | # 60 | if os.path.exists(outfile): 61 | os.unlink(outfile) 62 | zip = zipfile.ZipFile(outfile, 'w', zipfile.ZIP_STORED) 63 | zipws(infolder, zip, True) 64 | zip.close() 65 | arcpy.AddWarning(" Unable to compress zip file contents.") 66 | 67 | arcpy.AddMessage("Zip file created successfully") 68 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | ''' 2 | python setup.py bdist_wininst 3 | ''' 4 | from distutils.core import setup 5 | setup(name='CartoDB Toolbox For Arcgis', 6 | author='Juan Mendez (@dersteppen)', 7 | author_email='juan@gkudos.com', 8 | description='CartoDB Toolbox For Arcgis.', 9 | license='Apache 2.0', 10 | version='1.1', 11 | packages=['gkudos'], 12 | package_dir={'gkudos': 'gkudos'}, 13 | package_data={'gkudos': ['esri/toolboxes/*.*']}, 14 | classifiers=( 15 | 'Development Status :: Production/Stable', 16 | 'Intended Audience :: GIS Users', 17 | 'Natural Language :: English', 18 | 'License :: OSI Approved :: Apache Software License', 19 | 'Programming Language :: Python', 20 | 'Programming Language :: Python :: 2.6', 21 | 'Programming Language :: Python :: 2.7', 22 | 'Programming Language :: Python :: 3', 23 | 'Programming Language :: Python :: 3.3', 24 | 'Programming Language :: Python :: 3.4' 25 | ), 26 | ) --------------------------------------------------------------------------------