Example #1
0
        private void trackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
        {
            //Gets the shape from the tracked polygon. The tracked shapes can be found in the TrackShapeLayer of the TrackOverlay.
            AreaBaseShape areaBaseShape = (AreaBaseShape)winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures[0].GetShape();

            //Gets the features of the counties that are completely within the tracked polygon.
            LayerOverlay          layerOverlay          = (LayerOverlay)winformsMap1.Overlays["LayerOverlay"];
            ShapeFileFeatureLayer shapeFileFeatureLayer = (ShapeFileFeatureLayer)layerOverlay.Layers["CountiesLayer"];
            Collection <Feature>  features = shapeFileFeatureLayer.QueryTools.GetFeaturesWithin(areaBaseShape, ReturningColumnsType.NoColumns);

            //Adds the shape of the selected counties features to AreaBaseShape collection to perform the Union.
            Collection <AreaBaseShape> areaBaseShapes = new Collection <AreaBaseShape>();

            foreach (Feature feature in features)
            {
                areaBaseShapes.Add((AreaBaseShape)feature.GetShape());
            }
            MultipolygonShape unionMultipolygonShape = MultipolygonShape.Union(areaBaseShapes);

            //Gets the MultiPolygonShape with the inner ring(s) being the result of the Union of the selected shapes.
            MultipolygonShape resultMultiPolygonShape = areaBaseShape.GetDifference(unionMultipolygonShape);

            //Adds the result to the InMemoryFeatureLayer for display on the map.
            LayerOverlay         dynamicOverlay       = (LayerOverlay)winformsMap1.Overlays["DynamicOverlay"];
            InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["DynamicLayer"];

            inMemoryFeatureLayer.InternalFeatures.Clear();

            inMemoryFeatureLayer.InternalFeatures.Add(new Feature(resultMultiPolygonShape));

            //We clear the tracked shape so that it does not show on the map.
            winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();

            winformsMap1.Refresh(winformsMap1.Overlays["DynamicOverlay"]);
        }
Example #2
0
        private static IEnumerable <PolygonShape> ToPolygons(this AreaBaseShape area)
        {
            Collection <PolygonShape> results = null;

            PolygonShape      polygon           = area as PolygonShape;
            MultipolygonShape multipolygonShape = area as MultipolygonShape;

            if (polygon != null)
            {
                results = new Collection <PolygonShape> {
                    polygon
                };
            }
            else if (multipolygonShape != null)
            {
                results = multipolygonShape.Polygons;
            }
            else
            {
                var polygonShape = area.GetType().GetMethod("ToPolygon").Invoke(null, null) as PolygonShape;
                results = new Collection <PolygonShape> {
                    polygonShape
                };
            }

            return(results);
        }
Example #3
0
        private void TrackInteractiveOverlayOnTrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs args)
        {
            loadingView.StartAnimating();
            Task.Factory.StartNew(() =>
            {
                MultipolygonShape resultShape = PolygonShape.Union(iOSMap.TrackOverlay.TrackShapeLayer.InternalFeatures);

                ShapeFileFeatureLayer earthquakePointLayer = (ShapeFileFeatureLayer)Global.HighLightOverlay.Layers["EarthquakePointLayer"];

                earthquakePointLayer.Open();
                Collection <Feature> features = earthquakePointLayer.FeatureSource.GetFeaturesWithinDistanceOf(new Feature(resultShape), iOSMap.MapUnit, DistanceUnit.Meter, 0.0001, ReturningColumnsType.AllColumns);

                Global.QueriedFeatures.Clear();

                foreach (Feature feature in features)
                {
                    Global.QueriedFeatures.Add(feature);
                }

                Global.FilterSelectedEarthquakeFeatures();
                InvokeOnMainThread(() =>
                {
                    Global.HighLightOverlay.Refresh();
                    loadingView.StopAnimating();
                });
            });
        }
        private Feature BufferFeature(Feature feature)
        {
            MultipolygonShape bufferedShape   = BufferShape(feature.GetShape());
            Feature           bufferedFeature = new Feature(bufferedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues);

            return(bufferedFeature);
        }
