0% found this document useful (0 votes)
44 views

2008-04-01 - Advanced Geoprocessing, Python

This document provides an overview of a lecture on advanced geoprocessing and Python using ArcObjects. It discusses adding layers to a map and setting layer symbology programmatically using ArcObjects in Python. Sample code is provided to demonstrate adding a shapefile and feature class from a personal geodatabase to a map. The code also shows how to set the layer symbology by creating a renderer, symbol, and color and associating them with the feature layer. Reminders are given about upcoming lab and presentation deadlines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

2008-04-01 - Advanced Geoprocessing, Python

This document provides an overview of a lecture on advanced geoprocessing and Python using ArcObjects. It discusses adding layers to a map and setting layer symbology programmatically using ArcObjects in Python. Sample code is provided to demonstrate adding a shapefile and feature class from a personal geodatabase to a map. The code also shows how to set the layer symbology by creating a renderer, symbol, and color and associating them with the feature layer. Reminders are given about upcoming lab and presentation deadlines.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Week 12 Lecture:

Advanced Geoprocessing and Python


With ArcObjects
Introduction to Programming for GIS & Remote Sensing
GEO6938-4172
GEO4938 4166
GEO4938-4166
Reminder
The ArcObjects walk-through lab questions
are due on Thursday.

Lab this week used to finalize presentations

Presentations on 8th and 10th, NEXT WEEK!


– Present in alphabetical order of first name:
• Benjamin,
j , Cerian,, JJeffrey,
y, JJoshua,, Lindsay,
y, Mariano,,
Melissa, Michal, Michelle, Reggie
Re-cap
Re cap From Past Lectures
We’ve
We ve discussed ArcGIS and geoprocessing
– Model builder
– Exporting/importing scripts

ArcObjects are components exposing ArcGIS


to control by other programming languages:
– VBA examples
– In depth walk-through in Lab
Today’ss Lecture
Today

Further example of ArcObjects and object


relationships

Adding Layers to a Map


Setting Layer Symbology

ArcObjects in Python, it is possible!

Following slides based on lecture from


Sample: Add a Shapefile
Sh fil PProgrammatically
ti ll

WorkspaceFactory
p y Application
CoClass class

MxDocument
WorkSpace IFeatureWorkspace CoClass
CoClass
*
Imap Map
IActiveView CoClass

*
Set pFeatureLayer.FeatureClass = _ Layer
y
pFeatureWorkspace.OpenFeatureClass("Country") Abstract

FeatureLayer
C Cl
CoClass
Sample: Add a Personal Geodatabase
FeatureClass Programmatically
Public Sub AddFeatureClass()

Dim pWorkspaceFactory As IWorkspaceFactory


Dim pFeatureWorkspace As IFeatureWorkspace
Dim pFeatureLayer As IFeatureLayer
Dim pMxDocument As IMxDocument
Dim pMap As IMap

'Create a new ShapefileWorkspaceFactory object


'and open a shapefile folder

Set pWorkspaceFactory = New AccessWorkspaceFactory


Set p
pFeatureWorkspace
p = _p pWorkspaceFactory.OpenFromFile
p y p _
("C:\ArcObejcts\data\wilson_NC\wilson.mdb",0)

'Create a new FeatureLayer and assign a feature class to it

Set pFeatureLayer = New FeatureLayer


