Programming for Geographical Information Analysis: Advanced Skills Lecture 4: Arc Data Editing Addin Programming Dr Andy Evans.

Slides:



Advertisements
Similar presentations
Oct Ron McFadyen1 Singleton To guarantee that there is at most one instance of a class we can apply the singleton pattern. Singleton Static.
Advertisements

Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Lecture 18 Review the difference between abstract classes and interfaces The Cloneable interface Shallow and deep copies The ActionListener interface,
(c) University of Washington03-1 CSC 143 Java Inheritance Reading: Ch. 10.
Arc: Programming Options Dr Andy Evans. Programming ArcGIS ArcGIS: Most popular commercial GIS. Out of the box functionality good, but occasionally: You.
Overview Dennis L. Johnson What is GIS? Geographic Information System Geographic implies of or pertaining to the surface of the earth Information implies.
Working with cursors in Python GISDE Python Workshop Qiao Li.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Computer Science II 810:062 Section 01 Session 2 - Objects and Responsibilities.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
Nachos Phase 1 Code -Hints and Comments
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Martin Dodge Practical 2, 24th March 2004, pm Social Science Research Methodologies.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Attributes in ArcGIS. ArcGIS Attributes FID – ESRI’s internal identifier Shape – Actual spatial data.
Programming for Geographical Information Analysis: Advanced Skills Lecture 1: Introduction Programming Arc Dr Andy Evans.
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Collecting Things Together - Lists 1. We’ve seen that Python can store things in memory and retrieve, using names. Sometime we want to store a bunch of.
Arc: Accessing the Framework Dr Andy Evans. Code The code that goes in the addIn is then code to work with the ArcObjects framework. Ask App for Document.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Linked List. Background Arrays has certain disadvantages as data storage structures. ▫In an unordered array, searching is slow ▫In an ordered array, insertion.
10-Nov-15 Java Object Oriented Programming What is it?
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
O FFICE M ANAGEMENT T OOL - II B BA -V I TH. Abdus Salam2 Week-7 Introduction to Query Introduction to Query Querying from Multiple Tables Querying from.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
UID – Event Handling and Listeners Boriana Koleva
Object Oriented Programming.  Interface  Event Handling.
The Singleton Pattern SE-2811 Dr. Mark L. Hornick 1.
Session 13 Pinball Game Construction Kit (Version 3):
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Arc: Events Dr Andy Evans. Event communication Arc is, plainly, set up for Event Based Programming. You can register listeners with most GUI components.
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
Lecture 7 February 24, Javadoc version and author Tags These go in the comments before named classes. –Put your SS# on a separate line from the.
Creating a GUI Class An example of class design using inheritance and interfaces.
Lecture 8: Advanced OOP Part 2. Overview Review of Subtypes Interfaces Packages Sorting.
Unit 3: Text, Fields & Tables DT2510: Advanced CAD Methods.
Written by: Dr. JJ Shepherd
Programming for Geographical Information Analysis: Advanced Skills Lecture 3: Arc Data Framework Dr Andy Evans.
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Never Ends.
SourceAnatomy1 Java Source Anatomy Barb Ericson Georgia Institute of Technology July 2008.
Arc: Communications between Addins Dr Andy Evans.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Access Queries and Forms. Adding a New Field  To insert a field after you have saved your table, open Access, and open the table  It is easier to add.
CSC 205 Programming II Lecture 7 AWT – Event Handling & Layout.
Arc: Editing Data Dr Andy Evans. Editing Data Putting Arc into an editing session. Adding a new field/column. Changing a value.
Chapter 9: Continuing Classes By Matt Hirsch. Table Of Contents 1.Static Fields and Methods 2.Inheritance I. Recycle Code with Inheritance II. Overriding.
1 DemoBasic_v3, DemoBasic_v4 JButton JLabel. 2 Registering an ActionListener Register by invoking the following from within constructor DemoBasicFrame.
“Form Ever Follows Function” Louis Henri Sullivan
The Singleton Pattern SE-2811 Dr. Mark L. Hornick.
Ellen Walker Hiram College
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Arc: Getting Layers Dr Andy Evans.
Fall 2018 CISC124 2/24/2019 CISC124 Quiz 1 marking is complete. Quiz average was about 40/60 or 67%. TAs are still grading assn 1. Assn 2 due this Friday,
Java Programming Language
Programming with inheritance Based on slides by Alyssa Harding
Expanding the PinBallGame
CMPE212 – Reminders Assignment 2 due next Friday.
Presentation transcript:

