Skip to content

Commit

Permalink
Instances optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
chubrik committed May 11, 2019
1 parent d801a9b commit 40699e1
Show file tree
Hide file tree
Showing 18 changed files with 232 additions and 498 deletions.
2 changes: 1 addition & 1 deletion OsmDataKit.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void LoadRelationObject()
var relation = OsmObjectService.LoadRelationObject(SrcPath, cacheName: title, relationId: relationId);
Assert.IsTrue(relation.Type == OsmGeoType.Relation);
Assert.IsTrue(relation.Id == relationId);
Assert.IsTrue(relation.Title == title);
//Assert.IsTrue(relation.Title == title);
Assert.IsTrue(relation.Tags["type"] == "multipolygon");
Assert.IsTrue(relation.Tags["place"] == "island");
Assert.IsTrue(relation.Members.Count > 50);
Expand Down
176 changes: 0 additions & 176 deletions OsmDataKit/Data/DataConverter.cs

This file was deleted.

11 changes: 0 additions & 11 deletions OsmDataKit/Data/NodeData.cs

This file was deleted.

15 changes: 0 additions & 15 deletions OsmDataKit/Data/OsmGeoData.cs

This file was deleted.

27 changes: 0 additions & 27 deletions OsmDataKit/Data/OsmResponseData.cs

This file was deleted.

12 changes: 0 additions & 12 deletions OsmDataKit/Data/RelationData.cs

This file was deleted.

12 changes: 0 additions & 12 deletions OsmDataKit/Data/WayData.cs

This file was deleted.

2 changes: 1 addition & 1 deletion OsmDataKit/Extensions/RelationObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static IEnumerable<NodeObject> GetAllNodes(this RelationObject relation)

public static bool HasMissedParts(this RelationObject relation)
{
if (relation.MissedMembersInfo?.Count > 0)
if (relation.MissedMembers?.Count > 0)
return true;

foreach (var member in relation.Members)
Expand Down
86 changes: 26 additions & 60 deletions OsmDataKit/Models/GeoObject.cs
Original file line number Diff line number Diff line change
@@ -1,84 +1,50 @@
using OsmSharp;
using Kit;
using Newtonsoft.Json;
using OsmSharp;
using System.Collections.Generic;
using System.Linq;

namespace OsmDataKit
{
//#if DEBUG
// [DebuggerDisplay("{" + nameof(DebugInfo) + ",nq}")]
//#endif
public abstract class GeoObject
{
[JsonIgnore]
public abstract OsmGeoType Type { get; }

public long Id { get; }
[JsonProperty("i")]
public long Id { get; set; }

private Dictionary<string, string> _tags;
public Dictionary<string, string> Tags => _tags ?? (_tags = new Dictionary<string, string>(0));
[JsonProperty("g", NullValueHandling = NullValueHandling.Ignore)]
public Dictionary<string, string> _tagsOrNull { get; set; }

[JsonIgnore]
public Dictionary<string, string> Tags => _tagsOrNull ?? (_tagsOrNull = new Dictionary<string, string>(0));

protected GeoObject() { }

protected GeoObject(OsmGeo osmGeo)
{
Id = osmGeo.Id.GetValueOrDefault();

if (osmGeo.Tags.Count > 0)
_tags = osmGeo.Tags.ToDictionary(i => i.Key, i => i.Value);
_tagsOrNull = osmGeo.Tags.ToDictionary(i => i.Key, i => i.Value);
}

//protected GeoObject(
// long id,
// IReadOnlyDictionary<string, string> tags,
// Dictionary<string, string> data)
//{
// Debug.Assert(id > 0);

// Id = id;

// if (tags?.Count > 0)
// _tags = tags;

// if (data?.Count > 0)
// _data = data;
//}

//#region Title

//private static readonly List<string> _tagNames = new List<string> { "name:en", "int_name", "name", "name:ru" };
[JsonIgnore]
public string OsmUrl => $"https://www.openstreetmap.org/{Type.ToString().ToLower()}/{Id}";

//private bool _titleAssigned;
//private string _title;
private static readonly List<string> _tagNames = new List<string> { "name:en", "int_name", "name", "name:ru" };

//public string Title
//{
// get
// {
// if (_titleAssigned)
// return _title;

// _titleAssigned = true;

// if (_tags != null)
// foreach (var tagName in _tagNames)
// if (Tags.TryGetValue(tagName, out var title) && !title.IsNullOrWhiteSpace())
// return _title = title.Trim();

// return null;
// }
// set
// {
// _titleAssigned = true;
// _title = value;
// }
//}

//public bool HasTitle => Title != null;

//#endregion
public override string ToString()
{
var attr = Type.ToString()[0] + Id.ToString();

public string SourceUrl => $"https://www.openstreetmap.org/{Type.ToString().ToLower()}/{Id}";
if (_tagsOrNull != null)
foreach (var tagName in _tagNames)
if (Tags.TryGetValue(tagName, out var title) && !title.IsNullOrWhiteSpace())
return attr + " - " + title.Trim();

//#if DEBUG
// private string DebugInfo =>
// Type.ToString()[0] + Id.ToString() + " - " + Title;
//#endif
return attr;
}
}
}
Loading

0 comments on commit 40699e1

Please sign in to comment.