コード例 #1
0
 public TopoCollection(string type, TopoObject[] geometries)
     : base(type)
 {
     if (geometries == null)
         throw new ArgumentNullException("geometries");
     _geometries = geometries;
 }
コード例 #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);
        }
コード例 #3
0
 public TopoBuilder(string type, 
     long id, 
     IAttributesTable properties, 
     double[][] coordinates, 
     int[][][] arcs, 
     TopoObject[] geometries)
 {
     if (String.IsNullOrEmpty(type))
         throw new ArgumentNullException("type", "type null");
     _type = type;
     _id = id;
     _properties = properties ?? new AttributesTable();
     _coordinates = coordinates;
     _arcs = arcs;
     _geometries = geometries;
 }
コード例 #4
0
        private FeatureCollection CreateCollection(TopoObject[] data)
        {
            IFeature[] features = new IFeature[data.Length];
            for (int i = 0; i < data.Length; i++)
            {
                TopoObject component = data[i];
                FeatureCollection coll = Create(component);
                features[i] = coll[0];
            }

            FeatureCollection collection = new FeatureCollection();
            foreach (IFeature feature in features)
                collection.Add(feature);
            return collection;
        }