Example #5
0
        public void SimplifyClick(Map map, GeoCollection <object> args)
        {
            if (null == areaBaseShape)
            {
                areaBaseShape = ((InMemoryFeatureLayer)map.StaticOverlay.Layers["SimplificationLayer"]).InternalFeatures[0].GetShape() as AreaBaseShape;
            }
            string toleranceString                   = args[0] as string;
            string simplificationTypeString          = args[1] as string;
            InMemoryFeatureLayer simplificationLayer = (InMemoryFeatureLayer)map.StaticOverlay.Layers["SimplificationLayer"];

            double             tolerance          = Convert.ToDouble(toleranceString, CultureInfo.InvariantCulture);
            SimplificationType simplificationType = SimplificationType.DouglasPeucker;

            switch (simplificationTypeString)
            {
            case "TopologyPreserving":
                simplificationType = SimplificationType.TopologyPreserving;
                break;

            case "DouglasPeucker":
                simplificationType = SimplificationType.DouglasPeucker;
                break;
            }

            MultipolygonShape multipolygonShape = areaBaseShape.Simplify(tolerance, simplificationType);

            simplificationLayer.InternalFeatures.Clear();
            simplificationLayer.InternalFeatures.Add(new Feature(multipolygonShape));
        }
Example #6
0
 public static IEnumerable <PointShape> CollectPoints(MultipolygonShape multipolygon)
 {
     foreach (var polygon in multipolygon.Polygons)
     {
         foreach (var point in CollectPoints(polygon))
         {
             yield return(point);
         }
     }
 }
Example #7
0
    private static void GenerateMultipolygonShape(ExtractedOpenDataEntry entry, Color lineColor, Material lineMaterial, float lineWidth)
    {
        MultipolygonShape   multipolgyonShape = (MultipolygonShape)entry.openDataObject.Shape;
        List <PolygonShape> polygons          = multipolgyonShape.polygonShapes;

        foreach (PolygonShape polygon in polygons)
        {
            ExtractedOpenDataEntry tempEntry = new ExtractedOpenDataEntry(entry.relatedPrefab, new OpenDataObject(polygon), entry.name);
            GeneratePolygonShape(tempEntry, lineColor, lineMaterial, lineWidth);
        }
    }
        private void btnSimplify_Click(object sender, RoutedEventArgs e)
        {
            InMemoryFeatureLayer simplificationLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("SimplificationLayer");

            double             tolerance          = Convert.ToDouble(cmbTolerance.SelectedItem.ToString().Split(':')[1], CultureInfo.InvariantCulture);
            SimplificationType simplificationType = (SimplificationType)cmbSimplificationType.SelectedIndex;

            MultipolygonShape multipolygonShape = areaBaseShape.Simplify(tolerance, simplificationType);

            simplificationLayer.InternalFeatures.Clear();
            simplificationLayer.InternalFeatures.Add(new Feature(multipolygonShape));

            mapView.Overlays["SimplificationOverlay"].Refresh();
        }
