protected override Collection<Style> GetStylesCore(FeatureSource featureSource)
        {
            // here we generate CustomDotDensityStyle.
            double totalValue = 0;
            featureSource.Open();
            int featureCount = featureSource.GetCount();
            for (int i = 0; i < featureCount; i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double columnValue;

                if (double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue))
                {
                    totalValue += columnValue;
                }
            }
            featureSource.Close();

            CustomDotDensityStyle dotDensityStyle = new CustomDotDensityStyle();
            dotDensityStyle.ColumnName = SelectedColumns[0];
            dotDensityStyle.PointToValueRatio = DotDensityValue / (totalValue / featureCount);
            dotDensityStyle.CustomPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(Opacity, Color), 4);

            return new Collection<Style>() { dotDensityStyle };
        }
        protected override Collection<Style> GetStylesCore(FeatureSource featureSource)
        {
            // here we generated a class break style and a text style.
            Collection<GeoColor> familyColors = GeoColor.GetColorsInQualityFamily(Color, EndColor, classBreakCount, ColorWheelDirection);

            featureSource.Open();
            int featureCount = featureSource.GetCount();
            double[] values = new double[featureCount];
            for (int i = 0; i < featureCount; i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double columnValue;
                if (double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue))
                {
                    values[i] = columnValue;
                }
            }
            featureSource.Close();

            ClassBreakStyle classBreakStyle = new ClassBreakStyle(SelectedColumns[0]) { BreakValueInclusion = BreakValueInclusion.IncludeValue };
            double[] classBreakValues = GetClusterClassBreaks(values, ClassBreakCount - 1);
            for (int i = 0; i < classBreakValues.Length; i++)
            {
                ClassBreak classBreak = new ClassBreak(classBreakValues[i], AreaStyles.CreateSimpleAreaStyle(new GeoColor(this.Opacity, familyColors[i]), GeoColor.FromHtml("#f05133"), 1));
                classBreakStyle.ClassBreaks.Add(classBreak);
            }

            return new Collection<Style>() { classBreakStyle, TextStyles.Country1("NAME") };
        }
コード例 #3
0
        public virtual RoadNetwork CreateNetwork(FeatureSource featureSource)
        {
            featureSource.Open();
            QTreeSpatialIndex qtree = new QTreeSpatialIndex(featureSource.GetBoundingBox());

            #if DEBUG
            long featureCount = featureSource.GetCount();
            #endif

            RoadNetwork roadNetwork = new RoadNetwork();
            Collection<Feature> features = featureSource.GetAllFeatures(ReturningColumnsType.NoColumns);
            featureSource.Close();
            Collection<Collection<Feature>> featureGroups = GroupFeatures(features);
            int done = 0;
            var tasks = (from items in featureGroups
                         select Task.Factory.StartNew(() =>
                         {
                             var clonedFeatureSource = featureSource.CloneDeep();
                             clonedFeatureSource.Open();
                             foreach (var feature in items)
                             {
                                 Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
                                 // Get the lineshape of the processing feature.
                                 foreach (LineShape processingLineShape in processingLineShapes)
                                 {
                                     BuildNetworkNode(clonedFeatureSource, qtree, roadNetwork, processingLineShape.Vertices[0]);
                                     BuildNetworkNode(clonedFeatureSource, qtree, roadNetwork, processingLineShape.Vertices[processingLineShape.Vertices.Count - 1]);
                                 }
                                 done++;
                                 Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, done));
                             }

                         })).ToArray();
            //foreach (Feature feature in features)
            //{
            //    Task.Factory.StartNew(() =>
            //    {
            //        Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
            //        // Get the lineshape of the processing feature.
            //        foreach (LineShape processingLineShape in processingLineShapes)
            //        {
            //            BuildNetworkNode(featureSource, qtree, roadNetwork, processingLineShape.Vertices[0]);
            //            BuildNetworkNode(featureSource, qtree, roadNetwork, processingLineShape.Vertices[processingLineShape.Vertices.Count - 1]);
            //        }
            //    }
            //   );
            Task.WaitAll(tasks);

            #if DEBUG

            #endif

            //}
            //featureSource.Close();

            return roadNetwork;
        }
        protected override Collection<Style> GetStylesCore(FeatureSource featureSource)
        {
            // here we generated the PieZedGraphStyle.
            PieZedGraphStyle zedGraphStyle = new PieZedGraphStyle();
            zedGraphStyle.ZedGraphDrawing += ZedGraphStyle_ZedGraphDrawing;
            pieColors = GeoColor.GetColorsInQualityFamily(GeoColor.FromArgb(Opacity, Color), SelectedColumns.Count);

            for (int i = 0; i < SelectedColumns.Count; i++)
            {
                zedGraphStyle.RequiredColumnNames.Add(SelectedColumns[i]);
                zedGraphStyle.PieSlices.Add(SelectedColumnAliases[i], pieColors[i]);
            }

             return new Collection<Style>(){zedGraphStyle};
        }
        protected override Collection<Style> GetStylesCore(FeatureSource featureSource)
        {
            // here we generate a ValueCircle Style.
            double minValue = double.MaxValue;
            double maxValue = double.MinValue;

            featureSource.Open();
            for (int i = 0; i < featureSource.GetCount(); i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double columnValue;
                if (double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue))
                {
                    if (columnValue < minValue)
                    {
                        minValue = columnValue;
                    }
                    else if (columnValue > maxValue)
                    {
                        maxValue = columnValue;
                    }
                }
            }
            featureSource.Close();

            ValueCircleStyle valueCircleStyle = new ValueCircleStyle();
            valueCircleStyle.ColumnName = SelectedColumns[0];
            valueCircleStyle.DrawingRadiusRatio = radiusRatio;
            valueCircleStyle.MinValidValue = minValue;
            valueCircleStyle.MaxValidValue = maxValue;
            valueCircleStyle.MinCircleAreaInDefaultZoomLevel = 80;
            valueCircleStyle.MaxCircleAreaInDefaultZoomLevel = 10000;
            valueCircleStyle.InnerColor = GeoColor.FromArgb(this.Opacity, Color);
            valueCircleStyle.OuterColor = GeoColor.SimpleColors.White;

            return new Collection<Style>(){valueCircleStyle};
        }
        protected override Collection <Style> GetStylesCore(FeatureSource featureSource)
        {
            // here we generated a class break style and a text style.
            Collection <GeoColor> familyColors = GeoColor.GetColorsInQualityFamily(Color, EndColor, classBreakCount, ColorWheelDirection);

            featureSource.Open();
            int featureCount = featureSource.GetCount();

            double[] values = new double[featureCount];
            for (int i = 0; i < featureCount; i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double  columnValue;
                if (double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue))
                {
                    values[i] = columnValue;
                }
            }
            featureSource.Close();

            ClassBreakStyle classBreakStyle = new ClassBreakStyle(SelectedColumns[0])
            {
                BreakValueInclusion = BreakValueInclusion.IncludeValue
            };

            double[] classBreakValues = GetClusterClassBreaks(values, ClassBreakCount - 1);
            for (int i = 0; i < classBreakValues.Length; i++)
            {
                ClassBreak classBreak = new ClassBreak(classBreakValues[i], AreaStyles.CreateSimpleAreaStyle(new GeoColor(this.Opacity, familyColors[i]), GeoColor.FromHtml("#f05133"), 1));
                classBreakStyle.ClassBreaks.Add(classBreak);
            }

            return(new Collection <Style>()
            {
                classBreakStyle, TextStyles.CreateSimpleTextStyle("NAME", "Arial", 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, GeoColor.StandardColors.White, 3)
            });
        }
