コード例 #1
0
        private void GetFeaturesAndAddAttachment()
        {
            // TODO
            // open the file geodatabase c:\ProSDKWorkshop\data\generic.gdb
            using (Geodatabase geodatabase = new Geodatabase(@"c:\ProSDKWorkshop\data\generic.gdb"))
            {
                using (FeatureClass pointFeatureClass = geodatabase.OpenDataset <FeatureClass>("SamplePoints"))
                {
                    using (RowCursor features = pointFeatureClass.Search())
                    {
                        while (features.MoveNext())
                        {
                            Feature currentFeature = features.Current as Feature;
                            currentFeature.AddAttachment(new Attachment("SamplePicture", "image/png",
                                                                        CreateMemoryStreamFromContentsOf(@"C:\ProSDKWorkshop\data\redlands.png")));
                        }
                    }
                }
            }

            // TODO
            // open the SamplePoints feature class

            // TODO
            // retrieve all features by searching the feature class

            // TODO
            // for each feature add the attachment

            // TODO
            // add the sample picture as an attachment

            // add the feature class as a layer to the active map
            LayerFactory.CreateFeatureLayer(new Uri(@"c:\ProSDKWorkshop\data\generic.gdb\SamplePoints"), MapView.Active.Map);
        }
コード例 #2
0
        private void GetFeaturesAndAddAttachment()
        {
            // open the geodatabase
            using (var geodatabase = new Geodatabase(@"c:\ProSDKWorkshop\data\generic.gdb"))
            {
                // open the SamplePoints feature class
                var pointFeatureClass = geodatabase.OpenDataset <FeatureClass>("SamplePoints");

                // retrieve all features from the feature class
                using (var rowCursor = pointFeatureClass.Search())
                {
                    while (rowCursor.MoveNext())
                    {
                        // for each feature
                        using (var currentFeature = rowCursor.Current as Feature)
                        {
                            // add the sample picture as an attachment
                            currentFeature.AddAttachment(new Attachment("SamplePicture", "image/png",
                                                                        CreateMemoryStreamFromContentsOf(@"c:\ProSDKWorkshop\data\redlands.png")));
                        }
                    }
                }
            }

            // add the feature class as a layer to the active map
            LayerFactory.CreateFeatureLayer(new Uri(@"c:\ProSDKWorkshop\data\generic.gdb\SamplePoints"), MapView.Active.Map);
        }
コード例 #3
0
        public void SaveResults()
        {
            // Check for a feature layer connected to a feature class with the right name, type, etc.
            QueuedTask.Run(async() => {
                ProgressDialog pd;
                Geodatabase fgdb = null;
                try {
                    string resultFcName = Properties.Settings.Default.ResultFeatureClassName;
                    List <FeatureLayer> featureLayers = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>().ToList();
                    FeatureLayer flResults            = featureLayers.Find(lyr => lyr.GetFeatureClass().GetName() == resultFcName);
                    FeatureClass fc = null;

                    if (flResults == null)
                    {
                        // Look for a FC to connect it to
                        string defFgdbPath = Project.Current.DefaultGeodatabasePath;
                        try {
                            fgdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(defFgdbPath)));
                            IReadOnlyList <string> gpParams;
                            try {
                                fc = fgdb.OpenDataset <FeatureClass>(resultFcName);
                            } catch (GeodatabaseException) {
                                // Create results feature class
                                pd = new ProgressDialog("Creating results feature class..."); pd.Show();
                                string sTemplatePath = Path.Combine(
                                    System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                    @"Resources\Template.gdb\MilesPerDollar_template");
                                gpParams = Geoprocessing.MakeValueArray(
                                    defFgdbPath, resultFcName, "POLYGON", sTemplatePath, null, null,
                                    SpatialReferenceBuilder.CreateSpatialReference(Properties.Settings.Default.ResultFeatureClassSRWkid));
                                IGPResult resCreateFC = await Geoprocessing.ExecuteToolAsync("management.CreateFeatureclass", gpParams, flags: GPExecuteToolFlags.None);
                                if (resCreateFC.IsFailed)
                                {
                                    pd.Hide();
                                    List <string> errMsgs = resCreateFC.ErrorMessages.Select(errMsg => errMsg.Text).ToList();
                                    string sErrMsgs       = String.Join("\n", errMsgs);
                                    throw new Exception("Error creating results feature class:" + sErrMsgs);
                                }
                                pd.Hide();
                                fc = fgdb.OpenDataset <FeatureClass>(resultFcName);
                            }
                        } catch (Exception e) {
                            throw new Exception("Error opening or creating feature class", e);
                        }
                        flResults = LayerFactory.CreateFeatureLayer(fc, MapView.Active.Map, 0, "Miles Per Dollar Analysis Results");
                    }
                    else
                    {
                        fc = flResults.GetFeatureClass();
                    }

                    flResults?.SetVisibility(false);

                    //pd = new ProgressDialog("Creating result schema..."); pd.Show();
                    //try {
                    //    await AddResultFcFields(fc);
                    //} catch (Exception e) {
                    //    throw new Exception("Error adding fields to result feature class", e);
                    //} finally { pd.Hide();  }

                    // By default, the GDB is added to the map via a new feature layer
                    pd = new ProgressDialog("Creating result features..."); pd.Show();
                    try {
                        await AddResultFeatures(fc);
                    } catch (Exception e) {
                        throw new Exception("Error creating result features", e);
                    } finally { pd.Hide(); }

                    // If we got here, it was sucessful; we can discard the graphic overlays
                    Results.ClearResults();

                    flResults?.SetVisibility(true);
                } catch (Exception e) {
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    string sMsg = e.Message + ":\n" + e.InnerException.Message;
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(sMsg);
                } finally {
                    fgdb?.Dispose();
                }
            });
        }
コード例 #4
0
ファイル: Helpers.cs プロジェクト: xiaoai-li/data-assistant
 internal static FeatureLayer CreateFeatureLayer(Uri uri, Map map)
 {
     return(LayerFactory.CreateFeatureLayer(uri, MapView.Active.Map));
 }