Commit 3f3c1884 authored by Matthias Betz's avatar Matthias Betz
Browse files

change to citygml4j 3.0.0 rc4

change to quality ade 0.1.4
parent 92f3e523
Pipeline #6596 failed with stage
in 17 seconds
......@@ -18,10 +18,11 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import org.citygml4j.factory.GMLGeometryFactory;
import org.citygml4j.model.citygml.core.AbstractCityObject;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurface;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurfaceProperty;
import org.citygml4j.core.model.construction.AbstractFillingSurface;
import org.citygml4j.core.model.core.AbstractCityObject;
import org.citygml4j.core.util.geometry.GeometryFactory;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurface;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurfaceProperty;
import de.hft.stuttgart.citydoctor2.check.Check;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
......@@ -45,21 +46,22 @@ public class Opening extends CityObject {
private OpeningType type;
private SurfaceFeatureType featureType;
private AbstractCityObject ao;
private AbstractFillingSurface ao;
private Opening(OpeningType type) {
this.type = type;
}
public Opening(OpeningType type, SurfaceFeatureType featureType, BoundarySurface partOf, AbstractCityObject ao) {
public Opening(OpeningType type, SurfaceFeatureType featureType, BoundarySurface partOf,
AbstractFillingSurface ao) {
this.featureType = featureType;
this.partOf = partOf;
this.type = type;
this.ao = ao;
}
public void reCreateGeometries(GMLGeometryFactory factory, ParserConfiguration config) {
if (!ao.isSetId()) {
public void reCreateGeometries(GeometryFactory factory, ParserConfiguration config) {
if (ao.getId() != null) {
ao.setId(getGmlId().getGmlString());
}
for (Geometry geom : getGeometries()) {
......@@ -67,55 +69,33 @@ public class Opening extends CityObject {
MultiSurface ms = CityGmlUtils.createMultiSurface(geom, factory, config);
setGeometryAccordingToLod(geom.getLod(), new MultiSurfaceProperty(ms));
} else {
throw new IllegalStateException("BoundarySurfaces can only have MultiSurface geometries");
throw new IllegalStateException("Openings can only have MultiSurface geometries");
}
}
}
private void setGeometryAccordingToLod(Lod lod, MultiSurfaceProperty ms) {
switch (lod) {
case LOD0:
ao.setLod0MultiSurface(ms);
break;
case LOD1:
ao.setLod1MultiSurface(ms);
break;
case LOD2:
ao.setLod2MultiSurface(ms);
break;
case LOD3:
setLod3Ms(ms);
ao.setLod3MultiSurface(ms);
break;
case LOD4:
setLod4Ms(ms);
ao.getDeprecatedProperties().setLod4MultiSurface(ms);
break;
default:
throw new IllegalStateException("Cannot add geometry to opening because lod is not allowed: " + lod);
}
}
private void setLod3Ms(MultiSurfaceProperty ms) {
switch (featureType) {
case BRIDGE:
org.citygml4j.model.citygml.bridge.AbstractOpening bridgeAo = (org.citygml4j.model.citygml.bridge.AbstractOpening) ao;
bridgeAo.setLod3MultiSurface(ms);
break;
case BUILDING:
org.citygml4j.model.citygml.building.AbstractOpening buildAo = (org.citygml4j.model.citygml.building.AbstractOpening) ao;
buildAo.setLod3MultiSurface(ms);
break;
case TUNNEL:
org.citygml4j.model.citygml.tunnel.AbstractOpening tunAo = (org.citygml4j.model.citygml.tunnel.AbstractOpening) ao;
tunAo.setLod3MultiSurface(ms);
}
}
private void setLod4Ms(MultiSurfaceProperty ms) {
switch (featureType) {
case BRIDGE:
org.citygml4j.model.citygml.bridge.AbstractOpening bridgeAo = (org.citygml4j.model.citygml.bridge.AbstractOpening) ao;
bridgeAo.setLod4MultiSurface(ms);
break;
case BUILDING:
org.citygml4j.model.citygml.building.AbstractOpening buildAo = (org.citygml4j.model.citygml.building.AbstractOpening) ao;
buildAo.setLod4MultiSurface(ms);
break;
case TUNNEL:
org.citygml4j.model.citygml.tunnel.AbstractOpening tunAo = (org.citygml4j.model.citygml.tunnel.AbstractOpening) ao;
tunAo.setLod4MultiSurface(ms);
}
}
public SurfaceFeatureType getSurfaceFeatureType() {
return featureType;
......@@ -147,22 +127,11 @@ public class Opening extends CityObject {
}
public void unsetGmlGeometries() {
switch (featureType) {
case BRIDGE:
org.citygml4j.model.citygml.bridge.AbstractOpening bridgeAo = (org.citygml4j.model.citygml.bridge.AbstractOpening) ao;
bridgeAo.unsetLod3MultiSurface();
bridgeAo.unsetLod4MultiSurface();
break;
case BUILDING:
org.citygml4j.model.citygml.building.AbstractOpening buildAo = (org.citygml4j.model.citygml.building.AbstractOpening) ao;
buildAo.unsetLod3MultiSurface();
buildAo.unsetLod4MultiSurface();
break;
case TUNNEL:
org.citygml4j.model.citygml.tunnel.AbstractOpening tunAo = (org.citygml4j.model.citygml.tunnel.AbstractOpening) ao;
tunAo.unsetLod3MultiSurface();
tunAo.unsetLod4MultiSurface();
}
ao.setLod0MultiSurface(null);
ao.setLod1MultiSurface(null);
ao.setLod2MultiSurface(null);
ao.setLod3MultiSurface(null);
ao.getDeprecatedProperties().setLod4MultiSurface(null);
}
@Override
......@@ -188,13 +157,13 @@ public class Opening extends CityObject {
public Copyable createCopyInstance() {
return new Opening(type);
}
@Override
public void collectInstances(CopyHandler handler) {
super.collectInstances(handler);
handler.addInstance(partOf);
}
@Override
public void fillValues(Copyable original, CopyHandler handler) {
super.fillValues(original, handler);
......
......@@ -77,5 +77,7 @@ public abstract class Polygon extends GmlElement {
abstract void anonymize();
public abstract ConcretePolygon getOriginal();
public abstract void remove();
}
\ No newline at end of file
......@@ -21,14 +21,14 @@ package de.hft.stuttgart.citydoctor2.datastructure;
import java.util.ArrayList;
import java.util.List;
import org.citygml4j.factory.GMLGeometryFactory;
import org.citygml4j.model.citygml.core.AbstractCityObject;
import org.citygml4j.model.citygml.transportation.AbstractTransportationObject;
import org.citygml4j.model.citygml.transportation.AuxiliaryTrafficArea;
import org.citygml4j.model.citygml.transportation.TrafficArea;
import org.citygml4j.model.citygml.transportation.TransportationComplex;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurface;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurfaceProperty;
import org.citygml4j.core.model.core.AbstractCityObject;
import org.citygml4j.core.model.core.AbstractSpace;
import org.citygml4j.core.model.transportation.AbstractTransportationSpace;
import org.citygml4j.core.model.transportation.AuxiliaryTrafficArea;
import org.citygml4j.core.model.transportation.TrafficArea;
import org.citygml4j.core.util.geometry.GeometryFactory;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurface;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurfaceProperty;
import de.hft.stuttgart.citydoctor2.check.Check;
import de.hft.stuttgart.citydoctor2.check.CheckError;
......@@ -49,10 +49,10 @@ public class TransportationObject extends CityObject {
private static final long serialVersionUID = -2698907271726700390L;
public enum TransportationType {
ROAD, TRACK, RAILWAY, TRAFFIC_AREA, AUXILLIARY_TRAFFIC_AREA, TRANSPORTATION_COMPLEX, SQUARE
ROAD, TRACK, RAILWAY, TRAFFIC_AREA, AUXILLIARY_TRAFFIC_AREA, TRANSPORTATION_COMPLEX, SQUARE, AUXILLIARY_TRAFFIC_SPACE, TRAFFIC_SPACE
}
private AbstractTransportationObject ato;
private AbstractCityObject ato;
private List<TransportationObject> composesOf = new ArrayList<>(1);
private TransportationType type;
......@@ -66,17 +66,13 @@ public class TransportationObject extends CityObject {
}
@Override
public void reCreateGeometries(GMLGeometryFactory factory, ParserConfiguration config) {
public void reCreateGeometries(GeometryFactory factory, ParserConfiguration config) {
for (Geometry geom : getGeometries()) {
if (geom.getType() == GeometryType.MULTI_SURFACE) {
MultiSurface ms = CityGmlUtils.createMultiSurface(geom, factory, config);
switch (type) {
case ROAD:
case TRACK:
case RAILWAY:
case SQUARE:
case TRANSPORTATION_COMPLEX:
TransportationComplex tc = (TransportationComplex) ato;
case ROAD, TRACK, RAILWAY, SQUARE, TRANSPORTATION_COMPLEX:
AbstractTransportationSpace tc = (AbstractTransportationSpace) ato;
setMultiSurfaceAccordingToLod(tc, ms, geom.getLod());
break;
case TRAFFIC_AREA:
......@@ -87,6 +83,10 @@ public class TransportationObject extends CityObject {
AuxiliaryTrafficArea ata = (AuxiliaryTrafficArea) ato;
setMultiSurfaceAccordingToLod(ata, ms, geom.getLod());
break;
case AUXILLIARY_TRAFFIC_SPACE, TRAFFIC_SPACE:
AbstractSpace ats = (AbstractSpace) ato;
setMultiSurfaceAccordingToLod(ats, ms, geom.getLod());
break;
}
} else {
throw new IllegalStateException("Geometry in TransportationObject cannot be of type " + geom.getType()
......@@ -98,10 +98,26 @@ public class TransportationObject extends CityObject {
}
}
private void setMultiSurfaceAccordingToLod(TransportationComplex tc, MultiSurface ms, Lod lod) {
private void setMultiSurfaceAccordingToLod(AbstractSpace ats, MultiSurface ms, Lod lod) {
switch (lod) {
case LOD0:
ats.setLod0MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD2:
ats.setLod2MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD3:
ats.setLod3MultiSurface(new MultiSurfaceProperty(ms));
break;
default:
throw new IllegalStateException("cannot set geometry with LOD for AuxiliaryTrafficSpace: " + lod);
}
}
private void setMultiSurfaceAccordingToLod(AbstractTransportationSpace tc, MultiSurface ms, Lod lod) {
switch (lod) {
case LOD1:
tc.setLod1MultiSurface(new MultiSurfaceProperty(ms));
tc.getDeprecatedProperties().setLod1MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD2:
tc.setLod2MultiSurface(new MultiSurfaceProperty(ms));
......@@ -110,7 +126,7 @@ public class TransportationObject extends CityObject {
tc.setLod3MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD4:
tc.setLod4MultiSurface(new MultiSurfaceProperty(ms));
tc.getDeprecatedProperties().setLod4MultiSurface(new MultiSurfaceProperty(ms));
break;
default:
throw new IllegalStateException("cannot set geometry with LOD for TransportationComplex: " + lod);
......@@ -119,6 +135,12 @@ public class TransportationObject extends CityObject {
private void setMultiSurfaceAccordingToLod(AuxiliaryTrafficArea ata, MultiSurface ms, Lod lod) {
switch (lod) {
case LOD0:
ata.setLod0MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD1:
ata.setLod1MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD2:
ata.setLod2MultiSurface(new MultiSurfaceProperty(ms));
break;
......@@ -126,7 +148,7 @@ public class TransportationObject extends CityObject {
ata.setLod3MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD4:
ata.setLod4MultiSurface(new MultiSurfaceProperty(ms));
ata.getDeprecatedProperties().setLod4MultiSurface(new MultiSurfaceProperty(ms));
break;
default:
throw new IllegalStateException("cannot set geometry with LOD for AuxiliaryTrafficArea: " + lod);
......@@ -142,7 +164,7 @@ public class TransportationObject extends CityObject {
ta.setLod3MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD4:
ta.setLod4MultiSurface(new MultiSurfaceProperty(ms));
ta.getDeprecatedProperties().setLod4MultiSurface(new MultiSurfaceProperty(ms));
break;
default:
throw new IllegalStateException("cannot set geometry with LOD for TrafficArea: " + lod);
......@@ -217,28 +239,36 @@ public class TransportationObject extends CityObject {
case RAILWAY:
case SQUARE:
case TRANSPORTATION_COMPLEX:
TransportationComplex tc = (TransportationComplex) ato;
tc.unsetLod1MultiSurface();
tc.unsetLod2MultiSurface();
tc.unsetLod3MultiSurface();
tc.unsetLod4MultiSurface();
AbstractTransportationSpace tc = (AbstractTransportationSpace) ato;
tc.getDeprecatedProperties().setLod1MultiSurface(null);
tc.setLod2MultiSurface(null);
tc.setLod3MultiSurface(null);
tc.getDeprecatedProperties().setLod4MultiSurface(null);
break;
case TRAFFIC_AREA:
TrafficArea ta = (TrafficArea) ato;
ta.unsetLod2MultiSurface();
ta.unsetLod3MultiSurface();
ta.unsetLod4MultiSurface();
ta.setLod2MultiSurface(null);
ta.setLod3MultiSurface(null);
ta.getDeprecatedProperties().setLod4MultiSurface(null);
break;
case AUXILLIARY_TRAFFIC_AREA:
AuxiliaryTrafficArea ata = (AuxiliaryTrafficArea) ato;
ata.unsetLod2MultiSurface();
ata.unsetLod3MultiSurface();
ata.unsetLod4MultiSurface();
ata.setLod0MultiSurface(null);
ata.setLod1MultiSurface(null);
ata.setLod2MultiSurface(null);
ata.setLod3MultiSurface(null);
ata.getDeprecatedProperties().setLod4MultiSurface(null);
break;
case AUXILLIARY_TRAFFIC_SPACE, TRAFFIC_SPACE:
AbstractSpace ats = (AbstractSpace) ato;
ats.setLod0MultiSurface(null);
ats.setLod2MultiSurface(null);
ats.setLod3MultiSurface(null);
break;
}
}
public void setGmlObject(AbstractTransportationObject tc) {
public void setGmlObject(AbstractCityObject tc) {
ato = tc;
}
......
......@@ -18,22 +18,23 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import org.citygml4j.factory.GMLGeometryFactory;
import org.citygml4j.model.citygml.core.AbstractCityObject;
import org.citygml4j.model.citygml.vegetation.AbstractVegetationObject;
import org.citygml4j.model.citygml.vegetation.PlantCover;
import org.citygml4j.model.citygml.vegetation.SolitaryVegetationObject;
import org.citygml4j.model.gml.geometry.aggregates.MultiSolid;
import org.citygml4j.model.gml.geometry.aggregates.MultiSolidProperty;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurface;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurfaceProperty;
import org.citygml4j.model.gml.geometry.primitives.Solid;
import org.citygml4j.model.gml.geometry.primitives.SolidProperty;
import java.util.Collections;
import org.citygml4j.core.model.core.AbstractCityObject;
import org.citygml4j.core.model.vegetation.AbstractVegetationObject;
import org.citygml4j.core.model.vegetation.PlantCover;
import org.citygml4j.core.model.vegetation.SolitaryVegetationObject;
import org.citygml4j.core.util.geometry.GeometryFactory;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSolid;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSolidProperty;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurface;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurfaceProperty;
import org.xmlobjects.gml.model.geometry.primitives.Solid;
import org.xmlobjects.gml.model.geometry.primitives.SolidProperty;
import de.hft.stuttgart.citydoctor2.check.Check;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.CityGmlUtils;
import de.hft.stuttgart.citydoctor2.utils.CopyHandler;
import de.hft.stuttgart.citydoctor2.utils.Copyable;
/**
......@@ -63,7 +64,7 @@ public class Vegetation extends CityObject {
}
@Override
public void reCreateGeometries(GMLGeometryFactory factory, ParserConfiguration config) {
public void reCreateGeometries(GeometryFactory factory, ParserConfiguration config) {
for (Geometry geom : getGeometries()) {
if (geom.getType() == GeometryType.MULTI_SURFACE) {
MultiSurface ms = CityGmlUtils.createMultiSurface(geom, factory, config);
......@@ -90,16 +91,16 @@ public class Vegetation extends CityObject {
private void setSolidAccordingToLod(PlantCover pc, Solid solid, Lod lod) {
switch (lod) {
case LOD1:
pc.setLod1MultiSolid(new MultiSolidProperty(new MultiSolid(solid)));
pc.getDeprecatedProperties().setLod1MultiSolid(new MultiSolidProperty(new MultiSolid(Collections.singletonList(new SolidProperty(solid)))));
break;
case LOD2:
pc.setLod2MultiSolid(new MultiSolidProperty(new MultiSolid(solid)));
pc.getDeprecatedProperties().setLod2MultiSolid(new MultiSolidProperty(new MultiSolid(Collections.singletonList(new SolidProperty(solid)))));
break;
case LOD3:
pc.setLod3MultiSolid(new MultiSolidProperty(new MultiSolid(solid)));
pc.getDeprecatedProperties().setLod3MultiSolid(new MultiSolidProperty(new MultiSolid(Collections.singletonList(new SolidProperty(solid)))));
break;
case LOD4:
pc.setLod4MultiSolid(new MultiSolidProperty(new MultiSolid(solid)));
pc.getDeprecatedProperties().setLod4MultiSolid(new MultiSolidProperty(new MultiSolid(Collections.singletonList(new SolidProperty(solid)))));
break;
default:
throw new IllegalStateException("Cannot set Solid with lod to PlantCover:" + lod);
......@@ -109,16 +110,16 @@ public class Vegetation extends CityObject {
private void setSolidAccordingToLod(SolitaryVegetationObject svo, Solid solid, Lod lod) {
switch (lod) {
case LOD1:
svo.setLod1Geometry(new SolidProperty(solid));
svo.getDeprecatedProperties().setLod1Geometry(new SolidProperty(solid));
break;
case LOD2:
svo.setLod2Geometry(new SolidProperty(solid));
svo.getDeprecatedProperties().setLod2Geometry(new SolidProperty(solid));
break;
case LOD3:
svo.setLod3Geometry(new SolidProperty(solid));
svo.getDeprecatedProperties().setLod3Geometry(new SolidProperty(solid));
break;
case LOD4:
svo.setLod4Geometry(new SolidProperty(solid));
svo.getDeprecatedProperties().setLod4Geometry(new SolidProperty(solid));
break;
default:
throw new IllegalStateException("Cannot set Solid with lod to SolitaryVegetationObject:" + lod);
......@@ -128,7 +129,7 @@ public class Vegetation extends CityObject {
private void setMultiSurfaceAccordingToLod(PlantCover pc, MultiSurface ms, Lod lod) {
switch (lod) {
case LOD1:
pc.setLod1MultiSurface(new MultiSurfaceProperty(ms));
pc.getDeprecatedProperties().setLod1MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD2:
pc.setLod2MultiSurface(new MultiSurfaceProperty(ms));
......@@ -137,7 +138,7 @@ public class Vegetation extends CityObject {
pc.setLod3MultiSurface(new MultiSurfaceProperty(ms));
break;
case LOD4:
pc.setLod4MultiSurface(new MultiSurfaceProperty(ms));
pc.getDeprecatedProperties().setLod4MultiSurface(new MultiSurfaceProperty(ms));
break;
default:
throw new IllegalStateException("Cannot set MultiSurface with lod to PlantCover:" + lod);
......@@ -148,16 +149,16 @@ public class Vegetation extends CityObject {
private void setMultiSurfaceAccordingToLod(SolitaryVegetationObject svo, MultiSurface ms, Lod lod) {
switch (lod) {
case LOD1:
svo.setLod1Geometry(new MultiSurfaceProperty(ms));
svo.getDeprecatedProperties().setLod1Geometry(new MultiSurfaceProperty(ms));
break;
case LOD2:
svo.setLod2Geometry(new MultiSurfaceProperty(ms));
svo.getDeprecatedProperties().setLod2Geometry(new MultiSurfaceProperty(ms));
break;
case LOD3:
svo.setLod3Geometry(new MultiSurfaceProperty(ms));
svo.getDeprecatedProperties().setLod3Geometry(new MultiSurfaceProperty(ms));
break;
case LOD4:
svo.setLod4Geometry(new MultiSurfaceProperty(ms));
svo.getDeprecatedProperties().setLod4Geometry(new MultiSurfaceProperty(ms));
break;
default:
throw new IllegalStateException("Cannot set MultiSurface with lod to SolitaryVegetationObject:" + lod);
......@@ -181,16 +182,16 @@ public class Vegetation extends CityObject {
public void unsetGmlGeometries() {
if (type == VegetationType.SOLITARY_VEGETATION_OBJECT) {
SolitaryVegetationObject svo = (SolitaryVegetationObject) citygmlVegetation;
svo.unsetLod1Geometry();
svo.unsetLod2Geometry();
svo.unsetLod3Geometry();
svo.unsetLod4Geometry();
svo.getDeprecatedProperties().setLod1Geometry(null);
svo.getDeprecatedProperties().setLod2Geometry(null);
svo.getDeprecatedProperties().setLod3Geometry(null);
svo.getDeprecatedProperties().setLod4Geometry(null);
} else {
PlantCover pc = (PlantCover) citygmlVegetation;
pc.unsetLod1MultiSurface();
pc.unsetLod2MultiSurface();
pc.unsetLod3MultiSurface();
pc.unsetLod4MultiSurface();
pc.getDeprecatedProperties().setLod1MultiSurface(null);
pc.setLod2MultiSurface(null);
pc.setLod3MultiSurface(null);
pc.getDeprecatedProperties().setLod4MultiSurface(null);
}
}
......@@ -211,11 +212,4 @@ public class Vegetation extends CityObject {
public Copyable createCopyInstance() {
return new Vegetation(type);
}
@Override
public void fillValues(Copyable original, CopyHandler handler) {
super.fillValues(original, handler);
}
}
......@@ -18,11 +18,14 @@
*/
package de.hft.stuttgart.citydoctor2.datastructure;
import org.citygml4j.factory.GMLGeometryFactory;
import org.citygml4j.model.citygml.core.AbstractCityObject;
import org.citygml4j.model.citygml.waterbody.WaterBody;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurface;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurfaceProperty;
import java.util.ArrayList;
import java.util.List;
import org.citygml4j.core.model.core.AbstractCityObject;
import org.citygml4j.core.model.waterbody.WaterBody;
import org.citygml4j.core.util.geometry.GeometryFactory;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurface;
import org.xmlobjects.gml.model.geometry.aggregates.MultiSurfaceProperty;
import de.hft.stuttgart.citydoctor2.check.Check;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
......@@ -41,16 +44,17 @@ public class WaterObject extends CityObject {
private static final long serialVersionUID = -3821060595086337424L;
private WaterBody gmlWater;
private List<BoundarySurface> boundarySurfaceList = new ArrayList<>();
@Override
public void reCreateGeometries(GMLGeometryFactory factory, ParserConfiguration config) {
public void reCreateGeometries(GeometryFactory factory, ParserConfiguration config) {
for (Geometry geom : getGeometries()) {
if (geom.getType() == GeometryType.MULTI_SURFACE) {
MultiSurface ms = CityGmlUtils.createMultiSurface(geom, factory, config);
if (geom.getLod() == Lod.LOD0) {
gmlWater.setLod0MultiSurface(new MultiSurfaceProperty(ms));
} else if (geom.getLod() == Lod.LOD1) {
gmlWater.setLod1MultiSurface(new MultiSurfaceProperty(ms));
gmlWater.getDeprecatedProperties().setLod1MultiSurface(new MultiSurfaceProperty(ms));
} else {
throw new IllegalStateException(
"Cannot add MultiSurface geometry with lod to WaterBody:" + geom.getLod());
......@@ -60,6 +64,20 @@ public class WaterObject extends CityObject {
}
}
}
/**
* Getter for all boundary surfaces contained in this building.
*
* @return the boundary surfaces
*/
public List<BoundarySurface> getBoundarySurfaces() {
return boundarySurfaceList;
}
public void addBoundarySurface(BoundarySurface bs) {
boundarySurfaceList.add(bs);
bs.setParent(this);
}
@Override
public FeatureType getFeatureType() {
......@@ -81,12 +99,8 @@ public class WaterObject extends CityObject {
@Override
public void unsetGmlGeometries() {
gmlWater.unsetLod0MultiSurface();
gmlWater.unsetLod1MultiSurface();
gmlWater.unsetLod1Solid();
gmlWater.unsetLod2Solid();
gmlWater.unsetLod3Solid();
gmlWater.unsetLod4Solid();
gmlWater.setLod0MultiSurface(null);
gmlWater.getDeprecatedProperties().setLod1MultiSurface(null);
}
public void setGmlObject(WaterBody waterBody) {
......
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.exceptions;
public class CityDoctorWriteException extends Exception {
private static final long serialVersionUID = 2902212162405599516L;
public CityDoctorWriteException() {
super();
}
public CityDoctorWriteException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
public CityDoctorWriteException(String message, Throwable cause) {
super(message, cause);
}
public CityDoctorWriteException(String message) {
super(message);
}
public CityDoctorWriteException(Throwable cause) {
super(cause);
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.mapper;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.citygml4j.model.gml.geometry.AbstractGeometry;
import org.citygml4j.model.gml.geometry.GeometryProperty;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurface;
import org.citygml4j.model.gml.geometry.aggregates.MultiSurfaceProperty;
import org.citygml4j.model.gml.geometry.complexes.CompositeSurface;
import org.citygml4j.model.gml.geometry.primitives.AbstractRing;
import org.citygml4j.model.gml.geometry.primitives.AbstractRingProperty;
import org.citygml4j.model.gml.geometry.primitives.Coord;
import org.citygml4j.model.gml.geometry.primitives.DirectPosition;
import org.citygml4j.model.gml.geometry.primitives.DirectPositionList;
import org.citygml4j.model.gml.geometry.primitives.PosOrPointPropertyOrPointRep;
import org.citygml4j.model.gml.geometry.primitives.SolidProperty;
import org.citygml4j.model.gml.geometry.primitives.SurfaceProperty;
import org.citygml4j.util.walker.GeometryWalker;
import org.locationtech.proj4j.BasicCoordinateTransform;
import org.locationtech.proj4j.ProjCoordinate;
import de.hft.stuttgart.citydoctor2.datastructure.BoundarySurface;
import de.hft.stuttgart.citydoctor2.datastructure.BuildingInstallation;
import de.hft.stuttgart.citydoctor2.datastructure.CityObject;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
import de.hft.stuttgart.citydoctor2.datastructure.GeometryType;
import de.hft.stuttgart.citydoctor2.datastructure.GmlId;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.Localization;
import de.hft.stuttgart.citydoctor2.utils.Pair;
/**
*
* @author Matthias Betz
*
*/
public class GeometryMapper extends GeometryWalker {
private static final Logger logger = LogManager.getLogger(GeometryMapper.class);
private Geometry geom;
private ParserConfiguration config;
private Map<Vertex, Vertex> vertexMap;
private Map<String, ConcretePolygon> polygons;
private List<Pair<String, Geometry>> linkedPolygons;
private LinearRing currentRing;
private BoundarySurface bs;
private BuildingInstallation bi;
private ProjCoordinate p1 = new ProjCoordinate();
private ProjCoordinate p2 = new ProjCoordinate();
public GeometryMapper(Geometry geom, ParserConfiguration config, Map<String, ConcretePolygon> polygons,
List<Pair<String, Geometry>> linkedPolygons, Map<Vertex, Vertex> vertices) {
this.geom = geom;
this.config = config;
vertexMap = vertices;
this.polygons = polygons;
this.linkedPolygons = linkedPolygons;
}
public void setBoundarySurface(BoundarySurface bs) {
this.bs = bs;
}
public void setBuildingInstallation(BuildingInstallation bi) {
this.bi = bi;
}
@Override
public void visit(MultiSurface multiSurface) {
super.visit(multiSurface);
for (SurfaceProperty sp : multiSurface.getSurfaceMember()) {
if (sp.isSetHref()) {
String linkedPoly = sp.getHref();
if (linkedPoly.charAt(0) == '#') {
linkedPoly = linkedPoly.substring(1);
}
linkedPolygons.add(new Pair<>(linkedPoly, geom));
}
}
}
@Override
public void visit(CompositeSurface compositeSurface) {
super.visit(compositeSurface);
for (SurfaceProperty sp : compositeSurface.getSurfaceMember()) {
if (sp.isSetHref()) {
String linkedPoly = sp.getHref();
if (linkedPoly.charAt(0) == '#') {
linkedPoly = linkedPoly.substring(1);
}
linkedPolygons.add(new Pair<>(linkedPoly, geom));
}
}
}
@Override
public void visit(org.citygml4j.model.gml.geometry.primitives.Polygon gmlPoly) {
if (!gmlPoly.isSetExterior()) {
if (logger.isWarnEnabled()) {
logger.warn(Localization.getText("GeometryMapper.emptyPolygon"));
}
return;
}
ConcretePolygon cdPoly = new ConcretePolygon();
addPolygonToAvailablePolygons(gmlPoly, cdPoly);
geom.addPolygon(cdPoly);
if (bs != null) {
// polygon is part of a boundary surface
cdPoly.setPartOfSurface(bs);
if (bi != null) {
// polygon is part of a boundary surface in a building installation
cdPoly.setPartOfInstallation(bi);
}
} else {
if (bi != null) {
// polygon is only part of a building installation
cdPoly.setPartOfInstallation(bi);
}
}
// parse rings
LinearRing extRing = new LinearRing(LinearRingType.EXTERIOR);
cdPoly.setExteriorRing(extRing);
mapRing(gmlPoly.getExterior(), extRing);
if (gmlPoly.isSetInterior()) {
for (AbstractRingProperty arp : gmlPoly.getInterior()) {
if (arp.isSetRing()) {
LinearRing innerRing = new LinearRing(LinearRingType.INTERIOR);
cdPoly.addInteriorRing(innerRing);
mapRing(arp, innerRing);
}
}
}
}
private void addPolygonToAvailablePolygons(org.citygml4j.model.gml.geometry.primitives.Polygon gmlPoly,
ConcretePolygon cdPoly) {
if (gmlPoly.isSetId()) {
cdPoly.setGmlId(new GmlId(gmlPoly.getId()));
if (polygons.put(gmlPoly.getId(), cdPoly) != null) {
logger.warn("Found already existing polygon ID {}, duplicate IDs are not valid", gmlPoly.getId());
}
}
}
private void mapRing(AbstractRingProperty gmlRing, LinearRing cdRing) {
AbstractRing ringGeometry = gmlRing.getRing();
if (ringGeometry.isSetId()) {
cdRing.setGmlId(new GmlId(ringGeometry.getId()));
}
currentRing = cdRing;
// jump to LinearRing or Ring visit
ringGeometry.accept(this);
}
@Override
public void visit(org.citygml4j.model.gml.geometry.primitives.LinearRing linearRing) {
if (linearRing.isSetCoord()) {
List<Coord> coords = linearRing.getCoord();
for (Coord coord : coords) {
createVertex(coord.getX(), coord.getY(), coord.getZ());
}
}
if (linearRing.isSetPosList()) {
parsePosList(linearRing);
}
if (linearRing.isSetPosOrPointPropertyOrPointRep()) {
parsePoints(linearRing);
}
}
private void parsePoints(org.citygml4j.model.gml.geometry.primitives.LinearRing linearRing) {
List<PosOrPointPropertyOrPointRep> points = linearRing.getPosOrPointPropertyOrPointRep();
for (PosOrPointPropertyOrPointRep point : points) {
if (!point.isSetPos()) {
throw new UnsupportedOperationException("Cannot parse points for: " + linearRing.getId());
}
DirectPosition pos = point.getPos();
List<Double> coords = pos.getValue();
int dimension = getDimension(linearRing, pos, coords);
switch (dimension) {
case 1:
createVertex(coords.get(0), 0, 0);
break;
case 2:
createVertex(coords.get(0), coords.get(1), 0);
break;
case 3:
createVertex(coords.get(0), coords.get(1), coords.get(2));
break;
default:
throw new UnsupportedOperationException("Cannot parse Coordinates with dimension:" + dimension);
}
}
}
private void parsePosList(org.citygml4j.model.gml.geometry.primitives.LinearRing linearRing) {
DirectPositionList directPosList = linearRing.getPosList();
if (directPosList.isSetValue()) {
List<Double> coords = directPosList.getValue();
int dimension = getDimension(linearRing, directPosList, coords);
switch (dimension) {
case 1:
for (int i = 0; i < coords.size(); i++) {
createVertex(coords.get(i), 0, 0);
}
break;
case 2:
for (int i = 0; i < coords.size(); i = i + 2) {
createVertex(coords.get(i + 0), coords.get(i + 1), 0);
}
break;
case 3:
for (int i = 0; i < coords.size(); i = i + 3) {
createVertex(coords.get(i + 0), coords.get(i + 1), coords.get(i + 2));
}
break;
default:
throw new UnsupportedOperationException("Cannot parse Coordinates with dimension:" + dimension);
}
}
}
private int getDimension(org.citygml4j.model.gml.geometry.primitives.LinearRing linearRing, DirectPosition pos,
List<Double> coords) {
int dimension = 3;
if (pos.isSetSrsDimension()) {
dimension = pos.getSrsDimension();
}
if (coords.size() % dimension != 0) {
throw new IllegalStateException("Number of coordinates do not match dimension: " + dimension + ", ring: "
+ linearRing.getId() + ", polygon: " + currentRing.getParent().getGmlId().getGmlString());
}
return dimension;
}
private int getDimension(org.citygml4j.model.gml.geometry.primitives.LinearRing linearRing,
DirectPositionList directPosList, List<Double> coords) {
int dimension = 3;
if (directPosList.isSetSrsDimension()) {
dimension = directPosList.getSrsDimension();
}
if (coords.size() % dimension != 0) {
throw new IllegalStateException("Number of coordinates do not match dimension: " + dimension + ", ring: "
+ linearRing.getId() + ", polygon: " + currentRing.getParent().getGmlId().getGmlString());
}
return dimension;
}
private void createVertex(double x, double y, double z) {
// transform into utm, if available
BasicCoordinateTransform trans = config.getTargetTransform();
if (trans != null) {
p1.setValue(x, y);
trans.transform(p1, p2);
x = p2.x;
y = p2.y;
z = z / config.getFromMetres();
}
x = round(x, config.getNumberOfRoundingPlaces());
y = round(y, config.getNumberOfRoundingPlaces());
z = round(z, config.getNumberOfRoundingPlaces());
Vertex v = new Vertex(x, y, z);
Vertex duplicate = vertexMap.get(v);
if (duplicate == null) {
vertexMap.put(v, v);
} else {
v = duplicate;
}
currentRing.addVertex(v);
}
private double round(double value, int places) {
if (places < 0) {
throw new IllegalArgumentException();
}
BigDecimal bd = BigDecimal.valueOf(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
private static GeometryMapper parseGeometry(AbstractGeometry gmlG, Geometry geom, CityObject co,
ParserConfiguration config, Map<String, ConcretePolygon> polygons,
List<Pair<String, Geometry>> linkedPolygons, Map<Vertex, Vertex> vertexMap) {
if (gmlG.isSetId()) {
geom.setGmlId(new GmlId(gmlG.getId()));
}
co.addGeometry(geom);
GeometryMapper geomMapper = new GeometryMapper(geom, config, polygons, linkedPolygons, vertexMap);
gmlG.accept(geomMapper);
return geomMapper;
}
private static void parseIntoGeometry(AbstractGeometry geometry, GeometryMapper geomMapper, BoundarySurface bs,
BuildingInstallation coBi) {
geomMapper.setBoundarySurface(bs);
geomMapper.setBuildingInstallation(coBi);
geometry.accept(geomMapper);
}
public static void mapLod0MultiSurface(MultiSurfaceProperty lod0ms, CityObject co, ParserConfiguration config,
Map<String, ConcretePolygon> polygons, List<Pair<String, Geometry>> linkedPolygons,
Map<Vertex, Vertex> vertexMap) {
if (lod0ms == null || !lod0ms.isSetMultiSurface()) {
return;
}
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD0);
parseGeometry(lod0ms.getMultiSurface(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static GeometryMapper mapLod1MultiSurface(MultiSurfaceProperty lod1ms, CityObject co,
ParserConfiguration config, Map<String, ConcretePolygon> polygons,
List<Pair<String, Geometry>> linkedPolygons, Map<Vertex, Vertex> vertexMap) {
if (lod1ms == null || !lod1ms.isSetMultiSurface()) {
return null;
}
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD1);
return parseGeometry(lod1ms.getMultiSurface(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static GeometryMapper mapLod2MultiSurface(MultiSurfaceProperty lod2MultiSurface, CityObject co,
ParserConfiguration config, Map<String, ConcretePolygon> polygons,
List<Pair<String, Geometry>> linkedPolygons, Map<Vertex, Vertex> vertexMap) {
if (lod2MultiSurface == null || !lod2MultiSurface.isSetMultiSurface()) {
return null;
}
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
return parseGeometry(lod2MultiSurface.getMultiSurface(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static GeometryMapper mapLod3MultiSurface(MultiSurfaceProperty lod3MultiSurface, CityObject co,
ParserConfiguration config, Map<String, ConcretePolygon> polygons,
List<Pair<String, Geometry>> linkedPolygons, Map<Vertex, Vertex> vertexMap) {
if (lod3MultiSurface == null || !lod3MultiSurface.isSetMultiSurface()) {
return null;
}
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD3);
return parseGeometry(lod3MultiSurface.getMultiSurface(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static GeometryMapper mapLod4MultiSurface(MultiSurfaceProperty lod4MultiSurface, CityObject co,
ParserConfiguration config, Map<String, ConcretePolygon> polygons,
List<Pair<String, Geometry>> linkedPolygons, Map<Vertex, Vertex> vertexMap) {
if (lod4MultiSurface == null || !lod4MultiSurface.isSetMultiSurface()) {
return null;
}
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD4);
return parseGeometry(lod4MultiSurface.getMultiSurface(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static GeometryMapper mapLod1Solid(SolidProperty lod1Solid, CityObject co, ParserConfiguration config,
Map<String, ConcretePolygon> polygons, List<Pair<String, Geometry>> linkedPolygons,
Map<Vertex, Vertex> vertexMap) {
if (lod1Solid == null || !lod1Solid.isSetSolid()) {
return null;
}
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD1);
return parseGeometry(lod1Solid.getSolid(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static GeometryMapper mapLod2Solid(SolidProperty lod2Solid, CityObject co, ParserConfiguration config,
Map<String, ConcretePolygon> polygons, List<Pair<String, Geometry>> linkedPolygons,
Map<Vertex, Vertex> vertexMap) {
if (lod2Solid == null || !lod2Solid.isSetSolid()) {
return null;
}
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD2);
return parseGeometry(lod2Solid.getSolid(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static GeometryMapper mapLod3Solid(SolidProperty lod3Solid, CityObject co, ParserConfiguration config,
Map<String, ConcretePolygon> polygons, List<Pair<String, Geometry>> linkedPolygons,
Map<Vertex, Vertex> vertexMap) {
if (lod3Solid == null || !lod3Solid.isSetSolid()) {
return null;
}
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD3);
return parseGeometry(lod3Solid.getSolid(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static GeometryMapper mapLod4Solid(SolidProperty lod4Solid, CityObject co, ParserConfiguration config,
Map<String, ConcretePolygon> polygons, List<Pair<String, Geometry>> linkedPolygons,
Map<Vertex, Vertex> vertexMap) {
if (lod4Solid == null || !lod4Solid.isSetSolid()) {
return null;
}
Geometry geom = new Geometry(GeometryType.SOLID, Lod.LOD4);
return parseGeometry(lod4Solid.getSolid(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static void mapLod1Geometry(GeometryProperty<? extends AbstractGeometry> lod1Geometry, CityObject co,
ParserConfiguration config, Map<String, ConcretePolygon> polygons,
List<Pair<String, Geometry>> linkedPolygons, Map<Vertex, Vertex> vertexMap) {
if (lod1Geometry == null || !lod1Geometry.isSetGeometry()) {
return;
}
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD1);
parseGeometry(lod1Geometry.getGeometry(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static void mapLod2Geometry(GeometryProperty<? extends AbstractGeometry> lod2Geometry, CityObject co,
ParserConfiguration config, Map<String, ConcretePolygon> polygons,
List<Pair<String, Geometry>> linkedPolygons, Map<Vertex, Vertex> vertexMap) {
if (lod2Geometry == null || !lod2Geometry.isSetGeometry()) {
return;
}
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD2);
parseGeometry(lod2Geometry.getGeometry(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static void mapLod3Geometry(GeometryProperty<? extends AbstractGeometry> lod3Geometry, CityObject co,
ParserConfiguration config, Map<String, ConcretePolygon> polygons,
List<Pair<String, Geometry>> linkedPolygons, Map<Vertex, Vertex> vertexMap) {
if (lod3Geometry == null || !lod3Geometry.isSetGeometry()) {
return;
}
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD3);
parseGeometry(lod3Geometry.getGeometry(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static void mapLod4Geometry(GeometryProperty<? extends AbstractGeometry> lod4Geometry, CityObject co,
ParserConfiguration config, Map<String, ConcretePolygon> polygons,
List<Pair<String, Geometry>> linkedPolygons, Map<Vertex, Vertex> vertexMap) {
if (lod4Geometry == null || !lod4Geometry.isSetGeometry()) {
return;
}
Geometry geom = new Geometry(GeometryType.MULTI_SURFACE, Lod.LOD4);
parseGeometry(lod4Geometry.getGeometry(), geom, co, config, polygons, linkedPolygons, vertexMap);
}
public static void mapBoundarySurfaceIntoGeometry(MultiSurfaceProperty msp, GeometryMapper geom, BoundarySurface bs,
BuildingInstallation coBi) {
if (msp == null || !msp.isSetGeometry()) {
return;
}
parseIntoGeometry(msp.getGeometry(), geom, bs, coBi);
}
public static void mapBuildingInstallationIntoGeometry(GeometryProperty<? extends AbstractGeometry> gp,
GeometryMapper geom, BuildingInstallation coBi) {
if (gp == null || !gp.isSetGeometry()) {
return;
}
parseIntoGeometry(gp.getGeometry(), geom, null, coBi);
}
public Geometry getGeometry() {
return geom;
}
}
/*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.mapper.citygml3;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.locationtech.proj4j.BasicCoordinateTransform;
import org.locationtech.proj4j.ProjCoordinate;
import org.xmlobjects.gml.model.geometry.primitives.AbstractRing;
import org.xmlobjects.gml.model.geometry.primitives.AbstractRingProperty;
import org.xmlobjects.gml.model.geometry.primitives.Polygon;
import org.xmlobjects.gml.model.geometry.primitives.Ring;
import org.xmlobjects.gml.visitor.GeometryWalker;
import de.hft.stuttgart.citydoctor2.datastructure.ConcretePolygon;
import de.hft.stuttgart.citydoctor2.datastructure.GmlId;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing;
import de.hft.stuttgart.citydoctor2.datastructure.LinearRing.LinearRingType;
import de.hft.stuttgart.citydoctor2.datastructure.Vertex;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.utils.Localization;
public class Citygml3GeometryMapper extends GeometryWalker {
private static final Logger logger = LogManager.getLogger(Citygml3GeometryMapper.class);
private List<ConcretePolygon> polygons = new ArrayList<>();
private LinearRing currentRing = null;
private ParserConfiguration config;
private ProjCoordinate p1 = new ProjCoordinate();
private ProjCoordinate p2 = new ProjCoordinate();
private Map<Vertex, Vertex> vertexMap;
public Citygml3GeometryMapper(ParserConfiguration config, Map<Vertex, Vertex> vertices) {
this.config = config;
this.vertexMap = vertices;
}
@Override
public void visit(Polygon polygon) {
parsePolygon(polygon.getId(), polygon.getExterior(), polygon.getInterior());
if (polygon.getExterior() == null) {
System.out.println("No exterior: " + polygon.getId());
}
}
private void parsePolygon(String id, AbstractRingProperty exterior, List<AbstractRingProperty> interior) {
if (exterior == null || exterior.getObject() == null) {
if (logger.isWarnEnabled()) {
logger.warn(Localization.getText("GeometryMapper.emptyPolygon"));
}
return;
}
ConcretePolygon cdPoly = new ConcretePolygon();
polygons.add(cdPoly);
if (id != null) {
cdPoly.setGmlId(new GmlId(id));
}
currentRing = new LinearRing(LinearRingType.EXTERIOR);
exterior.getObject().accept(this);
cdPoly.setExteriorRing(currentRing);
for (AbstractRingProperty interiorGmlRing : interior) {
AbstractRing gmlRing = interiorGmlRing.getObject();
if (gmlRing == null) {
continue;
}
currentRing = new LinearRing(LinearRingType.INTERIOR);
gmlRing.accept(this);
cdPoly.addInteriorRing(currentRing);
}
}
@Override
public void visit(org.xmlobjects.gml.model.geometry.primitives.LinearRing gmlRing) {
if (gmlRing.getSrsDimension() != null && gmlRing.getSrsDimension() != 3) {
logger.warn("Cannot handle geometry with srsDimension not 3");
return;
}
if (gmlRing.getId() != null) {
currentRing.setGmlId(new GmlId(gmlRing.getId()));
}
List<Double> coordinates = gmlRing.toCoordinateList3D();
handleCoordinateList(coordinates);
}
@Override
public void visit(Ring ring) {
if (ring.getSrsDimension() != null && ring.getSrsDimension() != 3) {
logger.warn("Cannot handle geometry with srsDimension not 3");
return;
}
if (ring.getId() != null) {
currentRing.setGmlId(new GmlId(ring.getId()));
}
List<Double> coordinates = ring.toCoordinateList3D();
handleCoordinateList(coordinates);
}
private void handleCoordinateList(List<Double> coordinates) {
if (coordinates.size() % 3 != 0) {
String id;
if (currentRing.hasExistingGmlId()) {
id = currentRing.getGmlId().getGmlString();
} else {
id = "";
}
logger.warn("The number of coordinates for linear ring {} do not result in fully 3D points", id);
}
for (int i = 0; i < coordinates.size(); i = i + 3) {
double x = coordinates.get(i + 0);
double y = coordinates.get(i + 1);
double z = coordinates.get(i + 2);
createVertex(x, y, z);
}
}
private void createVertex(double x, double y, double z) {
// transform into utm, if available
BasicCoordinateTransform trans = config.getTargetTransform();
if (trans != null) {
p1.setValue(x, y);
trans.transform(p1, p2);
x = p2.x;
y = p2.y;
z = z / config.getFromMetres();
}
x = round(x, config.getNumberOfRoundingPlaces());
y = round(y, config.getNumberOfRoundingPlaces());
z = round(z, config.getNumberOfRoundingPlaces());
Vertex v = new Vertex(x, y, z);
Vertex duplicate = vertexMap.get(v);
if (duplicate == null) {
vertexMap.put(v, v);
} else {
v = duplicate;
}
currentRing.addVertex(v);
}
private double round(double value, int places) {
if (places < 0) {
throw new IllegalArgumentException();
}
BigDecimal bd = BigDecimal.valueOf(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
public List<ConcretePolygon> getPolygons() {
return polygons;
}
}
/*-
* Copyright 2022 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
*
* This file is part of CityDoctor2.
*
* CityDoctor2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CityDoctor2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with CityDoctor2. If not, see <https://www.gnu.org/licenses/>.
*/
package de.hft.stuttgart.citydoctor2.mapper.citygml3;
import de.hft.stuttgart.citydoctor2.datastructure.Geometry;
public record ResolvableReference(String href, Geometry geometry) {
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment