Last active
August 29, 2015 14:06
-
-
Save dshook/6d8269eb29f2fac88842 to your computer and use it in GitHub Desktop.
GeoJSON Import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var path = "C:\\new-path\simp.js"; | |
int counter = 0; | |
int commaCount = 0; | |
string line; | |
var newgeos = new List<Zipcode_geojson>(); | |
// Read the file and display it line by line. | |
System.IO.StreamReader file = new System.IO.StreamReader(path); | |
while((line = file.ReadLine()) != null) | |
{ | |
//Console.WriteLine (line); | |
counter++; | |
if(line == ","){ | |
commaCount++; | |
}else{ | |
var zipPos = line.IndexOf("GEOID10"); | |
var zipEndPos = line.IndexOf('"', zipPos + 9); | |
string zip = line.Substring(zipPos + 10, zipEndPos - zipPos - 3); | |
zip = zip.Replace("\"",""); | |
var latStrPos = line.IndexOf("INTPTLAT10"); | |
var endLatStrPos = line.IndexOf('"', latStrPos + 13); | |
decimal lat = Convert.ToDecimal(line.Substring(latStrPos + 14, endLatStrPos - latStrPos - 3)); | |
var longStrPos = line.IndexOf("INTPTLON10"); | |
var endLongStrPos = line.IndexOf('"', longStrPos + 13); | |
decimal longitude = Convert.ToDecimal(line.Substring(longStrPos + 14, endLongStrPos - longStrPos - 3)); | |
newgeos.Add(new Zipcode_geojson(){ Zip = zip, GeoJSON = line, Latitude = lat, Longitude = longitude}); | |
Console.WriteLine(string.Format("{0} {1},{2} len {3}", zip, lat,longitude, line.Length)); | |
} | |
} | |
file.Close(); | |
Zipcode_geojsons.InsertAllOnSubmit(newgeos); | |
SubmitChanges(); | |
Console.WriteLine(string.Format("{0} lines, {1} commas", counter, commaCount)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment