public IGPMessages Validate(IArray paramValues, bool updateValues, IGPEnvironmentManager envMgr) { if (m_util == null) // delay constructor activities.... they segfault arcmap { m_util = new GPUtilitiesClass(); m_outp_schema = new AoTable( AoField.Integer("left_fid"), AoField.Integer("right_fid") ); } IGPMessages ms = m_util.InternalValidate(ParameterInfo, paramValues, updateValues, true, envMgr); bool passed = AoGPParameter.ValidateAll(m_parms, paramValues, ms); IGPMessage m = (IGPMessage)ms; if (!passed || m.IsError()) { ms.AddError(2, "An error here."); return(ms); } // TODO: Set up the output schema. IGPParameter outparam = paramValues.get_Element(3) as IGPParameter; IGPFeatureLayer fl = outparam.Value as IGPFeatureLayer; if (fl == null) { fl = new GPFeatureLayerClass(); } fl.DEFeatureClass = new DEFeatureClassClass(); (fl.DEFeatureClass as IDETable).Fields = m_outp_schema.Fields; // Set up its catalog path / name.. // IDataElement de = (fc as IDataElement; // if ( (old_val == null || old_val.DEFeatureClass == null) && src_path != null && src_path.DEFeatureClass != null) { // //src_path = m_util.UnpackGPValue(src_path) as IGPFeatureLayer; // IDataElement srcde = src_path.DEFeatureClass as IDataElement; // lazy cut-n-paste shortcut // de.CatalogPath = srcde.GetPath() + "\\" + srcde.GetBaseName() + "_bndgen." + srcde.GetExtension();// old_val.CatalogPath; // de.Children = srcde.Children; // de.ChildrenExpanded = srcde.ChildrenExpanded; // de.MetadataRetrieved = srcde.MetadataRetrieved; // //de.Name = old_val.Name + "bndgen"; // de.Type = srcde.Type; // } m_util.PackGPValue(fl as IGPValue, outparam); return(ms); }
public void Execute(IArray paramvalues, ITrackCancel trackcancel, IGPEnvironmentManager envMgr, IGPMessages messages) { // Re-validate. IGPMessages ms = m_util.InternalValidate(ParameterInfo, paramvalues, false, false, envMgr); messages.AddMessage("MWSW Boundary Generator, v. 0.0"); if (((IGPMessage)(ms)).IsError()) { messages.AddMessages(ms); return; } if (!AoGPParameter.ValidateAll(m_parms, paramvalues, messages)) { return; } try { IGPValue inlyr = m_util.UnpackGPValue((paramvalues.get_Element(0) as IGPParameter).Value); IGPDouble ang_tol = m_util.UnpackGPValue((paramvalues.get_Element(1) as IGPParameter).Value) as IGPDouble; IGPDouble dist_tol = m_util.UnpackGPValue((paramvalues.get_Element(2) as IGPParameter).Value) as IGPDouble; IGPValue outlyr = m_util.UnpackGPValue((paramvalues.get_Element(3) as IGPParameter).Value); // DumpIt("In layer",inlyr,messages); // DumpIt("Out layer",outlyr,typeof(IGPValue),messages); IFeatureClass inputfc; IQueryFilter inputqf; m_util.DecodeFeatureLayer(inlyr, out inputfc, out inputqf); // DumpIt("In Featureclass",inputfc,typeof(IFeatureClass),messages); // DumpIt("In QF",inputqf,typeof(IQueryFilter),messages); messages.AddMessage("In angle tolerance: " + ang_tol.Value); messages.AddMessage("In distance tolerance: " + dist_tol.Value); messages.AddMessage("Input featureclass: " + inputfc.AliasName); messages.AddMessage("Output path: " + outlyr.GetAsText()); trackcancel.Progressor.Show(); trackcancel.Progressor.Message = "Processing..."; string outp_txt = outlyr.GetAsText(); AoFeatureClassName fcname = new AoFeatureClassName(outp_txt); ISpatialReference spref = AoTable.From(inputfc)[inputfc.ShapeFieldName].Field.GeometryDef.SpatialReference; string shapename = fcname.ShapeFieldName != "" ? fcname.ShapeFieldName : "Shape"; m_outp_schema[shapename] = AoField.Shape(shapename, esriGeometryType.esriGeometryPolyline, spref); // TODO: shapefiles seem to get an FID automatically, // while geodb needs an 'OBJECTID', // who knows about other workspace types? // Is there a way to figure this out w/o looking at the type? IFeatureClass outputfc = fcname.Workspace.CreateFeatureClass(fcname.Basename, m_outp_schema.Fields, null, null, esriFeatureType.esriFTSimple, shapename, ""); IStepProgressor progressor = trackcancel.Progressor as IStepProgressor; progressor.MaxRange = 200; BGenImp implementation = new BGenImp(spref, ang_tol.Value, dist_tol.Value); implementation.Run(inputfc, outputfc, delegate(double howfar) { progressor.Position = (int)(200.0 * howfar); }); messages.AddMessage("Finished, worked through " + implementation.TotalSegments + " line segments total."); return; } catch (Exception e) { while (e != null) { messages.AddError(1, "Exception: " + e.Message); e = e.InnerException; } } }