From e1a0dd70389df371a473f987ad1b39576c80f26f Mon Sep 17 00:00:00 2001 From: bertt Date: Thu, 12 Dec 2024 16:01:30 +0100 Subject: [PATCH] add other items --- cityjson.core.tests/UnitTest1.cs | 17 + .../cityjson.core.tests.csproj | 3 + .../building_with_innerring.city.json | 2108 +++++++++++++++++ .../MultiSurfaceGeometryExtensions.cs | 14 +- src/cityjson.core/IO/PolygonCreator.cs | 27 +- .../cityjson.core.v3.ncrunchproject | 7 + 6 files changed, 2169 insertions(+), 7 deletions(-) create mode 100644 cityjson.core.tests/fixtures/building_with_innerring.city.json create mode 100644 src/cityjson.core/cityjson.core.v3.ncrunchproject diff --git a/cityjson.core.tests/UnitTest1.cs b/cityjson.core.tests/UnitTest1.cs index 869c72c..3fa288a 100644 --- a/cityjson.core.tests/UnitTest1.cs +++ b/cityjson.core.tests/UnitTest1.cs @@ -8,6 +8,23 @@ namespace CityJSON.Tests { public class UnitTest1 { + [Test] + public void ReadBuildingWithInnerRingTest() + { + var json = File.ReadAllText("./fixtures/building_with_innerring.city.json"); + var cityjson = JsonConvert.DeserializeObject(json); + + Assert.That(cityjson.Type, Is.EqualTo("CityJSON")); + Assert.That(cityjson.Version, Is.EqualTo("1.0")); + + var wkt = cityjson.ToWkt(); + var reader = new NetTopologySuite.IO.WKTReader(); + var geom = reader.Read(wkt); + + Assert.That(geom.GeometryType, Is.EqualTo("MultiPolygon")); + Assert.That(geom.NumGeometries, Is.EqualTo(102)); + + } [Test] public void ReadCityJsonSeqFileMinimal() diff --git a/cityjson.core.tests/cityjson.core.tests.csproj b/cityjson.core.tests/cityjson.core.tests.csproj index b5ae0ac..ced8ff0 100644 --- a/cityjson.core.tests/cityjson.core.tests.csproj +++ b/cityjson.core.tests/cityjson.core.tests.csproj @@ -26,6 +26,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/cityjson.core.tests/fixtures/building_with_innerring.city.json b/cityjson.core.tests/fixtures/building_with_innerring.city.json new file mode 100644 index 0000000..d3abc14 --- /dev/null +++ b/cityjson.core.tests/fixtures/building_with_innerring.city.json @@ -0,0 +1,2108 @@ +{ + "type": "CityJSON", + "version": "1.0", + "CityObjects": { + "72894": { + "type": "Building", + "geographicalExtent": [ + 2609950.85, + 1264093.561, + 286.87, + 2609994.227, + 1264143.069, + 301.729 + ], + "attributes": { + "measuredHeight": 14.86, + "EGID": 2349595, + "LOD": 2, + "capacity": 17498.93, + "capacity_ag": 14031.34, + "eaves_z": 298.83, + "max_z": 301.73, + "mean_z": 299.92, + "min_z": 286.87, + "slope": 0.0, + "aspect": 0.0, + "projektiert": 0 + }, + "geometry": [ + { + "type": "MultiSurface", + "lod": 2.0, + "boundaries": [ + [ + [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 36, + 37, + 38, + 39 + ], + [ + 40, + 41, + 42, + 43, + 44, + 45 + ] + ], + [ + [ + 46, + 47, + 48, + 49 + ] + ], + [ + [ + 47, + 50, + 51, + 48 + ] + ], + [ + [ + 50, + 52, + 53, + 51 + ] + ], + [ + [ + 52, + 46, + 49, + 53 + ] + ], + [ + [ + 54, + 55, + 56, + 57 + ] + ], + [ + [ + 55, + 58, + 59, + 56 + ] + ], + [ + [ + 58, + 60, + 61, + 59 + ] + ], + [ + [ + 60, + 54, + 57, + 61 + ] + ], + [ + [ + 62, + 63, + 64, + 65 + ] + ], + [ + [ + 63, + 66, + 67, + 64 + ] + ], + [ + [ + 66, + 68, + 69, + 67 + ] + ], + [ + [ + 68, + 70, + 71, + 69 + ] + ], + [ + [ + 70, + 72, + 73, + 71 + ] + ], + [ + [ + 72, + 74, + 75, + 73 + ] + ], + [ + [ + 74, + 76, + 77, + 75 + ] + ], + [ + [ + 76, + 78, + 79, + 77 + ] + ], + [ + [ + 78, + 80, + 81, + 79 + ] + ], + [ + [ + 80, + 82, + 83, + 81 + ] + ], + [ + [ + 82, + 84, + 85, + 83 + ] + ], + [ + [ + 84, + 62, + 65, + 85 + ] + ], + [ + [ + 86, + 87, + 88, + 89 + ] + ], + [ + [ + 87, + 90, + 91, + 88 + ] + ], + [ + [ + 90, + 92, + 93, + 91 + ] + ], + [ + [ + 92, + 94, + 95, + 93 + ] + ], + [ + [ + 94, + 86, + 89, + 95 + ] + ], + [ + [ + 96, + 97, + 98, + 99 + ] + ], + [ + [ + 97, + 100, + 101, + 98 + ] + ], + [ + [ + 100, + 102, + 103, + 101 + ] + ], + [ + [ + 102, + 104, + 105, + 103 + ] + ], + [ + [ + 104, + 106, + 107, + 105 + ] + ], + [ + [ + 106, + 108, + 109, + 107 + ] + ], + [ + [ + 108, + 110, + 111, + 109 + ] + ], + [ + [ + 110, + 112, + 113, + 111 + ] + ], + [ + [ + 112, + 114, + 115, + 113 + ] + ], + [ + [ + 114, + 116, + 117, + 115 + ] + ], + [ + [ + 116, + 118, + 119, + 117 + ] + ], + [ + [ + 118, + 96, + 99, + 119 + ] + ], + [ + [ + 120, + 121, + 45, + 44 + ] + ], + [ + [ + 121, + 122, + 123, + 124 + ] + ], + [ + [ + 122, + 125, + 126, + 123 + ] + ], + [ + [ + 125, + 127, + 128, + 126 + ] + ], + [ + [ + 127, + 129, + 130, + 128 + ] + ], + [ + [ + 129, + 131, + 132, + 130 + ] + ], + [ + [ + 131, + 133, + 134, + 132 + ] + ], + [ + [ + 133, + 135, + 136, + 134 + ] + ], + [ + [ + 135, + 120, + 137, + 136 + ] + ], + [ + [ + 138, + 139, + 41, + 40 + ] + ], + [ + [ + 139, + 140, + 42, + 41 + ] + ], + [ + [ + 140, + 141, + 43, + 42 + ] + ], + [ + [ + 141, + 137, + 44, + 43 + ] + ], + [ + [ + 124, + 138, + 40, + 45 + ] + ], + [ + [ + 142, + 143, + 1, + 0 + ] + ], + [ + [ + 143, + 144, + 2, + 1 + ] + ], + [ + [ + 144, + 145, + 3, + 2 + ] + ], + [ + [ + 145, + 146, + 4, + 3 + ] + ], + [ + [ + 146, + 147, + 5, + 4 + ] + ], + [ + [ + 147, + 148, + 6, + 5 + ] + ], + [ + [ + 148, + 149, + 7, + 6 + ] + ], + [ + [ + 149, + 150, + 8, + 7 + ] + ], + [ + [ + 150, + 151, + 9, + 8 + ] + ], + [ + [ + 151, + 152, + 10, + 9 + ] + ], + [ + [ + 152, + 153, + 11, + 10 + ] + ], + [ + [ + 153, + 154, + 12, + 11 + ] + ], + [ + [ + 154, + 155, + 13, + 12 + ] + ], + [ + [ + 155, + 156, + 14, + 13 + ] + ], + [ + [ + 156, + 157, + 15, + 14 + ] + ], + [ + [ + 157, + 158, + 16, + 15 + ] + ], + [ + [ + 158, + 159, + 17, + 16 + ] + ], + [ + [ + 159, + 160, + 18, + 17 + ] + ], + [ + [ + 160, + 161, + 19, + 18 + ] + ], + [ + [ + 161, + 162, + 20, + 19 + ] + ], + [ + [ + 162, + 163, + 21, + 20 + ] + ], + [ + [ + 163, + 164, + 22, + 21 + ] + ], + [ + [ + 164, + 165, + 23, + 22 + ] + ], + [ + [ + 165, + 166, + 24, + 23 + ] + ], + [ + [ + 166, + 167, + 25, + 24 + ] + ], + [ + [ + 167, + 168, + 26, + 25 + ] + ], + [ + [ + 168, + 169, + 27, + 26 + ] + ], + [ + [ + 169, + 170, + 28, + 27 + ] + ], + [ + [ + 170, + 171, + 29, + 28 + ] + ], + [ + [ + 171, + 172, + 30, + 29 + ] + ], + [ + [ + 172, + 173, + 31, + 30 + ] + ], + [ + [ + 173, + 174, + 32, + 31 + ] + ], + [ + [ + 174, + 175, + 33, + 32 + ] + ], + [ + [ + 175, + 176, + 34, + 33 + ] + ], + [ + [ + 176, + 177, + 35, + 34 + ] + ], + [ + [ + 177, + 178, + 36, + 35 + ] + ], + [ + [ + 178, + 179, + 37, + 36 + ] + ], + [ + [ + 179, + 180, + 38, + 37 + ] + ], + [ + [ + 180, + 181, + 39, + 38 + ] + ], + [ + [ + 181, + 142, + 0, + 39 + ] + ], + [ + [ + 46, + 52, + 50, + 47 + ] + ], + [ + [ + 54, + 60, + 58, + 55 + ] + ], + [ + [ + 119, + 182, + 183, + 115, + 117 + ] + ], + [ + [ + 62, + 84, + 82, + 80, + 78, + 76, + 74, + 72, + 70, + 68, + 66, + 63 + ] + ], + [ + [ + 86, + 94, + 92, + 90, + 87 + ] + ], + [ + [ + 184, + 185, + 186, + 101, + 103 + ] + ], + [ + [ + 109, + 187, + 107 + ] + ], + [ + [ + 96, + 118, + 116, + 114, + 112, + 110, + 108, + 106, + 104, + 102, + 100, + 97 + ] + ], + [ + [ + 120, + 135, + 133, + 131, + 129, + 127, + 125, + 122, + 121 + ] + ], + [ + [ + 142, + 181, + 180, + 179, + 178, + 177, + 176, + 175, + 174, + 173, + 172, + 171, + 170, + 169, + 168, + 167, + 166, + 165, + 164, + 163, + 162, + 161, + 160, + 159, + 158, + 157, + 156, + 155, + 154, + 153, + 152, + 151, + 150, + 149, + 148, + 147, + 146, + 145, + 144, + 143 + ], + [ + 57, + 56, + 59, + 61 + ], + [ + 49, + 48, + 51, + 53 + ], + [ + 77, + 79, + 81, + 83, + 85, + 65, + 64, + 67, + 69, + 71, + 73, + 75 + ], + [ + 95, + 89, + 88, + 91, + 93 + ], + [ + 105, + 107, + 187, + 109, + 111, + 113, + 115, + 183, + 182, + 119, + 99, + 98, + 101, + 186, + 185, + 184, + 103 + ], + [ + 138, + 124, + 123, + 126, + 128, + 130, + 132, + 134, + 136, + 137, + 141, + 140, + 139 + ] + ] + ], + "semantics": { + "values": [ + 0, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2 + ], + "surfaces": [ + { + "type": "GroundSurface" + }, + { + "type": "WallSurface" + }, + { + "type": "RoofSurface" + } + ] + } + } + ] + } + }, + "vertices": [ + [ + 9987559, + 64093561, + 286869 + ], + [ + 9985377, + 64093899, + 286869 + ], + [ + 9985359, + 64093780, + 286869 + ], + [ + 9980618, + 64094517, + 286869 + ], + [ + 9980635, + 64094635, + 286869 + ], + [ + 9969063, + 64096440, + 286869 + ], + [ + 9957765, + 64098192, + 286869 + ], + [ + 9957747, + 64098072, + 286869 + ], + [ + 9953010, + 64098807, + 286869 + ], + [ + 9953028, + 64098927, + 286869 + ], + [ + 9950850, + 64099263, + 286869 + ], + [ + 9951829, + 64105688, + 286869 + ], + [ + 9951710, + 64105706, + 286869 + ], + [ + 9952434, + 64110449, + 286869 + ], + [ + 9952552, + 64110432, + 286869 + ], + [ + 9955828, + 64131897, + 286869 + ], + [ + 9955710, + 64131916, + 286869 + ], + [ + 9956434, + 64136660, + 286869 + ], + [ + 9956552, + 64136642, + 286869 + ], + [ + 9957534, + 64143068, + 286869 + ], + [ + 9959715, + 64142730, + 286869 + ], + [ + 9959734, + 64142848, + 286869 + ], + [ + 9964475, + 64142114, + 286869 + ], + [ + 9964456, + 64141995, + 286869 + ], + [ + 9970877, + 64140997, + 286869 + ], + [ + 9975767, + 64140215, + 286869 + ], + [ + 9980883, + 64139449, + 286869 + ], + [ + 9987304, + 64138454, + 286869 + ], + [ + 9987322, + 64138574, + 286869 + ], + [ + 9992063, + 64137839, + 286869 + ], + [ + 9992045, + 64137721, + 286869 + ], + [ + 9994227, + 64137381, + 286869 + ], + [ + 9993247, + 64130949, + 286869 + ], + [ + 9993366, + 64130932, + 286869 + ], + [ + 9992646, + 64126199, + 286869 + ], + [ + 9992528, + 64126217, + 286869 + ], + [ + 9989261, + 64104752, + 286869 + ], + [ + 9989381, + 64104734, + 286869 + ], + [ + 9988660, + 64099991, + 286869 + ], + [ + 9988541, + 64100010, + 286869 + ], + [ + 9966065, + 64109519, + 286869 + ], + [ + 9976087, + 64107956, + 286869 + ], + [ + 9979004, + 64127122, + 286869 + ], + [ + 9968993, + 64128682, + 286869 + ], + [ + 9968021, + 64122323, + 286869 + ], + [ + 9967477, + 64118758, + 286869 + ], + [ + 9989688, + 64109811, + 300545 + ], + [ + 9987001, + 64110355, + 300532 + ], + [ + 9987001, + 64110355, + 298846 + ], + [ + 9989688, + 64109811, + 298844 + ], + [ + 9987262, + 64111689, + 300555 + ], + [ + 9987262, + 64111689, + 298845 + ], + [ + 9989985, + 64111111, + 300567 + ], + [ + 9989985, + 64111111, + 298843 + ], + [ + 9979943, + 64105624, + 300382 + ], + [ + 9980150, + 64106980, + 300382 + ], + [ + 9980150, + 64106980, + 298854 + ], + [ + 9979943, + 64105624, + 298854 + ], + [ + 9981141, + 64106829, + 300382 + ], + [ + 9981141, + 64106829, + 298853 + ], + [ + 9980934, + 64105473, + 300382 + ], + [ + 9980934, + 64105473, + 298854 + ], + [ + 9984320, + 64119615, + 301679 + ], + [ + 9984013, + 64117474, + 301680 + ], + [ + 9984013, + 64117474, + 298845 + ], + [ + 9984320, + 64119615, + 298843 + ], + [ + 9983237, + 64117586, + 301682 + ], + [ + 9983237, + 64117586, + 298845 + ], + [ + 9983276, + 64117320, + 301682 + ], + [ + 9983276, + 64117320, + 298845 + ], + [ + 9981323, + 64117617, + 301687 + ], + [ + 9981323, + 64117617, + 298847 + ], + [ + 9981222, + 64117622, + 301687 + ], + [ + 9981222, + 64117622, + 298847 + ], + [ + 9980728, + 64117709, + 301688 + ], + [ + 9980728, + 64117709, + 298848 + ], + [ + 9979245, + 64117935, + 301692 + ], + [ + 9979245, + 64117935, + 298849 + ], + [ + 9979576, + 64120240, + 301691 + ], + [ + 9979576, + 64120240, + 298847 + ], + [ + 9982208, + 64119893, + 301684 + ], + [ + 9982208, + 64119893, + 298845 + ], + [ + 9982393, + 64119855, + 301684 + ], + [ + 9982393, + 64119855, + 298845 + ], + [ + 9982833, + 64119811, + 301682 + ], + [ + 9982833, + 64119811, + 298845 + ], + [ + 9977955, + 64117054, + 299761 + ], + [ + 9977570, + 64117113, + 299761 + ], + [ + 9977570, + 64117113, + 298851 + ], + [ + 9977955, + 64117054, + 298850 + ], + [ + 9978186, + 64121154, + 299761 + ], + [ + 9978186, + 64121154, + 298848 + ], + [ + 9978262, + 64121648, + 299761 + ], + [ + 9978262, + 64121648, + 298848 + ], + [ + 9978647, + 64121590, + 299761 + ], + [ + 9978647, + 64121590, + 298847 + ], + [ + 9966288, + 64122267, + 301696 + ], + [ + 9965933, + 64120006, + 301712 + ], + [ + 9965933, + 64120006, + 298859 + ], + [ + 9966288, + 64122267, + 298858 + ], + [ + 9964945, + 64120160, + 301715 + ], + [ + 9964945, + 64120160, + 298860 + ], + [ + 9962382, + 64120558, + 301724 + ], + [ + 9962382, + 64120558, + 298862 + ], + [ + 9961214, + 64120740, + 301728 + ], + [ + 9961214, + 64120740, + 298863 + ], + [ + 9961413, + 64121725, + 301722 + ], + [ + 9961413, + 64121725, + 298862 + ], + [ + 9961446, + 64121886, + 301720 + ], + [ + 9961446, + 64121886, + 298862 + ], + [ + 9961674, + 64123016, + 301713 + ], + [ + 9961674, + 64123016, + 298861 + ], + [ + 9962340, + 64122908, + 301710 + ], + [ + 9962340, + 64122908, + 298861 + ], + [ + 9962584, + 64122885, + 301709 + ], + [ + 9962584, + 64122885, + 298861 + ], + [ + 9962833, + 64122828, + 301708 + ], + [ + 9962833, + 64122828, + 298860 + ], + [ + 9964806, + 64122506, + 301702 + ], + [ + 9964806, + 64122506, + 298859 + ], + [ + 9968021, + 64122323, + 299788 + ], + [ + 9967477, + 64118758, + 299788 + ], + [ + 9966957, + 64118837, + 299788 + ], + [ + 9966957, + 64118837, + 298859 + ], + [ + 9967477, + 64118758, + 298858 + ], + [ + 9967183, + 64120305, + 299788 + ], + [ + 9967183, + 64120305, + 298858 + ], + [ + 9967195, + 64120425, + 299788 + ], + [ + 9967195, + 64120425, + 298858 + ], + [ + 9967296, + 64121063, + 299788 + ], + [ + 9967296, + 64121063, + 298857 + ], + [ + 9967341, + 64121418, + 299788 + ], + [ + 9967341, + 64121418, + 298857 + ], + [ + 9967354, + 64121443, + 299788 + ], + [ + 9967354, + 64121443, + 298857 + ], + [ + 9967501, + 64122402, + 299788 + ], + [ + 9967501, + 64122402, + 298857 + ], + [ + 9968021, + 64122323, + 298856 + ], + [ + 9966065, + 64109519, + 298864 + ], + [ + 9976087, + 64107956, + 298857 + ], + [ + 9979004, + 64127122, + 298844 + ], + [ + 9968993, + 64128682, + 298852 + ], + [ + 9987559, + 64093561, + 298854 + ], + [ + 9985377, + 64093899, + 298856 + ], + [ + 9985359, + 64093780, + 298856 + ], + [ + 9980618, + 64094517, + 298860 + ], + [ + 9980635, + 64094635, + 298860 + ], + [ + 9969063, + 64096440, + 298869 + ], + [ + 9957765, + 64098192, + 298878 + ], + [ + 9957747, + 64098072, + 298878 + ], + [ + 9953010, + 64098807, + 298881 + ], + [ + 9953028, + 64098927, + 298881 + ], + [ + 9950850, + 64099263, + 298883 + ], + [ + 9951829, + 64105688, + 298879 + ], + [ + 9951710, + 64105706, + 298879 + ], + [ + 9952434, + 64110449, + 298876 + ], + [ + 9952552, + 64110432, + 298876 + ], + [ + 9955828, + 64131897, + 298862 + ], + [ + 9955710, + 64131916, + 298862 + ], + [ + 9956434, + 64136660, + 298859 + ], + [ + 9956552, + 64136642, + 298859 + ], + [ + 9957534, + 64143068, + 298854 + ], + [ + 9959715, + 64142730, + 298853 + ], + [ + 9959734, + 64142848, + 298853 + ], + [ + 9964475, + 64142114, + 298849 + ], + [ + 9964456, + 64141995, + 298849 + ], + [ + 9970877, + 64140997, + 298844 + ], + [ + 9975767, + 64140215, + 298840 + ], + [ + 9980883, + 64139449, + 298836 + ], + [ + 9987304, + 64138454, + 298831 + ], + [ + 9987322, + 64138574, + 298831 + ], + [ + 9992063, + 64137839, + 298827 + ], + [ + 9992045, + 64137721, + 298827 + ], + [ + 9994227, + 64137381, + 298826 + ], + [ + 9993247, + 64130949, + 298830 + ], + [ + 9993366, + 64130932, + 298830 + ], + [ + 9992646, + 64126199, + 298833 + ], + [ + 9992528, + 64126217, + 298833 + ], + [ + 9989261, + 64104752, + 298847 + ], + [ + 9989381, + 64104734, + 298847 + ], + [ + 9988660, + 64099991, + 298850 + ], + [ + 9988541, + 64100010, + 298850 + ], + [ + 9964226, + 64122998, + 298859 + ], + [ + 9964439, + 64122741, + 298859 + ], + [ + 9962458, + 64120468, + 298862 + ], + [ + 9963071, + 64120243, + 298861 + ], + [ + 9964918, + 64120135, + 298860 + ], + [ + 9961350, + 64121802, + 298862 + ] + ], + "transform": { + "scale": [ + 0.001, + 0.001, + 0.001 + ], + "translate": [ + 2600000.0, + 1200000.0, + 0.0 + ] + }, + "metadata": { + "datasetReferenceDate": "2019-12-16", + "referenceSystem": "urn:ogc:def:crs:EPSG::2056", + "geographicalExtent": [ + 2609950.85, + 1264093.561, + 286.869, + 2609994.227, + 1264143.068, + 301.728 + ] + } +} \ No newline at end of file diff --git a/src/cityjson.core/Extensions/MultiSurfaceGeometryExtensions.cs b/src/cityjson.core/Extensions/MultiSurfaceGeometryExtensions.cs index 7dfa272..2de92e2 100644 --- a/src/cityjson.core/Extensions/MultiSurfaceGeometryExtensions.cs +++ b/src/cityjson.core/Extensions/MultiSurfaceGeometryExtensions.cs @@ -2,6 +2,7 @@ using CityJSON.Geometry; using CityJSON.IO; using NetTopologySuite.Geometries; +using NetTopologySuite.Noding; namespace CityJSON.Extensions { @@ -10,12 +11,17 @@ public static class MultiSurfaceGeometryExtensions public static List ToPolys(this MultiSurfaceGeometry multiSurfaceGeometry, List vertices, Transform transform) { var polygons = new List(); - var bnd0 = multiSurfaceGeometry.Boundaries[0]; - var outer0 = bnd0[0]; - var poly = PolygonCreator.GetPolygon(vertices, outer0, transform); + foreach(var bnd in multiSurfaceGeometry.Boundaries) + { + var outer = bnd[0]; + + var holes = bnd.Length>1?bnd[1..]:null; + + var poly = PolygonCreator.GetPolygon(vertices, outer, transform, holes); + polygons.Add(poly); + } - polygons.Add(poly); return polygons; } } diff --git a/src/cityjson.core/IO/PolygonCreator.cs b/src/cityjson.core/IO/PolygonCreator.cs index 65f4c8a..b0e6048 100644 --- a/src/cityjson.core/IO/PolygonCreator.cs +++ b/src/cityjson.core/IO/PolygonCreator.cs @@ -1,12 +1,13 @@ using System.Collections.Generic; using CityJSON.Extensions; +using NetTopologySuite.Algorithm; using NetTopologySuite.Geometries; namespace CityJSON.IO { public static class PolygonCreator { - public static Polygon GetPolygon(List vertices, int[] vertexList, Transform transform) + public static Polygon GetPolygon(List vertices, int[] vertexList, Transform transform, int[][] holes = null) { var coords = new Coordinate[vertexList.Length + 1]; for (int i = 0; i < vertexList.Length; i++) @@ -17,9 +18,29 @@ public static Polygon GetPolygon(List vertices, int[] vertexList, Transf coords[i] = coordinate.Transform(transform); } coords[vertexList.Length] = coords[0]; - var geometryFactory = new GeometryFactory(); + var geometryFactory = new GeometryFactory(); var extRing = geometryFactory.CreateLinearRing(coords); - var polygon = geometryFactory.CreatePolygon(extRing); + Polygon polygon = null; + if (holes != null) + { + foreach (var hole in holes) + { + var holeCoords = new Coordinate[hole.Length + 1]; + for (int i = 0; i < hole.Length; i++) + { + var vertex = vertices[hole[i]]; + var coordinate = new CoordinateZ(vertex.X, vertex.Y, vertex.Z); + holeCoords[i] = coordinate.Transform(transform); + } + holeCoords[hole.Length] = holeCoords[0]; + var holeRing = geometryFactory.CreateLinearRing(holeCoords); + polygon = geometryFactory.CreatePolygon((LinearRing)extRing, new LinearRing[] { holeRing }); + } + } + else + { + polygon = geometryFactory.CreatePolygon(extRing); + } return polygon; } diff --git a/src/cityjson.core/cityjson.core.v3.ncrunchproject b/src/cityjson.core/cityjson.core.v3.ncrunchproject new file mode 100644 index 0000000..5d07ca5 --- /dev/null +++ b/src/cityjson.core/cityjson.core.v3.ncrunchproject @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file