ArcObjects: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
Line 28: Line 28:
The best tip from the above-mentioned EDN doc is to use the "code snippets" feature in Visual Studio to tap into the code provided with the developer kit.
The best tip from the above-mentioned EDN doc is to use the "code snippets" feature in Visual Studio to tap into the code provided with the developer kit.
They are a big help!
They are a big help!
== Finding fields ==
Here is a sample windows app that gets a list of fields from a layer.
I dislike the fact that it wants a Windows form handle, makes it hard to write a command line version!
<pre>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.DataSourcesFile;
namespace EngineWindowsApplication1
{
    public partial class Form1 : Form
    {
        private BindingSource bindingSource1 = new BindingSource();
        public Form1()
        {
            InitializeComponent();
            FeatureWorkspace fw = new FeatureWorkspace(@"D:\AGIProducts\IncidentViewIII\SampleData\IncidentView.mdb", this.Handle);
            List<IField> fields = fw.GetFields("Addresses");
        }
    }
    public class FeatureWorkspace
    {
        IFeatureWorkspace featureworkspace;
        /// <summary>
        ///
        /// </summary>
        /// <param name="workspace">Path to geodatabase</param>
        /// <param name="handle">Handle to parent form</param>
        public FeatureWorkspace(string workspace, IntPtr handle)
        {
            IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2)new AccessWorkspaceFactory();
            featureworkspace = workspaceFactory.OpenFromFile(workspace, handle.ToInt32()) as IFeatureWorkspace;
        }
        public List<IField> GetFields(string layer)
        {
            List<IField> list = new List<IField>();
            // Add support for other workspace types here??
            ITable foundITable = featureworkspace.OpenFeatureClass(layer) as ITable;
            IFields fields = foundITable.Fields;
            for (int fieldcount = 0; fieldcount < fields.FieldCount; fieldcount++)
            {
                IField f = fields.get_Field(fieldcount);
                list.Add(f);
            }
            return list;
        }
    }
}
</pre>


== ArcReader Project publisher ==
== ArcReader Project publisher ==

Revision as of 00:53, 19 December 2008

Some ArcObjects projects that I am developing.

Getting off the ground

Just knowing where to start with ArcObjects is a pain.

I am using Visual Studio 2008 + ArcGIS Desktop 9.3 and programming in C#.

The only book I can find is "Getting To Know ArcObjects" which spends the first 1/2 of its content telling you how to drop an icon into a toolbar. Then it spends the second 1/2 on Visual Basic examples. In other words, it's useless.

Developer samples are helpful

Next I spent some time exploring the sample code buried in my development system at C:/Program Files/ArcGIS/DeveloperKit/SamplesNET/Desktop There are lots of C# samples. Too many in fact - they are all sort of just dropped into the directory with long names like "NAServerGeocodeRouteWebService" and little documentation. Dear ESRI: a table of contents would have been SO USEFUL.

The samples are a good place to start but the EDN site was better.

EDN works for me

Finally I found a useful document on EDN, the ESRI Developer Network site.

The page that got me running was this one: (Great name, huh?) http://edndoc.esri.com/arcobjects/9.2/NET/01c01659-cdf8-4579-9c87-2b965e872d84.htm

I have successfully built a sample command and run it in the debugger. It just lists out the names of every layer in the current map in a Windows Form Listbox.

Code snippets are really handy

The best tip from the above-mentioned EDN doc is to use the "code snippets" feature in Visual Studio to tap into the code provided with the developer kit. They are a big help!

Finding fields

Here is a sample windows app that gets a list of fields from a layer. I dislike the fact that it wants a Windows form handle, makes it hard to write a command line version!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.DataSourcesFile;

namespace EngineWindowsApplication1
{
    public partial class Form1 : Form
    {
        private BindingSource bindingSource1 = new BindingSource();

        public Form1()
        {
            InitializeComponent();

            FeatureWorkspace fw = new FeatureWorkspace(@"D:\AGIProducts\IncidentViewIII\SampleData\IncidentView.mdb", this.Handle);
            List<IField> fields = fw.GetFields("Addresses");
        }
    }

    public class FeatureWorkspace
    {
        IFeatureWorkspace featureworkspace;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="workspace">Path to geodatabase</param>
        /// <param name="handle">Handle to parent form</param>
        public FeatureWorkspace(string workspace, IntPtr handle)
        {
            IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2)new AccessWorkspaceFactory();
            featureworkspace = workspaceFactory.OpenFromFile(workspace, handle.ToInt32()) as IFeatureWorkspace;
        }

        public List<IField> GetFields(string layer)
        {
            List<IField> list = new List<IField>();

            // Add support for other workspace types here??
            ITable foundITable = featureworkspace.OpenFeatureClass(layer) as ITable;
            IFields fields = foundITable.Fields;
            for (int fieldcount = 0; fieldcount < fields.FieldCount; fieldcount++)
            {
                IField f = fields.get_Field(fieldcount);
                list.Add(f);
            }

            return list;
        }
    }
}

ArcReader Project publisher

As a tool within ArcMap

Read the currently open MXD file and publish the map as a PMF file. Then generate a manifest for a map containing a listing of all files required to reproduce it. This file should be usable by an external Python script to copy the files to a distributable cdrom as an ArcReader project.

If there are any unmanaged raster catalogs then include the list of rasters.

Report any problems such as layers that will not be reachable (outside the current directory tree.)

It might be interesting to embed the Python in the output so the manifest is runnable.

As a command (runnable from Python scripts)

http://edndoc.esri.com/arcobjects/9.2/NET/0D300185-2025-4FA9-A4FF-FEBD0FE4C298.htm


Mapbook

The client wants to be able to export a series of maps to PDF's using a column of data from a table on each map; if you change the extent of the map and click print it creates a new series.

Starting point

DS_mapbook from the developer samples

http://edndoc.esri.com/arcobjects/9.2/CPP_VB6_VBA_VCPP_Doc/COM_Samples_Docs/Cartography/Map_Production/DSMapBook/Visual_Basic/DSMapBookExt.cls.htm

Related pages

Windows programming