Friday, August 28, 2009

Important Links to Bookmark for Geoprocessing Tool Development

Here are some important links that I think any developer should have in there back pocket, if they are going to use, publish, or create GP tools.

This is about Feature and Record sets.

This is about the input and output types that are supported when publishing services.

Monday, August 24, 2009

Serialize Anything!

When you start with threading, especially in AGX 900 sdk, you are going to need to translate your objects into strings. To do this, just use the two functions below.



private byte[] getByteArrayWithObject( Object o )
{
/*

1) Create a new MemoryStream class with the CanWrite property set to true
(should be by default, using the default constructor).

2) Create a new instance of the BinaryFormatter class.

3) Pass the MemoryStream instance and your object to be serialized to the
Serialize method of the BinaryFormatter class.

4) Call the ToArray method on the MemoryStream class to get a byte array
with the serialized data.

*/


MemoryStream ms = new MemoryStream();
BinaryFormatter bf1 = new BinaryFormatter();
bf1.Serialize( ms, o );
return ms.ToArray();
}
private object getObjectWithByteArray( byte[] theByteArray )
{
MemoryStream ms = new MemoryStream( theByteArray );
BinaryFormatter bf1 = new BinaryFormatter();
ms.Position = 0;

return bf1.Deserialize( ms );
}



You can then translate your byte[] into a string using the built in Convert with .Net. Now you have values passed into the AGX BackGroundThread.

Enjoy

Monday, August 17, 2009

AGX 900 is released

ESRI has released AGX 900 with new ribbon technology. I am quite excited about this release except for one issue, which I'll get to later.

The AGX 900 SDK has been revamped. It is shiny and new, and now uses a flavor of background workers instead of the task and taskui classes. The use of background workers makes programming tasks very easy compared to the old way. Now here is the rub, though I love this product, it lack the capabilities to use published Geoprocessing tasks out of the box.

During beta testing of this product, I did not see many comments on if this point. I'm interested to see if AGX 900 will have an expansion pack to perform this.

Wednesday, July 15, 2009

List of All GeoProcessing Data Types

From the resource center of ESRI, comes a pdf that contains all the different type of GeoProcessing data types with correlating ArcObjects in it. This is very helpful, and any .NET GP developer should have it printed out and right next to them.

Enjoy

Thursday, July 9, 2009

2 GP Functions That Make Life Easier

Here are two functions that make life easier for custom GP development. The find parameter value by the parameter name, return parameter type IGPValue. The second method is get parameter by name, which returns IGPParameter3. Parameter value by name allows you to retrieve

Get Parameter By Name

public IGPParameter3 GetParameterByName( IArray paramvalues, string name )
{
IGPParameter3 gpParameter;
for (int i = 0; i < paramvalues.Count; i++)
{
gpParameter = (IGPParameter3)paramvalues.get_Element( i );
if (gpParameter.Name.Equals( name, StringComparison.OrdinalIgnoreCase ))
return gpParameter;
}
return null;
}


Get Parameter Value By Name

public IGPValue GetParameterValueByName( IArray paramvalues, string name )
{
IGPUtilities2 gpUtils = new GPUtilitiesClass();
IGPParameter3 gpParameter;

for (int i = 0; i < paramvalues.Count; i++)
{
gpParameter = (IGPParameter3)paramvalues.get_Element( i );
if (gpParameter.Name.ToUpper() == name.ToUpper())
return gpUtils.UnpackGPValue( gpParameter );
}
return null;
}

Wednesday, July 1, 2009

Creating a Feature Set via C#

A very powerful model builder feature is the create variable option. This will allow users to create almost any type of user input desire. The feature set variable is a very helpful variable when a user needs to interact with the map or recordset. The feature set allows users to draw points, polylines, or polygons on the fly. To do this in C#, you need to use the IGPRecordSetLayerClass(), but the process of making the interactive part work isn't that straight forward.

To get the interactive part of the Feature set to work, you must define the Schema with either a layer file or feature class in model builder. When you take a look at the ArcObject description of a parameter, you notice a pointer called Schema, but this isn't where you define the template data for a GPFeatureRecordSet, you define it in Value().


inputParameter.DataType = new GPFeatureRecordSetLayerTypeClass();
//
// create the GP Feature Recordset Layer Object
// from template data
//
IFeatureClass FC = (IFeatureClass)m_GPUtilities.OpenDatasetFromLocation( @"