Programming for Geographical Information Analysis: Advanced Skills Lecture 4: Arc Data Editing Addin Programming Dr Andy Evans

Editing Communications between addins Event-based communication

Editing Data Putting Arc into an editing session. Adding a new field/column. Changing a value.

Editing sessions Although some cursors can be used directly in some circumstances to edit data, it is usually worth opening an editing session programmatically. To do this, we need the workspace.

Workspaces Open a workspace (casts/try-catches removed throughout): IWorkspaceFactory wsF = new DataSourcesGDB.FileGDBWorkspaceFactoryClass(); IWorkspace ws = wsF.OpenFromFile(geodatabasePath, 0); Find current (note difficulties with proxy classes): IFeatureDatasetProxy ifdp = iGeoFeaturelayer.getFeatureClass(). getFeatureDataset(); IWorkspaceProxy iwp = ifdp.getWorkspace(); IWorkspaceFactory wf = iwp.getWorkspaceFactory(); IWorkspace ws = wf.openFromFile (iwp.getPathName(), 0);

Workspaces Make one: IWorkspaceName wsn = workspaceFactory.create ("c:\temp","tempGDB",null,0); IName name = wsn; IWorkspace iWorkspace = name.open(); Once we have an iWorkspace, cast to IWorkspaceEdit : IWorkspaceEdit iwe = (IWorkspaceEdit) iWorkspace;

Editing sessions iwe.startEditing(true); Opens a session iwe.startEditOperation(); Starts a group of edits iwe.stopEditOperation(); Ends a group of edits iwe.stopEditing(true); Closes session You can do multiple edit operations within a session. They are only needed for operations on features that are part of a Topology or Geometric Network, but are good practice.

Editing Data Putting Arc into an editing session. Adding a new field/column. Changing a field. Adding a field: First make a new Field. Then set it up. Then add it.

Making a field/column IField field = new Field(); Note rare making of a new object Note that the IField label is used to make the object, but we need an IFieldEdit view on it to edit things like the name. IFieldEdit fieldEdit = field; fieldEdit.setName("Population"); fieldEdit.setType (esriFieldType.esriFieldTypeInteger); bjects/com/esri/arcgis/geodatabase/esriFieldType.html

Adding a Field Get a FeatureClass from the IFeatureLayer IFeatureClass fClass = featurelayer.getFeatureClass(); Add the field to the existing fields. IFields fields = fClass.getFields(); fClass.addField(field); Might want to check the field doesn’t exist with fClass.findField("columnName") first (returns -1 when none found).

Editing data Use a cursor to find the features to edit. Get a feature. Edit its value for a specific column. Tell the cursor to store the changes back into the original database. Release the cursor resources.

Editing Data Data is set using a FeatureCursor to get the feature: IFeatureCursor fCursor = null; Three types: fCursor = fClass.IFeatureClass_update(null,false) fCursor = fClass.IFeatureClass_insert(false) fCursor = fClass.search(null, false) IFeature feature = pFCursor.nextFeature(); Cursors also have methods for adding and deleting rows.

Cursors “Recycling” cursors can reuse resources allocated to a row. We don’t want this, as these temporarily store changes we want. Therefore, we need to use non-recycling cursors: fCursor = fClass.IFeatureClass_insert(false) It also means we must be extra-careful to release resources at the end of editing. To do this we use the ESRI Cleaner class after we’ve finished with the cursor/editing: Cleaner.release(cursor);

Change the value feature.setValue(columnIndex, Object); To change a spatial location you set the shape: IPoint point = new Point(); point.setX( ); point.setY( ); feature.setValue(shapeColumnIndex,point); Or, better: feature.setShapeByRef(point);

Shapes Implement com.esri.arcgis.geometry IGeometry. Include: Line / Polyline Polygon / MultiPatch Point / Multipoint

Fix the value For an Update/Insert Cursor: fCursor.updateFeature(feature); For a Search Cursor: feature.store(); Note the different objects the methods are in. Note also that because IFeatures actually inherit from IRow, similar things can be done to table rows. See IFeatureClass docs for info. Note that under some circumstances editing using Update and Insert cursors is possible outside of an editing session, but isn’t advised.

Summary: Editing Open an edit session. Open an edit operation. Get a cursor of features to edit. Edit the features. Tell the cursor to fix the changes. Free up cursor resources. Close the edit operation. Close the edit session.

