Example #1
0
        protected override void RunCore(Dictionary <string, string> parameters)
        {
            bool parametersValid = TryParseParameters(parameters);

            try
            {
                if (parametersValid)
                {
                    var sourceFeatures = GetSourceFeatures();
                    var resultFeatures = MergeFeatures(sourceFeatures, columns);

                    ShpFileExporter shpFileExporter = new ShpFileExporter();
                    FileExportInfo  fileInfor       = new FileExportInfo(resultFeatures, columns, outputPath, Wkt);
                    shpFileExporter.ExportToFile(fileInfor);
                }
            }
            catch (Exception ex)
            {
                var args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Error);
                args.ExceptionInfo = new LongRunningTaskExceptionInfo(ex.Source, ex.StackTrace);
                OnUpdatingProgress(args);
            }
            finally
            {
                var args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating);
                args.Message = "Finished";
                OnUpdatingProgress(args);
            }
        }
        private void ExportToFile(string fileName, IEnumerable <Feature> features, IEnumerable <FeatureSourceColumn> columns)
        {
            ShpFileExporter exporter = new ShpFileExporter();
            var             results  = features.Where(tmpFeature => tmpFeature.GetBoundingBox().UpperLeftPoint.X > -180 && tmpFeature.GetBoundingBox().UpperRightPoint.X < 180).ToList();

            Console.WriteLine(results.Count);
            exporter.ExportToFile(new FileExportInfo(features, columns, fileName, wkt));
        }
        private void Output(IEnumerable <Feature> bufferedFeatures, string path, string projection)
        {
            ShpFileExporter exporter        = new ShpFileExporter();
            string          projectionInWKT = GdalHelper.Proj4ToWkt(projection);
            FileExportInfo  info            = new FileExportInfo(bufferedFeatures, columns, path, projectionInWKT);

            exporter.ExportToFile(info);
        }
