SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
String Ma nipulation
                                     cGIS
                 wit h python and Ar
 Getting started




       Guido Stein
   guido@avidgeo.com
AvidGeo Meetup 2/21/2013
G uido Stein

● GIS Analyst
  Applied Geographics, Inc.
  ○ Parcel Editing
  ○ Extract, Transform, and Load
  ○ Workflows
    ■ Model Builder
    ■ Calculate Field
    ■ Python
Overview

●   Municipal Data
●   Variables
●   Fields
●   Strings As Lists
●   String Functions
●   More About String
●   Concatenation
●   Putting It Together
●   Single Line Statement If/Else
●   Next Time
It's Ra ining Data

Planimetric Data
  ○ Road
  ○ Building
  ○ Fire Hydrant
Cadastral Data
  ○ Municipal Boundaries
  ○ Real Estate
    ■ Parcel
    ■ Property
e Data Mor e Problems
    Mor

Parcel Polygon      Property Table

045-267 / 88-3.A    45-88-3-A
045-267/ 88-4       45-88-4
045-267 / 88-5      45-88-5
045- 267/88-6       45-88-6
145- 267/88-7A      145-88-7A
145- 267/88-7B      145-88-7B
, a name I c all myself
    Me

String                 Variable Declaration
   "guido"             me = "guido"
Integer                age = 35
   35                  height = 5.75
Float                  sounds_like =
   5.75                ["Burrito","Dorito"]
List
["Burrito","Dorito"]
seltongue T ranslator
     Par

VB                    Python

[parcel_id]           !parcel_id!

trim([parcel_id])     !parcel_id!.strip()

"N" & [parcel_id]     "N" + !parcel_id!
Cutting t he Cheese

cheese = "Gorgonzola"        cheese[-4:]
                             "zola"
