Example #1
1
        public void BuildStradeFixed()
        {
            string path = "strade" + shp;
            Assert.IsTrue(File.Exists(path));
            
            ShapefileDataReader reader = new ShapefileDataReader(path, factory);
            List<Feature> features = new List<Feature>(reader.RecordCount);
            while (reader.Read())
            {
                Feature feature = new Feature(reader.Geometry, new AttributesTable());
                object[] values = new object[reader.FieldCount - 1];
                reader.GetValues(values);
                for (int i = 0; i < values.Length; i++)
                {
                    string name = reader.GetName(i + 1);
                    object value = values[i];
                    feature.Attributes.AddAttribute(name, value);
                }
                features.Add(feature);
            }
            Assert.AreEqual(703, features.Count);

            string shapepath = "strade_fixed";
            if (File.Exists(shapepath + shp))
                File.Delete(shapepath + shp);
            Assert.IsFalse(File.Exists(shapepath + shp));
            if (File.Exists(shapepath + shx))
                File.Delete(shapepath + shx);
            Assert.IsFalse(File.Exists(shapepath + shx));
            if (File.Exists(shapepath + dbf))
                File.Delete(shapepath + dbf);
            Assert.IsFalse(File.Exists(shapepath + dbf));

            DbaseFileHeader header = reader.DbaseHeader;
            
            ShapefileDataWriter writer = new ShapefileDataWriter(shapepath, factory);
            writer.Header = header;
            writer.Write(features);

            Assert.IsTrue(File.Exists(shapepath + shp));
            Assert.IsTrue(File.Exists(shapepath + shx));
            Assert.IsTrue(File.Exists(shapepath + dbf));
        }       
Example #2
0
        // If you select the ICustomTypeDescriptor implemented by RowStructure into a
        // property grid, the values are somehow missing, so copy them over to a class
        // that works.
        private AdhocPropertyList CreatePropertyList(ShapefileDataReader sfdr)
        {
            object[] vals = new object[sfdr.FieldCount-1]; // ignore the geometry column
            sfdr.GetValues(vals);
            AdhocPropertyList result = new AdhocPropertyList(vals.Length);

            for(int i=0; i<vals.Length; i++)
            {
                string name = sfdr.GetName(i+1); // yes it's +1
                result.Add(new AdhocProperty(name, vals[i], true, true)); // but the value isn't!
            }

            return result;
        }