コード例 #7
0
        protected override Style GetStyleCore(FeatureSource featureSource)
        {
            double minValue = double.MaxValue;
            double maxValue = double.MinValue;

            featureSource.Open();
            for (int i = 0; i < featureSource.GetCount(); i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double  columnValue;
                if (double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue))
                {
                    if (columnValue < minValue)
                    {
                        minValue = columnValue;
                    }
                    else if (columnValue > maxValue)
                    {
                        maxValue = columnValue;
                    }
                }
            }
            featureSource.Close();

            ValueCircleStyle valueCircleStyle = new ValueCircleStyle();

            valueCircleStyle.ColumnName         = SelectedColumns[0];
            valueCircleStyle.DrawingRadiusRatio = radiusRatio;
            valueCircleStyle.MinValidValue      = minValue;
            valueCircleStyle.MaxValidValue      = maxValue;
            valueCircleStyle.MinCircleAreaInDefaultZoomLevel = 80;
            valueCircleStyle.MaxCircleAreaInDefaultZoomLevel = 10000;
            valueCircleStyle.InnerColor = GeoColor.FromArgb(this.Opacity, Color);
            valueCircleStyle.OuterColor = GeoColor.SimpleColors.White;

            return(valueCircleStyle);
        }
コード例 #8
0
        public Collection <Feature> Clip(FeatureSource featureSource, IEnumerable <Feature> areaBaseShape, ClipType clipMode)
        {
            Collection <Feature> clipedFeatures = new Collection <Feature>();

            switch (clipMode)
            {
            case ClipType.Inverse:
                foreach (var feature in InverseClip(featureSource, areaBaseShape))
                {
                    clipedFeatures.Add(feature);
                }
                break;

            case ClipType.Standard:
            default:
                foreach (var feature in StandardClip(featureSource, areaBaseShape))
                {
                    clipedFeatures.Add(feature);
                }
                break;
            }

            return(clipedFeatures);
        }
コード例 #9
0
        public static void SafeProcess(this FeatureSource featureSource, Action process)
        {
            bool isClosed = false;

            if (!featureSource.IsOpen)
            {
                featureSource.Open();
                isClosed = true;
            }

            if (process != null)
            {
                process();
            }

            if (isClosed)
            {
                featureSource.Close();
                if (featureSource.Projection != null)
                {
                    featureSource.Projection.Close();
                }
            }
        }
コード例 #10
0
        protected override Collection <Style> GetStylesCore(FeatureSource featureSource)
        {
            Collection <GeoColor> familyColors = GeoColor.GetColorsInQualityFamily(Color, EndColor, classBreakCount, ColorWheelDirection);

            featureSource.Open();
            int featureCount = featureSource.GetCount();

            double[] values = new double[featureCount];
            for (int i = 0; i < featureCount; i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double  columnValue;
                double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue);
                values[i] = columnValue;
            }
            featureSource.Close();

            ClassBreakStyle classBreakStyle = new ClassBreakStyle(SelectedColumns[0])
            {
                BreakValueInclusion = BreakValueInclusion.IncludeValue
            };

            double[] classBreakValues = GetClusterClassBreaks(values, ClassBreakCount - 1);
            for (int i = 0; i < classBreakValues.Length; i++)
            {
                ClassBreak classBreak = new ClassBreak(classBreakValues[i], AreaStyles.CreateSimpleAreaStyle(new GeoColor(this.Opacity, familyColors[i]), GeoColor.FromHtml("#f05133"), 1));
                classBreakStyle.ClassBreaks.Add(classBreak);
            }

            TextStyle textStyle = TextStyles.Country1("NAME");

            return(new Collection <Style>()
            {
                classBreakStyle, textStyle
            });
        }
コード例 #11
0
        private static void GetAdjacentFeataureIds(FeatureSource featureSource, LineShape sourceShape, Collection <string> startIds, Collection <string> endIds)
        {
            Vertex startVertex = sourceShape.Vertices[0];
            Vertex endVertex   = sourceShape.Vertices[sourceShape.Vertices.Count - 1];
            Collection <Feature> tempfeatures = featureSource.GetFeaturesInsideBoundingBox(sourceShape.GetBoundingBox(), ReturningColumnsType.NoColumns);

            foreach (Feature tempFeature in tempfeatures)
            {
                LineShape tempShape = ((MultilineShape)tempFeature.GetShape()).Lines[0];
                if (sourceShape.Id == tempFeature.Id)
                {
                    continue;
                }

                if (tempShape.Vertices.Contains(startVertex))
                {
                    startIds.Add(tempFeature.Id);
                }
                else if (tempShape.Vertices.Contains(endVertex))
                {
                    endIds.Add(tempFeature.Id);
                }
            }
        }
コード例 #12
0
        private static Feature ConvertToExternalProjection(Feature feature, FeatureSource featureSource)
        {
            //Validators.CheckParameterIsNotNull(feature, "feature");

            Feature newFeature = feature;

            if (featureSource.Projection != null)
            {
                try
                {
                    newFeature = featureSource.Projection.ConvertToExternalProjection(feature);
                }
                catch
                {
                    if (!feature.IsValid() && feature.CanMakeValid)
                    {
                        feature    = feature.MakeValid();
                        newFeature = featureSource.Projection.ConvertToExternalProjection(feature);
                    }
                }
            }

            return(newFeature);
        }
コード例 #13
0
ファイル: support.cs プロジェクト: gisdevelope/MercuryGIS
        /// <summary>
        /// 用户向已有gdb中添加一个新的图层,该图层必须已存在shp文件
        /// 向该mapcontent中添加一个layer
        /// </summary>
        /// <param name="gdb"></param>
        /// <param name="layerpath"></param>
        /// <param name="stylepath"></param>
        /// <returns></returns>
        public string addLayer(string layerpath, string stylepath, string guid, string layername)
        {
            if (layerpath == null)
            {
                return(null);
            }
            FeatureSource featuresource = null;
            PGGeoDatabase gdb           = (PGGeoDatabase)this.gdb;

            //string layername =
            gdb.AddSHPFeatureSource(layerpath, guid);
            if (!this.gdb.featureSources.TryGetValue(guid, out featuresource))
            {
                return(null);
            }
            Style style = null;

            try
            {
                if (stylepath != null)
                {
                    style = Style.parseStyleFile(stylepath);
                }
            }
            catch (Exception e)
            {
            }
            if (style == null)
            {
                style = Style.createSimpleStyle(featuresource);
            }
            Layer layer = new Layer(layername, featuresource, style);

            this.layerlist.Insert(0, layer);
            return(layername);
        }
コード例 #14
0
        private bool TryParseParameters(Dictionary <string, string> parameters)
        {
            string[] parameterNames =
            {
                "OutputPath",
                "Wkt",
                "MatchColumns",
                "OperatorPairs",
                "FeatureSourceXml"
            };

            bool allExist = parameterNames.All(name => parameters.ContainsKey(name));

            if (allExist)
            {
                outputPath    = parameters[parameterNames[0]];
                Wkt           = parameters[parameterNames[1]];
                matchColumns  = GetMatchColumnsFromString(parameters[parameterNames[2]]);
                operatorPairs = GetOperatorPairsFromString(parameters[parameterNames[3]]);
                featureSource = GetFeatureSourceFromString(parameters[parameterNames[4]]);
            }

            return(allExist);
        }
