SlideShare ist ein Scribd-Unternehmen logo
1 von 37
1
AGENDA• Python And the ERSI Platform
• Key Items in ESRI Platform
o Connection Files
o ArcPy Cursors
• Branching out with Python
Libraries
o Pyodbc
o Cx_Oracle
• Sqlite – A hidden gem
• Code Focus – Example 1
• Code Focus – Example 2
2
It’s All Connected…
3
AGOL
Open
Source
Shapefiles
Flat Files
ArcSDE
ArcServer /
Portal
Connection Files: Gateways Between Platforms
Oracle
MS SQL
Server
4
ArcSDE
ArcServer/
Portal For
ArcGIS
AGOL
External
Data
Cursor Function Code
arcpy.da.SearchCursor
Read-only
access
arcpy.da.InsertCursor Inserts rows
arcpy.da.UpdateCursor
Updates or
deletes rows
5
6
import arcpy
fc = ‘C:/some.gdb/buildings’
fields = [ ‘OID@’, ‘SHAPE@XY’, ‘STRUCTURE’ ]
# Other Options: SHAPE@WKT, SHAPE@WKB, SHAPE@JSON
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
# Perform some task
7
import arcpy
row_values = [( ‘Barn’, (-84.005, 33.002)),
( ‘House’, (-84.899, 33.556))]
# Open an InsertCursor
cursor = arcpy.da.InsertCursor(‘C:/some.gdb/building',
[ ‘STRUCTURE’,
‘SHAPE@XY’ ])
# Insert new rows that include point nane and a x,y coordinate
# pair that represents the structure's center
for row in row_values:
cursor.insertRow(row)
# Delete cursor object
8
import arcpy
fc = ‘c:/some.gdb/buildings’
fields = [‘OID@’, ‘SHAPE@XY’, ‘STRUCTURE’]
# Create update cursor for feature class
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
row[2] = row[2].upper()
# Update the cursor with the updated list
cursor.updateRow(row)
Python Library - PyODBC
9
Pyodbc is an open source Python module
specifically designed for connecting to ODBC
databases. Based on the DB API 2.0 specification,
this library is also packed with even more Pythonic
convenience.
Pyodbc can connect to these Microsoft databases:
How to use PyODBC
10
# Import python library
import pyodbc
# Use the specific connection below for each Microsoft
database type.
# MS Access 2000 connection
DBfile = ‘C:/SomeMdb.mdb’
cnmdb = pyodbc.connect(‘‘‘DRIVER={Microsoft Access Driver
(*.mdb)};DBQ=’’’ +Dbfile)
11
# Sql Server Express Connection. Use FQDN for remote server
connection
cnxpress = pyodbc.connect(‘‘‘Driver=
{SQL Server Native Client 10.0};
Server=Instance Name;
Database=DB Name;
Uid=User; Pwd=Password;’’’)
PyODBC continued…
PyODBC continued…
12
# MS SQL Server Connection. Use FQDN for remote server
connection
cnmsql = pyodbc.connect(‘‘‘DRIVER={SQL Server};
SERVER=ServerName;
DATABASE=DB Name;
UID=User;
PWD=Password’’’)
PyODBC continued…
13
# MS SQL Server Connection
cnazure = pyodbc.connect(‘‘‘Driver=
{SQL Server Native Client 10.0};
Server=
tcp:ServerName.database.windows.net;
Database=DB NAME;
Uid=[LoginForDb]@[serverName];
Pwd=myPassword;Encrypt=yes;’’’)
cur = ConnChoice.cursor()
# Import python library
import cx_Oracle
# Create connection to Oracle DB. Versions 10g, 11g, and 12c
are applicable. Use FQDN for remote server connection.
con = cx_Oracle.connect(‘‘‘scott/tiger@server:port/instance’’’)
# Create database cursor
cur = con.cursor()
Python Library – cx_Oracle
14
What is SQLite?
15
SQLite is an open source transactional database that supports
ANSI SQL 92.
Why use SQLite with GIS?
SQLIte can be use as a traditional database on disk or invoked
solely in memory. Operations like joins are handled in a single
transaction versus multiple steps.
How to use SQLite
16
# Loads python library
import arcpy
# Execute CreateSQLiteDatabase for disk based database
arcpy.CreateSQLiteDatabase_management(‘C:/data/example.
sqlite’, ‘SPATIALITE’)
# Loads python library
import sqlite3 as lite
# Creating a SQLite DB connection in RAM
con = lite.connect(‘:memory:’)
# Generate cursor
cur = con.cursor()
How to use SQLite
17
“If you want to
succeed you
should strike out
on new paths,
rather than travel
the worn paths of
accepted
success.”
18
John D. Rockefeller
19
Take the provided CSV file and create a point
feature class using the coordinates provide.
Be sure to validate all text attributes for spacing
issues before creating feature class.
The final schema should look like the following:
Attribute Name Attribute Type Attribute Size
State_Terr Text 75
Capital Text 75
Latitude Double -
Longitude Double -
Conus Text 3
Type Text 10
Bridging Platforms
20
Case Example for Bridging Platforms
21
import arcpy
import datetime
import sqlite3 as lite
# Scripting environment variables
arcpy.env.workspace = r‘C:Shrug2017’
arcpy.env.overwriteOutput = True
csv = r‘C:Shrug2017Demo1states_terr.csv’
fields = [‘State_Terr’,‘Capital’,‘Latitude’,‘Longitude’,‘Conus’,
‘Type’]
# Optional: fields = [‘*’]
22
# Creating a SQLite DB in RAM
con = lite.connect(‘:memory:’)
# Generate cursor
cur = con.cursor()
print(‘Destination database created –’+
str(datetime.datetime.now()))
# Creates a table structure for incoming data
cur.execute(‘‘‘CREATE TABLE States(StateNme TEXT, Capital
TEXT, Lat REAL, Long REAL, Conus TEXT, Typ TEXT);’’’)
23
print(‘Working table created –’+ str(datetime.datetime.now()))
with arcpy.da.SearchCursor(csv, fields) as cursor:
for row in cursor:
# Inserting records to SQLite DB
to_db = [row[0],row[1],row[2],row[3],row[4],row[5] ]
cur.execute(‘‘‘INSERT INTO
States(StateNme,Capital,Lat,Long,
Conus,Typ)
VALUES(?,?,?,?,?,?);’’’, to_db)
con.commit()
24
print(‘CSV inserted into SQLite database table –’ +
str(datetime.datetime.now()))
#Removing white spacing from columns with text data type
cur.execute(‘‘‘UPDATE States
SET StateNme = TRIM(StateNme),
Capital = TRIM(Capital),
Conus = TRIM(Conus),
Typ = TRIM(Typ);’’’)
con.commit()
print(‘Validation process completed – ’+
str(datetime.datetime.now()))
25
cur.execute(‘‘‘ALTER TABLE States ADD ShapeXY TEXT’’’)
cur.execute(‘‘‘UPDATE States SET ShapeXY = ‘POINT’||‘(’
||Long|| ‘ ’||Lat|| ‘)’ ’’’)
con.commit()
print(‘Spatial column created – ’+ str(datetime.datetime.now()))
output_path = r‘C:Shrug2017Scratch.gdb’
out_name = ‘us_states_terr’
geometry_type = ‘Point’
26
wkt = ‘‘‘GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',
SPHEROID['WGS_1984',6378137.0,298.257223563]],
PRIMEM['Greenwich',0.0],
UNIT['Degree',0.0174532925199433]],
VERTCS['WGS_1984',DATUM['D_WGS_1984',
SPHEROID['WGS_1984',6378137.0,298.257223563]],
PARAMETER['Vertical_Shift',0.0],
PARAMETER['Direction',1.0],UNIT['Meter',1.0]];
-400 -400 1000000000;-100000 10000;-100000
10000;8.98315284119522E-09;
0.001;0.001;IsHighPrecision’’’
sr = arcpy.SpatialReference()
27
sr.loadFromString(wkt)
result = arcpy.CreateFeatureclass_management(output_path,
out_name,geometry_type,
‘’,
‘DISABLED’,‘DISABLED’,sr)
fcOut = result.getOutput(0)
arcpy.AddField_management(fcOut,‘State_Terr’,‘TEXT’,‘’,‘’,75)
arcpy.AddField_management(fcOut,‘Capital’,‘TEXT’,‘’,‘’,75)
arcpy.AddField_management(fcOut,‘Latitude’,‘DOUBLE’, 8,‘’, ‘’,
‘’, ‘NULLABLE’)
28
arcpy.AddField_management(fcOut,‘Longitude’,‘DOUBLE’,
8,‘’,‘’,‘’, ‘NULLABLE’)
arcpy.AddField_management(fcOut,‘Conus’,‘TEXT’,‘’,‘’, 3)
arcpy.AddField_management(fcOut,'Type','TEXT',‘’,‘’, 10)
print( ‘Shell featureclass created – ’+
str(datetime.datetime.now()) )
schema = [ ‘SHAPE@WKT’,‘State_Terr’,‘Capital’,
‘Latitude’,‘Longitude’,‘Conus’,‘Type’ ]
curESRI = arcpy.da.InsertCursor(fcOut,schema)
29
# Query to extract data from SQLITE DB table
rows = cur.execute(‘‘‘SELECT ShapeXY,StateNme,Capital,
Lat,Long,Conus,Typ FROM States’’’)
for row in rows:
curESRI.insertRow(row)
# close insert cursor
del curESRI
# close SQLite database connection
con.close()
print(‘SQLite table insertion completed –’+
str(datetime.datetime.now()))
30
The point data
that is displayed
in ArcGIS Pro was
created in 0.004
of second.
The table below
depicts the
processing times
for three different
configurations
Arc
Map
Arc
Pro
SQLite
1.47 s 0.39 s 0.004 s
31
Putting It All Together…
Prior Steps Before Starting Demo2
Create a MS SQL Server Express
database using the SQL scripts
provided.
Modified the previous script to add data
to a MS SQL Server Express database
table.
Upload ‘states_update1.csv’ to the
temp table in MSSQL Express
32
import pyodbc
import os
import datetime
print(‘Starting Update Process- ’ + str(datetime.datetime.now()))
# Sql Server connection
cnmsql = pyodbc.connect(‘DRIVER={SQL Server};
Server=Server;
Database=ShrugDemo;
UID=ScrptKng;PWD=python!’)
# Create cursor
cur = cnmsql.cursor()
33
# Issue update commands for states
counts = cur.execute(‘‘‘MERGE INTO dbo.States_Territories
USING dbo.States_Delta
ON dbo.States_Territories.State_Terr =
dbo.States_Delta.State_Terr
WHEN MATCHED THEN
UPDATE
SET Capital = dbo.States_Delta.Capital,
Latitude = dbo.States_Delta.Latitude,
Longitude =
dbo.States_Delta.Longitude,
Conus = dbo.States_Delta.Conus
Type = dbo.States_Delta.Type
34
WHEN NOT MATCHED THEN
INSERT(State_Terr,Capital,Latitude,
Longitude,Conus,Type)
VALUES(dbo.States_Delta.State_Terr,
dbo.States_Delta.Capital,
dbo.States_Delta.Latitude,
dbo.States_Delta.Longitude,
dbo.States_Delta.Conus,
dbo.States_Delta.Type);’’’).rowcount
print(‘Number of rows added or updated: ’+ str(counts)+ ‘-’ +
str(datetime.datetime.now()))
35
# Commits transactions to database
cur.commit()
# Closing cursor and database connection
cur.close()
cnmsql.close()
36
37
• Daniel Thomas
• ThomasD@leoncountyfl.gov
• TLCGIS.org
Goto http://shrug-gis.org/workshop/Workshop/Presentation-Resources
for this presentation, scripts, code snippets, and more!

