Esempio n. 1
0
 public CheckDataInput(IFeatureSet originalData, string field, string trans)
 {
     this._originalData = originalData;
     this.field = field;
     this.trans = trans;
 
 }
Esempio n. 2
0
 /// <summary>
 /// Show the dialog to join an Excel table with a feature set.
 /// </summary>
 /// <param name="e"></param>
 public void ExcelJoin(IFeatureSet e)
 {
     using (var jd = new JoinDialog(e))
     {
         ShowDialog(jd);
     }
 }
Esempio n. 3
0
        //when clicking "OK"
        private void btnOK_Click(object sender, EventArgs e)
        {
            queryResult = null;
            SpatiaLiteHelper slh = new SpatiaLiteHelper();
            queryResult = slh.ReadFeatureSet(connString, txtQuery.Text);

            dgQueryResult.DataSource = queryResult.DataTable;

            //SpatiaLiteHelper slh = new SpatiaLiteHelper();

            //foreach (DataGridViewRow r in dgGeometryColumns.Rows)
            //{
            //    if (r.Selected)
            //    {
            //        GeometryColumnInfo item = r.DataBoundItem as GeometryColumnInfo;
            //        if (item != null)
            //        {
            //            IFeatureSet fs = slh.ReadFeatureSet(connString, item);

            //            IMapFeatureLayer lay = mainMap.Layers.Add(fs);
            //            //lay.EditMode = false;

            //        }
            //    }
            //}
        }
 public static IMapFeatureLayer Insert(this IMapLayerCollection collection, int index, IFeatureSet featureSet)
 {
     if (featureSet != null)
     {
         featureSet.ProgressHandler = collection.ProgressHandler;
         if ((featureSet.FeatureType == FeatureType.Point) || (featureSet.FeatureType == FeatureType.MultiPoint))
         {
             IMapPointLayer item = new MapPointLayer(featureSet);
             collection.Insert(index, item);
             item.ProgressHandler = collection.ProgressHandler;
             return item;
         }
         if (featureSet.FeatureType == FeatureType.Line)
         {
             IMapLineLayer layer2 = new MapLineLayer(featureSet);
             collection.Insert(index, layer2);
             layer2.ProgressHandler = collection.ProgressHandler;
             return layer2;
         }
         if (featureSet.FeatureType == FeatureType.Polygon)
         {
             IMapPolygonLayer layer3 = new MapPolygonLayer(featureSet);
             collection.Insert(index, layer3);
             layer3.ProgressHandler = collection.ProgressHandler;
             return layer3;
         }
     }
     return null;
 }
Esempio n. 5
0
 /// <summary>
 /// Creates a new instance of a GeoPointLayer without sending any status messages
 /// </summary>
 /// <param name="featureSet">The IFeatureLayer of data values to turn into a graphical GeoPointLayer</param>
 public MapPointLayer(IFeatureSet featureSet)
     : base(featureSet)
 {
     // this simply handles the default case where no status messages are requested
     Configure();
     OnFinishedLoading();
 }
Esempio n. 6
0
 public SpatialAnalysis(string globalShapeFileDataPath)
 {
     string dataPath = globalShapeFileDataPath;
     fsWorldCountries = FeatureSet.Open(dataPath);
     fsWorldCountries.Reproject(DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984);
     countryCodes = GetCountryCodeMappings();
 }
Esempio n. 7
0
 /// <summary>
 /// Generates an empty featureset that has the combined fields from this featureset
 /// and the specified featureset.
 /// </summary>
 /// <param name="self">This featureset</param>
 /// <param name="other">The other featureset to combine fields with.</param>
 /// <returns></returns>
 public static IFeatureSet CombinedFields(this IFeatureSet self, IFeatureSet other)
 {
     IFeatureSet result = new FeatureSet(self.FeatureType);
     Dictionary<string, DataColumn> resultColumns = new Dictionary<string, DataColumn>();
     foreach (DataColumn dc in self.DataTable.Columns)
     {
         string name = dc.ColumnName;
         int i = 1;
         while (resultColumns.ContainsKey(name))
         {
             name = dc.ColumnName + i;
             i++;
         }
         resultColumns.Add(name, dc);
     }
     foreach (DataColumn dc in other.DataTable.Columns)
     {
         string name = dc.ColumnName;
         int i = 1;
         while (resultColumns.ContainsKey(name))
         {
             name = dc.ColumnName + i;
             i++;
         }
         resultColumns.Add(name, dc);
     }
     foreach (KeyValuePair<string, DataColumn> pair in resultColumns)
     {
         result.DataTable.Columns.Add(new DataColumn(pair.Key, pair.Value.DataType));
     }
     return result;
 }
Esempio n. 8
0
        /// <summary>
        /// Initializes a new instance of the IDW class
        /// </summary>
        /// <param name="shapeLayer">Shapefile type point</param>
        /// <param name="idField">Position of field that contains the Z value</param>
        public IDW(IFeatureSet shapeLayer, int idField) :
            base(shapeLayer, idField)
        {
            this.method = "IDW";

           // this.CreatePoints(shapeLayer, idField);
          //  this.CalculateDistances();
        }
Esempio n. 9
0
       public static IFeatureSet FeatureFromPoints(List<Kpoint> points, IFeatureSet refe)
        {
            foreach(Kpoint p in points)
               {
                }

            return refe;
        }
Esempio n. 10
0
        private void Configure(IFeatureSet inFeatureSet)
        {
            if (inFeatureSet == null) throw new ArgumentNullException("inFeatureSet");
            if (inFeatureSet.FeatureType != FeatureType.Polygon) throw new PolygonFeatureTypeException();

            Symbology = new PolygonScheme();
            Symbology.SetParentItem(this);
        }
Esempio n. 11
0
 private void Configure(IFeatureSet inFeatureSet)
 {
     if (inFeatureSet.FeatureType != FeatureType.Line)
     {
         throw new LineFeatureTypeException();
     }
     Symbology = new LineScheme();
 }
Esempio n. 12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="featureSet"></param>
 /// <param name="inFilter"></param>
 /// <param name="activeType"></param>
 /// <param name="isReadOnly"></param>
 public FeatureSelection(IFeatureSet featureSet, IDrawingFilter inFilter, FilterType activeType, bool isReadOnly)
 {
     _filter = inFilter;
     _activeType = activeType;
     _isReadOnly = isReadOnly;
     _featureSet = featureSet;
     Configure();
 }
Esempio n. 13
0
 /// <summary>
 /// Creates a new instance of FilterCollection, where the current state of the filter is
 /// recorded as the kind of "collection" that this item belongs to.  The filter can be
 /// altered later, and this will retain the original state.
 /// </summary>
 public FeatureSelection(IFeatureSet featureSet, IDrawingFilter inFilter, FilterType activeType)
 {
     _filter = inFilter;
     _activeType = activeType;
     _selectionState = true;
     _featureSet = featureSet;
     Configure();
 }