Example #4
0
        private void Output(IEnumerable <Feature> bufferedFeatures)
        {
            string         projectionInWKT = GdalHelper.Proj4ToWkt(displayProjectionParameters);
            FileExportInfo info            = new FileExportInfo(bufferedFeatures, GetColumns(), outputPath, projectionInWKT);

            ShpFileExporter exporter = new ShpFileExporter();

            exporter.ExportToFile(info);
        }
        private void OutPutResults(IEnumerable <Feature> resultFeatures)
        {
            string exportPath = string.Empty;

            //if (outputToMap)
            //{
            //    string dir = Path.GetDirectoryName(tempShapeFilePath);
            //    string fileName = Path.GetFileNameWithoutExtension(tempShapeFilePath);
            //    string outputToMapTempFilePath = Path.Combine(dir, fileName + "OutPutToMapResult.shp");

            //    exportPath = outputToMapTempFilePath;

            //    var args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating);
            //    args.Parameters.Add("OutputToMapTempFilePath", exportPath);
            //    OnUpdatingProgress(args);
            //}
            //else
            if (outputToFile && !string.IsNullOrEmpty(outputFilePath))
            {
                exportPath = outputFilePath;

                var args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating);
                args.Message = "Creating File";
                OnUpdatingProgress(args);
            }

            FileExportInfo  info     = new FileExportInfo(resultFeatures, columnsToInclude, exportPath, displayProjectionParameters);
            ShpFileExporter exporter = new ShpFileExporter();

            exporter.ExportToFile(info);

            OnUpdatingProgress(new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating)
            {
                Message = "Finished"
            });
        }
        private void Split()
        {
            try
            {
                var args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating);

                featureSource.Open();
                Collection <Feature> allFeatures = featureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
                var columns = featureSource.GetColumns();
                featureSource.Close();

                var featuresGroups = allFeatures.GroupBy(tmpFeature
                                                         => tmpFeature.ColumnValues[splitColumnName]);

                int i     = 0;
                int count = exportConfigs.Count;
                exportConfigs.ForEach(config =>
                {
                    string folderName = outputPath;
                    string fileName   = config.Value;
                    if (String.IsNullOrEmpty(fileName))
                    {
                        fileName = String.Format(CultureInfo.InvariantCulture, "{0}_{1}.shp", layerName, config.Key);
                    }

                    if (!fileName.EndsWith(".shp", StringComparison.OrdinalIgnoreCase))
                    {
                        fileName += ".shp";
                    }

                    string finalShapeFilePath = Path.Combine(folderName, fileName);

                    if (File.Exists(finalShapeFilePath) && overwriteOutputFiles)
                    {
                        //CloseExistingLayersAndCollectOverlaysToRefresh(this, finalShapeFilePath);
                        RemoveShapeFile(finalShapeFilePath);
                    }

                    //this.OutputShapeFileNames.Add(finalShapeFilePath);
                    var featureGroup = featuresGroups.FirstOrDefault(group => group.Key == config.Key);
                    if (featureGroup != null)
                    {
                        ShpFileExporter exporter = new ShpFileExporter();
                        exporter.ExportToFile(new FileExportInfo(featureGroup, columns, finalShapeFilePath, wkt));
                    }

                    args.Message = String.Format(CultureInfo.InvariantCulture, "Building... ({0}/{1})", ++i, count);
                    OnUpdatingProgress(args);
                });
            }
            catch (Exception ex)
            {
                //HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
            }
            finally
            {
                //this.IsBusy = false;
                //this.BusyContent = String.Empty;
                //this.CurrentThread = null;
            }
        }
        private void Dissolve()
        {
            try
            {
                Collection <Feature> dissolvedFeatures = new Collection <Feature>();
                // get features to dissolve.
                Collection <Feature> featuresToDissolve = GetFeaturesToDissolve();
                // group features.
                var featureGroupByShapeType = featuresToDissolve.GroupBy(f =>
                {
                    return(f.GetShape().GetType());
                });

                Action <IGrouping <Type, Feature>, Action <IEnumerable <Feature>, Dictionary <string, string> > > dissolveAction
                    = new Action <IGrouping <Type, Feature>, Action <IEnumerable <Feature>, Dictionary <string, string> > >
                          ((groupByType, finalProcessAction) =>
                {
                    //CancelTask(this.CancellationSource.Token, content, parameter);
                    var groupByColumns = GroupByColumns(groupByType, this.matchColumns);
                    groupByColumns.ForEach(groupFeature =>
                    {
                        //CancelTask(this.CancellationSource.Token, content, parameter);
                        Dictionary <string, string> newColumnValues = new Dictionary <string, string>();
                        foreach (var tmpMatchColumn in this.matchColumns)
                        {
                            newColumnValues.Add(tmpMatchColumn, groupFeature.First().ColumnValues[tmpMatchColumn]);
                        }

                        foreach (var operatorPair in this.operatorPairs)
                        {
                            //CancelTask(this.CancellationSource.Token, content, parameter);
                            CollectNewColumnValues(groupFeature, newColumnValues, operatorPair);
                        }

                        newColumnValues.Add("Count", groupFeature.Count().ToString());

                        try
                        {
                            if (finalProcessAction != null)
                            {
                                finalProcessAction(groupFeature, newColumnValues);
                            }
                        }
                        catch { }
                    });
                });

                featureGroupByShapeType.ForEach(groupByType =>
                {
                    //CancelTask(this.CancellationSource.Token, content, parameter);
                    if (groupByType.Key.IsSubclassOf(typeof(AreaBaseShape)))
                    {
                        dissolveAction(groupByType, (tmpFeatures, tmpColumnValues) =>
                        {
                            MultipolygonShape dissolveShape = AreaBaseShape.Union(GetValidFeatures(tmpFeatures));
                            if (dissolveShape != null)
                            {
                                Feature dissolveFeature = new Feature(dissolveShape, tmpColumnValues);
                                dissolvedFeatures.Add(dissolveFeature);
                            }
                        });
                    }
                    else if (groupByType.Key.IsSubclassOf(typeof(LineBaseShape)))
                    {
                        dissolveAction(groupByType, (tmpFeatures, tmpColumnValues) =>
                        {
                            //MultilineShape dissolveShape = LineBaseShape.Union(tmpFeatures);
                            //Feature dissolveFeature = new Feature(dissolveShape, tmpColumnValues);
                            //dissolveFeatures.Add(dissolveFeature);
                            MultilineShape dissolveShape = new MultilineShape();
                            tmpFeatures.ForEach(tmpFeature =>
                            {
                                BaseShape tmpShape      = tmpFeature.GetShape();
                                LineShape tmpLine       = tmpShape as LineShape;
                                MultilineShape tmpMLine = tmpShape as MultilineShape;
                                if (tmpLine != null)
                                {
                                    dissolveShape.Lines.Add(tmpLine);
                                }
                                else if (tmpMLine != null)
                                {
                                    tmpMLine.Lines.ForEach(tmpLineInMLine => dissolveShape.Lines.Add(tmpLineInMLine));
                                }
                            });

                            if (dissolveShape.Lines.Count > 0)
                            {
                                dissolvedFeatures.Add(new Feature(dissolveShape, tmpColumnValues));
                            }
                        });
                    }
                    else if (groupByType.Key.IsSubclassOf(typeof(PointBaseShape)))
                    {
                        dissolveAction(groupByType, (tmpFeatures, tmpColumnValues) =>
                        {
                            MultipointShape multipointShape = new MultipointShape();
                            tmpFeatures.ForEach(tmpFeature =>
                            {
                                BaseShape tmpShape        = tmpFeature.GetShape();
                                PointShape tmpPoint       = tmpShape as PointShape;
                                MultipointShape tmpMPoint = tmpShape as MultipointShape;
                                if (tmpPoint != null)
                                {
                                    multipointShape.Points.Add(tmpPoint);
                                }
                                else if (tmpMPoint != null)
                                {
                                    tmpMPoint.Points.ForEach(tmpPointInMPointShape => multipointShape.Points.Add(tmpPointInMPointShape));
                                }
                            });
                            dissolvedFeatures.Add(new Feature(multipointShape, tmpColumnValues));
                        });
                    }
                });

                // collect export columns.
                var filteredFeatureColumns = new Collection <FeatureSourceColumn>();
                foreach (var matchColumn in this.matchColumns)
                {
                    var tmpColumn = featureColumns.FirstOrDefault(f => f.ColumnName.Equals(matchColumn, StringComparison.Ordinal));
                    if (tmpColumn != null)
                    {
                        filteredFeatureColumns.Add(tmpColumn);
                    }
                }

                foreach (var extraColumn in this.operatorPairs)
                {
                    var tmpColumn = featureColumns.FirstOrDefault(f => f.ColumnName.Equals(extraColumn.ColumnName, StringComparison.Ordinal));
                    if (tmpColumn != null)
                    {
                        filteredFeatureColumns.Add(tmpColumn);
                    }
                }

                filteredFeatureColumns.Add(new FeatureSourceColumn("Count", "Integer", 8));

                string saveFolder = Path.GetDirectoryName(outputPath);
                if (!Directory.Exists(saveFolder))
                {
                    Directory.CreateDirectory(saveFolder);
                }

                ShpFileExporter exporter = new ShpFileExporter();
                exporter.ExportToFile(new FileExportInfo(dissolvedFeatures, filteredFeatureColumns, outputPath, Wkt));
            }
            catch (Exception e)
            {
            }
            finally
            {
                var args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating);
                args.Message = "Finished";

                OnUpdatingProgress(args);
            }
        }