Weitere ähnliche Inhalte

Was ist angesagt?

Graph Algorithms: Analytics for Understanding Data Relationships
Graph Algorithms: Analytics for Understanding Data RelationshipsGraph Algorithms: Analytics for Understanding Data Relationships
Graph Algorithms: Analytics for Understanding Data RelationshipsNeo4j
 
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...Altinity Ltd
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsNeo4j
 
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...Spark Summit
 
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEOClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEOAltinity Ltd
 
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)Altinity Ltd
 
Spark 4th Meetup Londond - Building a Product with Spark
Spark 4th Meetup Londond - Building a Product with SparkSpark 4th Meetup Londond - Building a Product with Spark
Spark 4th Meetup Londond - Building a Product with Sparksamthemonad
 
Webinar: Secrets of ClickHouse Query Performance, by Robert Hodges
Webinar: Secrets of ClickHouse Query Performance, by Robert HodgesWebinar: Secrets of ClickHouse Query Performance, by Robert Hodges
Webinar: Secrets of ClickHouse Query Performance, by Robert HodgesAltinity Ltd
 
Altinity Quickstart for ClickHouse
Altinity Quickstart for ClickHouseAltinity Quickstart for ClickHouse
Altinity Quickstart for ClickHouseAltinity Ltd
 
scalable machine learning
scalable machine learningscalable machine learning
scalable machine learningSamir Bessalah
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsNeo4j
 
Writing Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingWriting Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingToni Cebrián
 
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Data Provenance Support in...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Data Provenance Support in...Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Data Provenance Support in...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Data Provenance Support in...Data Con LA
 
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEOClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEOAltinity Ltd
 
Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020InfluxData
 
Your first ClickHouse data warehouse
Your first ClickHouse data warehouseYour first ClickHouse data warehouse
Your first ClickHouse data warehouseAltinity Ltd
 
Better than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseBetter than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseAltinity Ltd
 
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
Couchbase Tutorial: Big data Open Source Systems: VLDB2018Couchbase Tutorial: Big data Open Source Systems: VLDB2018
Couchbase Tutorial: Big data Open Source Systems: VLDB2018Keshav Murthy
 
Cs267 hadoop programming
Cs267 hadoop programmingCs267 hadoop programming
Cs267 hadoop programmingKuldeep Dhole
 
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEOTricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEOAltinity Ltd
 

Was ist angesagt? (20)

Graph Algorithms: Analytics for Understanding Data Relationships
Graph Algorithms: Analytics for Understanding Data RelationshipsGraph Algorithms: Analytics for Understanding Data Relationships
Graph Algorithms: Analytics for Understanding Data Relationships
 
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...
A Practical Introduction to Handling Log Data in ClickHouse, by Robert Hodges...
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
 
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEOClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
 
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
New features in ProxySQL 2.0 (updated to 2.0.9) by Rene Cannao (ProxySQL)
 
Spark 4th Meetup Londond - Building a Product with Spark
Spark 4th Meetup Londond - Building a Product with SparkSpark 4th Meetup Londond - Building a Product with Spark
Spark 4th Meetup Londond - Building a Product with Spark
 
Webinar: Secrets of ClickHouse Query Performance, by Robert Hodges
Webinar: Secrets of ClickHouse Query Performance, by Robert HodgesWebinar: Secrets of ClickHouse Query Performance, by Robert Hodges
Webinar: Secrets of ClickHouse Query Performance, by Robert Hodges
 
Altinity Quickstart for ClickHouse
Altinity Quickstart for ClickHouseAltinity Quickstart for ClickHouse
Altinity Quickstart for ClickHouse
 
scalable machine learning
scalable machine learningscalable machine learning
scalable machine learning
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
Writing Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using ScaldingWriting Hadoop Jobs in Scala using Scalding
Writing Hadoop Jobs in Scala using Scalding
 
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Data Provenance Support in...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Data Provenance Support in...Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Data Provenance Support in...
Big Data Day LA 2016/ Hadoop/ Spark/ Kafka track - Data Provenance Support in...
 
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEOClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
ClickHouse Query Performance Tips and Tricks, by Robert Hodges, Altinity CEO
 
Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020
 
Your first ClickHouse data warehouse
Your first ClickHouse data warehouseYour first ClickHouse data warehouse
Your first ClickHouse data warehouse
 
Better than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouseBetter than you think: Handling JSON data in ClickHouse
Better than you think: Handling JSON data in ClickHouse
 
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
Couchbase Tutorial: Big data Open Source Systems: VLDB2018Couchbase Tutorial: Big data Open Source Systems: VLDB2018
Couchbase Tutorial: Big data Open Source Systems: VLDB2018
 