Esempio n. 14
0
        public SearchResultItem(string serviceCode, IFeatureSet featureSet)
        {
            if (serviceCode == null) throw new ArgumentNullException("serviceCode");
            if (featureSet == null) throw new ArgumentNullException("featureSet");
            Contract.EndContractBlock();

            ServiceCode = serviceCode;
            FeatureSet = featureSet;
        }
Esempio n. 15
0
 /// <summary>
 /// Creates a new instance of Selection
 /// </summary>
 public Selection(IFeatureSet fs, IDrawingFilter inFilter):base(fs, inFilter, FilterTypes.Selection)
 {
     Selected = true;
     UseSelection = true;
     UseCategory = false;
     UseVisibility = false;
     UseChunks = false;
     SelectionMode = SelectionModes.IntersectsExtent;
 }
Esempio n. 16
0
 /// <summary>
 /// Generates a default instance of the data type so that tools have something to write too
 /// </summary>
 /// <param name="path"></param>
 public override void GenerateDefaultOutput(string path)
 {
     FeatureSet addedFeatureSet = new LineShapefile
                                      {
                                          Filename =
                                              Path.GetDirectoryName(path) +
                                              Path.DirectorySeparatorChar + ModelName + ".shp"
                                      };
     Value = addedFeatureSet;
 }
Esempio n. 17
0
 private void Configure(IFeatureSet inFeatureSet)
 {
     if (inFeatureSet.FeatureType != FeatureType.Polygon)
     {
         throw new PolygonFeatureTypeException();
     }
     PolygonScheme ps = new PolygonScheme();
     ps.SetParentItem(this);
     Symbology = ps;
 }
Esempio n. 18
0
 public LocalTrend(IFeatureSet shapeLayer, int idField, int order) :
     base(shapeLayer, idField)
 {
     this.method = "LocalTrend";
     this.order = order;
     if (order >= 1 || order <= 3)
     {
         serie = SerieCoef(order);
     }
 }
Esempio n. 19
0
        /// <summary>
        /// Calculates the unique colors as a scheme 
        /// </summary>
        /// <param name="fs">The featureset with the data Table definition</param>
        /// <param name="uniqueField">The unique field</param>
        public Hashtable GenerateUniqueColors(IFeatureSet fs, string uniqueField)
        {
            Hashtable result = new Hashtable(); // a hashtable of colors
            DataTable dt = fs.DataTable;
            ArrayList vals = new ArrayList();
            int i = 0;
            foreach (DataRow row in dt.Rows)
            {
                if (uniqueField != "FID")
                {

                    if (vals.Contains(row[uniqueField]) == false)
                    {
                        vals.Add(row[uniqueField]);
                    }
                }
                else
                {
                    vals.Add(i);
                    i++;
                }
            }
           
            Random rnd = new Random();
            foreach (object item in vals)
            {
                Color c = rnd.NextColor();
                while(result.ContainsKey(c))
                {
                   c = rnd.NextColor();
                }
                PolygonCategory cat = new PolygonCategory(c, c, 1);
                string flt = "[" + uniqueField + "] = ";
                if (uniqueField == "FID")
                {
                    flt += item;
                }
                else
                {
                    if (dt.Columns[uniqueField].DataType == typeof(string))
                    {
                        flt += "'" + item + "'";
                    }
                    else
                    {
                        flt += item.ToString();
                    }
                }
                cat.FilterExpression = flt;
                Categories.Add(cat);
                result.Add(c, item);
            }
            return result;
        }
Esempio n. 20
0
 public Trend(IFeatureSet shapeLayer, int idField, int order, double meanValue) :
       base(shapeLayer, idField)
 {
     this.method = "Trend";
     this.meanValue=meanValue;
     this.order = order;
     if (order>=1  || order <=3){
     serie = SerieCoef(order);
     GenerateMatrix(order, this.npoints, this.Kpoints);
     }
 }
Esempio n. 21
0
 public RequestContext(IRequest request, IResponse response,
     ISessionStore sessionStore, IAuthenticator authenticator,
     IIoCContainer container, IFeatureSet features,
     Interceptors interceptors = null)
 {
     Request = request;
     Response = response;
     _sessionStore = sessionStore;
     _authenticator = authenticator;
     _container = new ContainerWrapper(container);
     Features = features;
     _interceptors = interceptors ?? new Interceptors();
 }
Esempio n. 22
0
 /// <summary>
 /// Initializes a new instance of the Kriging class
 /// </summary>
 /// <param name="shapeLayer">Shapefile type point</param>
 /// <param name="idField">Position of field that contains the Z value</param>
 public UniversalKriging(IFeatureSet shapeLayer, int idField) :
     base(shapeLayer, idField)
 {
     this.method = "Universal Kriging";
     var modelLineal = new ModelLineal
                           {
                               C0 = 0,
                               C1 = 1,
                               Range = 1
                           };
     // this.CreatePoints(shapeLayer, idField);
     this.CalculateDistances();
 }
Esempio n. 23
0
    public override async Task<bool> Load()
    {
      lineCount = 0;
      fs = FeatureSet.Open(filename);
      var shapes = fs.ShapeIndices.ToList();
      foreach (var shape in shapes)
      {
        foreach (var part in shape.Parts)
        {
          lineCount += (part.NumVertices - 1);
        }
      }
      this.vertexArray = new float[lineCount * 2 * 3]; //2 points in each line  3 dim:xyz
      this.colorArray = new float[lineCount * 2 * 4];

      int  lineIndex = 0;

      foreach (var shape in shapes)
      {
        foreach (var part in shape.Parts)
        {
          for (int i = 2; i < part.NumVertices; i++)
          {
            int baseIndex = (2 * part.StartIndex) + i * 2;

            int baseVertex = 3 * 2 * lineIndex;
            this.vertexArray[baseVertex + 0] = ConvertLongitude(fs.Vertex[baseIndex - 2]);  //long1
            this.vertexArray[baseVertex + 1] = ConvertLatitude(fs.Vertex[baseIndex - 3]); //lat1
            this.vertexArray[baseVertex + 2] = 0.0f;
            this.vertexArray[baseVertex + 3] = ConvertLongitude(fs.Vertex[baseIndex - 0]); //long2
            this.vertexArray[baseVertex + 4] = ConvertLatitude(fs.Vertex[baseIndex - 1]); //lat2
            this.vertexArray[baseVertex + 5] = 0.0f;

            int baseColor = 4 * 2 * lineIndex;
            float alpha = 1.0f;
            this.colorArray[baseColor + 0] = r;
            this.colorArray[baseColor + 1] = g;
            this.colorArray[baseColor + 2] = b;
            this.colorArray[baseColor + 3] = alpha;
            this.colorArray[baseColor + 4] = r;
            this.colorArray[baseColor + 5] = g;
            this.colorArray[baseColor + 6] = b;
            this.colorArray[baseColor + 7] = alpha;
            lineIndex++;
          }
        }
      }
      //this.isLoaded = true;
      return true;
    }