コード例 #15
0
        private void WriteFeaturesIntoQueue(Collection <Feature> features, FeatureSource featureSource)
        {
            foreach (Feature feature in features)
            {
                Collection <LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
                // Get the lineshape of the processing feature.
                foreach (LineShape processingLineShape in processingLineShapes)
                {
                    // Define a variable to save the points where the adjacent lines intersect with current processing line.
                    Collection <PointShape> crossingPoints = new Collection <PointShape>();

                    // Get all the lines in current processing shape bounds.
                    Collection <Feature> adjacentFeatures = featureSource.GetFeaturesInsideBoundingBox(processingLineShape.GetBoundingBox(), ReturningColumnsType.NoColumns);

                    // Loop and see if the queried shape is intersected with processing shape.
                    foreach (Feature adjacentFeature in adjacentFeatures)
                    {
                        LineBaseShape   adjacentLineShape  = adjacentFeature.GetShape() as LineBaseShape;
                        MultipointShape tempCrossingPoints = processingLineShape.GetCrossing(adjacentLineShape);

                        // The queried shape is intersected with processing shape.
                        foreach (PointShape point in tempCrossingPoints.Points)
                        {
                            bool hasAdded = false;
                            foreach (var item in crossingPoints)
                            {
                                if (point.X == item.X && point.Y == item.Y)
                                {
                                    hasAdded = true;
                                    break;
                                }
                            }
                            if (!hasAdded)
                            {
                                crossingPoints.Add(point);
                            }
                        }
                    }

                    // Order the crossing points following the sequence of line vertex.
                    Collection <FlagedVertex> vertecesOfNewLine = GeometryHelper.AddCrossingPointToLine(processingLineShape, crossingPoints);
                    Collection <Vertex>       verteces          = new Collection <Vertex>();
                    Collection <Feature>      lineFeatures      = new Collection <Feature>();
                    foreach (var vertex in vertecesOfNewLine)
                    {
                        verteces.Add(vertex.Vertex);
                        if (vertex.Flag)
                        {
                            if (verteces.Count >= 2)
                            {
                                LineShape segment = new LineShape(verteces);
                                lineFeatures.Add(new Feature(segment, feature.ColumnValues));
                                verteces.RemoveAt(0);
                            }
                        }
                    }
                    if (lineFeatures.Count > 0)
                    {
                        queue.Enqueue(lineFeatures);
                    }
                }

#if DEBUG
                Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, features.Count));
#endif
            }
        }
コード例 #16
0
 public Collection <Style> GetStyles(FeatureSource featureSource)
 {
     return(GetStylesCore(featureSource));
 }
コード例 #17
0
 private FeatureSource CombineWith(FeatureSource source) =>
 new CompoundFeatureSource(source, SpecData.FeatureSource);
コード例 #18
0
        private void WriteFeaturesIntoQueue(Collection<Feature> features, FeatureSource featureSource)
        {
            foreach (Feature feature in features)
            {
                Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
                // Get the lineshape of the processing feature.
                foreach (LineShape processingLineShape in processingLineShapes)
                {
                    // Define a variable to save the points where the adjacent lines intersect with current processing line.
                    Collection<PointShape> crossingPoints = new Collection<PointShape>();

                    // Get all the lines in current processing shape bounds.
                    Collection<Feature> adjacentFeatures = featureSource.GetFeaturesInsideBoundingBox(processingLineShape.GetBoundingBox(), ReturningColumnsType.NoColumns);

                    // Loop and see if the queried shape is intersected with processing shape.
                    foreach (Feature adjacentFeature in adjacentFeatures)
                    {
                        LineBaseShape adjacentLineShape = adjacentFeature.GetShape() as LineBaseShape;
                        MultipointShape tempCrossingPoints = processingLineShape.GetCrossing(adjacentLineShape);

                        // The queried shape is intersected with processing shape.
                        foreach (PointShape point in tempCrossingPoints.Points)
                        {
                            bool hasAdded = false;
                            foreach (var item in crossingPoints)
                            {
                                if (point.X == item.X && point.Y == item.Y)
                                {
                                    hasAdded = true;
                                    break;
                                }
                            }
                            if (!hasAdded)
                            {
                                crossingPoints.Add(point);
                            }
                        }
                    }

                    // Order the crossing points following the sequence of line vertex.
                    Collection<FlagedVertex> vertecesOfNewLine = GeometryHelper.AddCrossingPointToLine(processingLineShape, crossingPoints);
                    Collection<Vertex> verteces = new Collection<Vertex>();
                    Collection<Feature> lineFeatures = new Collection<Feature>();
                    foreach (var vertex in vertecesOfNewLine)
                    {
                        verteces.Add(vertex.Vertex);
                        if (vertex.Flag)
                        {
                            if (verteces.Count >= 2)
                            {
                                LineShape segment = new LineShape(verteces);
                                lineFeatures.Add(new Feature(segment, feature.ColumnValues));
                                verteces.RemoveAt(0);
                            }
                        }
                    }
                    if (lineFeatures.Count > 0)
                    {
                        queue.Enqueue(lineFeatures);
                    }
                }

            #if DEBUG
                Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, features.Count));
            #endif
            }
        }
コード例 #19
0
        private Collection<Feature> GetAdjacentFeaturesOfVertex(FeatureSource featureSource, Vertex vertex)
        {
            RectangleShape startSmallBounds = GeometryHelper.CreateSmallRectangle(vertex, tolerance);
            // Get all the lines in current processing shape bounds.
            Collection<Feature> adjacentFeatures = featureSource.GetFeaturesInsideBoundingBox(startSmallBounds, ReturningColumnsType.AllColumns);

            return adjacentFeatures;
        }
コード例 #20
0
        private void BuildNetworkNode(FeatureSource featureSource, QTreeSpatialIndex qtree, RoadNetwork roadNetwork, Vertex vertex)
        {
            RectangleShape startSmallBounds = GeometryHelper.CreateSmallRectangle(vertex, tolerance);

            Collection<string> idsInside = qtree.GetFeatureIdsIntersectingBoundingBox(startSmallBounds);

            if (idsInside.Count <= 0)
            {
                Node startNode = CreateNode(featureSource, roadNetwork, vertex);
                roadNetwork.Nodes.Add(startNode);
                qtree.Add(new PointShape(vertex));
            }
        }
コード例 #21
0
 public SimpleFeatureSelector(FeatureSource source)
 {
     this.source = source;
 }
コード例 #22
0
        public static void ProcessTransaction(RectangleShape boundingBox, Collection <Feature> returnFeatures, FeatureSource featureSource, bool needUpdateProjection = false)
        {
            if (featureSource.IsInTransaction && featureSource.IsTransactionLive)
            {
                foreach (Feature feature in featureSource.TransactionBuffer.AddBuffer.Values)
                {
                    if (boundingBox.Intersects(feature.GetBoundingBox()))
                    {
                        var newFeature = needUpdateProjection ? ConvertToExternalProjection(feature, featureSource) : feature;
                        returnFeatures.Add(newFeature);
                    }
                }

                Dictionary <string, Feature> recordsInDictionary = new Dictionary <string, Feature>();
                if (featureSource.TransactionBuffer.EditBuffer.Count > 0 || featureSource.TransactionBuffer.DeleteBuffer.Count > 0)
                {
                    recordsInDictionary = GetFeaturesDictionaryFromCollecion(returnFeatures);
                }

                foreach (Feature feature in featureSource.TransactionBuffer.EditBuffer.Values)
                {
                    bool isContained = boundingBox.Intersects(feature.GetBoundingBox());
                    if (isContained)
                    {
                        if (recordsInDictionary.ContainsKey(feature.Id))
                        {
                            Feature oringalFeature = recordsInDictionary[feature.Id];
                            returnFeatures.Remove(oringalFeature);
                        }

                        var newFeature = needUpdateProjection ? ConvertToExternalProjection(feature, featureSource) : feature;
                        returnFeatures.Add(newFeature);
                    }
                    else if (!isContained && recordsInDictionary.ContainsKey(feature.Id))
                    {
                        Feature oringalFeature = recordsInDictionary[feature.Id];
                        returnFeatures.Remove(oringalFeature);
                    }
                }

                foreach (string id in featureSource.TransactionBuffer.DeleteBuffer)
                {
                    if (recordsInDictionary.ContainsKey(id))
                    {
                        if (boundingBox.Intersects(recordsInDictionary[id].GetBoundingBox()) && recordsInDictionary.ContainsKey(id))
                        {
                            Feature feature = recordsInDictionary[id];
                            returnFeatures.Remove(feature);
                        }
                    }
                }
            }
        }
コード例 #23
0
        public static void RemoveEmptyAndExcludeFeatures(Collection <Feature> sourceFeatures, FeatureSource featureSource)
        {
            Collection <int> features = new Collection <int>();

            for (int i = 0; i < sourceFeatures.Count; i++)
            {
                if (sourceFeatures[i] == null || sourceFeatures[i].GetWellKnownBinary() == null || sourceFeatures[i].GetWellKnownBinary().Length == 0 || featureSource.FeatureIdsToExclude.Contains(sourceFeatures[i].Id))
                {
                    features.Add(i);
                }
            }

            for (int i = features.Count - 1; i >= 0; i--)
            {
                sourceFeatures.RemoveAt(features[i]);
            }
        }
コード例 #24
0
        public static RectangleShape ConvertToInternalProjectionCall(RectangleShape rectangle, FeatureSource featureSource)
        {
            RectangleShape newRectangle = rectangle;

            if (featureSource.Projection != null)
            {
                newRectangle = featureSource.Projection.ConvertToInternalProjection(newRectangle);
            }

            return(newRectangle);
        }
コード例 #25
0
        private static Collection <Feature> ConvertToExternalProjection(IEnumerable <Feature> features, FeatureSource featureSource)
        {
            //Validators.CheckParameterIsNotNull(features, "features");

            Collection <Feature> returnFeatures = new Collection <Feature>();

            foreach (Feature feature in features)
            {
                if (feature.GetWellKnownBinary().Length != 0)
                {
                    returnFeatures.Add(ConvertToExternalProjection(feature, featureSource));
                }
                else
                {
                    returnFeatures.Add(feature);
                }
            }

            return(returnFeatures);
        }