Cs267 hadoop programming
Cs267 hadoop programmingCs267 hadoop programming
Cs267 hadoop programming
 
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEOTricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
 

Ähnlich wie Shrug2017 arcpy data_and_you

SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...Inhacking
 
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...Аліна Шепшелей
 
Structuring Apache Spark 2.0: SQL, DataFrames, Datasets And Streaming - by Mi...
Structuring Apache Spark 2.0: SQL, DataFrames, Datasets And Streaming - by Mi...Structuring Apache Spark 2.0: SQL, DataFrames, Datasets And Streaming - by Mi...
Structuring Apache Spark 2.0: SQL, DataFrames, Datasets And Streaming - by Mi...Databricks
 
Structuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
Structuring Spark: DataFrames, Datasets, and Streaming by Michael ArmbrustStructuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
Structuring Spark: DataFrames, Datasets, and Streaming by Michael ArmbrustSpark Summit
 
Memulai Data Processing dengan Spark dan Python
Memulai Data Processing dengan Spark dan PythonMemulai Data Processing dengan Spark dan Python
Memulai Data Processing dengan Spark dan PythonRidwan Fadjar
 
Structuring Spark: DataFrames, Datasets, and Streaming
Structuring Spark: DataFrames, Datasets, and StreamingStructuring Spark: DataFrames, Datasets, and Streaming
Structuring Spark: DataFrames, Datasets, and StreamingDatabricks
 
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun..."ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...Julia Cherniak
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)Paul Chao
 
Jump Start into Apache® Spark™ and Databricks
Jump Start into Apache® Spark™ and DatabricksJump Start into Apache® Spark™ and Databricks
Jump Start into Apache® Spark™ and DatabricksDatabricks
 
Spark SQL Deep Dive @ Melbourne Spark Meetup
Spark SQL Deep Dive @ Melbourne Spark MeetupSpark SQL Deep Dive @ Melbourne Spark Meetup
Spark SQL Deep Dive @ Melbourne Spark MeetupDatabricks
 
Barcelona MUG MongoDB + Hadoop Presentation
Barcelona MUG MongoDB + Hadoop PresentationBarcelona MUG MongoDB + Hadoop Presentation
Barcelona MUG MongoDB + Hadoop PresentationNorberto Leite
 
Spark SQL - 10 Things You Need to Know
Spark SQL - 10 Things You Need to KnowSpark SQL - 10 Things You Need to Know
Spark SQL - 10 Things You Need to KnowKristian Alexander
 
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...NoSQLmatters
 
Beyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesBeyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesDatabricks
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourPeter Friese
 

Ähnlich wie Shrug2017 arcpy data_and_you (20)

SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
SE2016 BigData Vitalii Bondarenko "HD insight spark. Advanced in-memory Big D...
 
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
Vitalii Bondarenko HDinsight: spark. advanced in memory big-data analytics wi...
 
Structuring Apache Spark 2.0: SQL, DataFrames, Datasets And Streaming - by Mi...
Structuring Apache Spark 2.0: SQL, DataFrames, Datasets And Streaming - by Mi...Structuring Apache Spark 2.0: SQL, DataFrames, Datasets And Streaming - by Mi...
Structuring Apache Spark 2.0: SQL, DataFrames, Datasets And Streaming - by Mi...
 
Structuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
Structuring Spark: DataFrames, Datasets, and Streaming by Michael ArmbrustStructuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
Structuring Spark: DataFrames, Datasets, and Streaming by Michael Armbrust
 
Memulai Data Processing dengan Spark dan Python
Memulai Data Processing dengan Spark dan PythonMemulai Data Processing dengan Spark dan Python
Memulai Data Processing dengan Spark dan Python
 
Structuring Spark: DataFrames, Datasets, and Streaming
Structuring Spark: DataFrames, Datasets, and StreamingStructuring Spark: DataFrames, Datasets, and Streaming
Structuring Spark: DataFrames, Datasets, and Streaming
 
Master tuning
Master   tuningMaster   tuning
Master tuning
 
Couchbas for dummies
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
 
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun..."ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
"ClojureScript journey: from little script, to CLI program, to AWS Lambda fun...
 
User Group3009
User Group3009User Group3009
User Group3009
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
 
Jump Start into Apache® Spark™ and Databricks
Jump Start into Apache® Spark™ and DatabricksJump Start into Apache® Spark™ and Databricks
Jump Start into Apache® Spark™ and Databricks
 
Spark SQL Deep Dive @ Melbourne Spark Meetup
Spark SQL Deep Dive @ Melbourne Spark MeetupSpark SQL Deep Dive @ Melbourne Spark Meetup
Spark SQL Deep Dive @ Melbourne Spark Meetup
 
Barcelona MUG MongoDB + Hadoop Presentation
Barcelona MUG MongoDB + Hadoop PresentationBarcelona MUG MongoDB + Hadoop Presentation
Barcelona MUG MongoDB + Hadoop Presentation
 
Spark SQL - 10 Things You Need to Know
Spark SQL - 10 Things You Need to KnowSpark SQL - 10 Things You Need to Know
Spark SQL - 10 Things You Need to Know
 
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
Simon Elliston Ball – When to NoSQL and When to Know SQL - NoSQL matters Barc...
 
Beyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFramesBeyond SQL: Speeding up Spark with DataFrames
Beyond SQL: Speeding up Spark with DataFrames
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 Hour
 
Orms vs Micro-ORMs
Orms vs Micro-ORMsOrms vs Micro-ORMs
Orms vs Micro-ORMs
 
