Skip to content

Commit

Permalink
New Areas
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKarlas committed Nov 25, 2023
1 parent 5f8b6e5 commit 22330cc
Show file tree
Hide file tree
Showing 3 changed files with 7,568 additions and 3,773 deletions.
26 changes: 21 additions & 5 deletions OsmGursBuildingImport/GursData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ record ProcessingArea(Geometry Geometry, string Name, List<BuildingInfo> Buildin
class GursData
{
private static GeometryFactory D96Factory = NtsGeometryServices.Instance.CreateGeometryFactory(new PrecisionModel(), 3794);
public Dictionary<int, ProcessingArea> ProcessingAreas = new();
public Dictionary<string, ProcessingArea> ProcessingAreas = new();

Dictionary<long, Address> Addresses = new();
List<VotingArea> VotingAreas = new();
Expand Down Expand Up @@ -118,7 +118,7 @@ private void BuildProcessingAreas(string tempDir)
votingArea.Id,
new List<BuildingInfo>(),
WritePoly(poliesDir, votingArea.Geometry, votingArea.Id));
ProcessingAreas.Add(int.Parse(votingArea.Id), newArea);
ProcessingAreas.Add(votingArea.Id, newArea);
}

Parallel.ForEach(ProcessingAreas.Values, (area) => {
Expand Down Expand Up @@ -199,17 +199,33 @@ static long ConvertToOldGursAddressId(long newId)

void LoadVotingAreasGeoJson()
{
using var sr = new StreamReader("VLV.geojson");
using var sr = new StreamReader(File.OpenRead(@"C:\Users\davkar\Documents\NewVLV.geojson"));
var reader = new GeoJsonReader();
var features = reader.Read<FeatureCollection>(sr.ReadToEnd());
var duplicatedVotingAreas = new List<VotingArea>();
foreach (var feature in features)
{
if (feature.Attributes["ENOTA"].ToString() != "LV")
if (feature.Attributes["ENOTA"]?.ToString() != "LV")
continue;
var id = feature.Attributes["VLV_ID"].ToString();
var name = feature.Attributes["VLV_UIME"].ToString();
var geometry = feature.Geometry;
VotingAreas.Add(new VotingArea(geometry, name, id));
duplicatedVotingAreas.Add(new VotingArea(geometry, name, id));
}

foreach (var groupedById in duplicatedVotingAreas.GroupBy(v => v.Id))
{
if (groupedById.Count() == 1)
{
VotingAreas.Add(groupedById.Single());
continue;
}
int index = 0;
foreach (var area in groupedById.OrderByDescending(g => g.Geometry.Area))
{
VotingAreas.Add(new(area.Geometry, area.Name + " #" + index, area.Id + "_" + index));
index++;
}
}
}

Expand Down
7 changes: 1 addition & 6 deletions OsmGursBuildingImport/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ static async Task<int> Process(string[] args, CancellationToken cancellationToke
return null;
}

if (!int.TryParse(filename[..dot], out var id))
{
return null;
}

if (gursData.ProcessingAreas.TryGetValue(id, out var area))
if (gursData.ProcessingAreas.TryGetValue(filename[..dot], out var area))
{
return area;
}
Expand Down
Loading

0 comments on commit 22330cc

Please sign in to comment.