コード例 #1
0
        public static Dictionary <string, GeoCodedLocation> ReadGeo(string path)
        {
            Dictionary <string, GeoCodedLocation> result = new Dictionary <string, GeoCodedLocation>(StringComparer.InvariantCultureIgnoreCase);

            using (TextReader textReader = new StreamReader(path, Encoding.UTF8))
            {
                var csv = new CsvParser(textReader);
                while (true)
                {
                    var row = csv.Read();
                    if (row == null)
                    {
                        break;
                    }

                    string ourName = row[2];

                    if (result.ContainsKey(ourName))
                    {
                        continue;
                    }

                    GeoCodedLocation city = null;

                    if (row[0] != "")
                    {
                        city = new GeoCodedLocation(double.Parse(row[0]), double.Parse(row[1]), row[3]);
                    }

                    result.Add(ourName, city);
                }
            }

            return(result);
        }
コード例 #2
0
        public void AddConnection(GeoCodedLocation location1, GeoCodedLocation location2)
        {
            AddLocation(location1);
            AddLocation(location2);

            GeoCodedLocation locationA;
            GeoCodedLocation locationB;

            if (location1.CompareTo(location2) < 0)
            {
                locationA = location1;
                locationB = location2;
            }
            else
            {
                locationA = location2;
                locationB = location1;
            }

            var key = new Tuple <GeoCodedLocation, GeoCodedLocation>(locationA, locationB);

            int newValue = CollectionUtils.Increment(usedConnections, key);

            if (newValue > maxConnectionValue)
            {
                maxConnectionValue = newValue;
            }
        }
コード例 #3
0
        private void AddLocation(GeoCodedLocation location)
        {
            int newValue = CollectionUtils.Increment(locationToConnectionsCount, location);

            if (newValue > maxLocationValue)
            {
                maxLocationValue = newValue;
            }
        }
コード例 #4
0
        public GeoCodedLocation GeoCode_OrNull(string location)
        {
            GeoCodedLocation found = null;

            if (knownLocations.TryGetValue(location, out found))
            {
                if (found != null)
                {
                    logger.Debug("Location already known and already successfully geo coded: \"{0}\" -> \"{1}\".", location, found.normalizedName);
                }
                else
                {
                    if (geoCoder != null && retry && !failedNow.Contains(location))
                    {
                        found = geoCoder.GetGeocoded(location);
                        knownLocations[location] = found;
                        if (found != null)
                        {
                            logger.Info("Location alredy known, failed previously, but geo coded successfully now: \"{0}\" -> \"{1}\".", location, found.normalizedName);
                        }
                        else
                        {
                            failedNow.Add(location);
                            logger.Warn("Location already known, failed to geo code even now after retry: \"{0}\".", location);
                        }
                    }
                    else
                    {
                        logger.Warn("Location already known, failed to geo code previously - not retrying: \"{0}\".", location);
                    }
                }
            }
            else
            {
                if (geoCoder != null)
                {
                    found = geoCoder.GetGeocoded(location);
                    knownLocations.Add(location, found);
                    if (found != null)
                    {
                        logger.Info("Location geo coded: \"{0}\" -> \"{1}\"", location, found.normalizedName);
                    }
                    else
                    {
                        failedNow.Add(location);
                        logger.Warn("Location failed to geo code: \"{0}\".", location);
                    }
                }
                else
                {
                    unknownLocations.Add(location);
                    logger.Warn("Location not geo coded previously, not geo coding now: \"{0}\".", location);
                }
            }

            return(found);
        }
コード例 #5
0
ファイル: KmlWriter.cs プロジェクト: scigeobib/scigeobib
        public void WriteLine(GeoCodedLocation from, GeoCodedLocation to, double width, int count)
        {
            xmlWriter.WriteStartElement("Placemark");

            xmlWriter.WriteStartElement("visibility");
            xmlWriter.WriteString("1");
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("open");
            xmlWriter.WriteString("0");
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("name");
            xmlWriter.WriteCData(from.normalizedName + "---" + to.normalizedName);
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("description");
            xmlWriter.WriteCData("Count: " + count);
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("Style");
            xmlWriter.WriteStartElement("LineStyle");

            xmlWriter.WriteStartElement("color");
            xmlWriter.WriteString("ffff55ff");
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("width");
            xmlWriter.WriteString(width.ToString(CultureInfo.InvariantCulture));
            xmlWriter.WriteEndElement();

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("LineString");

            xmlWriter.WriteStartElement("extrude");
            xmlWriter.WriteString("1");
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("tessellate");
            xmlWriter.WriteString("1");
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("altitudeMode");
            xmlWriter.WriteString("clampToGround");
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("coordinates");
            xmlWriter.WriteString(from.lon + "," + from.lat + ",0" + "\n" + to.lon + "," + to.lat + ",0");
            xmlWriter.WriteEndElement();

            xmlWriter.WriteEndElement();

            xmlWriter.WriteEndElement();
        }