Esempio n. 24
0
 /// <summary>
 /// The Voronoi Graph calculation creates a delaunay tesselation where
 /// each point is effectively converted into triangles.
 /// </summary>
 /// <param name="points">The points to use for creating the tesselation.</param>
 /// <returns>The generated line featureset.</returns>
 public static IFeatureSet DelaunayLines(IFeatureSet points)
 {
     double[] vertices = points.Vertex;
     VoronoiGraph gp = Fortune.ComputeVoronoiGraph(vertices);
     FeatureSet result = new FeatureSet();
     foreach (VoronoiEdge edge in gp.Edges)
     {
         Coordinate c1 = edge.RightData.ToCoordinate();
         Coordinate c2 = edge.LeftData.ToCoordinate();
         LineString ls = new LineString(new List<Coordinate> { c1, c2 });
         Feature f = new Feature(ls);
         result.AddFeature(f);
     }
     return result;
 }
Esempio n. 25
0
        /// <summary>
        /// The Voronoi Graph calculation creates the lines that form a voronoi diagram.
        /// </summary>
        /// <param name="points">The points to use for creating the tesselation.</param>
        /// <returns>An IFeatureSet that is the resulting set of lines in the diagram.</returns>
        public static IFeatureSet VoronoiLines(IFeatureSet points)
        {
            double[] vertices = points.Vertex;
            VoronoiGraph gp = Fortune.ComputeVoronoiGraph(vertices);

            HandleBoundaries(gp, points.Extent.ToEnvelope());

            FeatureSet result = new FeatureSet();
            foreach (VoronoiEdge edge in gp.Edges)
            {
                Coordinate c1 = edge.VVertexA.ToCoordinate();
                Coordinate c2 = edge.VVertexB.ToCoordinate();
                LineString ls = new LineString(new List<Coordinate> { c1, c2 });
                Feature f = new Feature(ls);
                result.AddFeature(f);
            }
            return result;
        }
Esempio n. 26
0
 private void Configure(IFeatureSet inFeatureSet)
 {
     FeatureType ft = inFeatureSet.FeatureType;
     if (ft != FeatureType.Point && ft != FeatureType.MultiPoint && ft != FeatureType.Unspecified)
     {
         throw new PointFeatureTypeException();
     }
     if (inFeatureSet.NumRows() == 0)
     {
         MyExtent = new Extent(-180, -90, 180, 90);
     }
     if (inFeatureSet.NumRows() == 1)
     {
         MyExtent = inFeatureSet.Extent.Copy();
         MyExtent.ExpandBy(10, 10);
     }
     Symbology = new PointScheme();
 }
Esempio n. 27
0
        /// <summary>
        /// Erase features from one feature set where they are intersected by another feature set. 
        /// </summary>
        /// <param name="TargetFeatures">Features which will be erased in part or whole.</param>
        /// <param name="SourceFeatures">Features which represent areas to erase.</param>
        /// <param name="cancelProgressHandler">Optional parameter to report progress and cancel entire process if needed.</param>
        /// <returns>A point feature set with the randomly created features.</returns>
        public static FeatureSet EraseFeatures(IFeatureSet TargetFeatures, IFeatureSet SourceFeatures, ICancelProgressHandler cancelProgressHandler = null)
        {
            if (TargetFeatures == null || SourceFeatures == null)
            {
                return null;
            }
            //Erase features from one feature set where they are intersected by another feature set
            //Note: we use the ShapeIndices here rather than for each feature in featureset.features as a memory management technique.
            //The current version does not preserve any attribute info. 
            //Dan Ames 2/27/2013
            FeatureSet ResultFeatures = new FeatureSet();                   //the resulting featureset
            IFeature TF, SF;                                                //a single output feature
            ResultFeatures.CopyTableSchema(TargetFeatures);                 //set up the data table in the new feature set

            for (Int16 i = 0; i <= TargetFeatures.ShapeIndices.Count - 1; i++)
            {
                TF = TargetFeatures.GetFeature(i);                          //get the full undifferenced feature
                for (Int16 j = 0; j <= SourceFeatures.ShapeIndices.Count - 1; j++)
                {
                    SF = SourceFeatures.GetFeature(j);
                    if (SF.Envelope.Intersects(TF.Envelope))
                    {
                        TF = TF.Difference(SF);                             //clip off any pieces of SF that overlap FR
                    }
                    if (TF == null)
                    {                                                       //sometimes difference leaves nothing left of a feature
                        break;
                    }
                }
                if (TF != null)
                {
                    ResultFeatures.AddFeature(TF).CopyAttributes(TargetFeatures.GetFeature(i));  //add the fully clipped feature to the results
                }
                if (cancelProgressHandler != null)
                {
                    if (cancelProgressHandler.Cancel) { return null; }
                    int progress = Convert.ToInt32(i * 100 / TargetFeatures.ShapeIndices.Count);
                    cancelProgressHandler.Progress(String.Empty, progress, String.Empty);
                }
            }
            return ResultFeatures;
        }
Esempio n. 28
0
        /// <summary>
        /// A static function to compute the buffer and return the result to the Execute function.
        /// </summary>
        /// <param name="input">The feature set that will be buffered.</param>
        /// <param name="bufferDistance">The distance of the buffer.</param>
        /// <param name="outputFeatures">The resulting feature set that will show the buffer.</param>
        /// <param name="cancelProgressHandler">Optional parameter to report progress and cancel if needed.</param>
        /// <returns></returns>
        public static bool AddBuffer(IFeatureSet inputFeatures, double bufferDistance, IFeatureSet outputFeatures, ICancelProgressHandler cancelProgressHandler = null)
        {
            int numFeatures = inputFeatures.Features.Count;
            for (int i = 0; i < numFeatures; i++)
            {
                inputFeatures.Features[i].Buffer(bufferDistance, outputFeatures);

                // Here we update the progress
                if (cancelProgressHandler != null)
                {
                    if (cancelProgressHandler.Cancel)
                    {
                        return false;
                    }
                    int progress = Convert.ToInt32(i * 100 / numFeatures);
                    cancelProgressHandler.Progress("buffer_tool", progress, "Buffering features.");
                }
            }
            return true;
        }
Esempio n. 29
0
 /// <summary>
 /// Generates an empty featureset that has the combined fields from this featureset
 /// and the specified featureset.
 /// </summary>
 /// <param name="self">This featureset</param>
 /// <param name="other">The other featureset to combine fields with.</param>
 /// <returns></returns>
 public static IFeatureSet CombinedFields(this IFeatureSet self, IFeatureSet other)
 {
     IFeatureSet result = new FeatureSet(self.FeatureType);
     var uniqueNames = new HashSet<string>();
     foreach (var fs in new []{self, other})
     {
         foreach (DataColumn dc in fs.DataTable.Columns)
         {
             var name = dc.ColumnName;
             var i = 1;
             while (uniqueNames.Contains(name))
             {
                 name = dc.ColumnName + i;
                 i++;
             }
             uniqueNames.Add(name);
             result.DataTable.Columns.Add(new DataColumn(name, dc.DataType));
         }   
     }
     return result;
 }
