/// <summary> /// 根据位置类型,实例化对应的编译方式 /// </summary> /// <param name="locationType"></param> /// <returns></returns> public static IGeoLocation Create(GeoType locationType) { IGeoLocation geoLocation = null; switch (locationType) { case GeoType.Baidu: geoLocation = new Baidu.BaiduGeoLocation(); break; case GeoType.Gaode: geoLocation = new Gaode.GaodeGeoLocation(); break; case GeoType.Google: geoLocation = new Google.GoogleGeoLocation(); break; default: geoLocation = new Baidu.BaiduGeoLocation(); break; } return geoLocation; }
/// <summary> /// Reads and parses a ways (OSMPBF.Way) /// </summary> /// <param name="ways">List of ways</param> private void ReadWays(PrimitiveBlock primitiveBlock, List <Helpers.ReadPdb.Way> ways) { int dateGranularity = primitiveBlock.date_granularity; long second = 0; string key, val; int idKey, idValue; TypeValueTag typeValueTag; // Is it possible to import on the basis of the presence of significant tags bool IsImportToDb; for (int wayIndex = 0; wayIndex < ways.Count; wayIndex++) { Helpers.ReadPdb.Way osmpbfWay = ways[wayIndex]; DateTime stamp = new DateTime(); if (osmpbfWay.info != null) { Info info = osmpbfWay.info; second = (info.timestamp * dateGranularity) / 1000; stamp = this.timeEpoche.AddSeconds(second); } long deltaref = 0; var way = new Way(osmpbfWay.id, stamp); for (int nodeRef = 0; nodeRef < osmpbfWay.refs.Count; nodeRef++) { deltaref += osmpbfWay.refs[nodeRef]; way.Nodes.Add(this.AddNodeSimpleToNodesRefs(deltaref)); } IsImportToDb = false; GeoType geoType = null; if (osmpbfWay.keys.Count != 0 || osmpbfWay.keys.Count != 0) { for (int keyId = 0; keyId < osmpbfWay.keys.Count; keyId++) { key = UTF8Encoding.UTF8.GetString( primitiveBlock.stringtable.s[Convert.ToInt32(osmpbfWay.keys[keyId])]); val = UTF8Encoding.UTF8.GetString( primitiveBlock.stringtable.s[Convert.ToInt32(osmpbfWay.vals[keyId])]); OsmRepository.TagsRepository.AddTag(key, val, out idKey, out idValue, out typeValueTag); if (typeValueTag != TypeValueTag.NoImport) { IsImportToDb = true; this.InsertTagsAndValue(way.Id, idKey, idValue, val, typeValueTag); if (_importConfigurator.GetTypeOGC(Type.GetType("OsmImportToSqlServer.OsmData.Way"), key, out geoType)) { way.GeoType = geoType; } } } } //// DEBUG //Console.WriteLine(DateTime.Now + " Way - " + way.Id + ", " + way.Nodes.Count + " nodes"); if (IsImportToDb) { if (way.GeoType != null) { this.AddWay(way); } else { way.GeoType = this.WayIsPolygonOrLine(way); this.AddWay(way); } } else { this.AddWay(way); } } }
private static GeoType SetGeoType(string geoTypeId, string description, string geoTypePurposeId, string userLoginId, GeoType geoType = null) { if (geoType == null) { geoType = new GeoType { GeoTypeId = string.IsNullOrEmpty(geoTypeId) ? Utility.GetId() : geoTypeId, }; } geoType.Description = description; geoType.GeoTypePurposeId = geoTypePurposeId; geoType.UserLoginId = userLoginId; return(geoType); }
/// <summary> /// Create a new geo feature. /// </summary> /// <param name="_GeoCoordinates">A list of geo coordinates.</param> /// <param name="_Type">The type of the feature.</param> public GeoFeature(IEnumerable <GeoCoord> _GeoCoordinates, GeoType _Type = GeoType.undefined) { GeoCoordinates = new List <GeoCoord>(_GeoCoordinates); Type = _Type; }
public MapAdjust(GeoType geoType) { _geoType = geoType; }
public async Task <List <string> > GetGeoDictionaryVariantsAsync(GeoType type, string filterKeyword, string filterCity, string fiterRegion, RequestSettings rs = null, string filterCountry = "RU") { await Task.Delay(5).ConfigureAwait(false); return(GetGeoDictionaryVariants(type, filterKeyword, filterCity, fiterRegion, rs, filterCountry)); }
public List <string> GetGeoDictionaryVariants(GeoType type, string filterKeyword, string filterCity, string fiterRegion, RequestSettings rs = null, string filterCountry = "RU") { return(new List <string> { "1", "2", "3", "4" }); }
void drawEntityCollection(Graphics gfx, GeoType type, bool preDrawing) { foreach (var entity in mapEntities) if (entity.Value.GeoType == type && (type == GeoType.City || preDrawing || entity.Value.Box.IntersectsWith(viewportBox))) entity.Value.Draw(gfx); }
public void Highlight(string[] entities, int qType, bool initQuestion = false, bool mapExploration = false) { if (initQuestion) { if (selectedCountries != null) colorRegions(ColorRegionsMode.Reset); selectedCountries = new List<string>(); } foreach (var ent in mapEntities) { ent.Value.Highlighted = false; if (initQuestion && (ent.Value.GeoType == GeoType.MarineArea || ent.Value.GeoType == GeoType.Country || ent.Value.GeoType == GeoType.City || ent.Value.GeoType == GeoType.Region || ent.Value.GeoType == GeoType.River || ent.Value.GeoType == GeoType.Lake)) ent.Value.Enabled = false; } if (entities == null) return; bool mapEntitiesExist = true; foreach (string mapEnt in entities) if (mapEntities.ContainsKey(mapEnt)) { if (qType != 2) { if (mapEntities[mapEnt].GeoType == GeoType.City && qType == -3) mapEntities[mapEnt].Enabled = true; else { if (mapEntities[mapEnt].GeoType == GeoType.River && qType == -3) mapEntities[mapEnt].Enabled = true; mapEntities[mapEnt].Highlighted = true; } } } else { mapEntitiesExist = false; break; } if (qType != -2 && entities != null && mapEntitiesExist) { this.qType = qType; qGeoType = mapEntities[entities[0]].GeoType; highlightedEntities.Clear(); List<string> highlightedEntitiesNames = new List<string>(); //only used for Regions (to find out what country they belong to) highlightedEntitiesNames.Add(entities[0]); switch (qType) { case 2: //select five more random entities (from the nearest neighbors) SortedList<float, string> neighbors = new SortedList<float, string>(); //key is the approximated distance to the region, value is the region's name RectangleF entitiesBox = new RectangleF(mapEntities[entities[0]].Box.X, mapEntities[entities[0]].Box.Y, mapEntities[entities[0]].Box.Width, mapEntities[entities[0]].Box.Height); for (int i = 1; i < entities.Length; i++) addRectangles(ref entitiesBox, mapEntities[entities[i]].Box); foreach (var ent in mapEntities) if (!ArrayContainsString(entities, ent.Key) && !neighbors.ContainsValue(getBaseName(ent.Key)) && ent.Value.GeoType == qGeoType) { string entName = getBaseName(ent.Key); float distance = 0; if (qGeoType == GeoType.River || qGeoType == GeoType.Lake || qGeoType == GeoType.Region) { //create a Box that includes all segments of the river/lake/region RectangleF riverBox = new RectangleF(ent.Value.Box.X, ent.Value.Box.Y, ent.Value.Box.Width, ent.Value.Box.Height); for (int i = 2; mapEntities.ContainsKey(entName + " " + i.ToString()); i++) addRectangles(ref riverBox, mapEntities[entName + " " + i.ToString()].Box); distance = distanceBetweenRegions(riverBox, entitiesBox); } else distance = distanceBetweenRegions(ent.Value.Box, entitiesBox); //remember closest 20 regions if (neighbors.Count < 20) neighbors.Add(distance, entName); else if (distance < neighbors.Keys[19]) { neighbors.RemoveAt(19); while (neighbors.ContainsKey(distance)) //prevent two entries having the same distance distance += 0.000001f; neighbors.Add(distance, entName); } } //choose 5 random neighbors Random rand = new Random((int)DateTime.Now.Ticks); for (int i = 0; i < 5 && neighbors.Count > 0; i++) { int index = rand.Next(neighbors.Count); if (qGeoType == GeoType.River || qGeoType == GeoType.Lake || qGeoType == GeoType.Region) { //add all river/lake/region segments string river = getBaseName(neighbors.Values[index]); highlightedEntities.Add(mapEntities[river]); for (int j = 2; mapEntities.ContainsKey(river + " " + j.ToString()); j++) highlightedEntities.Add(mapEntities[river + " " + j.ToString()]); } else { string entName = neighbors.Values[index]; highlightedEntitiesNames.Add(entName); highlightedEntities.Add(mapEntities[entName]); } neighbors.RemoveAt(index); } break; case 3: if (!mapExploration) { //unzoom to a continental-wide view RectangleF box = new RectangleF(mapEntities[entities[0]].Box.X, mapEntities[entities[0]].Box.Y, mapEntities[entities[0]].Box.Width, mapEntities[entities[0]].Box.Height); for (int i = 1; i < entities.Length; i++) addRectangles(ref box, mapEntities[entities[i]].Box); rand = new Random((int)DateTime.Now.Ticks); zoomOnPoint(box.Left + box.Width / 2 + (float)rand.NextDouble() * 10.0f - 5.0f, box.Top + box.Height * 2 + (float)rand.NextDouble() * 10.0f - 5.0f, 10); //the center of the view is randomly displaced to prevent the user from zooming into the target location } return; } foreach (string ent in entities) highlightedEntities.Add(mapEntities[ent]); if (Math.Abs(qType) != 3 || qGeoType == GeoType.MarineArea) foreach (Shape ent in highlightedEntities) //enable these Shapes ent.Enabled = true; RectangleF highlightedEntitiesBox = new RectangleF(highlightedEntities[0].Box.X, highlightedEntities[0].Box.Y, highlightedEntities[0].Box.Width, highlightedEntities[0].Box.Height); for (int i = 1; i < highlightedEntities.Count; i++) addRectangles(ref highlightedEntitiesBox, highlightedEntities[i].Box); if (qType > 0) { if (mapExploration) preDrawMap(); else { //zoom in on the highlighted entities float newZoom; if (highlightedEntitiesBox.Width / highlightedEntitiesBox.Height > 1) newZoom = windowSize.Width / highlightedEntitiesBox.Width * 0.75f; else newZoom = windowSize.Height / highlightedEntitiesBox.Height * 0.75f; newZoom = Math.Min(newZoom, 200); zoomOnPoint(highlightedEntitiesBox.X + highlightedEntitiesBox.Width / 2, highlightedEntitiesBox.Y + highlightedEntitiesBox.Height / 2, newZoom); } } if (initQuestion) { if (qGeoType == GeoType.City) { //find out what countries the target cities are located in foreach (Shape ent in highlightedEntities) { string country = GetSelectedArea(ent.Box.Location, GeoType.Country); if (country != "" && !selectedCountries.Contains(country)) selectedCountries.Add(country); } colorRegions(ColorRegionsMode.Highlight); } else if (qGeoType == GeoType.Region) { //find out what countries the target regions are located in foreach (string region in highlightedEntitiesNames) foreach (var country in countryRegions) if (ArrayContainsString(country.Value, region) && !selectedCountries.Contains(country.Key)) { selectedCountries.Add(country.Key); break; } colorRegions(ColorRegionsMode.Highlight, highlightedEntitiesNames); } } } }
public string GetSelectedArea(PointF coords, GeoType geoType) { try { List<Tuple<string, double>> enclosingAreas = new List<Tuple<string, double>>(); double avgDistance; if (geoType == GeoType.All) { foreach (var entity in mapEntities) if ((entity.Value.GeoType == GeoType.City || entity.Value.Box.Contains(coords)) && entity.Value.IsSelected(coords.X, coords.Y, out avgDistance)) enclosingAreas.Add(new Tuple<string, double>(entity.Key, avgDistance)); } else { foreach (var entity in mapEntities) if (entity.Value.GeoType == geoType && (entity.Value.GeoType == GeoType.City || entity.Value.Box.Contains(coords)) && entity.Value.IsSelected(coords.X, coords.Y, out avgDistance)) enclosingAreas.Add(new Tuple<string, double>(entity.Key, avgDistance)); } //there may be more than one enclosing area if the user selected an enclave (e.g. San Marino or Lesotho), so select the one whose points are on average closest to the point of selection double minAvgDistance = double.MaxValue; string selectedArea = ""; foreach (var area in enclosingAreas) if (area.Item2 < minAvgDistance) { selectedArea = area.Item1; minAvgDistance = area.Item2; } if (selectedArea != "" && (geoType == GeoType.River || ((geoType == GeoType.Lake || geoType == GeoType.Region) && selectedArea.Contains("(composite)")))) { //rivers (and some administrative regions (and a lake or two)) often have more than one segment; selectedArea needs to include them all string baseName = selectedArea = getBaseName(selectedArea); int i = 2; while (mapEntities.ContainsKey(baseName + " " + i.ToString())) selectedArea += "+" + baseName + " " + (i++).ToString(); } return selectedArea; } catch (Exception exc) { MessageBox.Show("Exception in GetSelectedArea(float, float, GeoType): " + exc.Message); return ""; } }
public BaseGeometry(Window window, GeoType type) { m_Win = window; mGeoType = type; }
public bool Index(string indexName, IEnumerable <IDictionary <string, object> > items, bool archive = true) { if (!IndexExists(indexName)) { throw new Exception("Index not exists"); } if (items == null || items.Count() == 0) { return(true); } var mapping = _resources.GetMapping(indexName); List <Document> docs = new List <Document>(); foreach (var item in items) { if (item == null) { continue; } var itemType = item.GetType(); var doc = new Document(); foreach (var field in mapping.Fields) { #region AutoSetValues switch (field.FieldType) { case FieldTypes.GuidType: doc.Add(new StringField( field.Name, Guid.NewGuid().ToString("N").ToLower(), Field.Store.YES)); continue; } #endregion if (!item.ContainsKey(field.Name)) { continue; } var value = item[field.Name]; if (value == null) { continue; } switch (field.FieldType) { case FieldTypes.StringType: if (field.Index) { doc.Add(new StringField( field.Name, value.ToString(), field.Store ? Field.Store.YES : Field.Store.NO)); } else { doc.Add(new Lucene.Net.Documents.StoredField(field.Name, value.ToString())); } break; case FieldTypes.TextType: if (field.Index) { doc.Add(new TextField( field.Name, value.ToString(), field.Store ? Field.Store.YES : Field.Store.NO)); } else { doc.Add(new Lucene.Net.Documents.StoredField(field.Name, value.ToString())); } break; case FieldTypes.Int32Type: if (field.Index) { doc.Add(new Int32Field( field.Name, value.ToInt32(), field.Store ? Field.Store.YES : Field.Store.NO)); } else { doc.Add(new Lucene.Net.Documents.StoredField(field.Name, Convert.ToInt32(value))); } break; case FieldTypes.DoubleType: if (field.Index) { doc.Add(new DoubleField( field.Name, value.ToDouble(), field.Store ? Field.Store.YES : Field.Store.NO)); } else { doc.Add(new Lucene.Net.Documents.StoredField(field.Name, Convert.ToDouble(value))); } break; case FieldTypes.SingleType: if (field.Index) { doc.Add(new SingleField( field.Name, value.ToSingle(), field.Store ? Field.Store.YES : Field.Store.NO)); } else { doc.Add(new Lucene.Net.Documents.StoredField(field.Name, Convert.ToSingle(value))); } break; case FieldTypes.DateTimeType: if (field.Index) { value = DateTools.DateToString(Convert.ToDateTime(value.ToString()).ToUniversalTime(), DateTools.Resolution.SECOND); doc.Add(new StringField( field.Name, (string)value, field.Store ? Field.Store.YES : Field.Store.NO)); } else { doc.Add(new Lucene.Net.Documents.StoredField(field.Name, value.ToString())); } break; case FieldTypes.GeoType: InitSpatial(); GeoType geoValue = GeoType.Parse(value); if (geoValue is GeoPoint && geoValue.IsValid()) { var geoPoint = (GeoPoint)geoValue; var strategy = new RecursivePrefixTreeStrategy(_tree, field.Name); var point = _spatialContext.MakePoint(geoPoint.Longidute, geoPoint.Latitude); foreach (var f in strategy.CreateIndexableFields(point)) { doc.Add(f); } if (field.Store) { doc.Add(new Lucene.Net.Documents.StoredField(field.Name, geoPoint.ToString())); } } break; } } docs.Add(doc); } //lock (_writeLocker) { var writer = _resources.GetIndexWriter(indexName); writer.AddDocuments(docs); writer.Flush(triggerMerge: false, applyAllDeletes: false); } if (archive) { _archive.Index(indexName, items); } return(true); }
/// <summary> /// Parse and set coordinates. /// </summary> /// <param name="type">Geographical information type.</param> /// <param name="target">Target geographical information.</param> /// <param name="reader">Current xml feed reader.</param> /// <param name="feed">Current feed.</param> /// <param name="nodeInfo">Current node information.</param> /// <returns>List of geographical coordinates.</returns> private async Task SetCoordinates(GeoType type, GeoInformation target, XmlReader reader, Feed feed, NodeInformation nodeInfo) { //Init target.coordinates ??= new List <GeoCoordinate>(); if (!reader.IsEmptyElement) { var content = await reader.ReadStartElementAndContentAsStringAsync().ConfigureAwait(false); if (!string.IsNullOrWhiteSpace(content)) { //Attempt to parse coordinates var index = 0; content = content.Replace(",", ".").Trim(); var coords = content.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(part => part.Trim()).ToList(); if (coords.Count % 2 == 0) { //Set target type target.Type = type; //Get all coordinates while (index < coords.Count) { if (double.TryParse(coords[index], NumberStyles.Float, CultureInfo.InvariantCulture, out var latitude)) { if (double.TryParse(coords[index + 1], NumberStyles.Float, CultureInfo.InvariantCulture, out var longitude)) { try { //Add coordinate to target coordinates target.coordinates.Add(new GeoCoordinate(latitude, longitude)); } catch (ArgumentOutOfRangeException ex) { //Unknown coordinates format SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, $"Latitude: {latitude}, Longitude: {longitude}", ex.Message); } //Next coordinates index += 2; } else { //Parse longitude failed! SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, coords[index + 1], $"Parse longitude failed! (Index: {index + 1})"); } } else { //Parse latitude failed! SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, coords[index], $"Parse latitude failed! (Index: {index})"); } } } else { //Coordinates must have both latitude and longitude! SetParseError(ParseErrorType.UnknownNodeFormat, nodeInfo, feed, content, "Coordinates must have both latitude and longitude!"); } } } }