Example #9
0
        private void btnSimplify_Click(object sender, EventArgs e)
        {
            InMemoryFeatureLayer simplificationLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("SimplificationLayer");

            double             tolerance          = Convert.ToDouble(cmbTolerance.Text, CultureInfo.InvariantCulture);
            SimplificationType simplificationType = (SimplificationType)cmbSimplificationType.SelectedIndex;

            MultipolygonShape multipolygonShape = areaBaseShape.Simplify(tolerance, simplificationType);

            simplificationLayer.InternalFeatures.Clear();
            simplificationLayer.InternalFeatures.Add(new Feature(multipolygonShape));

            winformsMap1.Refresh(winformsMap1.Overlays["SimplificationOverlay"]);
        }
        private MultipolygonShape BufferShape(BaseShape shape)
        {
            MultipolygonShape bufferedShape = null;

            if (capstyle == BufferCapType.Round)
            {
                bufferedShape = SqlTypesGeometryHelper.Buffer(shape, Distance, Smoothness, Capstyle, MapUnit, DistanceUnit);
            }
            else
            {
                bufferedShape = shape.Buffer(distance, smoothness, capstyle, mapUnit, distanceUnit);
            }
            return(bufferedShape);
        }
        private void GenerateResultShapeByVertex(RectangleShape currentExtent, Vertex vertex1, Vertex vertex2, bool needRemoveVertex = false)
        {
            var snappingLayer = snappingLayers.FirstOrDefault();

            if (snappingLayer != null)
            {
                snappingLayer.Open();
                Collection <Feature> features = snappingLayer.QueryTools.GetFeaturesInsideBoundingBox(currentExtent, ReturningColumnsType.NoColumns);

                bool found = false;

                foreach (var item in features)
                {
                    BaseShape shape = item.GetShape();

                    if (shape is PolygonShape)
                    {
                        PolygonShape polygon = shape as PolygonShape;

                        if (polygon.OuterRing.Vertices.Contains(vertex1) && polygon.OuterRing.Vertices.Contains(vertex2))
                        {
                            GenerateResultShape(vertex1, vertex2, polygon.OuterRing.Vertices, needRemoveVertex);
                            break;
                        }
                    }
                    else if (shape is MultipolygonShape)
                    {
                        MultipolygonShape multipolygon = shape as MultipolygonShape;

                        if (multipolygon != null)
                        {
                            foreach (var p in multipolygon.Polygons)
                            {
                                if (p.OuterRing.Vertices.Contains(vertex1) && p.OuterRing.Vertices.Contains(vertex2))
                                {
                                    GenerateResultShape(vertex1, vertex2, p.OuterRing.Vertices, needRemoveVertex);
                                    found = true;
                                    break;
                                }
                            }

                            if (found)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
Example #12
0
        private void btnBuffer_Click(object sender, EventArgs e)
        {
            InMemoryFeatureLayer inMemoryLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("InMemoryFeatureLayer");
            InMemoryFeatureLayer bufferLayer   = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("BufferLayer");

            AreaBaseShape     baseShape     = (AreaBaseShape)inMemoryLayer.InternalFeatures["POLYGON"].GetShape();
            MultipolygonShape bufferedShape = baseShape.Buffer(100, 8, BufferCapType.Butt, GeographyUnit.DecimalDegree, DistanceUnit.Kilometer);
            Feature           bufferFeature = new Feature(bufferedShape.GetWellKnownBinary(), "Buffer1");

            bufferLayer.InternalFeatures.Clear();
            bufferLayer.InternalFeatures.Add("BufferFeature", bufferFeature);

            winformsMap1.Refresh(winformsMap1.Overlays["BufferOverlay"]);
        }
    private static MultipolygonShape GetMultipolygonShape(string lineElement)
    {
        // MULTIPOLYGON (((16.000000 48.00000, 16.0002 48.261)), ((16.003 48.262, 16.0002 48.261)))
        Regex           regex   = new Regex(@"\(([^)]*)\)");
        MatchCollection matches = regex.Matches(lineElement);

        MultipolygonShape multipolygonShape = new MultipolygonShape();

        foreach (var match in matches)
        {
            multipolygonShape.polygonShapes.Add(GetPolygonShape(match.ToString()));
        }

        return(multipolygonShape);
    }
Example #14
0
        private void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
        {
            MultipolygonShape resultShape = PolygonShape.Union(Global.MapView.TrackOverlay.TrackShapeLayer.InternalFeatures);

            FeatureLayer featureLayer = earthquakePointLayer;

            if (!featureLayer.IsOpen)
            {
                featureLayer.Open();
            }
            Collection <Feature> features = featureLayer.FeatureSource.GetFeaturesWithinDistanceOf(new Feature(resultShape), Global.MapView.MapUnit, DistanceUnit.Meter, 0.0001, ReturningColumnsType.AllColumns);

            Global.BackupQueriedFeatures(features);
            Global.FilterSelectedEarthquakeFeatures(Global.GetBackupQueriedFeatures());
        }
Example #15
0
        protected override void DrawCore(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers)
        {
            PointShape centerPoint = canvas.CurrentWorldExtent.GetCenterPoint();

            double            currentRingDistance = RingDistance;
            MultipolygonShape circle = null;

            // Keep drawing rings until the only barley fit inside the current extent.
            do
            {
                circle = centerPoint.Buffer(currentRingDistance, RingGeography, RingDistanceUnit);

                canvas.DrawArea(circle, RingAreaStyle.OutlinePen, RingAreaStyle.FillBrush, DrawingLevel.LevelOne);
                currentRingDistance += RingDistance;
            } while (canvas.CurrentWorldExtent.Contains(circle));
        }
Example #16
0
        private void BufferButtonClick(object sender, System.EventArgs e)
        {
            LayerOverlay bufferOverLay = (LayerOverlay)androidMap.Overlays["BufferOverlay"];

            InMemoryFeatureLayer inMemoryLayer = (InMemoryFeatureLayer)bufferOverLay.Layers["InMemoryFeatureLayer"];
            InMemoryFeatureLayer bufferLayer   = (InMemoryFeatureLayer)bufferOverLay.Layers["BufferLayer"];

            AreaBaseShape     baseShape     = (AreaBaseShape)inMemoryLayer.InternalFeatures["POLYGON"].GetShape();
            MultipolygonShape bufferedShape = baseShape.Buffer(100, 8, BufferCapType.Butt, GeographyUnit.DecimalDegree, DistanceUnit.Kilometer);
            Feature           bufferFeature = new Feature(bufferedShape.GetWellKnownBinary(), "Buffer1");

            bufferLayer.InternalFeatures.Clear();
            bufferLayer.InternalFeatures.Add("BufferFeature", bufferFeature);

            androidMap.Overlays["BufferOverlay"].Refresh();
        }
Example #17
0
        public void BufferFeature(Map map, GeoCollection <object> args)
        {
            if (null != map)
            {
                InMemoryFeatureLayer mapShapeLayer = (InMemoryFeatureLayer)((LayerOverlay)(map.CustomOverlays["BufferLayerOverLayer"])).Layers["InMemoryFeatureLayer"];
                InMemoryFeatureLayer bufferLayer   = (InMemoryFeatureLayer)((LayerOverlay)(map.CustomOverlays["BufferLayerOverLayer"])).Layers["BufferLayer"];

                AreaBaseShape     baseShape     = (AreaBaseShape)mapShapeLayer.InternalFeatures["POLYGON"].GetShape();
                MultipolygonShape bufferedShape = baseShape.Buffer(1000, 8, BufferCapType.Round, GeographyUnit.DecimalDegree, DistanceUnit.Kilometer);
                Feature           bufferFeature = new Feature(bufferedShape);

                bufferLayer.InternalFeatures.Clear();
                bufferLayer.InternalFeatures.Add("BufferFeature", bufferFeature);
                ((LayerOverlay)(map.CustomOverlays["BufferLayerOverLayer"])).Redraw();
            }
        }
        public static Collection <AreaBaseShape> GetSplitResult(this AreaBaseShape polygon, Collection <LineShape> lines)
        {
            SqlGeometry polygonGeom = SqlGeometry.STGeomFromWKB(new SqlBytes(polygon.GetWellKnownBinary()), 0);

            if (!polygonGeom.STIsValid())
            {
                polygonGeom = polygonGeom.MakeValid();
            }
            //GeometryLibrary library = BaseShape.GeometryLibrary;
            //BaseShape.GeometryLibrary = GeometryLibrary.Unmanaged;
            foreach (var item in lines)
            {
                //MultipolygonShape multipolygon = item.Buffer(0.2, 8, BufferCapType.Square, GeographyUnit.DecimalDegree, DistanceUnit.Meter);
                MultipolygonShape multipolygon     = SqlTypesGeometryHelper.Buffer(item, 0.2, 8, BufferCapType.Square, GeographyUnit.DecimalDegree, DistanceUnit.Meter);
                SqlGeometry       multipolygonGeom = SqlGeometry.STGeomFromWKB(new SqlBytes(multipolygon.GetWellKnownBinary()), 0);
                if (!multipolygonGeom.STIsValid())
                {
                    multipolygonGeom = multipolygonGeom.MakeValid();
                }

                polygonGeom = polygonGeom.STDifference(multipolygonGeom);
            }

            //BaseShape.GeometryLibrary = library;

            byte[]    bytes = polygonGeom.STAsBinary().Value;
            BaseShape shape = BaseShape.CreateShapeFromWellKnownData(bytes) as AreaBaseShape;

            MultipolygonShape splittedMultipolygonShape = shape as MultipolygonShape;
            PolygonShape      splittedPolygonShape      = shape as PolygonShape;

            if (splittedMultipolygonShape == null && splittedPolygonShape != null)
            {
                splittedMultipolygonShape = new MultipolygonShape();
                splittedMultipolygonShape.Polygons.Add(splittedPolygonShape);
                shape = splittedMultipolygonShape;
            }

            Collection <AreaBaseShape> shapes = new Collection <AreaBaseShape>();

            if (splittedMultipolygonShape != null)
            {
                CloseSplittedPolygons(polygon, splittedMultipolygonShape, lines[0], GeographyUnit.DecimalDegree, DistanceUnit.Meter, .3);
                FillShapes(shapes, shape);
            }
            return(shapes);
        }
        public static void CloseSplittedPolygons(AreaBaseShape sourcePolygon, MultipolygonShape splitedPolygon, LineShape splitLine, GeographyUnit mapUnit, DistanceUnit distanceUnit, double distance)
        {
            var multiline = splitLine.GetIntersection(sourcePolygon);

            foreach (var vertex in multiline.Lines.SelectMany(l => l.Vertices))
            {
                var closeArea = new PointShape(vertex).Buffer(distance, mapUnit, distanceUnit).GetBoundingBox();
                foreach (var polygon in splitedPolygon.Polygons)
                {
                    CloseSplittedRing(vertex, closeArea, polygon.OuterRing);
                    foreach (var ring in polygon.InnerRings)
                    {
                        CloseSplittedRing(vertex, closeArea, ring);
                    }
                }
            }
        }
Example #20
0
        private int StandardClipLines(IEnumerable <Feature> features, Collection <Feature> results, Collection <Feature> sourceFeatures, int index, int count)
        {
            //MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(features));
            List <AreaBaseShape> clippingAreaShapes = GetValidFeatures(features).Select(f => f.GetShape()).OfType <AreaBaseShape>().ToList();
            MultipolygonShape    areaBaseShape      = (MultipolygonShape)SqlTypesGeometryHelper.Union(clippingAreaShapes);

            ConcurrentQueue <Feature> concurrentResult = new ConcurrentQueue <Feature>();

            Parallel.ForEach(sourceFeatures, feature =>
            {
                try
                {
                    //if (areaBaseShape.Contains(feature))
                    if (SqlTypesGeometryHelper.Contains(areaBaseShape, feature))
                    {
                        concurrentResult.Enqueue(feature);
                    }
                    else
                    {
                        //var clippedShape = ((LineBaseShape)feature.GetShape()).GetIntersection(areaBaseShape);
                        var clippedShape = SqlTypesGeometryHelper.GetIntersection(feature.GetShape(), areaBaseShape) as MultilineShape;
                        if (clippedShape != null && clippedShape.Lines.Count > 0)
                        {
                            concurrentResult.Enqueue(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                        }
                    }
                }
                catch (Exception ex)
                {
                    GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                    HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                }
                finally
                {
                    isCanceled = ReportProgress(index++, count);
                }
            });

            foreach (var feature in concurrentResult)
            {
                results.Add(feature);
            }
            return(index);
        }
    public static void ExtractRawOpenDataMap(RawOpenDataMap rawMap, string extractedFilename)
    {
        ExtractedOpenDataMap finishedMap = ScriptableObject.CreateInstance <ExtractedOpenDataMap>();
        int fileCount = 0;

        foreach (var entry in rawMap.dataEntries)
        {
            List <OpenDataObject> objectsFromCsv = CsvReader.GetEveryLineAsObjectFromCSV(entry.openDataFile);

            for (int i = 0; i < objectsFromCsv.Count; i++)
            {
                if (objectsFromCsv[i].Shape is PointShape)
                {
                    objectsFromCsv[i] = ApplyAllRules(objectsFromCsv[i]);
                }
                else if (objectsFromCsv[i].Shape is LinestringShape)
                {
                    objectsFromCsv[i] = ApplyAllRules(objectsFromCsv[i]);
                }
                else if (objectsFromCsv[i].Shape is PolygonShape)
                {
                    objectsFromCsv[i] = ApplyAllRules(objectsFromCsv[i]);
                }
                else if (objectsFromCsv[i].Shape is MultipolygonShape)
                {
                    MultipolygonShape multipolygon = (MultipolygonShape)objectsFromCsv[i].Shape;

                    for (int y = 0; y < multipolygon.polygonShapes.Count; y++)
                    {
                        for (int index = 0; index < multipolygon.polygonShapes[y].coordinates.Count; index++)
                        {
                            multipolygon.polygonShapes[y].coordinates[index] = ApplyCoordinatePreparationRules(multipolygon.polygonShapes[y].coordinates[index]);
                        }
                    }
                    objectsFromCsv[i].Shape = multipolygon;
                }

                SaveInDestinationObject(finishedMap, new ExtractedOpenDataEntry(entry.relatedPrefab, objectsFromCsv[i], entry.openDataFile.name));
            }
            Debug.Log("Files: " + fileCount++);
        }
        SaveFinishedDestinationFile(finishedMap, extractedFilename);
        Debug.Log("Finished Extraction");
    }
Example #22
0
        /// <summary>
        /// Returns the center of the feature.
        /// </summary>
        /// <param name="shapeFileFeatureLayer"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static PointShape GetFeatureCenterPoint(ShapeFileFeatureLayer shapeFileFeatureLayer, int index)
        {
            PointShape returnValue = new PointShape();

            try
            {
                List <string> featuresToExclude = shapeFileFeatureLayer.FeatureIdsToExclude.ToList();
                shapeFileFeatureLayer.FeatureIdsToExclude.Clear();

                if (!shapeFileFeatureLayer.IsOpen)
                {
                    shapeFileFeatureLayer.Open();
                }

                Feature feature = shapeFileFeatureLayer.QueryTools.GetFeatureById(index.ToString(),
                                                                                  ReturningColumnsType.NoColumns);

                foreach (string s in featuresToExclude)
                {
                    shapeFileFeatureLayer.FeatureIdsToExclude.Add(s);
                }

                if (feature != null)
                {
                    MultipolygonShape polygonShape = new MultipolygonShape(feature.GetWellKnownBinary());
                    returnValue = polygonShape.GetCenterPoint();
                    return(returnValue);
                }
                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                if (shapeFileFeatureLayer.IsOpen)
                {
                    shapeFileFeatureLayer.Close();
                }
            }
        }
Example #23
0
        private static void ReadGeometry(BasFeatureEntity featureEntiye, Collection <RecordCoordinate> coordinates)
        {
            if (coordinates.Count > 0)
            {
                //MultilineShape multilineShape = new MultilineShape();
                //foreach (var coord in coordinates)
                //{
                //    Vertex vertex1 = ConvertHelper.LatLonToVertex(coord.StartPointLonLat);
                //    Vertex vertex2 = ConvertHelper.LatLonToVertex(coord.EndPointLonLat);
                //    multilineShape.Lines.Add(new LineShape(new Collection<Vertex>() { vertex1, vertex2 }));
                //}
                //ShapeValidationResult validateResult = multilineShape.Validate(ShapeValidationMode.Simple);
                //if (!validateResult.IsValid)
                //{
                //    throw new ArgumentException();
                //}
                MultipolygonShape multiPolygonShape = new MultipolygonShape();

                PolygonShape tempPolygon = new PolygonShape();
                foreach (var coord in coordinates)
                {
                    Vertex vertex1 = ConvertHelper.LatLonToVertex(coord.StartPointLonLat);
                    Vertex vertex2 = ConvertHelper.LatLonToVertex(coord.EndPointLonLat);
                    tempPolygon.OuterRing.Vertices.Add(vertex1);
                    tempPolygon.OuterRing.Vertices.Add(vertex2);

                    if (coord.EndOfPolygonFlag)
                    {
                        multiPolygonShape.Polygons.Add(tempPolygon);
                        tempPolygon = new PolygonShape();
                    }
                }
                ShapeValidationResult validateResult = multiPolygonShape.Validate(ShapeValidationMode.Simple);
                if (!validateResult.IsValid)
                {
                    throw new ArgumentException();
                }
                featureEntiye.Shape = multiPolygonShape;
            }
        }
Example #24
0
        private static AreaBaseShape ToPolygonOrMultiPolygon(this AreaBaseShape area)
        {
            AreaBaseShape result = null;

            PolygonShape      polygon           = area as PolygonShape;
            MultipolygonShape multipolygonShape = area as MultipolygonShape;

            if (polygon != null)
            {
                result = polygon;
            }
            else if (multipolygonShape != null)
            {
                result = multipolygonShape;
            }
            else
            {
                result = area.GetType().GetMethod("ToPolygon").Invoke(null, null) as PolygonShape;
            }

            return(result);
        }
Example #25
0
        private static MultipolygonShape ConvertSqlQueryResultToMultiPolygonShape(BaseShape unionResultShape)
        {
            bool isUnionResultPolygon                 = unionResultShape is PolygonShape;
            bool isUnionResultMultiPolygon            = unionResultShape is MultipolygonShape;
            bool isUnionResultGeometryCollectionShape = unionResultShape is GeometryCollectionShape;

            MultipolygonShape concreteUnionResult = new MultipolygonShape();

            if (isUnionResultPolygon)
            {
                concreteUnionResult.Polygons.Add((PolygonShape)unionResultShape);
            }
            else if (isUnionResultMultiPolygon)
            {
                concreteUnionResult = (MultipolygonShape)unionResultShape;
            }
            else if (isUnionResultGeometryCollectionShape)
            {
                GeometryCollectionShape geometryCollectionShape = (GeometryCollectionShape)unionResultShape;
                foreach (BaseShape shape in geometryCollectionShape.Shapes)
                {
                    if (shape is PolygonShape)
                    {
                        concreteUnionResult.Polygons.Add((PolygonShape)shape);
                    }
                    else if (shape is MultipolygonShape)
                    {
                        MultipolygonShape multiPolygonShape = (MultipolygonShape)shape;
                        foreach (PolygonShape polygonShape in multiPolygonShape.Polygons)
                        {
                            concreteUnionResult.Polygons.Add(polygonShape);
                        }
                    }
                }
            }

            return(concreteUnionResult);
        }
Example #26
0
        private static Feature CombineAreaShapes(Feature[] features)
        {
            MultipolygonShape result = new MultipolygonShape();

            foreach (var feature in features)
            {
                PolygonShape      polygon      = feature.GetShape() as PolygonShape;
                MultipolygonShape multipolygon = feature.GetShape() as MultipolygonShape;
                if (polygon != null)
                {
                    result.Polygons.Add(polygon);
                }
                else if (multipolygon != null)
                {
                    foreach (var item in multipolygon.Polygons)
                    {
                        result.Polygons.Add(item);
                    }
                }
            }

            return(new Feature(result));
        }
Example #27
0
        private Feature GetValidPolygonFeature(Feature feature)
        {
            var featureType = feature.GetWellKnownType();

            if (featureType == WellKnownType.Polygon || featureType == WellKnownType.Multipolygon)
            {
                return(feature);
            }
            if (featureType == WellKnownType.GeometryCollection)
            {
                MultipolygonShape       multipolygonShape       = new MultipolygonShape();
                GeometryCollectionShape geometryCollectionShape = (GeometryCollectionShape)feature.GetShape();
                foreach (var innerShape in geometryCollectionShape.Shapes)
                {
                    var innerShapeType = innerShape.GetWellKnownType();
                    if (innerShapeType == WellKnownType.Polygon)
                    {
                        multipolygonShape.Polygons.Add((PolygonShape)innerShape);
                    }
                    else if (innerShapeType == WellKnownType.Multipolygon)
                    {
                        foreach (var innerPolygon in ((MultipolygonShape)innerShape).Polygons)
                        {
                            multipolygonShape.Polygons.Add(innerPolygon);
                        }
                    }
                }

                if (multipolygonShape.Polygons.Count > 0)
                {
                    return(new Feature(multipolygonShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                }
            }

            return(null);
        }
        private static Feature GetMultiPolygonFromCollection(Feature feature)
        {
            var shapeColleciton = (GeometryCollectionShape)feature.GetShape();
            var multipolygon    = new MultipolygonShape();

            foreach (var shape in shapeColleciton.Shapes)
            {
                var shapeWellKnownType = shape.GetWellKnownType();

                if (shapeWellKnownType == WellKnownType.Polygon)
                {
                    multipolygon.Polygons.Add(shape as PolygonShape);
                }
                else if (shapeWellKnownType == WellKnownType.Multipolygon)
                {
                    foreach (var polygon in ((MultipolygonShape)shape).Polygons)
                    {
                        multipolygon.Polygons.Add(polygon);
                    }
                }
            }

            return(new Feature(multipolygon.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
        }
        private static Feature MakeFeatureValidate(Feature feature)
        {
            Feature validFeature = feature.MakeValid();

            WellKnownType featureType   = feature.GetWellKnownType();
            WellKnownType validatedType = validFeature.GetWellKnownType();

            Feature result = validFeature;

            if (validatedType != featureType &&
                validatedType == WellKnownType.GeometryCollection)
            {
                GeometryCollectionShape geoCollectionShape = validFeature.GetShape() as GeometryCollectionShape;
                if (geoCollectionShape != null)
                {
                    BaseShape resultShape = null;
                    switch (featureType)
                    {
                    case WellKnownType.Point:
                    case WellKnownType.Multipoint:
                        Collection <PointShape> points = new Collection <PointShape>();
                        foreach (var shape in geoCollectionShape.Shapes)
                        {
                            PointShape point = shape as PointShape;
                            if (point != null)
                            {
                                points.Add(point);
                            }
                        }
                        resultShape = new MultipointShape(points);
                        break;

                    case WellKnownType.Line:
                    case WellKnownType.Multiline:
                        Collection <LineShape> lines = new Collection <LineShape>();
                        foreach (var shape in geoCollectionShape.Shapes)
                        {
                            LineShape line = shape as LineShape;
                            if (line != null)
                            {
                                lines.Add(line);
                            }
                        }
                        resultShape = new MultilineShape(lines);
                        break;

                    case WellKnownType.Polygon:
                    case WellKnownType.Multipolygon:
                        Collection <PolygonShape> polygons = new Collection <PolygonShape>();
                        foreach (var shape in geoCollectionShape.Shapes)
                        {
                            PolygonShape polygon = shape as PolygonShape;
                            if (polygon != null)
                            {
                                polygons.Add(polygon);
                            }
                        }
                        resultShape = new MultipolygonShape(polygons);
                        break;

                    default:
                        break;
                    }

                    if (resultShape != null)
                    {
                        result = new Feature(resultShape);
                    }
                }
            }

            return(result);
        }
        private IEnumerable <Feature> ShatterTwoFeatures(Feature feature1, Feature feature2)
        {
            var shape1 = (AreaBaseShape)feature1.GetShape();
            var shape2 = (AreaBaseShape)feature2.GetShape();

            bool intersects = !shape1.IsDisjointed(shape2);

            var columns = GetColumnValues(feature1, feature2);

            if (intersects)
            {
                MultipolygonShape intersection = null;
                MultipolygonShape difference12 = null;
                MultipolygonShape difference21 = null;
                try
                {
                    intersection = shape1.GetIntersection(shape2);

                    difference12 = shape1.GetDifference(shape2);

                    difference21 = shape2.GetDifference(shape1);
                }
                catch (Exception e)
                {
                    HandleExceptionFromInvalidFeature(feature1.Id, e.Message);
                    HandleExceptionFromInvalidFeature(feature2.Id, e.Message);
                }

                if (intersection != null)
                {
                    foreach (var item in intersection.Polygons)
                    {
                        yield return(new Feature(item, columns));
                    }
                }

                if (difference12 != null)
                {
                    foreach (var item in difference12.Polygons)
                    {
                        yield return(new Feature(item, columns));
                    }
                }
                else
                {
                    yield return(new Feature(shape1, columns));
                }


                if (difference21 != null)
                {
                    foreach (var item in difference21.Polygons)
                    {
                        yield return(new Feature(item, columns));
                    }
                }
                else
                {
                    yield return(new Feature(shape2, columns));
                }
            }
            else
            {
                yield return(feature1);

                yield return(feature2);
            }
        }