Esempio n. 30
0
        /// <summary>
        /// Executes the Union Opaeration tool programaticaly
        /// </summary>
        /// <param name="input">The input are feature sets</param>
        /// <param name="output">The output feature set</param>
        /// <param name="CancelProgressHandler">The progress handler</param>
        /// <returns></returns>
        public bool Execute(IFeatureSet self, IFeatureSet output, MapWindow.Tools.ICancelProgressHandler cancelProgressHandler)
        {
            //Validates the input and output data
            if (self == null || self.Features == null || self.Features.Count == 0 || output == null)
            {
                return false;
            }

            IFeature result = self.Features[0];
            MapWindow.Main.ProgressMeter pm = new MapWindow.Main.ProgressMeter(cancelProgressHandler, "Unioning Shapes", self.Features.Count);
            for(int i = 1; i < self.Features.Count; i++)
            {
                if (self.Features[i] == null) continue;
                result = result.Union(self.Features[i]);
                pm.CurrentValue = i;
            }
            pm.Reset();
            output.Features.Add(result);
            output.SaveAs(output.Filename, true);
            return true;
                
        }
        /// <summary>
        /// Validates shapes and returns list of errors.
        /// </summary>
        private IEnumerable <ErrorInfo> GetErrors(IFeatureSet fs, ITaskHandle task)
        {
            var lastPercent = 0;

            for (var i = 0; i < fs.NumFeatures; i++)
            {
                task.CheckPauseAndCancel();
                task.Progress.TryUpdate("Calculating...", i, fs.NumFeatures, ref lastPercent);

                var gm = fs.Features[i].Geometry;
                if (gm.IsValid)
                {
                    continue;
                }

                var info = ValidationHelper.GetErrorInfo(fs, i, gm.IsValidReason);

                Log.Info(info.Message);

                yield return(info);
            }

            task.Progress.Clear();
        }
Esempio n. 32
0
        private IFeatureSet CorrectFeatures(IFeatureSet featureSet)
        {
            IFeatureSet corFeatureSet = featureSet;
            List <int>  corList       = new List <int>();

            for (int i = 0; i < featureSet.ShapeIndices.Count; i++)
            {
                try
                {
                    IFeature    feature      = featureSet.GetFeature(i);
                    IFeatureSet reFeatureSet = new FeatureSet();
                    reFeatureSet.Features.Add(feature);
                    //有待检验能否检测出其他异常
                    reFeatureSet.SelectByAttribute("");
                    corList.Add(i);
                }
                catch
                {
                    //featureSet.Features.RemoveAt(i);
                }
            }
            corFeatureSet = corFeatureSet.CopySubset(corList);
            return(corFeatureSet);
        }
Esempio n. 33
0
        /// <summary>
        /// Adds sites from the list of data series which are inside the polygons
        /// to an existing feature set
        /// <param name="seriesList"></param>
        /// <param name="fs"></param>
        /// <param name="polygons"></param>
        /// </summary>
        private static void AddToFeatureSet(IEnumerable <SeriesDataCart> seriesList, IFeatureSet fs, IList <IFeature> polygons)
        {
            if (polygons.Count == 0)
            {
                AddToFeatureSet(seriesList, fs);
                return;
            }

            foreach (SeriesDataCart series in seriesList)
            {
                double lat   = series.Latitude;
                double lon   = series.Longitude;
                var    coord = new Coordinate(lon, lat);

                if (TestPointInPolygons(coord, polygons))
                {
                    var f = new Feature(FeatureType.Point, new[] { coord });
                    fs.Features.Add(f);

                    DataRow row = f.DataRow;
                    PopulateDataRow(series, row);
                }
            }
        }
Esempio n. 34
0
        /// <summary>
        /// Once the parameters have been configured, the Execute command can be called, it returns true if succesful
        /// </summary>
        public override bool Execute(ICancelProgressHandler cancelProgressHandler)
        {
            //Get the needed input and output parameters
            IFeatureSet inputFeatures  = _inputParam[0].Value as IFeatureSet;
            DoubleParam dp             = _inputParam[1] as DoubleParam;
            double      bufferDistance = 1;

            if (dp != null)
            {
                bufferDistance = dp.Value;
            }
            IFeatureSet outputFeatures = _outputParam[0].Value as IFeatureSet;

            if (Buffer.AddBuffer(inputFeatures, bufferDistance, outputFeatures, cancelProgressHandler))
            {
                outputFeatures.Save();
                return(true);
            }
            else
            {
                _outputParam = null;
                return(false);
            }
        }
        /// <summary>
        /// Make fieldAttributes sub-set of fieldAttributes specific number of random elements from the selected
        /// feature layer in the map legend.
        /// </summary>
        /// <param name="pSampleSize">Number of elements to return</param>
        public static FeatureSet CreateRandomSelection(IFeatureLayer mLayer, int pSampleSize)
        {
            if (mLayer == null)
            {
                Utilities.LogDebug("The specified layer is null");
                return(null);
            }

            var         mRndFeatureSet = new FeatureSet();
            IFeatureSet mFeatureSet    = mLayer.DataSet;

            mRndFeatureSet.DataTable = mFeatureSet.DataTable.Clone();

            int mFeatureSetSize = mFeatureSet.Features.Count;

            Utilities.ResetRndGenerator();
            for (int i = 0; i < pSampleSize; i++)
            {
                IFeature mOldFeature = mFeatureSet.Features[Utilities.GetRndBetween(0, mFeatureSetSize)];
                IFeature mNewFeature = mRndFeatureSet.AddFeature(mOldFeature.Copy());
                mNewFeature.CopyAttributes(mOldFeature);
            }
            return(mRndFeatureSet);
        }
Esempio n. 36
0
        /// <summary>
        /// Applies the default style to categories, preserving only those properties that are among categories.
        /// </summary>
        public static void ApplyDefaultStyleToCategories(this IFeatureSet fs)
        {
            if (fs == null)
            {
                throw new ArgumentNullException("fs");
            }

            var categories = fs.Categories;

            if (categories.Count == 0)
            {
                return;
            }

            var style = fs.Style;

            CopyMatchedProperties(categories.Select(ct => ct.Style.Fill), style.Fill);

            CopyMatchedProperties(categories.Select(ct => ct.Style.Line), style.Line);

            CopyMatchedProperties(categories.Select(ct => ct.Style.Vertices), style.Vertices);

            CopyMatchedProperties(categories.Select(ct => ct.Style.Marker), style.Marker);
        }
Esempio n. 37
0
        /// <summary>
        /// Once the Parameter have been configured the Execute command can be called, it returns true if successful
        /// </summary>
        /// <param name="cancelProgressHandler">The progress handler.</param>
        /// <returns>True, if executed successfully.</returns>
        public override bool Execute(ICancelProgressHandler cancelProgressHandler)
        {
            IFeatureSet self  = _inputParam[0].Value as IFeatureSet;
            IFeatureSet other = _inputParam[1].Value as IFeatureSet;

            if (self != null && other != null)
            {
                self.FillAttributes();
                other.FillAttributes();
            }

            IFeatureSet result = Overlay.EraseFeatures(self, other, cancelProgressHandler);

            if (cancelProgressHandler.Cancel)
            {
                _outputParam = null;
                return(false);
            }

            result.Filename = ((IFeatureSet)_outputParam[0].Value).Filename;
            result.Save();
            _outputParam[0].Value = result;
            return(true);
        }