Blazing Fast Windows 8 Apps using Visual C++
Blazing Fast Windows 8 Apps using Visual C++Blazing Fast Windows 8 Apps using Visual C++
Blazing Fast Windows 8 Apps using Visual C++
 

Kürzlich hochgeladen

Top Rated Pune Call Girls Dapodi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Dapodi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Dapodi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Dapodi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Call Girls in Nagpur High Profile
 
VIP Russian Call Girls in Indore Ishita 💚😋 9256729539 🚀 Indore Escorts
VIP Russian Call Girls in Indore Ishita 💚😋  9256729539 🚀 Indore EscortsVIP Russian Call Girls in Indore Ishita 💚😋  9256729539 🚀 Indore Escorts
VIP Russian Call Girls in Indore Ishita 💚😋 9256729539 🚀 Indore Escortsaditipandeya
 
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Top Rated Pune Call Girls Bhosari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls Bhosari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls Bhosari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls Bhosari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Call Girls in Nagpur High Profile
 
2024 Zoom Reinstein Legacy Asbestos Webinar
2024 Zoom Reinstein Legacy Asbestos Webinar2024 Zoom Reinstein Legacy Asbestos Webinar
2024 Zoom Reinstein Legacy Asbestos WebinarLinda Reinstein
 
Global debate on climate change and occupational safety and health.
Global debate on climate change and occupational safety and health.Global debate on climate change and occupational safety and health.
Global debate on climate change and occupational safety and health.Christina Parmionova
 
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Just Call Vip call girls Wardha Escorts ☎️8617370543 Starting From 5K to 25K ...
Just Call Vip call girls Wardha Escorts ☎️8617370543 Starting From 5K to 25K ...Just Call Vip call girls Wardha Escorts ☎️8617370543 Starting From 5K to 25K ...
Just Call Vip call girls Wardha Escorts ☎️8617370543 Starting From 5K to 25K ...Dipal Arora
 
Zechariah Boodey Farmstead Collaborative presentation - Humble Beginnings
Zechariah Boodey Farmstead Collaborative presentation -  Humble BeginningsZechariah Boodey Farmstead Collaborative presentation -  Humble Beginnings
Zechariah Boodey Farmstead Collaborative presentation - Humble Beginningsinfo695895
 
Call On 6297143586 Yerwada Call Girls In All Pune 24/7 Provide Call With Bes...
Call On 6297143586  Yerwada Call Girls In All Pune 24/7 Provide Call With Bes...Call On 6297143586  Yerwada Call Girls In All Pune 24/7 Provide Call With Bes...
Call On 6297143586 Yerwada Call Girls In All Pune 24/7 Provide Call With Bes...tanu pandey
 
2024: The FAR, Federal Acquisition Regulations - Part 29
2024: The FAR, Federal Acquisition Regulations - Part 292024: The FAR, Federal Acquisition Regulations - Part 29
2024: The FAR, Federal Acquisition Regulations - Part 29JSchaus & Associates
 
Regional Snapshot Atlanta Aging Trends 2024
Regional Snapshot Atlanta Aging Trends 2024Regional Snapshot Atlanta Aging Trends 2024
Regional Snapshot Atlanta Aging Trends 2024ARCResearch
 
Night 7k to 12k Call Girls Service In Navi Mumbai 👉 BOOK NOW 9833363713 👈 ♀️...
Night 7k to 12k  Call Girls Service In Navi Mumbai 👉 BOOK NOW 9833363713 👈 ♀️...Night 7k to 12k  Call Girls Service In Navi Mumbai 👉 BOOK NOW 9833363713 👈 ♀️...
Night 7k to 12k Call Girls Service In Navi Mumbai 👉 BOOK NOW 9833363713 👈 ♀️...aartirawatdelhi
 
Call On 6297143586 Viman Nagar Call Girls In All Pune 24/7 Provide Call With...
Call On 6297143586  Viman Nagar Call Girls In All Pune 24/7 Provide Call With...Call On 6297143586  Viman Nagar Call Girls In All Pune 24/7 Provide Call With...
Call On 6297143586 Viman Nagar Call Girls In All Pune 24/7 Provide Call With...tanu pandey
 
EDUROOT SME_ Performance upto March-2024.pptx
EDUROOT SME_ Performance upto March-2024.pptxEDUROOT SME_ Performance upto March-2024.pptx
EDUROOT SME_ Performance upto March-2024.pptxaaryamanorathofficia
 
WIPO magazine issue -1 - 2024 World Intellectual Property organization.
WIPO magazine issue -1 - 2024 World Intellectual Property organization.WIPO magazine issue -1 - 2024 World Intellectual Property organization.
WIPO magazine issue -1 - 2024 World Intellectual Property organization.Christina Parmionova
 
