Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polygon fixes #407

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions backend/src/BIE.Core/BIE.Core.API/LoadLocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private static void AggregateDataForChargingStations(List<DatasetItem> generalDa

chargingStationsItems.Add(item);
}
individualData.AddRange(chargingStationsItems);
AppendLimitedEntries(individualData, chargingStationsItems, "EV_charging_stations");
generalData.Add(new DatasetItem
{
DatasetId = "EV_charging_stations",
Expand Down Expand Up @@ -373,13 +373,13 @@ private static void AggregateDataForHousefootprints(List<DatasetItem> generalDat

generalData.Add(new DatasetItem
{
DisplayName = "Potential Area for geothermal use",
DisplayName = "Potential area for Geothermal Use",
DatasetId = "house_footprints",
Value = Math.Max(totalAreaSearchPolygon - totalBuildingArea, 0).ToString("N2") + "m²",
});
generalData.Add(new DatasetItem
{
DisplayName = "Total number of buildings",
DisplayName = "Total building number",
DatasetId = "house_footprints",
Value = totalCountHouseFootprints.ToString()
});
Expand Down Expand Up @@ -447,12 +447,12 @@ private static void AggregateDataForLod2Citygml(List<DatasetItem> generalData, L
double totalBuildingArea = totalBuildingAreas.Sum();
generalData.Add(new DatasetItem
{
DisplayName = "Potential Area for geothermal use",
DisplayName = "Potential area for geothermal use",
Value = Math.Max(totalAreaSearchPolygon - totalBuildingArea, 0).ToString("N2") + "m²",
});
generalData.Add(new DatasetItem
{
DisplayName = "Total number of LOD2 buildings",
DisplayName = "Total building number (LOD2)",
DatasetId = "building_models",
Value = totalCountLod2Buildings.ToString()
});
Expand All @@ -465,18 +465,18 @@ private static void AggregateDataForLod2Citygml(List<DatasetItem> generalData, L
if (totalBuildingVolumes.Count > 0)
generalData.Add(GenerateDatalistStatisticsEntry(totalBuildingVolumes, "Total building volume", "building_models", "m³"));
if (totalSolarPotentials.Count > 0)
generalData.Add(GenerateDatalistStatisticsEntry(totalSolarPotentials, "Total usable Area for Solar Panels", "building_models"));
generalData.Add(GenerateDatalistStatisticsEntry(totalSolarPotentials, "Total usable area for Solar Panels", "building_models"));

}

private static void AppendLimitedEntries(List<DatasetItem> individualData, List<DatasetItem> allEntriesForindividualData, string datasetId)
{
if (allEntriesForindividualData.Count > 15)
if (allEntriesForindividualData.Count > 10)
{
individualData.AddRange(allEntriesForindividualData.Take(15));
individualData.AddRange(allEntriesForindividualData.Take(10));
individualData.Add(new()
{
DisplayName = $"Skipped {allEntriesForindividualData.Count - 15} additional elements",
DisplayName = $"Skipped {allEntriesForindividualData.Count - 10} additional entries",
DatasetId = datasetId,
});
}
Expand Down
12 changes: 6 additions & 6 deletions backend/src/BIE.DataPipeline/DbHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed class DbHelper
private readonly StringBuilder mStringBuilder;

private int mCount;
private const int MaxCount = 999;
private const int MaxCount = 900;


public DbHelper()
Expand Down Expand Up @@ -47,7 +47,7 @@ public static bool CanSkip(DataSourceDescription description)
if (description.options.if_table_exists == InsertBehaviour.replace)
{
Console.WriteLine($"Dropping table {description.table_name} if it exists.");
if(description.source.data_format == "CITYGML")
if (description.source.data_format == "CITYGML")
{
DropCityGMLTable(description.table_name);
}
Expand Down Expand Up @@ -265,7 +265,7 @@ FROM dbo.{tableName}
var bboxCmd = db.CreateCommand(bboxQuery);
var (bboxReader, bboxConnection) = db.ExecuteReader(bboxCmd);

float minX = 0 , minY = 0, maxX = 0, maxY = 0;
float minX = 0, minY = 0, maxX = 0, maxY = 0;

if (bboxReader.Read())
{
Expand Down Expand Up @@ -322,7 +322,7 @@ DistrictKey VARCHAR(255),
END";
}

var query = $@"
var query = $@"
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{description.table_name}')
BEGIN CREATE TABLE {description.table_name} (";

Expand Down Expand Up @@ -390,7 +390,7 @@ private void ExecuteInsert()
throw;
}

if(cityGMLStringBuilder.Length > 0)
if (cityGMLStringBuilder.Length > 0)
{
PushRoofData();
}
Expand Down Expand Up @@ -489,7 +489,7 @@ public void InsertRoofData(string building, string area, string orientation, str

cityGMLCount++;

if(cityGMLCount >= MaxCount)
if (cityGMLCount >= MaxCount)
{
mCount = MaxCount;
}
Expand Down
9 changes: 3 additions & 6 deletions backend/src/BIE.DataPipeline/Import/ShapeImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void SetupParser()
dbfByteStream,
true,
true);

mParser = Shapefile.CreateDataReader(providerRegistry, GeometryFactory.Default);

mHeader = mParser.DbaseHeader;
Expand Down Expand Up @@ -131,21 +131,18 @@ public bool ReadLine(out string nextLine)
mStringBuilder.Append($"GEOMETRY::STGeomFromText('");
mStringBuilder.Append(geometry.AsText());
mStringBuilder.Append("', 4326)");
// nextLine = $"GEOMETRY::STGeomFromText('POLYGON (11.060226859896797 49.496927347229494, 11.060276626123832 49.49695803564076)')', 4326)";

for (int i = 1; i < mHeader.Fields.Length + 1; i++)
{
var value = mParser.GetValue(i);
mStringBuilder.Append(", '");
var bytes = Encoding.GetEncoding("ISO-8859-1").GetBytes(value?.ToString() ?? "");
var str = Encoding.UTF8.GetString(bytes).Replace("'", "_");
var bytes = Encoding.GetEncoding("Windows-1252").GetBytes(value?.ToString() ?? "");
var str = Encoding.UTF8.GetString(bytes).Replace("'", "''");
mStringBuilder.Append(str);
mStringBuilder.Append('\'');
// nextLine += $", \'{(value != "" ? value : "null")}\'";
}

mStringBuilder.Append($",{CalculateAreaInSquareMeters(geometry)}");
// nextLine += $",{CalculateAreaInSquareMeters(geometry)}";
nextLine = mStringBuilder.ToString();

return true;
Expand Down
17 changes: 15 additions & 2 deletions frontend/src/components/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,18 @@ const SearchBar: React.FC = () => {
},
});
drawPolygon.addTo(currentMapCache.drawnItems!);
let newMultiPolygon: MultiPolygon;
if (item.polygon.type === "Polygon") {
newMultiPolygon = {
type: "MultiPolygon",
coordinates: [item.polygon.coordinates],
};
} else {
newMultiPolygon = item.polygon as MultiPolygon;
}
console.log(newMultiPolygon);
const polygonSelection = new PolygonSelection(
item.polygon as MultiPolygon,
newMultiPolygon,
item.displayName,
false
);
Expand All @@ -165,7 +175,10 @@ const SearchBar: React.FC = () => {
item.displayName,
false
);
currentMapCache.selectedCoordinates = markerSelection;
setCurrentMapCache({
...currentMapCache,
selectedCoordinates: markerSelection,
});
mapInstance.flyTo(targetPosition, currentMapCache.zoom, {
animate: true,
duration: 5,
Expand Down
Loading