Esempio n. 38
0
        /// <inheritdocs/>
        public void RemoveAt(int index)
        {
            // Get shape range so we can update header smartly
            int         startIndex = index;
            IFeatureSet ifs        = Select(null, null, ref startIndex, 1);

            if (ifs.NumRows() > 0)
            {
                var shx = new ShapefileIndexFile();
                shx.Open(Filename);
                shx.Shapes.RemoveAt(index);
                shx.Save();

                AttributeTable dbf = GetAttributeTable(Filename);
                dbf.RemoveRowAt(index);
                if (_trackDeletedRows)
                {
                    _deletedRows = dbf.DeletedRows;
                }

                // Update extent in header if feature being deleted is NOT completely contained
                var hdr = new ShapefileHeader(Filename);

                Envelope featureEnv = ifs.GetFeature(0).Geometry.EnvelopeInternal;
                if (featureEnv.MinX <= hdr.Xmin || featureEnv.MaxX >= hdr.Xmax || featureEnv.MaxY >= hdr.Ymax || featureEnv.MinY <= hdr.Ymin)
                {
                    UpdateExtents();
                }

                // Update the Quadtree
                if (null != Quadtree)
                {
                    Quadtree.Remove(featureEnv, index);
                }
            }
        }
Esempio n. 39
0
        public void loadSocialFiles(string inFileName)
        {
            List <base_social> mySocialSites = new List <base_social>();
            IFeatureSet        fs            = FeatureSet.Open(inFileName);
            DataTable          dt            = fs.DataTable;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                base_social social = new base_social();
                IFeature    f      = fs.Features[i];
                social.geom       = DbGeometry.FromText(f.BasicGeometry.ToString());
                social.OCCUP_FEMA = dt.Rows[i]["OCCUP_FEMA"].ToString();
                social.OCCUP_MALE = dt.Rows[i]["OCCUP_MALE"].ToString();
                social.SUITABILIT = dt.Rows[i]["SUITABILIT"].ToString();

                mySocialSites.Add(social);
            }
            using (me = new MapEntites())
            {
                me.Database.ExecuteSqlCommand("Truncate Table [base_social]");
                me.base_social.AddRange(mySocialSites);
                me.SaveChanges();
            }
        }
 private void btnStart_Click(object sender, RoutedEventArgs e)
 {
     if (this.m_CurrentFeaset == null)
     {
         MessageBox.Show("Please select a target layer");
         return;
     }
     if (this.txtPath.Text == "")
     {
         MessageBox.Show("Please select save path");
         return;
     }
     this.groupAdd.IsEnabled = false;
     this.btnEnd.IsEnabled   = true;
     //start
     MainWindow.m_DotMap.Cursor = System.Windows.Forms.Cursors.Cross;
     //创建新的FeatureSet 复制要素
     m_ResultFeaset = new FeatureSet(FeatureType.Line);
     foreach (DataColumn column in m_CurrentFeaset.DataTable.Columns)
     {
         DataColumn col = new DataColumn(column.ColumnName, column.DataType);
         m_ResultFeaset.DataTable.Columns.Add(col);
     }
     foreach (var fea in m_CurrentFeaset.Features)
     {
         IFeature pFea = m_ResultFeaset.AddFeature(fea.Geometry);
         for (int i = 0; i < fea.DataRow.ItemArray.Count(); i++)
         {
             pFea.DataRow[i] = fea.DataRow[i];
         }
     }
     m_ResultFeaset.Projection  = MainWindow.m_DotMap.Projection;
     m_ResultFeaset.Name        = m_CurrentFeaset.Name;
     m_PolylineLayer            = MainWindow.m_DotMap.Layers.Add(m_ResultFeaset);
     m_PolylineLayer.LegendText = m_ResultFeaset.Name + "_copy";
 }
Esempio n. 41
0
        /// <summary>
        /// Reprojects layer source, including shapefiles, images and grids.
        /// </summary>
        public TestingResult Reproject(ILayerSource layer, out ILayerSource newLayer, ISpatialReference projection, TesterReportForm report)
        {
            if (layer.SeekSubstituteFile(projection, out newLayer))
            {
                return(TestingResult.Substituted);
            }

            string newFilename = ProjectionHelper.FilenameWithProjectionSuffix(layer.Filename, layer.Projection, projection);

            newFilename = GetSafeNewName(newFilename);

            switch (layer.LayerType)
            {
            case LayerType.Shapefile:
                newLayer = Reproject(layer as IFeatureSet, projection, newFilename);
                break;

            case LayerType.Grid:
                newLayer = Reproject(layer as GridSource, projection, newFilename);
                break;

            case LayerType.Image:
                newLayer = Reproject(layer as BitmapSource, projection, newFilename);
                break;

            case LayerType.VectorLayer:
                int         count = 0;
                IFeatureSet fs    = (layer as VectorLayer).Data.Reproject(projection, out count);
                if (count > 0 && (fs != null))
                {
                    newLayer = fs;
                }
                break;
            }
            return(newLayer != null ? TestingResult.Ok : TestingResult.Error);
        }
Esempio n. 42
0
        /// <summary>
        /// Not Implemented yet
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="featureType"></param>
        /// <param name="inRam"></param>
        /// <param name="container"></param>
        /// <param name="progressHandler"></param>
        /// <returns></returns>
        public IFeatureLayer CreateNew(string fileName, FeatureType featureType, bool inRam, ICollection <ILayer> container, IProgressHandler progressHandler)
        {
            ShapefileDataProvider dp = new ShapefileDataProvider();
            IFeatureSet           fs = dp.CreateNew(fileName, featureType, inRam, progressHandler);

            if (progressHandler == null)
            {
                progressHandler = LayerManager.DefaultLayerManager.ProgressHandler;
            }

            if (fs.FeatureType == FeatureType.Line)
            {
                return(new MapLineLayer(fs, container));
            }
            if (fs.FeatureType == FeatureType.Polygon)
            {
                return(new MapPolygonLayer(fs, container));
            }
            if (fs.FeatureType == FeatureType.Point || fs.FeatureType == FeatureType.MultiPoint)
            {
                return(new MapPointLayer(fs, container));
            }
            return(null);
        }
Esempio n. 43
0
        private DotSpatial.Controls.IMapFeatureLayer GetMapLayerFromFeatureSet(IFeatureSet featureSet)
        {
            if (featureSet == null)
            {
                return(null);
            }

            IMapFeatureLayer layer = null;

            if (featureSet.FeatureType == FeatureType.Point || featureSet.FeatureType == FeatureType.MultiPoint)
            {
                layer = new MapPointLayer(featureSet);
            }
            else if (featureSet.FeatureType == FeatureType.Line)
            {
                layer = new MapLineLayer(featureSet);
            }
            else if (featureSet.FeatureType == FeatureType.Polygon)
            {
                layer = new MapPolygonLayer(featureSet);
            }

            return(layer);
        }
