-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter object stream by perimeter (#7)
- Loading branch information
Showing
6 changed files
with
305 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package ch.geowerkstatt.lk2dxf; | ||
|
||
import ch.interlis.iom.IomObject; | ||
import ch.interlis.iom_j.itf.impl.jtsext.geom.JtsextGeometryFactory; | ||
import ch.interlis.iox.IoxException; | ||
import ch.interlis.iox_j.jts.Iox2jtsext; | ||
import com.vividsolutions.jts.geom.Geometry; | ||
import com.vividsolutions.jts.geom.GeometryFactory; | ||
|
||
public record GeometryObject(Geometry geometry, IomObject iomObject) { | ||
private static final String BASKET_NAME = "SIA405_LKMap_2015_LV95.SIA405_LKMap"; | ||
private static final GeometryFactory GEOMETRY_FACTORY = new JtsextGeometryFactory(); | ||
|
||
/** | ||
* Creates a new geometry object from the given {@link IomObject}. | ||
* @param iomObject The {@link IomObject} to create the geometry object from. | ||
* @return A geometry object containing the {@link IomObject} and its extracted {@link Geometry}. | ||
* @throws IllegalArgumentException If the object tag is not supported. | ||
* @throws RuntimeException If an error occurs while extracting the geometry. | ||
*/ | ||
public static GeometryObject create(IomObject iomObject) { | ||
try { | ||
Geometry geometry = switch (iomObject.getobjecttag()) { | ||
case BASKET_NAME + ".LKPunkt" -> readPoint(iomObject, "SymbolPos"); | ||
case BASKET_NAME + ".LKLinie" -> readLine(iomObject, "Linie"); | ||
case BASKET_NAME + ".LKFlaeche" -> readSurface(iomObject, "Flaeche"); | ||
case BASKET_NAME + ".LKObjekt_Text" -> readPoint(iomObject, "TextPos"); | ||
default -> throw new IllegalArgumentException("Unsupported object tag: " + iomObject.getobjecttag()); | ||
}; | ||
return new GeometryObject(geometry, iomObject); | ||
} catch (IoxException e) { | ||
throw new RuntimeException("Error creating geometry for object with id \"" + iomObject.getobjectoid() + "\".", e); | ||
} | ||
} | ||
|
||
private static Geometry readPoint(IomObject iomObject, String attributeName) throws IoxException { | ||
IomObject position = iomObject.getattrobj(attributeName, 0); | ||
return GEOMETRY_FACTORY.createPoint(Iox2jtsext.coord2JTS(position)); | ||
} | ||
|
||
private static Geometry readLine(IomObject iomObject, String attributeName) throws IoxException { | ||
IomObject line = iomObject.getattrobj(attributeName, 0); | ||
return Iox2jtsext.polyline2JTS(line, false, 0.0); | ||
} | ||
|
||
private static Geometry readSurface(IomObject iomObject, String attributeName) throws IoxException { | ||
IomObject surface = iomObject.getattrobj(attributeName, 0); | ||
return Iox2jtsext.surface2JTS(surface, 0.0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/test/data/LKMapXtfReaderTest/ValidMultipleBaskets.xtf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?xml version ="1.0" encoding ="UTF-8"?> | ||
<TRANSFER xmlns="http://www.interlis.ch/INTERLIS2.3"> | ||
<HEADERSECTION VERSION="2.3" SENDER="Test"> | ||
<MODELS> | ||
<MODEL NAME="Units" URI="http://www.interlis.ch/models" VERSION="2012-02-20" /> | ||
<MODEL NAME="Base_LV95" URI="http://www.sia.ch/405" VERSION="05.10.2018" /> | ||
<MODEL NAME="SIA405_Base_LV95" URI="http://www.sia.ch/405" VERSION="05.10.2018" /> | ||
<MODEL NAME="SIA405_LKMap_2015_LV95" URI="http://www.sia.ch/405" VERSION="27.04.2018" /> | ||
</MODELS> | ||
<COMMENT>test data</COMMENT> | ||
</HEADERSECTION> | ||
<DATASECTION> | ||
<SIA405_LKMap_2015_LV95.SIA405_LKMap BID="x1"> | ||
<SIA405_LKMap_2015_LV95.SIA405_LKMap.LKFlaeche TID="basket1object001"> | ||
<OBJ_ID>basket1object001</OBJ_ID> | ||
<Metaattribute> | ||
<SIA405_Base_LV95.Metaattribute> | ||
<Datenherr>Test</Datenherr> | ||
<Datenlieferant>Test</Datenlieferant> | ||
<Letzte_Aenderung>20241030</Letzte_Aenderung> | ||
</SIA405_Base_LV95.Metaattribute> | ||
</Metaattribute> | ||
<Eigentuemer>Test</Eigentuemer> | ||
<Lagebestimmung>unbekannt</Lagebestimmung> | ||
<Status>in_Betrieb</Status> | ||
<Flaeche> | ||
<SURFACE> | ||
<BOUNDARY> | ||
<POLYLINE> | ||
<COORD> | ||
<C1>2669992.781</C1> | ||
<C2>1208904.666</C2> | ||
</COORD> | ||
<COORD> | ||
<C1>2669971.614</C1> | ||
<C2>1206904.416</C2> | ||
</COORD> | ||
<COORD> | ||
<C1>2672924.364</C1> | ||
<C2>1206936.166</C2> | ||
</COORD> | ||
<COORD> | ||
<C1>2672818.531</C1> | ||
<C2>1208915.250</C2> | ||
</COORD> | ||
<COORD> | ||
<C1>2669992.781</C1> | ||
<C2>1208904.666</C2> | ||
</COORD> | ||
</POLYLINE> | ||
</BOUNDARY> | ||
</SURFACE> | ||
</Flaeche> | ||
<Objektart>Wasser.unbekannt</Objektart> | ||
</SIA405_LKMap_2015_LV95.SIA405_LKMap.LKFlaeche> | ||
<SIA405_LKMap_2015_LV95.SIA405_LKMap.LKPunkt TID="basket1object002"> | ||
<OBJ_ID>basket1object002</OBJ_ID> | ||
<Metaattribute> | ||
<SIA405_Base_LV95.Metaattribute> | ||
<Datenherr>Test</Datenherr> | ||
<Datenlieferant>Test</Datenlieferant> | ||
<Letzte_Aenderung>20241030</Letzte_Aenderung> | ||
</SIA405_Base_LV95.Metaattribute> | ||
</Metaattribute> | ||
<Eigentuemer>Test</Eigentuemer> | ||
<Lagebestimmung>unbekannt</Lagebestimmung> | ||
<Status>in_Betrieb</Status> | ||
<SymbolPos> | ||
<COORD> | ||
<C1>2669992.781</C1> | ||
<C2>1208904.666</C2> | ||
</COORD> | ||
</SymbolPos> | ||
<Objektart>Wasser.Absperrorgan</Objektart> | ||
</SIA405_LKMap_2015_LV95.SIA405_LKMap.LKPunkt> | ||
</SIA405_LKMap_2015_LV95.SIA405_LKMap> | ||
<SIA405_LKMap_2015_LV95.SIA405_LKMap BID="x2"> | ||
<SIA405_LKMap_2015_LV95.SIA405_LKMap.LKPunkt TID="basket2object001"> | ||
<OBJ_ID>basket2object001</OBJ_ID> | ||
<Metaattribute> | ||
<SIA405_Base_LV95.Metaattribute> | ||
<Datenherr>Test</Datenherr> | ||
<Datenlieferant>Test</Datenlieferant> | ||
<Letzte_Aenderung>20241030</Letzte_Aenderung> | ||
</SIA405_Base_LV95.Metaattribute> | ||
</Metaattribute> | ||
<Eigentuemer>Test</Eigentuemer> | ||
<Lagebestimmung>ungenau</Lagebestimmung> | ||
<Status>in_Betrieb</Status> | ||
<SymbolPos> | ||
<COORD> | ||
<C1>2669992.781</C1> | ||
<C2>1208904.666</C2> | ||
</COORD> | ||
</SymbolPos> | ||
<Objektart>Fernwaerme.unbekannt</Objektart> | ||
</SIA405_LKMap_2015_LV95.SIA405_LKMap.LKPunkt> | ||
</SIA405_LKMap_2015_LV95.SIA405_LKMap> | ||
</DATASECTION> | ||
</TRANSFER> |
Oops, something went wrong.