コード例 #1
0
        static void Main(string[] args)
        {
            try{
                Console.WriteLine("Starting Harlow interactions.");

                string          shapeFile = @"D:\Data\geo\tiger\TIGER2016\STATE\tl_2016_us_state.shp";
                ShapeFileReader reader    = new ShapeFileReader(shapeFile);
                reader.RequiredPrecision = 6;
                reader.LoadFile();

                using (StreamWriter sw = new StreamWriter(@"C:\Projects\Layered.io\Data\JSON\HarlowFeatures\us_states_features_temp.txt")){
                    //		sw.WriteLine("[");
                    foreach (var f in reader.Features)
                    {
                        string json = JsonConvert.SerializeObject(f);
                        //			var fe = JsonConvert.DeserializeObject<VectorShape>(json);

                        sw.WriteLine(json);
                        //			sw.WriteLine(",");
                    }
                    //		sw.WriteLine("]");
                }
            } finally {
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }
コード例 #2
0
        public void USGS_CitiesAndTowns()
        {
            ShapeFileReader reader = new ShapeFileReader(pointFile);

            reader.LoadFile();

            string json = reader.FeaturesAsJson();

            File.WriteAllText("point.json", reader.FeatureAsJson(42));

            Assert.AreEqual(6062745, json.Length);
            Assert.AreEqual(38187, reader.Features.Length);

            Assert.AreEqual(157, reader.FeatureAsJson(0).Length);
            Assert.AreEqual(159, reader.FeatureAsJson(38186).Length);

            VectorPoint[] features = reader.Features as VectorPoint[];

            Assert.AreEqual(-100.06096779999996, features[0].Coordinates[0]);
            Assert.AreEqual(48.813056899065479, features[0].Coordinates[1]);
            Assert.AreEqual(-101.22071379999994, features[42].Coordinates[0]);
            Assert.AreEqual(48.513074399064209, features[42].Coordinates[1]);
            Assert.AreEqual(-149.22967529296875, features[38186].Coordinates[0]);
            Assert.AreEqual(61.541870116397909, features[38186].Coordinates[1]);

            Assert.AreEqual(5, reader.Features[0].Properties.Count);

            Assert.AreEqual("dunseith", reader.Features[0].Properties["nam"]);
            Assert.AreEqual("al020", reader.Features[0].Properties["f_code"]);
            Assert.AreEqual("773", reader.Features[0].Properties["pop"]);
            Assert.AreEqual("2010", reader.Features[0].Properties["ypc"]);
            Assert.AreEqual("usa", reader.Features[0].Properties["soc"]);

            Assert.AreEqual(reader.Features[42].Properties.Count, 5);
            Assert.AreEqual("glenburn", reader.Features[42].Properties["nam"]);
            Assert.AreEqual("al020", reader.Features[42].Properties["f_code"]);
            Assert.AreEqual("380", reader.Features[42].Properties["pop"]);
            Assert.AreEqual("2010", reader.Features[42].Properties["ypc"]);
            Assert.AreEqual("usa", reader.Features[42].Properties["soc"]);

            Assert.AreEqual(reader.Features[38186].Properties.Count, 5);
            Assert.AreEqual("matanuska", reader.Features[38186].Properties["nam"]);
            Assert.AreEqual("al020", reader.Features[38186].Properties["f_code"]);
            Assert.AreEqual("-999", reader.Features[38186].Properties["pop"]);
            Assert.AreEqual("2010", reader.Features[38186].Properties["ypc"]);
            Assert.AreEqual("usa", reader.Features[38186].Properties["soc"]);
        }
コード例 #3
0
        public void Tiger_US_PlaceBoundaries()
        {
            ShapeFileReader reader = new ShapeFileReader(polyFile);

            reader.LoadFile();

            string json = reader.FeaturesAsJson();

            File.WriteAllText("polygon.json", reader.FeatureAsJson(42));

            Assert.AreEqual(25301992, json.Length);
            Assert.AreEqual(1516, reader.Features.Length);

            Assert.AreEqual(4780, reader.FeatureAsJson(0).Length);
            Assert.AreEqual(13137, reader.FeatureAsJson(1515).Length);

            VectorShape[] features = reader.Features as VectorShape[];

            Assert.AreEqual(-118.456008, features[0].Coordinates[0][0].Value[0]);
            Assert.AreEqual(34.284903, features[0].Coordinates[0][0].Value[1]);
            Assert.AreEqual(-118.30807, features[42].Coordinates[0][0].Value[0]);
            Assert.AreEqual(34.161224, features[42].Coordinates[0][0].Value[1]);
            Assert.AreEqual(-122.060783, features[1515].Coordinates[0][0].Value[0]);
            Assert.AreEqual(37.05574, features[1515].Coordinates[0][0].Value[1]);

            Assert.AreEqual(16, reader.Features[0].Properties.Count);

            Assert.AreEqual("06", reader.Features[42].Properties["statefp"]);
            Assert.AreEqual("30000", reader.Features[42].Properties["placefp"]);
            Assert.AreEqual("02410597", reader.Features[42].Properties["placens"]);
            Assert.AreEqual("0630000", reader.Features[42].Properties["geoid"]);
            Assert.AreEqual("glendale", reader.Features[42].Properties["name"]);
            Assert.AreEqual("glendale city", reader.Features[42].Properties["namelsad"]);
            Assert.AreEqual("25", reader.Features[42].Properties["lsad"]);
            Assert.AreEqual("c1", reader.Features[42].Properties["classfp"]);
            Assert.AreEqual("y", reader.Features[42].Properties["pcicbsa"]);
            Assert.AreEqual("n", reader.Features[42].Properties["pcinecta"]);
            Assert.AreEqual("g4110", reader.Features[42].Properties["mtfcc"]);
            Assert.AreEqual("a", reader.Features[42].Properties["funcstat"]);
            Assert.AreEqual("78848571", reader.Features[42].Properties["aland"]);
            Assert.AreEqual("337673", reader.Features[42].Properties["awater"]);
            Assert.AreEqual("+34.1813929", reader.Features[42].Properties["intptlat"]);
            Assert.AreEqual("-118.2458301", reader.Features[42].Properties["intptlon"]);
        }
コード例 #4
0
ファイル: LineTest.cs プロジェクト: Tsiou/Harlow
        public void Tiger_CA_SanFran_Roads()
        {
            ShapeFileReader reader = new ShapeFileReader(lineFile);

            reader.LoadFile();

            string json = reader.FeaturesAsJson();

            File.WriteAllText("line.json", reader.FeatureAsJson(42));

            Assert.AreEqual(2166881, json.Length);
            Assert.AreEqual(4589, reader.Features.Length);

            Assert.AreEqual(283, reader.FeatureAsJson(0).Length);
            Assert.AreEqual(649, reader.FeatureAsJson(4588).Length);

            VectorShape[] features = reader.Features as VectorShape[];

            Assert.AreEqual(-122.480706, features[0].Coordinates[0][0].Value[0]);
            Assert.AreEqual(37.792316, features[0].Coordinates[0][0].Value[1]);
            Assert.AreEqual(-122.469023, features[42].Coordinates[0][0].Value[0]);
            Assert.AreEqual(37.737949, features[42].Coordinates[0][0].Value[1]);
            Assert.AreEqual(-122.364304, features[4588].Coordinates[0][0].Value[0]);
            Assert.AreEqual(37.819468, features[4588].Coordinates[0][0].Value[1]);

            Assert.AreEqual(4, reader.Features[0].Properties.Count);

            Assert.AreEqual("110498938555", reader.Features[0].Properties["linearid"]);
            Assert.AreEqual("n van horn ln", reader.Features[0].Properties["fullname"]);
            Assert.AreEqual("m", reader.Features[0].Properties["rttyp"]);
            Assert.AreEqual("s1400", reader.Features[0].Properties["mtfcc"]);

            Assert.AreEqual("110498935016", reader.Features[42].Properties["linearid"]);
            Assert.AreEqual("w portal ave", reader.Features[42].Properties["fullname"]);
            Assert.AreEqual("m", reader.Features[42].Properties["rttyp"]);
            Assert.AreEqual("s1400", reader.Features[42].Properties["mtfcc"]);

            Assert.AreEqual("110498933806", reader.Features[4588].Properties["linearid"]);
            Assert.AreEqual("avenue n", reader.Features[4588].Properties["fullname"]);
            Assert.AreEqual("m", reader.Features[4588].Properties["rttyp"]);
            Assert.AreEqual("s1400", reader.Features[4588].Properties["mtfcc"]);
        }