Esempio n. 44
0
        /// <summary>
        /// Adds a new entry to the drop down list from data provider.
        /// </summary>
        /// <param name="sender">Sender that raised the event.</param>
        /// <param name="e">The event args.</param>
        private void BtnAddDataClick(object sender, EventArgs e)
        {
            // Replace with something that uses the default data provider
            IFeatureSet tempFeatureSet = DataManager.DefaultDataManager.OpenVector();

            // If the feature is null don't do anything the user probably hit cancel on the dialog
            if (tempFeatureSet == null)
            {
                return;
            }

            // Else if the wrong feature type is returned don't add it and indicate whats wrong
            if (tempFeatureSet.FeatureType != FeatureType.Polygon)
            {
                MessageBox.Show(ModelingMessageStrings.FeatureTypeException);
            }
            else
            {
                // If its good add the feature set and save it
                _addedFeatureSet = new DataSetArray(Path.GetFileNameWithoutExtension(tempFeatureSet.Filename), tempFeatureSet);
                Param.ModelName  = _addedFeatureSet.Name;
                Param.Value      = _addedFeatureSet.DataSet;
            }
        }
Esempio n. 45
0
        /// <summary>
        /// Returns label string formed by the first record of attribute table.
        /// </summary>
        private static string get_LabelTextCore(IFeatureSet sf, string expression, bool byClassificationField = false)
        {
            const int rowIndex = 0;

            if (expression.ToLower() == NoExpression)
            {
                if (sf.Labels.Items.Count > 0)
                {
                    return(sf.Labels.Items[rowIndex].Text);
                }

                return(string.Empty);
            }

            if (byClassificationField)
            {
                int index = sf.Labels.ClassificationField;
                var val   = sf.Table.CellValue(index, rowIndex);

                if (val != null)
                {
                    return(val.ToString());
                }
            }
            else
            {
                object obj; string err;
                expression = FixExpression(expression);
                if (sf.Table.Calculate(expression, rowIndex, out obj, out err))
                {
                    return(obj.ToString());
                }
            }

            return("");
        }
Esempio n. 46
0
        /// <summary>
        /// Generates an empty featureset that has the combined fields from this featureset
        /// and the specified featureset.
        /// </summary>
        /// <param name="self">This featureset.</param>
        /// <param name="other">The other featureset to combine fields with.</param>
        /// <returns>The created featureset.</returns>
        public static IFeatureSet CombinedFields(this IFeatureSet self, IFeatureSet other)
        {
            IFeatureSet result      = new FeatureSet(self.FeatureType);
            var         uniqueNames = new HashSet <string>();

            foreach (var fs in new[] { self, other })
            {
                foreach (DataColumn dc in fs.DataTable.Columns)
                {
                    var name = dc.ColumnName;
                    var i    = 1;
                    while (uniqueNames.Contains(name))
                    {
                        name = dc.ColumnName + i;
                        i++;
                    }

                    uniqueNames.Add(name);
                    result.DataTable.Columns.Add(new DataColumn(name, dc.DataType));
                }
            }

            return(result);
        }
        private async void Initialize()
        {
            // Set the UI to indicate that the geoprocessing is running.
            SetBusy(true);

            // Get versions from a geodatabase.
            IFeatureSet versionsFeatureSet = await GetGeodatabaseVersionsAsync();

            // Continue if there is a valid geoprocessing result.
            if (versionsFeatureSet != null)
            {
                // Create a string builder to hold all of the information from the geoprocessing
                // task to display in the UI.
                StringBuilder stringBuilder = new StringBuilder();

                // Loop through each Feature in the FeatureSet.
                foreach (Feature version in versionsFeatureSet)
                {
                    // Loop through each attribute (a <key,value> pair).
                    foreach (KeyValuePair <string, object> attribute in version.Attributes)
                    {
                        // Add the key and value strings to the string builder.
                        stringBuilder.AppendLine(attribute.Key + ": " + attribute.Value);
                    }

                    // Add a blank line after each Feature (the listing of geodatabase versions).
                    stringBuilder.AppendLine();
                }

                // Display the results to the user.
                _geodatabaseListField.Text = stringBuilder.ToString();
            }

            // Set the UI to indicate that the geoprocessing is not running.
            SetBusy(false);
        }
Esempio n. 48
0
 /// <summary>
 /// Creates a new instance of a PointLayer for storing and drawing points
 /// </summary>
 /// <param name="inFeatureSet">Any implentation of an IFeatureLayer</param>
 /// <param name="progressHandler">A valid implementation of the IProgressHandler interface.</param>
 /// <exception cref="PointFeatureTypeException">Thrown if the featureSet FeatureType is not point or multi-point</exception>
 public PointLayer(IFeatureSet inFeatureSet, IProgressHandler progressHandler)
     : base(inFeatureSet, null, progressHandler)
 {
     Configure(inFeatureSet);
 }
Esempio n. 49
0
 /// <summary>
 /// Creates a new instance of a PointLayer for storing and drawing points.
 /// </summary>
 /// <param name="inFeatureSet">Any implementation of an IFeatureLayer.</param>
 /// <param name="container">An IContainer to contain this layer.</param>
 /// <param name="progressHandler">A valid implementation of the IProgressHandler interface.</param>
 /// <exception cref="PointFeatureTypeException">Thrown if the featureSet FeatureType is
 ///  not point or multi-point.</exception>
 public PointLayer(IFeatureSet inFeatureSet, ICollection <ILayer> container, IProgressHandler progressHandler)
     : base(inFeatureSet, container, progressHandler)
 {
     Configure(inFeatureSet);
 }
