Exemplo n.º 1
0
        private static async Task CreateFeatureClass(string dataset, string connection, SpatialReference spatialRef, List <MapPoint> mapPointList, MapView mapview, bool isKML = false)
        {
            try
            {
                List <object> arguments = new List <object>();
                // store the results in the geodatabase
                arguments.Add(connection);
                // name of the feature class
                arguments.Add(dataset);
                // type of geometry
                arguments.Add("POINT");
                // no template
                arguments.Add("");
                // m values
                arguments.Add("DISABLED");
                // no z values
                arguments.Add("DISABLED");
                arguments.Add(spatialRef);

                var env = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);

                var valueArray = Geoprocessing.MakeValueArray(arguments.ToArray());

                IGPResult result = await Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management",
                                                                        valueArray,
                                                                        env,
                                                                        null,
                                                                        null,
                                                                        GPExecuteToolFlags.Default);

                await CreateFeatures(mapPointList);

                if (isKML)
                {
                    await KMLUtils.ConvertLayerToKML(connection, dataset, MapView.Active);

                    // Delete temporary Shapefile
                    string[] extensionNames     = { ".cpg", ".dbf", ".prj", ".shx", ".shp" };
                    string   datasetNoExtension = Path.GetFileNameWithoutExtension(dataset);
                    foreach (string extension in extensionNames)
                    {
                        string shapeFile = Path.Combine(connection, datasetNoExtension + extension);
                        File.Delete(shapeFile);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a feature class
        /// </summary>
        /// <param name="dataset">Name of the feature class to be created.</param>
        /// <param name="featureclassType">Type of feature class to be created. Options are:
        /// <list type="bullet">
        /// <item>POINT</item>
        /// <item>MULTIPOINT</item>
        /// <item>POLYLINE</item>
        /// <item>POLYGON</item></list></param>
        /// <param name="connection">connection path</param>
        /// <param name="spatialRef">SpatialReference</param>
        /// <param name="graphicsList">List of graphics</param>
        /// <param name="mapview">MapView object</param>
        /// <param name="isKML">Is this a kml output</param>
        /// <returns></returns>
        private static async Task CreateFeatureClass(string dataset, GeomType geomType, string connection, SpatialReference spatialRef, List <ProGraphic> graphicsList, MapView mapview, bool isKML = false)
        {
            try
            {
                string strGeomType = geomType == GeomType.PolyLine ? "POLYLINE" : "POLYGON";

                List <object> arguments = new List <object>();
                // store the results in the geodatabase
                arguments.Add(connection);
                // name of the feature class
                arguments.Add(dataset);
                // type of geometry
                arguments.Add(strGeomType);
                // no template
                arguments.Add("");
                // no z values
                arguments.Add("DISABLED");
                // no m values
                arguments.Add("DISABLED");
                arguments.Add(spatialRef);

                var       valueArray = Geoprocessing.MakeValueArray(arguments.ToArray());
                IGPResult result     = await Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management", valueArray);

                await CreateFeatures(graphicsList, dataset);

                if (isKML)
                {
                    await KMLUtils.ConvertLayerToKML(connection, dataset, MapView.Active);

                    // Delete temporary Shapefile
                    string[] extensionNames     = { ".cpg", ".dbf", ".prj", ".shx", ".shp" };
                    string   datasetNoExtension = Path.GetFileNameWithoutExtension(dataset);
                    foreach (string extension in extensionNames)
                    {
                        string shapeFile = Path.Combine(connection, datasetNoExtension + extension);
                        File.Delete(shapeFile);
                    }
                }
            }
            catch (Exception ex)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(ex.ToString());
            }
        }
Exemplo n.º 3
0
        private static async Task CreateFeatureClass(string dataset, string connection, SpatialReference spatialRef, List <CCProGraphic> mapPointList, MapView mapview, bool isKML = false)
        {
            try
            {
                List <object> arguments = new List <object>();
                // store the results in the geodatabase
                arguments.Add(connection);
                // name of the feature class
                arguments.Add(dataset);
                // type of geometry
                arguments.Add("POINT");
                // no template
                arguments.Add("");
                // m values
                arguments.Add("DISABLED");
                // no z values
                arguments.Add("DISABLED");
                arguments.Add(spatialRef);

                var env = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);

                var valueArray = Geoprocessing.MakeValueArray(arguments.ToArray());

                IGPResult result = await Geoprocessing.ExecuteToolAsync("CreateFeatureclass_management",
                                                                        valueArray,
                                                                        env,
                                                                        null,
                                                                        null,
                                                                        GPExecuteToolFlags.Default);

                // Add additional fields based on type of graphic
                string nameNoExtension = Path.GetFileNameWithoutExtension(dataset);
                string featureClass    = "";
                if (isKML)
                {
                    featureClass = connection + "/" + nameNoExtension + ".shp";
                }
                else
                {
                    featureClass = connection + "/" + dataset;
                }

                if (mapPointList.Count > 0 && mapPointList[0].Attributes != null && mapPointList[0].Attributes.Count > 0)
                {
                    foreach (var field in mapPointList[0].Attributes)
                    {
                        var lstDT = new List <DataType>();
                        foreach (var item in mapPointList.SelectMany(x => x.Attributes.Where(y => y.Key == field.Key).Select(y => y.Value)))
                        {
                            lstDT.Add(ParseString(item));
                        }
                        var dataType     = "TEXT";
                        var totalCount   = lstDT.Count;
                        var matchedCount = lstDT.Where(x => x == lstDT.FirstOrDefault()).Count();
                        if (totalCount == matchedCount)
                        {
                            if (lstDT.FirstOrDefault() == DataType.System_Boolean)
                            {
                                dataType = "TEXT";
                            }
                            else if (lstDT.FirstOrDefault() == DataType.System_DateTime)
                            {
                                dataType = "DATE";
                            }
                            else if (lstDT.FirstOrDefault() == DataType.System_Double)
                            {
                                dataType = "DOUBLE";
                            }
                            else if (lstDT.FirstOrDefault() == DataType.System_Int32)
                            {
                                dataType = "LONG";
                            }
                            else if (lstDT.FirstOrDefault() == DataType.System_Int64)
                            {
                                dataType = "DOUBLE";
                            }
                            else if (lstDT.FirstOrDefault() == DataType.System_String)
                            {
                                dataType = "TEXT";
                            }
                        }
                        else
                        {
                            dataType = "TEXT";
                        }
                        IGPResult addFieldResult = await Geoprocessing.ExecuteToolAsync("AddField_management", makeValueArray(featureClass, field.Key, dataType));
                    }
                }

                await CreateFeatures(mapPointList, dataset, isKML);

                if (isKML)
                {
                    await KMLUtils.ConvertLayerToKML(connection, dataset, MapView.Active);

                    // Delete temporary Shapefile
                    string[] extensionNames     = { ".cpg", ".dbf", ".prj", ".shx", ".shp" };
                    string   datasetNoExtension = Path.GetFileNameWithoutExtension(dataset);
                    foreach (string extension in extensionNames)
                    {
                        string shapeFile = Path.Combine(connection, datasetNoExtension + extension);
                        File.Delete(shapeFile);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }