ArcObjects

From Wildsong
Revision as of 17:15, 25 January 2018 by Brian Wilson (talk | contribs)
Jump to navigationJump to search

Some ArcObjects projects that I am developing.

Getting off the ground

I started this page in 2008 and this statement is still just as true: "Just knowing where to start with ArcObjects is a pain."

What's changed since then? There is now a "Community" (free) version of Visual Studio 2017. This is the real deal not just an editor.

This is also still true: there is a dearth of written materials on ArcObjects or ArcGIS+C# programming. In 2008 I said: "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." There are several other (outdated) books now, all written for Visual Basic and therefore useless.

This one holds promise, I am ordering a copy: "Beginning ArcGIS for Desktop Development using .NET"

Look on Youtube for IGeometry. I have a hard time sitting still for videos but many people don't, apparently.

It's just not a hot topic.

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.

This is about creating an ArcObjects command, not a standalone program. (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 the fields in a layer

Finding fields using a workspace

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;
        }
    }
}

Finding fields using a map object

add code here...

ArcReader Project publisher

This is a project idea I had a while ago...

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