コード例 #6
0
        public void DoWork()
        {
            try
            {
                collaborations_byCity        = new CollaborationMatrix();
                collaborations_byCountry     = new CollaborationMatrix();
                collaborations_byInstitution = new CollaborationMatrix();

                FieldsExtractor extractor = new FieldsExtractor(publicationsFile.Type);

                foreach (Publication publication in publicationsFile.publications)
                {
                    AddCollaborations(collaborations_byCity, extractor.GetCities(publication));
                    AddCollaborations(collaborations_byCountry, extractor.GetCountries(publication));
                    AddCollaborations(collaborations_byInstitution, extractor.GetInstitutions(publication));
                }

                statistics = new Statistics();
                foreach (Publication publication in publicationsFile.publications)
                {
                    string country = extractor.GetCountry(publication);
                    string journal = extractor.GetJournal(publication);
                    if (country != null)
                    {
                        GeoCodedLocation geoCodedCountry = geoCoding.GeoCode_OrNull(country);

                        if (geoCodedCountry != null)
                        {
                            statistics.AddPublicationInCountry(geoCodedCountry);

                            if (journal != null)
                            {
                                statistics.AddJournalInCountry(geoCodedCountry, journal);
                            }
                        }
                    }
                }

                geoCoding.LogTotals();

                logger.Info("Done");
            }
            catch (Exception e)
            {
                logger.Error(e, "Error while doing work.");
                throw;
            }
        }
コード例 #7
0
        private void AddCollaborations(CollaborationMatrix addTo, List <FieldsExtractor.ParsedLocation> extractedLocations)
        {
            List <GeoCodedLocation> publicationCitiesResolved = extractedLocations.Select(
                x =>
            {
                GeoCodedLocation loc = geoCoding.GeoCode_OrNull(x.NameForGeocoding);
                if (loc != null)
                {
                    loc = new GeoCodedLocation(loc.lat, loc.lon, x.AdditionalNamePrefix + loc.normalizedName);
                }
                return(loc);
            }
                ).Where(x => x != null).Distinct().ToList();

            for (int i = 0; i < publicationCitiesResolved.Count; ++i)
            {
                for (int j = i + 1; j < publicationCitiesResolved.Count; ++j)
                {
                    addTo.AddConnection(publicationCitiesResolved[i], publicationCitiesResolved[j]);
                }
            }
        }
コード例 #8
0
ファイル: KmlWriter.cs プロジェクト: scigeobib/scigeobib
        public void WriteCity(GeoCodedLocation city, double width, int count)
        {
            xmlWriter.WriteStartElement("Placemark");

            xmlWriter.WriteStartElement("Point");

            xmlWriter.WriteStartElement("coordinates");
            xmlWriter.WriteString(city.lon + " , " + city.lat);
            xmlWriter.WriteEndElement();

            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("name");
            xmlWriter.WriteString(city.normalizedName);
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("description");
            xmlWriter.WriteString("Count: " + count);
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("Style");
            xmlWriter.WriteStartElement("IconStyle");

            xmlWriter.WriteStartElement("scale");
            xmlWriter.WriteString(width.ToString(CultureInfo.InvariantCulture));
            xmlWriter.WriteEndElement();

            xmlWriter.WriteStartElement("Icon");
            xmlWriter.WriteStartElement("href");
            xmlWriter.WriteString("http://maps.google.com/mapfiles/kml/pal2/icon18.png");
            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndElement();

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndElement();

            xmlWriter.WriteEndElement();
        }
コード例 #9
0
        public GeoCodedLocation GetGeocoded(string query)
        {
            var request = new GeocodeRequest()
            {
                Query       = query,
                MaxResults  = 1,
                BingMapsKey = apiKey
            };

            var response = ServiceManager.GetResponseAsync(request).Result;

            if (response.AuthenticationResultCode != "ValidCredentials")
            {
                throw new Exception("Invalid GeoCoder API key");
            }

            if (response.StatusCode != 200)
            {
                throw new Exception("Invalid GeoCoder response status code: " + response.StatusCode);
            }

            if (response != null &&
                response.ResourceSets != null &&
                response.ResourceSets.Length > 0 &&
                response.ResourceSets[0].Resources != null &&
                response.ResourceSets[0].Resources.Length > 0)
            {
                var result = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;

                GeoCodedLocation geoCity = new GeoCodedLocation(result.Point.Coordinates[0], result.Point.Coordinates[1], result.Address.FormattedAddress);

                return(geoCity);
            }

            return(null);
        }
コード例 #10
0
ファイル: Statistics.cs プロジェクト: scigeobib/scigeobib
 public void AddJournalInCountry(GeoCodedLocation country, string journal)
 {
     CollectionUtils.AddToSet(countryToJournals, country, journal);
 }
コード例 #11
0
ファイル: Statistics.cs プロジェクト: scigeobib/scigeobib
 public void AddPublicationInCountry(GeoCodedLocation country)
 {
     CollectionUtils.Increment(countryToPublicationsCount, country);
 }