["G","o","r","g","o","n","   ● Like right() in VB
z","o","l","a"]
                             cheese[4:-4]
cheese[:4]                   "on"
"Gorg"                       ● Like mid() in VB
● Like left() in VB
Function al Design 1

● strip(), lstrip(),   par[:8].strip()
   rstrip()            "045-267"
   ● like VB trim()
par = "045-267 / 88-   par.lstrip("0")
3.A"                   "45-267 / 88-3.A"

par[:8]                par.strip(" 0.3A-8/")
"045-267 "             "45-267"
Function al Design 2

● split()                ● replace()
par = "045-267 / 88-
3.A"

par.split('/')           par.replace('.','-')
["045-267 "," 88-3.A"]   "045-267 / 88-3-A"

par.split('/')[0]
"045-267 "
something completely
    Now for
    different
Escape                If you use single quote
                     around string literal
New Line              then double quotes
n                    don't need to be
                      escaped
single/double quote
' "
                      Vise versa
C oncatenate

par = '045-267 / 88-3.A'

!par![1:3] + '-' + !par![4:7]
'%s-%s' % (!par![1:3],!par![4:7])
'45-267'

● %s - string
● %i - integer
● %.2f - float with 2 decimal points
Putting it together

par = '045-267 / 88-3.A'

'%s-%s' % (
   par[1:3],
   par.split('/')[1].replace('.','-').strip()
)

'45-88-3-A'
g it togethe r for real
    Puttin

'%s-%s' % (
!parcel_id![1:3], !parcel_id!.split('/')[1].
replace('.','-').strip()
)
e Data Mor e Problems
    Mor

Parcel Polygon      Property Table

045-267 / 88-3.A    45-88-3-A
045-267/ 88-4       45-88-4
045-267 / 88-5      45-88-5
045- 267/88-6       45-88-6
145- 267/88-7A      145-88-7A
145- 267/88-7B      145-88-7B
ogether for real, really
     P utting it t

'%s-%s' % ( !parcel_id!.split('/')[0].strip(' 0'), !
parcel_id!.split('/')[1].replace('.','-').strip())
ther for re al, really,
    Pu tting it toge
    really
'%s-%s' % ( !parcel_id!.split('/')[0].strip(' 0').
split('-')[0], !parcel_id!.split('/')[1].replace
('.','-').strip())
One More thing

Null = None
It will crash your statement

alternate statement if field is None else
primary statement

'' if !parcel_id! is None else ('%s-%s' % ( !
parcel_id!.split('/')[0].strip(' 0').split('-')[0], !
parcel_id!.split('/')[1].replace('.','-').strip()))
N ext Time

Advanced Calculate
● building your own functions
● tabbing
● if,then, else, elif
● import libraries
  ○ re
● More string functions
● variable comparison
String Ma nipulation
                                     cGIS
                 wit h python and Ar
 Getting started




       Guido Stein
   guido@avidgeo.com
AvidGeo Meetup 2/21/2013

Weitere ähnliche Inhalte

Was ist angesagt? (6)

Integrating Survey Data into a GIS
Integrating Survey Data into a GISIntegrating Survey Data into a GIS
Integrating Survey Data into a GIS
 
CM 1.0 geometry3 MrG 2011.0914 - sage
CM 1.0 geometry3 MrG 2011.0914  - sageCM 1.0 geometry3 MrG 2011.0914  - sage
CM 1.0 geometry3 MrG 2011.0914 - sage
 
Bezier curve computer graphics
Bezier curve computer graphicsBezier curve computer graphics
Bezier curve computer graphics
 
Trigo
TrigoTrigo
Trigo
 
Computer aided machine drawing
Computer aided machine drawingComputer aided machine drawing
Computer aided machine drawing
 
Vogel's Approximation Method
Vogel's Approximation MethodVogel's Approximation Method
Vogel's Approximation Method
 

Andere mochten auch

Automation in ArcGIS using Arcpy
Automation in ArcGIS using ArcpyAutomation in ArcGIS using Arcpy
Automation in ArcGIS using Arcpy
Geodata AS
 

Andere mochten auch (12)

Start Podcasting?
Start Podcasting?Start Podcasting?
Start Podcasting?
 
Automation in ArcGIS using Arcpy
Automation in ArcGIS using ArcpyAutomation in ArcGIS using Arcpy
Automation in ArcGIS using Arcpy
 
BK2015 Arcgis pro
BK2015 Arcgis proBK2015 Arcgis pro
BK2015 Arcgis pro
 
Loading Parcels Into Smallworld GIS via FME
Loading Parcels Into Smallworld GIS via FMELoading Parcels Into Smallworld GIS via FME
Loading Parcels Into Smallworld GIS via FME
 
ArcGIS Lesson 3
ArcGIS Lesson 3ArcGIS Lesson 3
ArcGIS Lesson 3
 
Python Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part IPython Programming for ArcGIS: Part I
Python Programming for ArcGIS: Part I
 
Python and ArcGIS 10.1
Python and ArcGIS 10.1Python and ArcGIS 10.1
Python and ArcGIS 10.1
 
ArcGIS Python Programming (3Nov11)
ArcGIS Python Programming (3Nov11)ArcGIS Python Programming (3Nov11)
ArcGIS Python Programming (3Nov11)
 
Python Scripting for ArcGIS
Python Scripting for ArcGISPython Scripting for ArcGIS
Python Scripting for ArcGIS
 
Editing for ArcGIS 10 and 10.1
Editing for ArcGIS 10 and 10.1Editing for ArcGIS 10 and 10.1
Editing for ArcGIS 10 and 10.1
 
Applications of Arc GIS
Applications of Arc GISApplications of Arc GIS
Applications of Arc GIS
 
如何用 grs 擷取台灣上市股票股價資訊 PyCon APAC 2014
如何用 grs 擷取台灣上市股票股價資訊 PyCon APAC 2014如何用 grs 擷取台灣上市股票股價資訊 PyCon APAC 2014
如何用 grs 擷取台灣上市股票股價資訊 PyCon APAC 2014
 

Ähnlich wie Avidgeo String Manipulation : Getting Started with Python and ArcGIS

Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
guesta3202
 
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docxcalc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
RAHUL126667
 

Ähnlich wie Avidgeo String Manipulation : Getting Started with Python and ArcGIS (20)

Combined Line - Double Bubbles - Pie chart.
Combined Line - Double Bubbles - Pie chart.Combined Line - Double Bubbles - Pie chart.
Combined Line - Double Bubbles - Pie chart.
 
Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
 
MH prediction modeling and validation in r (1) regression 190709
MH prediction modeling and validation in r (1) regression 190709MH prediction modeling and validation in r (1) regression 190709
MH prediction modeling and validation in r (1) regression 190709
 
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
Let us c(by Yashwant Kanetkar) 5th edition solution chapter 1
 
Writing DSLs with Parslet - Wicked Good Ruby Conf
Writing DSLs with Parslet - Wicked Good Ruby ConfWriting DSLs with Parslet - Wicked Good Ruby Conf
Writing DSLs with Parslet - Wicked Good Ruby Conf
 
LAMP_TRAINING_SESSION_6
LAMP_TRAINING_SESSION_6LAMP_TRAINING_SESSION_6
LAMP_TRAINING_SESSION_6
 
gsub (MOTM 2009.09)
gsub (MOTM 2009.09)gsub (MOTM 2009.09)
gsub (MOTM 2009.09)
 
Applied Regression Analysis using R
Applied Regression Analysis using RApplied Regression Analysis using R
Applied Regression Analysis using R
 
chapter3
chapter3chapter3
chapter3
 
Groovy
GroovyGroovy
Groovy
 
R Programming: Transform/Reshape Data In R
R Programming: Transform/Reshape Data In RR Programming: Transform/Reshape Data In R
R Programming: Transform/Reshape Data In R
 
Slaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in RubySlaying the Dragon: Implementing a Programming Language in Ruby
Slaying the Dragon: Implementing a Programming Language in Ruby
 
dplyr
dplyrdplyr
dplyr
 
Regression and Classification with R
Regression and Classification with RRegression and Classification with R
Regression and Classification with R
 
[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R[系列活動] Data exploration with modern R
[系列活動] Data exploration with modern R
 
C language concept with code apna college.pdf
C language concept with code apna college.pdfC language concept with code apna college.pdf
C language concept with code apna college.pdf
 
Arduino coding class
Arduino coding classArduino coding class
Arduino coding class
 
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docxcalc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
calc3build# calc3bison -y -d calc3.yflex calc3.lgcc -c .docx
 
Eurogroup Consulting - Shopping 2020 - Supply Chain Final
Eurogroup Consulting - Shopping 2020 - Supply Chain FinalEurogroup Consulting - Shopping 2020 - Supply Chain Final
Eurogroup Consulting - Shopping 2020 - Supply Chain Final
 
The Ring programming language version 1.5.4 book - Part 85 of 185
The Ring programming language version 1.5.4 book - Part 85 of 185The Ring programming language version 1.5.4 book - Part 85 of 185
The Ring programming language version 1.5.4 book - Part 85 of 185
 

Kürzlich hochgeladen

Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Kürzlich hochgeladen (20)

ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxBT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 

Avidgeo String Manipulation : Getting Started with Python and ArcGIS

  • 1. String Ma nipulation cGIS wit h python and Ar Getting started Guido Stein guido@avidgeo.com AvidGeo Meetup 2/21/2013
  • 2. G uido Stein ● GIS Analyst Applied Geographics, Inc. ○ Parcel Editing ○ Extract, Transform, and Load ○ Workflows ■ Model Builder ■ Calculate Field ■ Python
  • 3. Overview ● Municipal Data ● Variables ● Fields ● Strings As Lists ● String Functions ● More About String ● Concatenation ● Putting It Together ● Single Line Statement If/Else ● Next Time
  • 4. It's Ra ining Data Planimetric Data ○ Road ○ Building ○ Fire Hydrant Cadastral Data ○ Municipal Boundaries ○ Real Estate ■ Parcel ■ Property
  • 5. e Data Mor e Problems Mor Parcel Polygon Property Table 045-267 / 88-3.A 45-88-3-A 045-267/ 88-4 45-88-4 045-267 / 88-5 45-88-5 045- 267/88-6 45-88-6 145- 267/88-7A 145-88-7A 145- 267/88-7B 145-88-7B
  • 6. , a name I c all myself Me String Variable Declaration "guido" me = "guido" Integer age = 35 35 height = 5.75 Float sounds_like = 5.75 ["Burrito","Dorito"] List ["Burrito","Dorito"]
  • 7. seltongue T ranslator Par VB Python [parcel_id] !parcel_id! trim([parcel_id]) !parcel_id!.strip() "N" & [parcel_id] "N" + !parcel_id!
  • 8. Cutting t he Cheese cheese = "Gorgonzola" cheese[-4:] "zola" ["G","o","r","g","o","n"," ● Like right() in VB z","o","l","a"] cheese[4:-4] cheese[:4] "on" "Gorg" ● Like mid() in VB ● Like left() in VB
  • 9. Function al Design 1 ● strip(), lstrip(), par[:8].strip() rstrip() "045-267" ● like VB trim() par = "045-267 / 88- par.lstrip("0") 3.A" "45-267 / 88-3.A" par[:8] par.strip(" 0.3A-8/") "045-267 " "45-267"
  • 10. Function al Design 2 ● split() ● replace() par = "045-267 / 88- 3.A" par.split('/') par.replace('.','-') ["045-267 "," 88-3.A"] "045-267 / 88-3-A" par.split('/')[0] "045-267 "
  • 11. something completely Now for different Escape If you use single quote around string literal New Line then double quotes n don't need to be escaped single/double quote ' " Vise versa
  • 12. C oncatenate par = '045-267 / 88-3.A' !par![1:3] + '-' + !par![4:7] '%s-%s' % (!par![1:3],!par![4:7]) '45-267' ● %s - string ● %i - integer ● %.2f - float with 2 decimal points
  • 13. Putting it together par = '045-267 / 88-3.A' '%s-%s' % ( par[1:3], par.split('/')[1].replace('.','-').strip() ) '45-88-3-A'
  • 14. g it togethe r for real Puttin '%s-%s' % ( !parcel_id![1:3], !parcel_id!.split('/')[1]. replace('.','-').strip() )
  • 15. e Data Mor e Problems Mor Parcel Polygon Property Table 045-267 / 88-3.A 45-88-3-A 045-267/ 88-4 45-88-4 045-267 / 88-5 45-88-5 045- 267/88-6 45-88-6 145- 267/88-7A 145-88-7A 145- 267/88-7B 145-88-7B
  • 16. ogether for real, really P utting it t '%s-%s' % ( !parcel_id!.split('/')[0].strip(' 0'), ! parcel_id!.split('/')[1].replace('.','-').strip())
  • 17. ther for re al, really, Pu tting it toge really '%s-%s' % ( !parcel_id!.split('/')[0].strip(' 0'). split('-')[0], !parcel_id!.split('/')[1].replace ('.','-').strip())
  • 18. One More thing Null = None It will crash your statement alternate statement if field is None else primary statement '' if !parcel_id! is None else ('%s-%s' % ( ! parcel_id!.split('/')[0].strip(' 0').split('-')[0], ! parcel_id!.split('/')[1].replace('.','-').strip()))
  • 19. N ext Time Advanced Calculate ● building your own functions ● tabbing ● if,then, else, elif ● import libraries ○ re ● More string functions ● variable comparison
  • 20. String Ma nipulation cGIS wit h python and Ar Getting started Guido Stein guido@avidgeo.com AvidGeo Meetup 2/21/2013