コード例 #26
0
        private IEnumerable <Feature> StandardClip(FeatureSource featureSource, IEnumerable <Feature> features)
        {
            lock (featureSource)
            {
                Collection <Feature> results = new Collection <Feature>();

                //There is a bug about projection boundingbox, here is a workaround for it.
                bool       isOpen        = false;
                Projection tmpProjection = null;
                if (featureSource.Projection != null &&
                    featureSource.Projection is GISEditorManagedProj4Projection &&
                    ((GISEditorManagedProj4Projection)featureSource.Projection).IsProjectionParametersEqual)
                {
                    tmpProjection = featureSource.Projection;
                    if (featureSource.IsOpen)
                    {
                        featureSource.Close();
                        featureSource.Projection.Close();
                        isOpen = true;
                    }
                    featureSource.Projection = null;
                }

                if (!featureSource.IsOpen)
                {
                    featureSource.Open();
                }
                Collection <Feature> sourceFeatures = featureSource.GetFeaturesInsideBoundingBox(ExtentHelper.GetBoundingBoxOfItems(features), ReturningColumnsType.AllColumns);

                if (tmpProjection != null)
                {
                    featureSource.Projection = tmpProjection;
                    if (isOpen)
                    {
                        featureSource.Open();
                    }
                }

                ShapeFileType shapeFileType = ((ShapeFileFeatureSource)featureSource).GetShapeFileType();
                if (featureSource.IsOpen)
                {
                    featureSource.Close();
                }

                int index = 1;
                int count = sourceFeatures.Count;
                if (shapeFileType == ShapeFileType.Point || shapeFileType == ShapeFileType.Multipoint)
                {
                    return(StandardClipPoints(sourceFeatures, features, shapeFileType));
                }
                else if (shapeFileType == ShapeFileType.Polyline)
                {
                    MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(features));
                    foreach (var feature in sourceFeatures)
                    {
                        ReportProgress(index * 100 / count);
                        index++;
                        try
                        {
                            if (areaBaseShape.Contains(feature))
                            {
                                results.Add(feature);
                            }
                            else
                            {
                                var clippedShape = ((LineBaseShape)feature.GetShape()).GetIntersection(areaBaseShape);
                                if (clippedShape != null && clippedShape.Lines.Count > 0)
                                {
                                    results.Add(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    }
                }
                else if (shapeFileType == ShapeFileType.Polygon)
                {
                    MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(features));
                    foreach (var feature in sourceFeatures)
                    {
                        ReportProgress(index * 100 / count);
                        try
                        {
                            index++;
                            if (areaBaseShape.Contains(feature))
                            {
                                results.Add(feature);
                            }
                            else
                            {
                                var clippedShape = areaBaseShape.GetIntersection(feature);
                                if (clippedShape != null && clippedShape.Polygons.Count > 0)
                                {
                                    results.Add(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException("The ShapeFileType is not supported.");
                }
                return(results);
            }
        }
コード例 #27
0
        private Collection <string> GetRequiredColumnNamesForLink(IEnumerable <string> returningColumnNames, FeatureSource featureSource)
        {
            //IEnumerable<string> requiredLinkColumnNames = GetRequiredLinkColumnNames(featureSource);
            //IEnumerable<string> tempColumnNames = returningColumnNames
            //    .Where(c => !requiredLinkColumnNames.Contains(c.ToUpperInvariant()))
            //    .Concat(requiredLinkColumnNames)
            //    .Distinct();

            Collection <string> resultColumnNames = new Collection <string>();

            returningColumnNames.ForEach(columnName => resultColumnNames.Add(columnName));
            return(resultColumnNames);
        }
コード例 #28
0
ファイル: support.cs プロジェクト: gisdevelope/MercuryGIS
 public Layer(string layername, FeatureSource featuresource, Style style)
 {
     this.layername     = layername;
     this.featuresource = featuresource;
     this.style         = style;
 }
コード例 #29
0
        /////////////////////////////////////////////////////////////////////////////////////////////
        // create a shapefile
        public IFeatureClass CreateShapefile(string strShapeFolder, FeatureSource selLayer, string shpFileName)
        {
            Console.WriteLine(shpFileName);

            // prepared the shapefile fodler
            try
            {
                if (!System.IO.Directory.Exists(strShapeFolder))
                    System.IO.Directory.CreateDirectory(strShapeFolder);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            // if shapefile already exists, overwrite?
            string shpfileName = strShapeFolder + "\\" + shpFileName + ".shp";
            string dbffileName = strShapeFolder + "\\" + shpFileName + ".dbf";
            string shxfileName = strShapeFolder + "\\" + shpFileName + ".shx";
            if (File.Exists(shpfileName) || File.Exists(dbffileName) || File.Exists(shxfileName))
            {
                if (MessageBox.Show("shape file: " + strShapeFolder + "\\" + selLayer.Name + " already exists", "overwrite?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    return null;
                else
                {
                    File.Delete(shpfileName);
                    File.Delete(dbffileName);
                    File.Delete(shxfileName);
                }
            }

            // create workspace
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(strShapeFolder, 0);

            // get the feature table
            FeatureDataTable ftable = selLayer.GetDataTable();
            int rowCount = ftable.Rows.Count;
            int colCount = ftable.Columns.Count;
            int geometryColIndex = ftable.GeometryColumnIndex;

            // create fields
            //fields
            ESRI.ArcGIS.Geodatabase.IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
            pFieldsEdit.FieldCount_2 = colCount;
            Console.WriteLine("Colume Counts = " + colCount.ToString());

            //field
            IField pField;
            IFieldEdit pFieldEdit;
            string shpFldName = "";

            for (int col = 0; col < colCount; col++)
            {
                DataColumn dc = ftable.Columns[col];
                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;

                String colname = dc.ColumnName;
                if (colname.Length > 10)
                {
                    colname = colname.Substring(0, 8) + col.ToString();
                }

                pFieldEdit.AliasName_2 = colname;
                pFieldEdit.Name_2 = colname;
                pFieldEdit.IsNullable_2 = true;
                pFieldEdit.Editable_2 = true;

                Type dt = dc.DataType;
                Console.WriteLine(dc.ColumnName + "\t\t" + colname + "\t\t" + dt.ToString());

                if (dt == typeof(String))
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;

                else if ((dt == typeof(Boolean)))
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                else if ((dt == typeof(Int16)) || (dt == typeof(Int32)) || (dt == typeof(Int64)))
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                else if (dt == typeof(Double))
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                else if (dt == typeof(Single))
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeSingle;
                else if (dt == typeof(DateTime))
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate;
                else if (dt == typeof(Guid))
                    //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGUID;    // not supported by shapefile
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                else if (dt == typeof(ESRI.ArcGIS.Mobile.GlobalId))
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGlobalID;  // not supported by shapefile

                else if (dt == typeof(Bitmap))   // raster or blob, not supported by shapefile,
                {
                    Console.WriteLine(dc.ColumnName + ": raster field found\n");
                    string folder = strShapeFolder + "\\" + dc.ColumnName;
                    try
                    {
                        if (!Directory.Exists(folder))
                            Directory.CreateDirectory(folder);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        return null;
                    }
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                }
                else if (dt == typeof(System.Byte[]))   // raster or blob, not supported by shapefile,
                {
                    Console.WriteLine(dc.ColumnName + ": blob field found\n");
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                }
                else if (dt == typeof(Bitmap))   // raster or blob, not supported by shapefile,
                {
                    Console.WriteLine(dc.ColumnName + ": raster field found\n");
                    string folder = strShapeFolder + "\\" + dc.ColumnName;
                    try
                    {
                        if (!Directory.Exists(folder))
                            Directory.CreateDirectory(folder);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        return null;
                    }

                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                }
                else if (dt == typeof(System.Byte[]))   // raster or blob, not supported by shapefile,
                {
                    Console.WriteLine(dc.ColumnName + ": blob field found\n");
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                }
                else if (dt == typeof(ESRI.ArcGIS.Mobile.Geometries.Geometry))
                {
                    Console.WriteLine("geometry field found\n");
                    shpFldName = dc.ColumnName;
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                    IGeometryDef pGeoDef = new GeometryDefClass();
                    IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
                    pGeoDefEdit.GeometryType_2 = (ESRI.ArcGIS.Geometry.esriGeometryType)selLayer.GeometryType;
                    pGeoDefEdit.SpatialReference_2 = new ESRI.ArcGIS.Geometry.UnknownCoordinateSystemClass();
                    pFieldEdit.GeometryDef_2 = pGeoDef;
                }

                else
                {
                    throw (new Exception("different data type found, modify the code"));
                }

                // add the field to fields
                pFieldsEdit.set_Field(col, pFieldEdit);
            }

            for (int ii = 0; ii < pFields.FieldCount; ii++)
            {
                Console.WriteLine(pFields.get_Field(ii).Name + "\t\t" + pFields.get_Field(ii).Type.ToString());
            }

            //create shapefile
            IFeatureClass fc = null;
            try
            {
                fc = pWS.CreateFeatureClass(shpFileName, pFields, null, null, esriFeatureType.esriFTSimple, shpFldName, "");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

            if (fc != null)
                return fc;
            else
                return null;
        }
コード例 #30
0
        public virtual void ImportData(FeatureSource featureSourceForRead, FeatureSource featureSourceForSave)
        {
            bool readCompleted = false;
            featureSourceForRead.Open();
            featureSourceForSave.Open();
            #if DEBUG
            long featureCount = featureSourceForRead.GetCount();
            #endif
            Collection<Feature> features = featureSourceForRead.GetAllFeatures(ReturningColumnsType.AllColumns);
            Collection<Collection<Feature>> featureGroups = GroupFeatures(features);
            var writeTasks = (from items in featureGroups
                              select Task.Factory.StartNew(() => WriteFeaturesIntoQueue(items, featureSourceForRead))).ToArray();

            var readTask = Task.Factory.StartNew(() =>
            {
                while (!readCompleted || queue.Count > 0)
                {
                    while (queue.Count > 0)
                    {
                        Collection<Feature> lineFeatures = queue.Dequeue();
                        SaveFeatures(lineFeatures, featureSourceForSave);
                    }
                }
            });

            Task.WaitAll(writeTasks);
            readCompleted = true;
            Task.WaitAny(readTask);
            #region Old version
            //foreach (Feature feature in features)
            //{
            //    Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
            //    // Get the lineshape of the processing feature.
            //    foreach (LineShape processingLineShape in processingLineShapes)
            //    {
            //        // Define a variable to save the points where the adjacent lines intersect with current processing line.
            //        Collection<PointShape> crossingPoints = new Collection<PointShape>();

            //        // Get all the lines in current processing shape bounds.
            //        Collection<Feature> adjacentFeatures = featureSourceForRead.GetFeaturesInsideBoundingBox(processingLineShape.GetBoundingBox(), ReturningColumnsType.NoColumns);

            //        // Loop and see if the queried shape is intersected with processing shape.
            //        foreach (Feature adjacentFeature in adjacentFeatures)
            //        {
            //            LineBaseShape adjacentLineShape = adjacentFeature.GetShape() as LineBaseShape;
            //            MultipointShape tempCrossingPoints = processingLineShape.GetCrossing(adjacentLineShape);

            //            // The queried shape is intersected with processing shape.
            //            foreach (PointShape point in tempCrossingPoints.Points)
            //            {
            //                bool hasAdded = false;
            //                foreach (var item in crossingPoints)
            //                {
            //                    if (point.X == item.X && point.Y == item.Y)
            //                    {
            //                        hasAdded = true;
            //                        break;
            //                    }
            //                }
            //                if (!hasAdded)
            //                {
            //                    crossingPoints.Add(point);
            //                }
            //            }
            //        }

            //        // Order the crossing points following the sequence of line vertex.
            //        Collection<FlagedVertex> vertecesOfNewLine = GeometryHelper.AddCrossingPointToLine(processingLineShape, crossingPoints);

            //        // Split current processing lineshape into segments.
            //        featureSourceForSave.BeginTransaction();
            //        Collection<Vertex> verteces = new Collection<Vertex>();
            //        foreach (var vertex in vertecesOfNewLine)
            //        {
            //            verteces.Add(vertex.Vertex);
            //            if (vertex.Flag)
            //            {
            //                if (verteces.Count >= 2)
            //                {
            //                    LineShape segment = new LineShape(verteces);
            //                    featureSourceForSave.AddFeature(new Feature(segment, feature.ColumnValues));

            //                    verteces.RemoveAt(0);
            //                }
            //            }
            //        }
            //        featureSourceForSave.CommitTransaction();
            //    }

            //#if DEBUG
            //Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, featureCount));
            //#endif
            //}

            #endregion
            featureSourceForRead.Close();
            featureSourceForSave.Close();
        }
 public EarthquakeHeatFeatureLayer(FeatureSource featureSource)
     : base()
 {
     FeatureSource = featureSource;
 }
コード例 #32
0
        private Node CreateNode(FeatureSource featureSource, RoadNetwork roadNetwork, Vertex vertex)
        {
            // Create node based on vertex.
            // Todo: check if it has been existed.
            Collection<Feature> adjacentTailNodeFeatures = GetAdjacentFeaturesOfVertex(featureSource, vertex);
            Node tailNode = InitializeNodeFromVeterx(vertex, adjacentTailNodeFeatures);
            roadNetwork.Nodes.Add(tailNode);

            // Loop and see if the queried shape is intersected with processing shape.
            foreach (Feature adjacentTailNodeFeature in adjacentTailNodeFeatures)
            {
                // Given the adjacent line is line shape, and create adjacent list without un-direction consideration.
                LineShape adjacentLineShape = GeometryHelper.GetLineShapes(adjacentTailNodeFeature)[0];
                adjacentLineShape.Id = adjacentTailNodeFeature.Id;

                // Check if it's start vertext or end vertex of the adjacent line shape.
                int vertexIndex = 0;
                if (GeometryHelper.IsSamePoint(vertex, adjacentLineShape.Vertices[adjacentLineShape.Vertices.Count - 1], tolerance))
                {
                    vertexIndex = adjacentLineShape.Vertices.Count - 1;
                }

                // Todo: check if it has been existed.
                Collection<Feature> adjacentHeadNodeFeatures = GetAdjacentFeaturesOfVertex(featureSource, adjacentLineShape.Vertices[vertexIndex]);
                Node headNode = InitializeNodeFromVeterx(adjacentLineShape.Vertices[vertexIndex], adjacentHeadNodeFeatures);
                roadNetwork.Nodes.Add(headNode);

                Arc adjacentArc = new Arc(adjacentTailNodeFeature.Id, headNode, tailNode, CalculateRoadCost(adjacentLineShape));

                // Check if the direction is the allowed of current segment?
                RoadDirection roadDirection = CalculateRoadDirection(adjacentTailNodeFeature, adjacentLineShape, vertex);
                if (roadDirection == RoadDirection.Forward)
                {
                    tailNode.OutgoingArcs.Add(adjacentArc);
                }
                else if (roadDirection == RoadDirection.Backward)
                {
                    tailNode.IncomingArcs.Add(adjacentArc);
                }
            }

            return tailNode;
        }
コード例 #33
0
ファイル: PostGisIO.cs プロジェクト: gisdevelope/MercuryGIS
        //指定表名读出成一个FeatureSource
        public FeatureSource ReadFromTable(string table)
        {
            string connStr = "Server=" + server + ";Port=" + port + ";UserId=" + user + ";Password="******";Database=" + database + ";";

            try
            {
                //获得图层类型和参考坐标系
                Dictionary <string, string> dt1          = GetSchemePara(table);
                OSGeo.OGR.wkbGeometryType   geometryType = String2Type.String2wkbGeometryType(dt1["type"]);
                ReferenceSystem             rs           = new SRS(new OSGeo.OSR.SpatialReference(Int2SRText(int.Parse(dt1["srid"]))));

                NpgsqlConnection conn = new NpgsqlConnection(connStr);
                conn.Open();
                IDbCommand dbcmd = conn.CreateCommand();
                dbcmd.CommandText = "SELECT *,ST_AsText(geom) AS geom1 FROM \"" + table + "\"";
                IDataReader dr = dbcmd.ExecuteReader();

                Dictionary <string, OSGeo.OGR.FieldDefn> fields = new Dictionary <string, OSGeo.OGR.FieldDefn>();
                string[] fieldNames = new string[dr.FieldCount - 2];
                for (int i = 0; i < dr.FieldCount - 2; i++)
                {
                    OSGeo.OGR.FieldDefn d = GetFieldDefn(dr.GetName(i), dr.GetDataTypeName(i));
                    fields.Add(dr.GetName(i), d);
                    fieldNames[i] = dr.GetName(i);
                }

                Schema schema = new Schema(table, geometryType, rs, fields);

                List <Feature> flst = new List <Feature>();
                while (dr.Read())
                {
                    int featureID = int.Parse(dr[0].ToString());
                    Geometry.Geometry           geometry   = WKT2Feature.WKT2Geometry(dr[dr.FieldCount - 1].ToString());
                    Dictionary <string, Object> attributes = new Dictionary <string, object>();
                    for (int i = 0; i < dr.FieldCount - 2; i++)
                    {
                        Object o;
                        switch (fields[fieldNames[i]].GetFieldType())
                        {
                        case OSGeo.OGR.FieldType.OFTInteger:
                            o = int.Parse(dr[i].ToString());
                            break;

                        case OSGeo.OGR.FieldType.OFTReal:
                            o = double.Parse(dr[i].ToString());
                            break;

                        default:
                            o = dr[i].ToString();
                            break;
                        }
                        attributes.Add(fieldNames[i], o);
                    }
                    Feature feature = new Feature(featureID, schema, geometry, attributes);
                    flst.Add(feature);
                }

                FeatureCollection fc = new FeatureCollection(flst);
                FeatureSource     fs = new FeatureSource(schema, fc);
                return(fs);

                conn.Close();
            }
            catch (Exception e)
            {
                return(null);
            }
        }
コード例 #34
0
 private void SaveFeatures(Collection<Feature> features, FeatureSource featureSource)
 {
     featureSource.BeginTransaction();
     foreach (var feature in features)
     {
         featureSource.AddFeature(feature);
     }
     featureSource.CommitTransaction();
 }
コード例 #35
0
 protected abstract Collection<Style> GetStylesCore(FeatureSource featureSource);
コード例 #36
0
 public VectorOverlay()
 {
     FeatureSource = new FeatureSource();
     ZoomLevelSet = new ZoomLevelSet();
 }
コード例 #37
0
        void layersMenuHandler(object sender, EventArgs e)
        {
            // unchecks the last selected layer
            if (currentLayerMenuItem != null)
                currentLayerMenuItem.CheckState = CheckState.Unchecked;

            // sets selected layer to the current one
            currentLayerMenuItem = sender as ToolStripMenuItem;
            currentLayerMenuItem.CheckState = CheckState.Checked;
            selLayerName = sender.ToString();
             selLayer = mobileCache1.FeatureSources[selLayerName] as FeatureSource;

            selectionMapAction1.SelectionFeatureSources.Clear();
            selectionMapAction1.SelectionFeatureSources.Add(selLayer);

            int originalcount = selLayer.GetFeatureCount(EditState.Original);
            int addedcount = selLayer.GetFeatureCount(EditState.Added);
            int modifiedcount = selLayer.GetFeatureCount(EditState.Modified);
            int deletedcount = selLayer.GetFeatureCount(EditState.Deleted);
            int currentcount = selLayer.GetFeatureCount(EditState.Current);

            // message on the status bar
            layerToolStripStatusLabel.Text = selLayerName + " ["
                + originalcount.ToString() + " Original, "
                + addedcount.ToString() + " Added, "
                + modifiedcount.ToString() + " Modified, "
                + deletedcount.ToString() + " deleted,  "
                + currentcount.ToString() + " Current ]";
        }
コード例 #38
0
 public CompoundFeatureSource(FeatureSource first, FeatureSource second)
 {
     this.first  = first;
     this.second = second;
 }
コード例 #39
0
 public EarthquakeHeatFeatureLayer(FeatureSource featureSource)
     : base()
 {
     FeatureSource = featureSource;
 }
コード例 #40
0
 protected abstract Collection <Style> GetStylesCore(FeatureSource featureSource);
コード例 #41
0
 public Style GetStyle(FeatureSource featureSource)
 {
     return(GetStyleCore(featureSource));
 }
コード例 #42
0
        public virtual void ImportData(FeatureSource featureSourceForRead, FeatureSource featureSourceForSave)
        {
            bool readCompleted = false;

            featureSourceForRead.Open();
            featureSourceForSave.Open();
#if DEBUG
            long featureCount = featureSourceForRead.GetCount();
#endif
            Collection <Feature> features = featureSourceForRead.GetAllFeatures(ReturningColumnsType.AllColumns);
            Collection <Collection <Feature> > featureGroups = GroupFeatures(features);
            var writeTasks = (from items in featureGroups
                              select Task.Factory.StartNew(() => WriteFeaturesIntoQueue(items, featureSourceForRead))).ToArray();


            var readTask = Task.Factory.StartNew(() =>
            {
                while (!readCompleted || queue.Count > 0)
                {
                    while (queue.Count > 0)
                    {
                        Collection <Feature> lineFeatures = queue.Dequeue();
                        SaveFeatures(lineFeatures, featureSourceForSave);
                    }
                }
            });

            Task.WaitAll(writeTasks);
            readCompleted = true;
            Task.WaitAny(readTask);
            #region Old version
            //foreach (Feature feature in features)
            //{
            //    Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
            //    // Get the lineshape of the processing feature.
            //    foreach (LineShape processingLineShape in processingLineShapes)
            //    {
            //        // Define a variable to save the points where the adjacent lines intersect with current processing line.
            //        Collection<PointShape> crossingPoints = new Collection<PointShape>();

            //        // Get all the lines in current processing shape bounds.
            //        Collection<Feature> adjacentFeatures = featureSourceForRead.GetFeaturesInsideBoundingBox(processingLineShape.GetBoundingBox(), ReturningColumnsType.NoColumns);

            //        // Loop and see if the queried shape is intersected with processing shape.
            //        foreach (Feature adjacentFeature in adjacentFeatures)
            //        {
            //            LineBaseShape adjacentLineShape = adjacentFeature.GetShape() as LineBaseShape;
            //            MultipointShape tempCrossingPoints = processingLineShape.GetCrossing(adjacentLineShape);

            //            // The queried shape is intersected with processing shape.
            //            foreach (PointShape point in tempCrossingPoints.Points)
            //            {
            //                bool hasAdded = false;
            //                foreach (var item in crossingPoints)
            //                {
            //                    if (point.X == item.X && point.Y == item.Y)
            //                    {
            //                        hasAdded = true;
            //                        break;
            //                    }
            //                }
            //                if (!hasAdded)
            //                {
            //                    crossingPoints.Add(point);
            //                }
            //            }
            //        }

            //        // Order the crossing points following the sequence of line vertex.
            //        Collection<FlagedVertex> vertecesOfNewLine = GeometryHelper.AddCrossingPointToLine(processingLineShape, crossingPoints);

            //        // Split current processing lineshape into segments.
            //        featureSourceForSave.BeginTransaction();
            //        Collection<Vertex> verteces = new Collection<Vertex>();
            //        foreach (var vertex in vertecesOfNewLine)
            //        {
            //            verteces.Add(vertex.Vertex);
            //            if (vertex.Flag)
            //            {
            //                if (verteces.Count >= 2)
            //                {
            //                    LineShape segment = new LineShape(verteces);
            //                    featureSourceForSave.AddFeature(new Feature(segment, feature.ColumnValues));

            //                    verteces.RemoveAt(0);
            //                }
            //            }
            //        }
            //        featureSourceForSave.CommitTransaction();
            //    }

            //#if DEBUG
            //Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, featureCount));
            //#endif
            //}

            #endregion
            featureSourceForRead.Close();
            featureSourceForSave.Close();
        }
コード例 #43
0
 protected abstract Style GetStyleCore(FeatureSource featureSource);
コード例 #44
0
ファイル: LevelUp.cs プロジェクト: ThyWoof/ToyBox
            public static bool Prefix([NotNull] LevelUpState state, [NotNull] UnitDescriptor unit, [NotNull] IList <BlueprintFeatureBase> features, [CanBeNull] FeatureSource source, int level)
            {
                if (!Main.IsInGame)
                {
                    return(false);
                }
#if true
                //Logger.Log($"feature count = {features.ToArray().Count()} ");
                var description = source.Blueprint.GetDescription() ?? "nil";
                //Logger.Log($"source: {source.Blueprint.name} - {description}");
                foreach (BlueprintFeature blueprintFeature in features.OfType <BlueprintFeature>())
                {
                    if (blueprintFeature.MeetsPrerequisites((FeatureSelectionState)null, unit, state, true))
                    {
                        //Logger.Log($"    name: {blueprintFeature.Name} : {blueprintFeature.GetType()}");
                        if (blueprintFeature is IFeatureSelection selection)
                        {
                            // Bug Fix - due to issues in the implementation of FeatureSelectionState.CanSelectAnything we can get level up blocked so this is an attempt to work around for that
                            var numToAdd = settings.featsMultiplier;
                            if (selection is BlueprintFeatureSelection bpFS)
                            {
                                var bpFeatures = bpFS;
                                var items      = bpFS.ExtractSelectionItems(unit, null);
                                //Logger.Log($"        items: {items.Count()}");
                                var availableCount = 0;
                                foreach (var item in items)
                                {
#if false
                                    if (bpFS.is BlueprintParametrizedFeature bppF)
                                    {
                                        Logger.Log($"checking parameterized feature {bppF.Name}");
                                        if (selection.CanSelect(unit, state, null, item))
                                        {
                                            Logger.Log($"        {item.Feature.name}  is avaiable");
                                            availableCount++;
                                        }
                                    }
                                    else
#endif
                                    if (!unit.Progression.Features.HasFact(item.Feature))
                                    {
                                        availableCount++;
                                        //                                        Logger.Log($"        {item.Feature.name}  is avaiable");
                                    }
#if false
                                    if (selection.CanSelect(unit, state, null, item))
                                    {
                                        Logger.Log($"        {item.Feature.name}  is avaiable");
                                        availableCount++;
                                    }
                                    else
                                    {
                                        Logger.Log($"        {item.Feature.name}  is NOT avaiable");
                                    }
                                    if (!unit.Progression.Features.HasFact(item.Feature))
                                    {
                                        if (item.Feature.MeetsPrerequisites(null, unit, state, true))
                                        {
                                            Logger.Log($"        {item.Feature.name}  is avaiable");
                                            availableCount++;
                                        }
                                    }
                                    else
                                    {
                                        Logger.Log($"        has Fact {item.Feature.Name}");
                                    }
#endif
                                }
                                if (numToAdd > availableCount)
                                {
                                    Logger.Log($"reduced numToAdd: {numToAdd} -> {availableCount}");
                                    numToAdd = availableCount;
                                }
                            }
                            //Logger.Log($"        IFeatureSelection: {selection} adding: {numToAdd}");
                            for (int i = 0; i < numToAdd; ++i)
                            {
                                state.AddSelection((FeatureSelectionState)null, source, selection, level);
                            }
                        }
                        Kingmaker.UnitLogic.Feature feature     = (Kingmaker.UnitLogic.Feature)unit.AddFact((BlueprintUnitFact)blueprintFeature);
                        BlueprintProgression        progression = blueprintFeature as BlueprintProgression;
                        if ((UnityEngine.Object)progression != (UnityEngine.Object)null)
                        {
                            //Logger.Log($"        BlueprintProgression: {progression}");
                            LevelUpHelper.UpdateProgression(state, unit, progression);
                        }
                        FeatureSource source1 = source;
                        int           level1  = level;
                        feature.SetSource(source1, level1);
                    }
コード例 #45
0
ファイル: support.cs プロジェクト: gisdevelope/MercuryGIS
        public static Style createRankStyle(FeatureSource featuresource, string attributename, int num, Color startcolor, Color endcolor)
        {
            Schema         schema = featuresource.schema;
            SymbolizerType sign   = SymbolizerType.POINT;

            switch (schema.geometryType)
            {
            case OSGeo.OGR.wkbGeometryType.wkbPoint:
                sign = SymbolizerType.POINT;
                break;

            case OSGeo.OGR.wkbGeometryType.wkbLineString:
                sign = SymbolizerType.LINE;
                break;

            case OSGeo.OGR.wkbGeometryType.wkbPolygon:
                sign = SymbolizerType.POLYGON;
                break;
            }
            FieldDefn fielddefn = null;

            if (schema.fields.TryGetValue(attributename, out fielddefn) || attributename.Equals("FeatureID"))
            {
                FieldType type = FieldType.OFTString;
                if (!attributename.Equals("FeatureID"))
                {
                    type = fielddefn.GetFieldType();
                }
                if (type == FieldType.OFTInteger || type == FieldType.OFTReal || attributename.Equals("FeatureID"))
                {
                    double maxvalue = double.MinValue;
                    double minvalue = double.MaxValue;
                    foreach (GisSmartTools.Data.Feature feature in featuresource.features.featureList)
                    {
                        double value = 0;
                        if (type == FieldType.OFTInteger || attributename.Equals("FeatureID"))
                        {
                            value = (int)feature.GetArrtributeByName(attributename);
                        }
                        if (type == FieldType.OFTReal)
                        {
                            value = (double)feature.GetArrtributeByName(attributename);
                        }
                        if (value > maxvalue)
                        {
                            maxvalue = value;
                        }
                        if (value < minvalue)
                        {
                            minvalue = value;
                        }
                    }
                    if (num == 0)
                    {
                        return(null);
                    }
                    double x = (maxvalue - minvalue) / num;
                    //逐个创建对应的rule
                    Color[]           colorarray    = Utils.GetLinearColorList(startcolor, endcolor, num);
                    double            temp_minvalue = minvalue;
                    double            temp_maxvalue = minvalue + x;
                    List <RenderRule> rulelist      = new List <RenderRule>();
                    // Printer.printnode("min=" + minvalue + " max=" + maxvalue, "");

                    for (int i = 0; i < num; i++)
                    {
                        RenderRule           rule       = RenderRule.createDefaultRule(sign, colorarray[i]);
                        Filter_Larger        larger     = new Filter_Larger(attributename, temp_minvalue);
                        Filter_Less          less       = new Filter_Less(attributename, temp_maxvalue);
                        List <Filter.Filter> filterlist = new List <Filter.Filter>();
                        filterlist.Add(larger); filterlist.Add(less);
                        Filter_And andfilter = new Filter_And(filterlist);
                        rule.filter = andfilter;
                        rulelist.Add(rule);
                        // Printer.printnode("temp_" + i, "min=" + temp_minvalue + " max=" + temp_maxvalue);
                        temp_minvalue += x; temp_maxvalue += x;
                    }
                    Style rankstyle = new Style("RankStyle", StyleType.RANKSTYLE, RenderRule.createDefaultRule(sign, startcolor));
                    rankstyle.rulelist = rulelist;
                    Printer.printnode("rulist,count=", "" + rulelist.Count);
                    return(rankstyle);
                }
            }
            return(null);
        }
コード例 #46
0
        public List <Feature> ParseFeatures(List <string> featureTextLines, string sourceName, FeatureSource featureSource, ContentType contentType)
        {
            var features = new List <Feature>();

            var featureNameLineIndexes = featureTextLines.FindAllIndexOf(f => f.StartsWith("### "));

            for (var i = 0; i < featureNameLineIndexes.Count - 1; i++)
            {
                var currentFeatureNameLineIndex = featureNameLineIndexes[i];
                var nextFeatureNameLineIndex    = featureNameLineIndexes.ElementAtOrDefault(i + 1);
                var featureLines = nextFeatureNameLineIndex == 0
                    ? featureTextLines.Skip(currentFeatureNameLineIndex).RemoveEmptyLines().ToList()
                    : featureTextLines.Skip(currentFeatureNameLineIndex)
                                   .Take(nextFeatureNameLineIndex - currentFeatureNameLineIndex).RemoveEmptyLines().ToList();

                var name = featureLines[0].Split("# ")[1].Trim();


                var levels = GetFeatureLevels(featureLines.Skip(1).CleanListOfStrings().ToList());

                foreach (var level in levels)
                {
                    var feature = new Feature
                    {
                        Name         = name,
                        SourceEnum   = featureSource,
                        Text         = string.Join("\r\n", featureLines.Skip(1).CleanListOfStrings()),
                        PartitionKey = contentType.ToString(),
                        SourceName   = sourceName,
                        Level        = level,
                        RowKey       = $"{featureSource}-{sourceName}-{name}-{level}".Replace("/", string.Empty)
                                       .Replace(@"\", string.Empty)
                    };

                    features.Add(feature);
                }
            }

            return(features);
        }
コード例 #47
0
 public Collection<Style> GetStyles(FeatureSource featureSource)
 {
     return GetStylesCore(featureSource);
 }