Human-AI Collaboration for Virtual Capacity in Emergency Operation Centers (E...
Human-AI Collaborationfor Virtual Capacity in Emergency Operation Centers (E...Human-AI Collaborationfor Virtual Capacity in Emergency Operation Centers (E...
Human-AI Collaboration for Virtual Capacity in Emergency Operation Centers (E...Hemant Purohit
 
Cunningham Road Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Cunningham Road Call Girls Bangalore WhatsApp 8250192130 High Profile ServiceCunningham Road Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Cunningham Road Call Girls Bangalore WhatsApp 8250192130 High Profile ServiceHigh Profile Call Girls
 
Expressive clarity oral presentation.pptx
Expressive clarity oral presentation.pptxExpressive clarity oral presentation.pptx
Expressive clarity oral presentation.pptxtsionhagos36
 

Kürzlich hochgeladen (20)

Top Rated Pune Call Girls Dapodi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Dapodi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Dapodi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Dapodi ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
VIP Russian Call Girls in Indore Ishita 💚😋 9256729539 🚀 Indore Escorts
VIP Russian Call Girls in Indore Ishita 💚😋  9256729539 🚀 Indore EscortsVIP Russian Call Girls in Indore Ishita 💚😋  9256729539 🚀 Indore Escorts
VIP Russian Call Girls in Indore Ishita 💚😋 9256729539 🚀 Indore Escorts
 
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service
 
Top Rated Pune Call Girls Bhosari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated  Pune Call Girls Bhosari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...Top Rated  Pune Call Girls Bhosari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
Top Rated Pune Call Girls Bhosari ⟟ 6297143586 ⟟ Call Me For Genuine Sex Ser...
 
2024 Zoom Reinstein Legacy Asbestos Webinar
2024 Zoom Reinstein Legacy Asbestos Webinar2024 Zoom Reinstein Legacy Asbestos Webinar
2024 Zoom Reinstein Legacy Asbestos Webinar
 
Global debate on climate change and occupational safety and health.
Global debate on climate change and occupational safety and health.Global debate on climate change and occupational safety and health.
Global debate on climate change and occupational safety and health.
 
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service
 
Just Call Vip call girls Wardha Escorts ☎️8617370543 Starting From 5K to 25K ...
Just Call Vip call girls Wardha Escorts ☎️8617370543 Starting From 5K to 25K ...Just Call Vip call girls Wardha Escorts ☎️8617370543 Starting From 5K to 25K ...
Just Call Vip call girls Wardha Escorts ☎️8617370543 Starting From 5K to 25K ...
 
Zechariah Boodey Farmstead Collaborative presentation - Humble Beginnings
Zechariah Boodey Farmstead Collaborative presentation -  Humble BeginningsZechariah Boodey Farmstead Collaborative presentation -  Humble Beginnings
Zechariah Boodey Farmstead Collaborative presentation - Humble Beginnings
 
Rohini Sector 37 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 37 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 37 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 37 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Call On 6297143586 Yerwada Call Girls In All Pune 24/7 Provide Call With Bes...
Call On 6297143586  Yerwada Call Girls In All Pune 24/7 Provide Call With Bes...Call On 6297143586  Yerwada Call Girls In All Pune 24/7 Provide Call With Bes...
Call On 6297143586 Yerwada Call Girls In All Pune 24/7 Provide Call With Bes...
 
2024: The FAR, Federal Acquisition Regulations - Part 29
2024: The FAR, Federal Acquisition Regulations - Part 292024: The FAR, Federal Acquisition Regulations - Part 29
2024: The FAR, Federal Acquisition Regulations - Part 29
 
Regional Snapshot Atlanta Aging Trends 2024
Regional Snapshot Atlanta Aging Trends 2024Regional Snapshot Atlanta Aging Trends 2024
Regional Snapshot Atlanta Aging Trends 2024
 
Night 7k to 12k Call Girls Service In Navi Mumbai 👉 BOOK NOW 9833363713 👈 ♀️...
Night 7k to 12k  Call Girls Service In Navi Mumbai 👉 BOOK NOW 9833363713 👈 ♀️...Night 7k to 12k  Call Girls Service In Navi Mumbai 👉 BOOK NOW 9833363713 👈 ♀️...
Night 7k to 12k Call Girls Service In Navi Mumbai 👉 BOOK NOW 9833363713 👈 ♀️...
 
Call On 6297143586 Viman Nagar Call Girls In All Pune 24/7 Provide Call With...
Call On 6297143586  Viman Nagar Call Girls In All Pune 24/7 Provide Call With...Call On 6297143586  Viman Nagar Call Girls In All Pune 24/7 Provide Call With...
Call On 6297143586 Viman Nagar Call Girls In All Pune 24/7 Provide Call With...
 
EDUROOT SME_ Performance upto March-2024.pptx
EDUROOT SME_ Performance upto March-2024.pptxEDUROOT SME_ Performance upto March-2024.pptx
EDUROOT SME_ Performance upto March-2024.pptx
 
WIPO magazine issue -1 - 2024 World Intellectual Property organization.
WIPO magazine issue -1 - 2024 World Intellectual Property organization.WIPO magazine issue -1 - 2024 World Intellectual Property organization.
WIPO magazine issue -1 - 2024 World Intellectual Property organization.
 
Human-AI Collaboration for Virtual Capacity in Emergency Operation Centers (E...
Human-AI Collaborationfor Virtual Capacity in Emergency Operation Centers (E...Human-AI Collaborationfor Virtual Capacity in Emergency Operation Centers (E...
Human-AI Collaboration for Virtual Capacity in Emergency Operation Centers (E...
 
Cunningham Road Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Cunningham Road Call Girls Bangalore WhatsApp 8250192130 High Profile ServiceCunningham Road Call Girls Bangalore WhatsApp 8250192130 High Profile Service
Cunningham Road Call Girls Bangalore WhatsApp 8250192130 High Profile Service
 
Expressive clarity oral presentation.pptx
Expressive clarity oral presentation.pptxExpressive clarity oral presentation.pptx
Expressive clarity oral presentation.pptx
 

Shrug2017 arcpy data_and_you

  • 1. 1
  • 2. AGENDA• Python And the ERSI Platform • Key Items in ESRI Platform o Connection Files o ArcPy Cursors • Branching out with Python Libraries o Pyodbc o Cx_Oracle • Sqlite – A hidden gem • Code Focus – Example 1 • Code Focus – Example 2 2
  • 4. Connection Files: Gateways Between Platforms Oracle MS SQL Server 4 ArcSDE ArcServer/ Portal For ArcGIS AGOL External Data
  • 5. Cursor Function Code arcpy.da.SearchCursor Read-only access arcpy.da.InsertCursor Inserts rows arcpy.da.UpdateCursor Updates or deletes rows 5
  • 6. 6 import arcpy fc = ‘C:/some.gdb/buildings’ fields = [ ‘OID@’, ‘SHAPE@XY’, ‘STRUCTURE’ ] # Other Options: SHAPE@WKT, SHAPE@WKB, SHAPE@JSON with arcpy.da.SearchCursor(fc, fields) as cursor: for row in cursor: # Perform some task
  • 7. 7 import arcpy row_values = [( ‘Barn’, (-84.005, 33.002)), ( ‘House’, (-84.899, 33.556))] # Open an InsertCursor cursor = arcpy.da.InsertCursor(‘C:/some.gdb/building', [ ‘STRUCTURE’, ‘SHAPE@XY’ ]) # Insert new rows that include point nane and a x,y coordinate # pair that represents the structure's center for row in row_values: cursor.insertRow(row) # Delete cursor object
  • 8. 8 import arcpy fc = ‘c:/some.gdb/buildings’ fields = [‘OID@’, ‘SHAPE@XY’, ‘STRUCTURE’] # Create update cursor for feature class with arcpy.da.UpdateCursor(fc, fields) as cursor: for row in cursor: row[2] = row[2].upper() # Update the cursor with the updated list cursor.updateRow(row)
  • 9. Python Library - PyODBC 9 Pyodbc is an open source Python module specifically designed for connecting to ODBC databases. Based on the DB API 2.0 specification, this library is also packed with even more Pythonic convenience. Pyodbc can connect to these Microsoft databases:
  • 10. How to use PyODBC 10 # Import python library import pyodbc # Use the specific connection below for each Microsoft database type. # MS Access 2000 connection DBfile = ‘C:/SomeMdb.mdb’ cnmdb = pyodbc.connect(‘‘‘DRIVER={Microsoft Access Driver (*.mdb)};DBQ=’’’ +Dbfile)
  • 11. 11 # Sql Server Express Connection. Use FQDN for remote server connection cnxpress = pyodbc.connect(‘‘‘Driver= {SQL Server Native Client 10.0}; Server=Instance Name; Database=DB Name; Uid=User; Pwd=Password;’’’) PyODBC continued…
  • 12. PyODBC continued… 12 # MS SQL Server Connection. Use FQDN for remote server connection cnmsql = pyodbc.connect(‘‘‘DRIVER={SQL Server}; SERVER=ServerName; DATABASE=DB Name; UID=User; PWD=Password’’’)
  • 13. PyODBC continued… 13 # MS SQL Server Connection cnazure = pyodbc.connect(‘‘‘Driver= {SQL Server Native Client 10.0}; Server= tcp:ServerName.database.windows.net; Database=DB NAME; Uid=[LoginForDb]@[serverName]; Pwd=myPassword;Encrypt=yes;’’’) cur = ConnChoice.cursor()
  • 14. # Import python library import cx_Oracle # Create connection to Oracle DB. Versions 10g, 11g, and 12c are applicable. Use FQDN for remote server connection. con = cx_Oracle.connect(‘‘‘scott/tiger@server:port/instance’’’) # Create database cursor cur = con.cursor() Python Library – cx_Oracle 14
  • 15. What is SQLite? 15 SQLite is an open source transactional database that supports ANSI SQL 92. Why use SQLite with GIS? SQLIte can be use as a traditional database on disk or invoked solely in memory. Operations like joins are handled in a single transaction versus multiple steps.
  • 16. How to use SQLite 16 # Loads python library import arcpy # Execute CreateSQLiteDatabase for disk based database arcpy.CreateSQLiteDatabase_management(‘C:/data/example. sqlite’, ‘SPATIALITE’)
  • 17. # Loads python library import sqlite3 as lite # Creating a SQLite DB connection in RAM con = lite.connect(‘:memory:’) # Generate cursor cur = con.cursor() How to use SQLite 17
  • 18. “If you want to succeed you should strike out on new paths, rather than travel the worn paths of accepted success.” 18 John D. Rockefeller
  • 19. 19 Take the provided CSV file and create a point feature class using the coordinates provide. Be sure to validate all text attributes for spacing issues before creating feature class. The final schema should look like the following: Attribute Name Attribute Type Attribute Size State_Terr Text 75 Capital Text 75 Latitude Double - Longitude Double - Conus Text 3 Type Text 10 Bridging Platforms
  • 20. 20 Case Example for Bridging Platforms
  • 21. 21 import arcpy import datetime import sqlite3 as lite # Scripting environment variables arcpy.env.workspace = r‘C:Shrug2017’ arcpy.env.overwriteOutput = True csv = r‘C:Shrug2017Demo1states_terr.csv’ fields = [‘State_Terr’,‘Capital’,‘Latitude’,‘Longitude’,‘Conus’, ‘Type’] # Optional: fields = [‘*’]
  • 22. 22 # Creating a SQLite DB in RAM con = lite.connect(‘:memory:’) # Generate cursor cur = con.cursor() print(‘Destination database created –’+ str(datetime.datetime.now())) # Creates a table structure for incoming data cur.execute(‘‘‘CREATE TABLE States(StateNme TEXT, Capital TEXT, Lat REAL, Long REAL, Conus TEXT, Typ TEXT);’’’)
  • 23. 23 print(‘Working table created –’+ str(datetime.datetime.now())) with arcpy.da.SearchCursor(csv, fields) as cursor: for row in cursor: # Inserting records to SQLite DB to_db = [row[0],row[1],row[2],row[3],row[4],row[5] ] cur.execute(‘‘‘INSERT INTO States(StateNme,Capital,Lat,Long, Conus,Typ) VALUES(?,?,?,?,?,?);’’’, to_db) con.commit()
  • 24. 24 print(‘CSV inserted into SQLite database table –’ + str(datetime.datetime.now())) #Removing white spacing from columns with text data type cur.execute(‘‘‘UPDATE States SET StateNme = TRIM(StateNme), Capital = TRIM(Capital), Conus = TRIM(Conus), Typ = TRIM(Typ);’’’) con.commit() print(‘Validation process completed – ’+ str(datetime.datetime.now()))
  • 25. 25 cur.execute(‘‘‘ALTER TABLE States ADD ShapeXY TEXT’’’) cur.execute(‘‘‘UPDATE States SET ShapeXY = ‘POINT’||‘(’ ||Long|| ‘ ’||Lat|| ‘)’ ’’’) con.commit() print(‘Spatial column created – ’+ str(datetime.datetime.now())) output_path = r‘C:Shrug2017Scratch.gdb’ out_name = ‘us_states_terr’ geometry_type = ‘Point’
  • 27. 27 sr.loadFromString(wkt) result = arcpy.CreateFeatureclass_management(output_path, out_name,geometry_type, ‘’, ‘DISABLED’,‘DISABLED’,sr) fcOut = result.getOutput(0) arcpy.AddField_management(fcOut,‘State_Terr’,‘TEXT’,‘’,‘’,75) arcpy.AddField_management(fcOut,‘Capital’,‘TEXT’,‘’,‘’,75) arcpy.AddField_management(fcOut,‘Latitude’,‘DOUBLE’, 8,‘’, ‘’, ‘’, ‘NULLABLE’)
  • 28. 28 arcpy.AddField_management(fcOut,‘Longitude’,‘DOUBLE’, 8,‘’,‘’,‘’, ‘NULLABLE’) arcpy.AddField_management(fcOut,‘Conus’,‘TEXT’,‘’,‘’, 3) arcpy.AddField_management(fcOut,'Type','TEXT',‘’,‘’, 10) print( ‘Shell featureclass created – ’+ str(datetime.datetime.now()) ) schema = [ ‘SHAPE@WKT’,‘State_Terr’,‘Capital’, ‘Latitude’,‘Longitude’,‘Conus’,‘Type’ ] curESRI = arcpy.da.InsertCursor(fcOut,schema)
  • 29. 29 # Query to extract data from SQLITE DB table rows = cur.execute(‘‘‘SELECT ShapeXY,StateNme,Capital, Lat,Long,Conus,Typ FROM States’’’) for row in rows: curESRI.insertRow(row) # close insert cursor del curESRI # close SQLite database connection con.close() print(‘SQLite table insertion completed –’+ str(datetime.datetime.now()))
  • 30. 30 The point data that is displayed in ArcGIS Pro was created in 0.004 of second. The table below depicts the processing times for three different configurations Arc Map Arc Pro SQLite 1.47 s 0.39 s 0.004 s
  • 31. 31 Putting It All Together… Prior Steps Before Starting Demo2 Create a MS SQL Server Express database using the SQL scripts provided. Modified the previous script to add data to a MS SQL Server Express database table. Upload ‘states_update1.csv’ to the temp table in MSSQL Express
  • 32. 32 import pyodbc import os import datetime print(‘Starting Update Process- ’ + str(datetime.datetime.now())) # Sql Server connection cnmsql = pyodbc.connect(‘DRIVER={SQL Server}; Server=Server; Database=ShrugDemo; UID=ScrptKng;PWD=python!’) # Create cursor cur = cnmsql.cursor()
  • 33. 33 # Issue update commands for states counts = cur.execute(‘‘‘MERGE INTO dbo.States_Territories USING dbo.States_Delta ON dbo.States_Territories.State_Terr = dbo.States_Delta.State_Terr WHEN MATCHED THEN UPDATE SET Capital = dbo.States_Delta.Capital, Latitude = dbo.States_Delta.Latitude, Longitude = dbo.States_Delta.Longitude, Conus = dbo.States_Delta.Conus Type = dbo.States_Delta.Type
  • 34. 34 WHEN NOT MATCHED THEN INSERT(State_Terr,Capital,Latitude, Longitude,Conus,Type) VALUES(dbo.States_Delta.State_Terr, dbo.States_Delta.Capital, dbo.States_Delta.Latitude, dbo.States_Delta.Longitude, dbo.States_Delta.Conus, dbo.States_Delta.Type);’’’).rowcount print(‘Number of rows added or updated: ’+ str(counts)+ ‘-’ + str(datetime.datetime.now()))
  • 35. 35 # Commits transactions to database cur.commit() # Closing cursor and database connection cur.close() cnmsql.close()
  • 36. 36
  • 37. 37 • Daniel Thomas • ThomasD@leoncountyfl.gov • TLCGIS.org Goto http://shrug-gis.org/workshop/Workshop/Presentation-Resources for this presentation, scripts, code snippets, and more!