예제 #1
0
        private void BuildSpatialIndex(IGPValue gpFeatureClass, Geoprocessor.Geoprocessor geoProcessor, IGPUtilities gpUtil,
            ITrackCancel trackCancel, IGPMessages message)
        {
            if ((gpFeatureClass == null) || (geoProcessor == null) || (gpUtil == null))
                return;

            // Check if the feature class supports spatial index grids
            IFeatureClass fc = gpUtil.OpenDataset(gpFeatureClass) as IFeatureClass;
            if (fc == null)
                return;

            int idxShapeField = fc.FindField(fc.ShapeFieldName);
            if (idxShapeField >= 0)
            {
                IField shapeField = fc.Fields.get_Field(idxShapeField);
                if (shapeField.GeometryDef.GridCount > 0)
                {
                    if (shapeField.GeometryDef.get_GridSize(0) == -2.0)
                        return;
                }
            }

            // Create the new spatial index grid
            bool storedOriginal = geoProcessor.AddOutputsToMap;

            try
            {
                geoProcessor.AddOutputsToMap = false;

                DataManagementTools.CalculateDefaultGridIndex calculateDefaultGridIndex =
                    new DataManagementTools.CalculateDefaultGridIndex(gpFeatureClass);
                IGeoProcessorResult2 gpResults2 =
                    geoProcessor.Execute(calculateDefaultGridIndex, trackCancel) as IGeoProcessorResult2;
                message.AddMessages(gpResults2.GetResultMessages());

                if (gpResults2 != null)
                {
                    DataManagementTools.RemoveSpatialIndex removeSpatialIndex =
                        new DataManagementTools.RemoveSpatialIndex(gpFeatureClass.GetAsText());
                    removeSpatialIndex.out_feature_class = gpFeatureClass.GetAsText();
                    gpResults2 = geoProcessor.Execute(removeSpatialIndex, trackCancel) as IGeoProcessorResult2;
                    message.AddMessages(gpResults2.GetResultMessages());

                    DataManagementTools.AddSpatialIndex addSpatialIndex =
                        new DataManagementTools.AddSpatialIndex(gpFeatureClass.GetAsText());
                    addSpatialIndex.out_feature_class = gpFeatureClass.GetAsText();

                    addSpatialIndex.spatial_grid_1 = calculateDefaultGridIndex.grid_index1;
                    addSpatialIndex.spatial_grid_2 = calculateDefaultGridIndex.grid_index2;
                    addSpatialIndex.spatial_grid_3 = calculateDefaultGridIndex.grid_index3;

                    gpResults2 = geoProcessor.Execute(addSpatialIndex, trackCancel) as IGeoProcessorResult2;
                    message.AddMessages(gpResults2.GetResultMessages());
                }
            }
            catch (Exception ex)
            {
                message.AddWarning(ex.Message);
            }
            finally
            {
                geoProcessor.AddOutputsToMap = storedOriginal;
            }
        }
예제 #2
0
        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;
                }
            }
        }