Editing Communications between addins Event-based communication

Communication between addins There are various ways of getting hold of other addins, built into the system. However, these are addin specific. Eg. IDockableWindowManager dwm = new IDockableWindowManagerProxy(app); UID uid = new UID(); uid.setValue(uk.ac.leeds.geog.geog5790.OurWindow); IDockableWindow tableWin = dwm.getDockableWindow(uid);

More generic method Every addin is held as a static variable within ArcGIS. That is, there is only one copy of it. We could get hold of this, if only we had a method to do so. To understand how we can build such a method, we need to understand Singletons.

Singletons Singletons are both a class and a static variable. Because they are static, there is only ever one copy of them. However, they are not troubled by the problems of containing static code, as they are also perfectly normal classes. How is this amazing trick done?

Simple Singleton class Singleton { static Singleton single = null; static Singleton getInstance() { if (single = null) { single = new Singleton(); } return single; } // other methods. }

Use Note that as getInstance is static, we can call it using the class: Singleton s = Singleton.getInstance(); But it returns to us the class as an object we can use: s.whateverMethodInSingletonWeWant(); But the object is static, so if we call getInstance somewhere else, we get exactly the same object, including any changes we’ve made to it in other code.

Simple Singleton However, we want to make sure no one does this: Singleton s = new Singleton(); Let alone this: s.single = someOtherSingleton; So the constructor (unusually) and the variable are set to private, so no one outside the Singleton class can use them. We must include the empty (or otherwise) constructor, to force it to be private.

Simple Singleton class Singleton { private static Singleton single = null; private Singleton() {} public static Singleton getInstance() { if (single = null) { single = new Singleton(); } return single; } // other methods. } Here the constructor is called from within the class, so it works fine, even though the constructor is private.

Uses Wherever you need one specific version of something, e.g. for storage, that everything else can get at. Wherever you need to communicate between different code running on the JVM. e.g. between Applets running in different webpage frames. Note, however, that which can see it will depend on how the JVM classloader is activated.

AddIns As addins are static variables in Arc, if we build them to be Singletons, we can use the Class’ getInstance() method to get hold of them in other code. Note, however, that as Arc is making the static variable, from the class, we shouldn’t. We don’t need to call the constructor. Arc, however, does need access to it, so it must be public.

AddIn Singleton class AddIn{ private static AddIn addIn = null; public AddIn() { addIn = this; // Grab our static } // variable as Arc makes it. public static AddIn getInstance() { return addIn; } // other methods. } Note the use of “this” to get the object we are currently inside.

Use Again, then, we can: AddIn a = AddIn.getInstance(); a.whateverMethodInSingletonWeWant();

Editing Communications between addins Event-based communication

Event communication Arc is, plainly, set up for Event Based Programming. You can register listeners with most GUI components and many non-GUI components (for example, for data changes).

Useful MxDocument: addIDocumentEventsDispListener Map : addIActiveViewEventsListener Map : addIMapEventsListener FeatureLayer : addIFeatureLayerSelectionEventsListener TIN/Raster/Feature/NetworkLayer : addILayerEventsListener

Adapters We saw that java.awt supplies Adapter classes. These are classes that match an interface, but with nothing in the methods. You can extend the class, and then override the methods you want to, without having to do all of them. However, we saw them in anonymous inner classes.

Shutting a Window myFrame.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } ); Arc has a number of Adapters you can use like this for key jobs. Check what classes implement the Listeners in the docs.

New document ((MxDocument)mxDoc).addIDocumentEventsListener( new public void newDocument (IDocumentEventsNewDocumentEvent e){ // Do something when new document. } ); NB: This needs some additional try-catch blocks.

Closing document ((MxDocument)mxDoc).addIDocumentEventsListener( new public boolean beforeCloseDocument (IDocumentEventsBeforeCloseDocumentEvent e){ // Do something when closing document. } );

Dirty, dirty, document If you close a document but have made programmatic changes to it, this can be lost unless the user saves the map. To ask the user if they want to, set the document as “dirty”, e.g. at the end of the beforeCloseDocument method. IDocumentDirty doc = (IDocumentDirty)app.getDocument(); doc.setDirty(); They will then be asked before final closing.

DIY Of course, you can make your own listeners. Just add a new class to your project/package.

Next Lecture Java and Databases Practical Inter-addin communication.