Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ...
-
Upload
harold-barker -
Category
Documents
-
view
213 -
download
0
Transcript of Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ...
![Page 1: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/1.jpg)
Extending Python
Extending Python
Doing more than just interfacing with the geoprocessor
Free example utility for NZ Projections
Kim Ollivier
![Page 2: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/2.jpg)
Extending Python
Gluing it all togetherstrong -> weak
• Your own Python modules for utilities
• Other Python modules eg ODBC, XML
• Other COM interfaces eg Excel
• ArcGIS toolbox for forms interface
• ESRI Geoprocessor COM object
• VBA for ArcMap graphical interaction
![Page 3: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/3.jpg)
Extending Python
Helpers and Hints
• Good idea to use Python 2.4
• Python extensions do anything
• Early binding for COM (Makepy)
• Direct Python interfaces are best
• Samples toolbox in 9.1 are a start
• Maybe contribute your own?
![Page 4: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/4.jpg)
Extending Python
Python Modules
• import mymodule – that’s all there is to it!• Would contain your own pythonic functions
and classes, documentation, test code• Port your arc-only aml utilities• My example module is called corax (etools
has gone)• Do not depend on toolbox validation
![Page 5: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/5.jpg)
Extending Python
Creating an NZ Grid Index
1. Decide on the series scale2. Get the limits for the index: eg Prime name or
coordinates or interactive. For interactive input you have to use VBA, UITool, save results to a file.
3. Repeatedly call a function to get [name,extent]…for each sheet in the list
4. Output polys direct or Create a text file
5. Add as a layer or Create the index
![Page 6: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/6.jpg)
Extending Python
Step 1 Make a list of sheets
• Get limits [xmin,ymin,xmax,ymax]
• Find the sheets at lower left and top right• [name,bound] = corax.nztmsheet(scale,x,y)
• Create a [list] of [name,x1,y1,x2,y2]…
• Name has 4 parts: prime-scale_col.row
![Page 7: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/7.jpg)
Extending Python
Step 2 Get extents of sheets
• Use the module with custom functions
• import corax• [name,bounds] = corax.nztmsheet(scale,x,y)
• Add to [list] of [name,x1,y1,x2,y2]…
![Page 8: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/8.jpg)
Extending Python
Step 3 Plan A : Write a text file
(If only points, load as XY events, export)
For lines and polygons :Two files, sample tool to load generate-like file, add
attributes.txt, join tables, export. Watch for extra spaces!!!
• Easier to code, but risks ms-click RSI
• For a one-off this is convenient enough
![Page 9: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/9.jpg)
Extending Python
Step 3 Plan B : Create directly using gp…
• Delete the last featureclass!
• Define a projection object
• (NZTM or NZMG)
• Create a featureclass (shapefile)
• Add fields to hold sheet name parts
![Page 10: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/10.jpg)
Extending Python
Step 4 Load the sheet rectangles
• ESRI sample adds layer, but no names
• Own module adds names but no layer
• Note names have “/” replaced with “_” to work with MapBook
• Don’t forget the projection definition
• What is a projection definition?
![Page 11: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/11.jpg)
Extending Python
Review
• If you can create a text file, then use samples tool for a one-off project.
• No graphic interaction which means you will have to stay with ArcPlot amls.
• Projection definitions are obscure.
• Could not integrate it with MapBook.
• Could not call sample from another script.
![Page 12: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/12.jpg)
Extending Python
Enhancement Requests
• Upgrade standard install to Python 2.4+
• Fix documentation errors and omissions
• Performance, usability, functionality
• Add COM error messages
• More support for Win32 Python
• Interaction with a map
• An ArcMap COM interface
![Page 13: Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.](https://reader036.fdocuments.net/reader036/viewer/2022080223/56649e495503460f94b3cfd8/html5/thumbnails/13.jpg)
Extending Python
References
• The bible for COM interfaces and Python
• “Python Programming on Win32” - Mark Hammond, O’Reilly Press
• www.ollivier.co.nz/support