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"]); }
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"]); }
public async Task <IEnumerable <Location> > RetrieveLocationsFromContent() { var importFolder = Directory.GetParent(_fileLocation).FullName; var extractionFolder = Path.GetFileNameWithoutExtension(_fileLocation); var fullExtractionFolder = Path.Combine(importFolder, extractionFolder); await Task.Run(() => ZipFile.ExtractToDirectory(_fileLocation, fullExtractionFolder, true)); var shapeFileDirectory = Directory.EnumerateDirectories(fullExtractionFolder, "MSI", SearchOption.AllDirectories).First(); var shapeFileLocation = Directory.EnumerateFiles(shapeFileDirectory, "*.shp").First(); var shape = new ShapeFileReader(shapeFileLocation); var featuresAsJson = await Task.Run(() => shape.FeaturesAsJson()); var jsonContent = featuresAsJson.Replace("\\u0000", string.Empty); jsonContent = MapJsonToCorrectFormat(jsonContent); var data = JsonConvert.DeserializeObject <IEnumerable <Feature> >(jsonContent); return(data); }