Set pFeatureLayer.FeatureClass
pFeatureLayer FeatureClass = _ pFeatureWorkspace.OpenFeatureClass(“Streets
pFeatureWorkspace OpenFeatureClass(“Streets"))
pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName

'Add the FeatureLayer to the focus map


Set pMxDocument = Application.Document
Set p
pMapp=ppMxDocument.FocusMap pp
pMap.AddLayer
p y pFeatureLayer
p y

End Sub
Layer Objects

Layer
Abstract

FeatureLayer RasterLayer GraphicsLayer



CoClass CoClass CoClass

Dim pFLayer as IFeatureLayer


Set pFLayer = New FeatureLayer

Dim pRLayer as IRasterLayer


Set pRLayer = New RasterLayer
WorkspaceFactory Objects

WorkspaceFactory
Abstract

Access Raster Shapefile


W k
WorkspaceFactory
F t W k
WorkspaceFactory
F t W k
WorkspaceFactory
F t …
CoClass CoClass CoClass

Dim ppAWorkspaceFactory
p y as IWorkspaceFactory
p y
Set pAWorkspaceFactory = New AccessWorkspaceFactory
Set pFeatureWorkspace = pAWorkspaceFactory.OpenFromFile
("C:\Program Files\ArcGIS\DeveloperKit\Samples\Data\World.mdb", 0)
Dim ppFeatureClass as IFeatureClass
Set pFeatureClass = pFeatureWorkspace.OpenFeatureClass (“Streets”)
Sample: Setting Layer Symbology
'Create a renderer, a symbol and a color to display the building footprint layer
'Color - Light Orange
Dim pLtOrange As IRgbColor
Set pLtOrange = New RgbColor

pLtOrange.Red
L O R d = 246
pLtOrange.Green = 197
pLtOrange.Blue = 103

'symbol - light orange color and .5 width simple line symbol


Dim pLine As ISimpleLineSymbol
Set pLine = New SimpleLineSymbol

Dim pLinesym As ILineSymbol


Set pLinesym = pLine

pLinesym.Color = pLtOrange
pLinesym.Width = 0.5

'renderer
Dim pRenderer As ISimpleRenderer
S t pRenderer
Set R d =N
New Si
SimpleRenderer
l R d

Set pRenderer.Symbol = pLinesym


pRenderer.Label = "Streets"

'associate
associate the renderer with the feature layer
Dim pGeoFLayer As IGeoFeatureLayer
Set pGeoFLayer = pFeatureLayer

Set pGeoFLayer.Renderer = pRenderer


Setting
g Layer
y Symbology:
y gy Color

F
FeatureLayer
L F t
FeatureRenderer
R d

*
Symbol

Color IRgbColor
RgbColor

Dim pLtOrange as IRgbColor


Set pLtOrange = New RgbColor

pLtOrange.Red = 246
pLtOrange.Green = 197
pLtOrange.Blue = 103
Display Object Model Diagram
Display Object Model Diagram
Setting
g Layer
y Symbology:
y gy Symbol
y

F t
FeatureRenderer
R d Dim pLine as ISimpleLineSymbol
F
FeatureLayer
L
Set pLine = New SimpleLineSymbol

Dim pLinesym as ILineSymbol


* Set pLineSym = pLine

Symbol pLineSym.Color = pLtOrange


pLineSym.Width = 0.5

Color
ILineSymbol LineSymbol
Width

ISimpleLineSymbol SimpleLineSymbol
Setting Layer Symbology: FeatureRenderer

FeatureLayer

FeatureRenderer

UniqueValueRenderer DotDensityRender

Label
ISimpleRenderer SimpleRenderer
Symbol

Dim pRenderer as ISimpleRenderer


Set pRenderer = New SimpleRenderer

Set pRenderer.Symbol = pLinesym


pRenderer.Label = “Streets”
Setting Layer Symbology: Featurelayer
Application
class
Dim pGeoFLayer as IGeoFeatureLayer
Set pGeoFLayer = pFeatureLayer

Set pGeoFLayer.Renderer = pRenderer MxDocument


CoClass

*
Map
CoClass

*
IFeatureLayer Layer
FeatureLayer Abstract
IGeoFeatureLayer
Examples Using ArcObjects in
Python
Must use a .NET
NET go-between to give Python
access:
– http://pythonnet.sourceforge.net/readme.html
http://pythonnet sourceforge net/readme html

Once installed, all .NET assemblies (modules)


on system are available to Python

You might also like