コード例 #1
0
ファイル: TopoBuilder.cs プロジェクト: klosejay/Gisoft.Map
        public TopoObject Build()
        {
            TopoObject obj;

            switch (_type)
            {
            case "Point":
                obj = new TopoPoint(_type, _coordinates);
                break;

            case "LineString":
                obj = new TopoLineString(_type, _arcs);
                break;

            case "Polygon":
                obj = new TopoPolygon(_type, _arcs);
                break;

            case "MultiPoint":
                obj = new TopoMultiPoint(_type, _coordinates);
                break;

            case "MultiLineString":
                obj = new TopoMultiLineString(_type, _arcs);
                break;

            case "MultiPolygon":
                obj = new TopoMultiPolygon(_type, _arcs);
                break;

            case "GeometryCollection":
                obj = new TopoCollection(_type, _geometries);
                break;

            default:
                throw new ArgumentOutOfRangeException("unhandled type: " + _type);
            }
            obj.Id         = _id;
            obj.Properties = _properties;
            return(obj);
        }
コード例 #2
0
        public FeatureCollection Create(TopoObject data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            string type = data.Type;

            if (String.IsNullOrEmpty(type))
            {
                throw new ArgumentException("type undefined", "data");
            }

            if (String.Equals("GeometryCollection", type))
            {
                // a TopoJSON "GeometryCollection" actually is an IFeature array
                // so we handle this stuff as a special case
                TopoCollection coll = (TopoCollection)data;
                return(CreateCollection(coll.Geometries));
            }

            IGeometry geometry;

            switch (type)
            {
            case "Point":
                TopoPoint point = (TopoPoint)data;
                geometry = CreatePoint(point.Coordinates);
                break;

            case "MultiPoint":
                TopoMultiPoint mpoint = (TopoMultiPoint)data;
                geometry = CreateMultiPoint(mpoint.Coordinates);
                break;

            case "LineString":
                TopoLineString lstring = (TopoLineString)data;
                geometry = CreateLineString(lstring.Arcs);
                break;

            case "MultiLineString":
                TopoMultiLineString mlstring = (TopoMultiLineString)data;
                geometry = CreateMultiLineString(mlstring.Arcs);
                break;

            case "Polygon":
                TopoPolygon poly = (TopoPolygon)data;
                geometry = CreatePolygon(poly.Arcs);
                break;

            case "MultiPolygon":
                TopoMultiPolygon mpoly = (TopoMultiPolygon)data;
                geometry = CreateMultiPolygon(mpoly.Arcs);
                break;

            default:
                string s = string.Format("type unsupported: {0}", type);
                throw new NotSupportedException(s);
            }

            IAttributesTable      properties = data.Properties;
            Feature               feature    = new Feature(geometry, properties);
            Collection <IFeature> collection = new Collection <IFeature> {
                feature
            };

            return(new FeatureCollection(collection));
        }