Esempio n. 50
0
        /// <summary>
        /// This tests each feature of the input
        /// </summary>
        /// <param name="self">This featureSet</param>
        /// <param name="other">The featureSet to perform intersection with</param>
        /// <param name="joinType">The attribute join type</param>
        /// <param name="progHandler">A progress handler for status messages</param>
        /// <returns>An IFeatureSet with the intersecting features, broken down based on the join Type</returns>
        public static IFeatureSet Intersection(this IFeatureSet self, IFeatureSet other, FieldJoinType joinType, IProgressHandler progHandler)
        {
            IFeatureSet   result = null;
            ProgressMeter pm     = new ProgressMeter(progHandler, "Calculating Intersection", self.Features.Count);

            if (joinType == FieldJoinType.All)
            {
                result = CombinedFields(self, other);

                // Intersection is symmetric, so only consider I X J where J <= I
                if (!self.AttributesPopulated)
                {
                    self.FillAttributes();
                }
                if (!other.AttributesPopulated)
                {
                    other.FillAttributes();
                }

                for (int i = 0; i < self.Features.Count; i++)
                {
                    IFeature        selfFeature     = self.Features[i];
                    List <IFeature> potentialOthers = other.Select(selfFeature.Geometry.EnvelopeInternal.ToExtent());
                    foreach (IFeature otherFeature in potentialOthers)
                    {
                        selfFeature.Intersection(otherFeature, result, joinType);
                    }

                    pm.CurrentValue = i;
                }

                pm.Reset();
            }
            else if (joinType == FieldJoinType.LocalOnly)
            {
                if (!self.AttributesPopulated)
                {
                    self.FillAttributes();
                }

                result = new FeatureSet();
                result.CopyTableSchema(self);
                result.FeatureType = self.FeatureType;
                if (other.Features != null && other.Features.Count > 0)
                {
                    pm = new ProgressMeter(progHandler, "Calculating Union", other.Features.Count);
                    IFeature union = other.Features[0];
                    for (int i = 1; i < other.Features.Count; i++)
                    {
                        union           = union.Union(other.Features[i].Geometry);
                        pm.CurrentValue = i;
                    }

                    pm.Reset();
                    pm = new ProgressMeter(progHandler, "Calculating Intersections", self.NumRows());
                    Extent otherEnvelope = union.Geometry.EnvelopeInternal.ToExtent();
                    for (int shp = 0; shp < self.ShapeIndices.Count; shp++)
                    {
                        if (!self.ShapeIndices[shp].Extent.Intersects(otherEnvelope))
                        {
                            continue;
                        }

                        IFeature selfFeature = self.GetFeature(shp);
                        selfFeature.Intersection(union, result, joinType);
                        pm.CurrentValue = shp;
                    }

                    pm.Reset();
                }
            }
            else if (joinType == FieldJoinType.ForeignOnly)
            {
                if (!other.AttributesPopulated)
                {
                    other.FillAttributes();
                }

                result = new FeatureSet();
                result.CopyTableSchema(other);
                result.FeatureType = other.FeatureType;
                if (self.Features != null && self.Features.Count > 0)
                {
                    pm = new ProgressMeter(progHandler, "Calculating Union", self.Features.Count);
                    IFeature union = self.Features[0];
                    for (int i = 1; i < self.Features.Count; i++)
                    {
                        union           = union.Union(self.Features[i].Geometry);
                        pm.CurrentValue = i;
                    }

                    pm.Reset();
                    if (other.Features != null)
                    {
                        pm = new ProgressMeter(progHandler, "Calculating Intersection", other.Features.Count);
                        for (int i = 0; i < other.Features.Count; i++)
                        {
                            other.Features[i].Intersection(union, result, FieldJoinType.LocalOnly);
                            pm.CurrentValue = i;
                        }
                    }

                    pm.Reset();
                }
            }

            return(result);
        }
Esempio n. 51
0
 /// <summary>
 /// Creates a new instance of a PointLayer without sending any status messages
 /// </summary>
 /// <param name="inFeatureSet">The IFeatureLayer of data values to turn into a graphical PointLayer</param>
 /// <exception cref="PointFeatureTypeException">Thrown if the featureSet FeatureType is not point or multi-point</exception>
 public PointLayer(IFeatureSet inFeatureSet)
     : this(inFeatureSet, null)
 {
     // this simply handles the default case where no status messages are requested
 }
Esempio n. 52
0
 /// <summary>
 /// Creates a new raster with the specified cell size.  If the cell size
 /// is zero, this will default to the shorter of the width or height
 /// divided by 256.  If the cell size produces a raster that is greater
 /// than 8, 000 pixels in either dimension, it will be re-sized to
 /// create an 8, 000 length or width raster.
 /// </summary>
 /// <param name="fs">The featureset to convert to a raster.</param>
 /// <param name="cellSize">The double extent of the cell.</param>
 /// <param name="fieldName">The integer field index of the file.</param>
 /// <param name="outputFileName">The fileName of the raster to create.</param>
 /// <param name="driverCode">The optional GDAL driver code to use if using GDAL
 /// for a format that is not discernable from the file extension.  An empty string
 ///  is usually perfectly acceptable here.</param>
 /// <param name="options">For GDAL rasters, they can be created with optional parameters
 ///  passed in as a string array.  In most cases an empty string is perfectly acceptable.</param>
 /// <param name="progressHandler">An interface for handling the progress messages.</param>
 /// <returns>Generates a raster from the vectors.</returns>
 public static IRaster ToRaster(IFeatureSet fs, double cellSize, string fieldName, string outputFileName, string driverCode, string[] options, IProgressHandler progressHandler)
 {
     return(ToRaster(fs, fs.Extent, cellSize, fieldName, outputFileName, driverCode, options, progressHandler));
 }
Esempio n. 53
0
 /// <summary>
 /// Creates a new raster with the specified cell size.  If the cell size
 /// is zero, this will default to the shorter of the width or height
 /// divided by 256.  If the cell size produces a raster that is greater
 /// than 8, 000 pixels in either dimension, it will be re-sized to
 /// create an 8, 000 length or width raster.
 /// </summary>
 /// <param name="fs">The featureset to convert to a raster.</param>
 /// <param name="cellSize">The double extent of the cell.</param>
 /// <param name="fieldName">The integer field index of the file.</param>
 /// <param name="outputFileName">The fileName of the raster to create.</param>
 /// <returns>The resulting IRaster generated by the ToRaster operation.</returns>
 public static IRaster ToRaster(IFeatureSet fs, double cellSize, string fieldName, string outputFileName)
 {
     return(ToRaster(fs, fs.Extent, cellSize, fieldName, outputFileName, string.Empty, new string[] { }, null));
 }
Esempio n. 54
0
 /// <summary>
 /// 通过shapefile对应的IFeatureSet对象,创建一个ShpConvert实例
 /// </summary>
 /// <param name="fs">shapefile对应的IFeatureSet对象</param>
 public ShpConvert(IFeatureSet fs)
 {
     this.Fs = fs;
 }
Esempio n. 55
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapLabelLayer"/> class based on the specified featureset.
 /// </summary>
 /// <param name="inFeatureSet">The feature set to build the label layer from.</param>
 public MapLabelLayer(IFeatureSet inFeatureSet)
     : base(inFeatureSet)
 {
     Configure();
 }
