protected override SimpleShapeType GetFeatureSimpleShapeTypeCore(FeatureLayer featureLayer)
        {
            WellKnownType result = WellKnownType.Invalid;

            if (featureLayer != null)
            {
                featureLayer.SafeProcess(() =>
                {
                    Feature firstFeature = featureLayer.QueryTools.GetFeatureById("1", ReturningColumnsType.NoColumns);
                    result = firstFeature.GetWellKnownType();

                    if (result == WellKnownType.GeometryCollection)
                    {
                        GeometryCollectionShape geometryCollectionShape = (GeometryCollectionShape)firstFeature.GetShape();
                        result = geometryCollectionShape.Shapes[0].GetWellKnownType();
                    }
                });
            }
            return(MapHelper.GetSimpleShapeType(result));
        }
Exemple #2
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);
        }
Exemple #3
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 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);
        }