Esempio n. 56
0
        /// <summary>
        /// Creates a new raster with the specified cell size.  If the cell size
        /// is zero, this will default to the shorter of the width or height
        /// divided by 256.  If the cell size produces a raster that is greater
        /// than 8, 000 pixels in either dimension, it will be re-sized to
        /// create an 8, 000 length or width raster.
        /// </summary>
        /// <param name="fs">The featureset to convert to a raster.</param>
        /// <param name="extent">Force the raster to this specified extent.</param>
        /// <param name="cellSize">The double extent of the cell.</param>
        /// <param name="fieldName">The integer field index of the file.</param>
        /// <param name="outputFileName">The fileName of the raster to create.</param>
        /// <param name="driverCode">The optional GDAL driver code to use if using GDAL
        /// for a format that is not discernable from the file extension.  An empty string
        ///  is usually perfectly acceptable here.</param>
        /// <param name="options">For GDAL rasters, they can be created with optional parameters
        ///  passed in as a string array.  In most cases an empty string is perfectly acceptable.</param>
        /// <param name="progressHandler">An interface for handling the progress messages.</param>
        /// <returns>Generates a raster from the vectors.</returns>
        public static IRaster ToRaster(IFeatureSet fs, Extent extent, double cellSize, string fieldName, string outputFileName, string driverCode, string[] options, IProgressHandler progressHandler)
        {
            Extent env = extent;

            if (cellSize == 0)
            {
                if (env.Width < env.Height)
                {
                    cellSize = env.Width / 256;
                }
                else
                {
                    cellSize = env.Height / 256;
                }
            }

            int w = (int)Math.Ceiling(env.Width / cellSize);

            if (w > 8000)
            {
                w        = 8000;
                cellSize = env.Width / 8000;
            }

            int h = (int)Math.Ceiling(env.Height / cellSize);

            if (h > 8000)
            {
                h = 8000;
            }

            Bitmap   bmp = new(w, h);
            Graphics g   = Graphics.FromImage(bmp);

            g.Clear(Color.Transparent);
            g.SmoothingMode     = SmoothingMode.None;
            g.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
            g.InterpolationMode = InterpolationMode.NearestNeighbor;
            Hashtable colorTable;
            MapArgs   args = new(new Rectangle(0, 0, w, h), env, g);

            switch (fs.FeatureType)
            {
            case FeatureType.Polygon:
            {
                MapPolygonLayer mpl = new(fs);
                PolygonScheme   ps  = new();
                colorTable    = ps.GenerateUniqueColors(fs, fieldName);
                mpl.Symbology = ps;

                // first draw the normal colors and then the selection colors on top
                mpl.DrawRegions(args, new List <Extent> {
                        env
                    }, false);
                mpl.DrawRegions(args, new List <Extent> {
                        env
                    }, true);
            }

            break;

            case FeatureType.Line:
            {
                MapLineLayer mpl = new(fs);
                LineScheme   ps  = new();
                colorTable    = ps.GenerateUniqueColors(fs, fieldName);
                mpl.Symbology = ps;

                // first draw the normal colors and then the selection colors on top
                mpl.DrawRegions(args, new List <Extent> {
                        env
                    }, false);
                mpl.DrawRegions(args, new List <Extent> {
                        env
                    }, true);
            }

            break;

            default:
            {
                MapPointLayer mpl = new(fs);
                PointScheme   ps  = new();
                colorTable    = ps.GenerateUniqueColors(fs, fieldName);
                mpl.Symbology = ps;

                // first draw the normal colors and then the selection colors on top
                mpl.DrawRegions(args, new List <Extent> {
                        env
                    }, false);
                mpl.DrawRegions(args, new List <Extent> {
                        env
                    }, true);
            }

            break;
            }

            Type tp = fieldName == "FID" ? typeof(int) : fs.DataTable.Columns[fieldName].DataType;

            // We will try to convert to double if it is a string
            if (tp == typeof(string))
            {
                tp = typeof(double);
            }

            InRamImageData image = new(bmp, env);
            ProgressMeter  pm    = new(progressHandler, "Converting To Raster Cells", h);

            var output = Raster.Create(outputFileName, driverCode, w, h, 1, tp, options);

            output.Bounds = new RasterBounds(h, w, env);

            double noDataValue = output.NoDataValue;

            if (fieldName != "FID")
            {
                // We can't use this method to calculate Max on a non-existent FID field.
                double dtMax = Convert.ToDouble(fs.DataTable.Compute("Max(" + fieldName + ")", string.Empty));
                double dtMin = Convert.ToDouble(fs.DataTable.Compute("Min(" + fieldName + ")", string.Empty));

                if (dtMin <= noDataValue && dtMax >= noDataValue)
                {
                    if (dtMax != GetFieldValue(tp, "MaxValue"))
                    {
                        output.NoDataValue = noDataValue;
                    }
                    else if (dtMin != GetFieldValue(tp, "MinValue"))
                    {
                        output.NoDataValue = noDataValue;
                    }
                }
            }

            List <RcIndex> locations   = new();
            List <string>  failureList = new();

            for (int row = 0; row < h; row++)
            {
                for (int col = 0; col < w; col++)
                {
                    Color c = image.GetColor(row, col);
                    if (c.A == 0)
                    {
                        output.Value[row, col] = output.NoDataValue;
                    }
                    else
                    {
                        if (colorTable.ContainsKey(c) == false)
                        {
                            if (c.A < 125)
                            {
                                output.Value[row, col] = output.NoDataValue;
                                continue;
                            }

                            // Use a color matching distance to pick the closest member
                            object val = GetCellValue(w, h, row, col, image, c, colorTable, locations);

                            output.Value[row, col] = GetDouble(val, failureList);
                        }
                        else
                        {
                            output.Value[row, col] = GetDouble(colorTable[c], failureList);
                        }
                    }
                }

                pm.CurrentValue = row;
            }

            const int MaxIterations = 5;
            int       iteration     = 0;

            while (locations.Count > 0)
            {
                List <RcIndex> newLocations = new();
                foreach (RcIndex location in locations)
                {
                    object val = GetCellValue(w, h, location.Row, location.Column, image, image.GetColor(location.Row, location.Column), colorTable, newLocations);
                    output.Value[location.Row, location.Column] = GetDouble(val, failureList);
                }

                locations = newLocations;
                iteration++;
                if (iteration > MaxIterations)
                {
                    break;
                }
            }

            pm.Reset();
            return(output);
        }
Esempio n. 57
0
 /// <summary>
 /// Calculates the unique colors as a scheme.
 /// </summary>
 /// <param name="fs">The featureset with the data table definition.</param>
 /// <param name="uniqueField">The unique field.</param>
 /// <returns>A hashtable with the generated unique colors.</returns>
 public Hashtable GenerateUniqueColors(IFeatureSet fs, string uniqueField)
 {
     return(GenerateUniqueColors(fs, uniqueField, color => new PolygonCategory(color, color, 1)));
 }
        public static System.Collections.Generic.IEnumerable <IFeature> PointsInPolygon(IFeatureSet polygons, IFeatureSet points,
                                                                                        double bufferPolygon = 0d)
        {
            var sishp = new SpatiallyIndexedFeatureSet(points);

            foreach (var feature in polygons.Features)
            {
                var geom = Topology.Geometry.FromBasicGeometry(feature.BasicGeometry);
                if (bufferPolygon > 0)
                {
                    geom = geom.Buffer(bufferPolygon);
                }

                var candidates = sishp.Intersect(geom);
                foreach (var candidate in candidates)
                {
                    if (geom.Contains(Topology.Geometry.FromBasicGeometry(candidate.BasicGeometry)))
                    {
                        yield return(candidate);
                    }
                }
            }
        }
Esempio n. 59
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PolygonLayer"/> class.
 /// </summary>
 /// <param name="inFeatureSet">A featureset that contains polygons.</param>
 /// <exception cref="PolygonFeatureTypeException">Thrown if a non-polygon featureset is supplied.</exception>
 public PolygonLayer(IFeatureSet inFeatureSet)
     : base(inFeatureSet)
 {
     Configure(inFeatureSet);
 }
Esempio n. 60
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PolygonScheme"/> class.
 /// </summary>
 /// <param name="fs">THe featureset with the data Table definition to use for symbolizing.</param>
 /// <param name="uniqueField">The string name of the field to use
 /// when calculating separate color codes. Unique entries will be
 /// assigned a random color.</param>
 public PolygonScheme(IFeatureSet fs, string uniqueField)
 {
     GenerateUniqueColors(fs, uniqueField);
 }