use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString in project geotoolkit by Geomatys.
the class JTSGeometryBindingTest method MultiCurveMarshalingTest.
/**
* Test Composite curve Marshalling.
*/
@Test
public void MultiCurveMarshalingTest() throws Exception {
CoordinateReferenceSystem crs = CRS.forCode("urn:ogc:def:crs:epsg::4326");
assertTrue(crs != null);
DirectPosition p1 = new GeneralDirectPosition(crs);
p1.setOrdinate(0, 35.840973);
p1.setOrdinate(1, 0.14967346);
DirectPosition p2 = new GeneralDirectPosition(crs);
p2.setOrdinate(0, 44.11891);
p2.setOrdinate(1, 3.6755037);
JTSLineString l1 = new JTSLineString();
l1.getControlPoints().add(p1);
l1.getControlPoints().add(p2);
JTSCurve c2 = new JTSCurve(crs);
c2.getSegments().add(l1);
JTSCurve c1 = new JTSCurve(crs);
JTSLineString l2 = new JTSLineString();
DirectPosition p21 = new GeneralDirectPosition(crs);
p21.setOrdinate(0, 51.174034);
p21.setOrdinate(1, 12.365124);
DirectPosition p22 = new GeneralDirectPosition(crs);
p22.setOrdinate(0, 55.288635);
p22.setOrdinate(1, 7.583888);
DirectPosition p23 = new GeneralDirectPosition(crs);
p23.setOrdinate(0, 56.534782);
p23.setOrdinate(1, 4.1457024);
l2.getControlPoints().add(p21);
l2.getControlPoints().add(p22);
l2.getControlPoints().add(p23);
c1.getSegments().add(l2);
JTSMultiCurve multiCurve = new JTSMultiCurve(crs);
multiCurve.getElements().add(c2);
multiCurve.getElements().add(c1);
StringWriter sw = new StringWriter();
m.marshal(factory.createJTSMultiCurve(multiCurve), sw);
String result = sw.toString();
result = result.replaceAll("(?i)epsg\\:\\d+\\.\\d+\\.?\\d*\\:", "epsg::");
String expResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + '\n' + "<gml:MultiCurve xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"urn:ogc:def:crs:epsg::4326\" >" + '\n' + " <gml:curveMember>" + '\n' + " <gml:LineString>" + '\n' + " <gml:posList>35.840973 0.14967346 44.11891 3.6755037</gml:posList>" + '\n' + " </gml:LineString>" + '\n' + " </gml:curveMember>" + '\n' + " <gml:curveMember>" + '\n' + " <gml:LineString>" + '\n' + " <gml:posList>51.174034 12.365124 55.288635 7.583888 56.534782 4.1457024</gml:posList>" + '\n' + " </gml:LineString>" + '\n' + " </gml:curveMember>" + '\n' + "</gml:MultiCurve>" + '\n';
assertXmlEquals(expResult, result, "xmlns:*");
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString in project geotoolkit by Geomatys.
the class PolyhedralSurfaceType method getIsoPolyHedralSurface.
public JTSPolyhedralSurface getIsoPolyHedralSurface() {
JTSPolyhedralSurface result = new JTSPolyhedralSurface(coordinateReferenceSystem);
for (JTSSurfaceBoundary s : patchList.getPatches()) {
s.setCoordinateReferenceSystem(coordinateReferenceSystem);
((JTSRing) s.getExterior()).setCoordinateReferenceSystem(coordinateReferenceSystem);
for (Primitive p : s.getExterior().getElements()) {
if (p instanceof JTSCurve) {
JTSCurve curve = (JTSCurve) p;
curve.setCoordinateReferenceSystem(coordinateReferenceSystem);
for (CurveSegment cv : curve.getSegments()) {
if (cv instanceof JTSLineString) {
JTSLineString line = (JTSLineString) cv;
PointArray pa = line.getControlPoints();
List<Position> newPositions = new ArrayList<Position>();
for (Position pos : pa) {
if (pos instanceof GeneralDirectPosition) {
((GeneralDirectPosition) pos).setCoordinateReferenceSystem(coordinateReferenceSystem);
newPositions.add(pos);
}
}
line.getControlPoints().clear();
line.getControlPoints().addAll(newPositions);
}
}
}
}
if (s.getInteriors() != null) {
for (Ring ring : s.getInteriors()) {
((JTSRing) ring).setCoordinateReferenceSystem(coordinateReferenceSystem);
for (Primitive p : ring.getElements()) {
if (p instanceof JTSCurve) {
JTSCurve curve = (JTSCurve) p;
curve.setCoordinateReferenceSystem(coordinateReferenceSystem);
for (CurveSegment cv : curve.getSegments()) {
if (cv instanceof JTSLineString) {
JTSLineString line = (JTSLineString) cv;
PointArray pa = line.getControlPoints();
List<Position> newPositions = new ArrayList<Position>();
for (Position pos : pa) {
if (pos instanceof GeneralDirectPosition) {
((GeneralDirectPosition) pos).setCoordinateReferenceSystem(coordinateReferenceSystem);
newPositions.add(pos);
}
}
line.getControlPoints().clear();
line.getControlPoints().addAll(newPositions);
}
}
}
}
}
}
result.getPatches().add(new JTSPolygon(s));
}
return result;
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString in project geotoolkit by Geomatys.
the class LineStringPosListType method getJTSLineString.
public JTSLineString getJTSLineString() {
CoordinateReferenceSystem crs = null;
if (this.srsName != null) {
try {
crs = CRS.forCode(srsName);
} catch (FactoryException ex) {
Logger.getLogger("org.geotoolkit.internal.jaxb").log(Level.WARNING, null, ex);
}
}
final JTSLineString result = new JTSLineString(crs);
if (posList != null) {
for (int i = 0; i < posList.getValue().size(); i = i + 2) {
result.getPositions().add(new GeneralDirectPosition(posList.getValue().get(i), posList.getValue().get(i + 1)));
}
} else if (coordinates != null) {
for (int i = 0; i < coordinates.getValues().size(); i = i + 2) {
result.getPositions().add(new GeneralDirectPosition(coordinates.getValues().get(i), coordinates.getValues().get(i + 1)));
}
}
return result;
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString in project geotoolkit by Geomatys.
the class LinearRingPosListType method getJTSRing.
public JTSRing getJTSRing() {
final List<Double> values;
if (posList != null) {
values = posList.getValue();
} else if (coordinates != null) {
values = coordinates.getValues();
} else {
values = new ArrayList<Double>();
}
final JTSLineString line = new JTSLineString();
for (int i = 0; i < values.size() - 1; i = i + 2) {
double x = values.get(i);
double y = values.get(i + 1);
final DirectPosition pos = new GeneralDirectPosition(x, y);
line.getControlPoints().add(pos);
}
JTSCurve curve = new JTSCurve();
curve.getSegments().add(line);
JTSRing ring = new JTSRing();
ring.getElements().add(curve);
return ring;
}
use of org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString in project geotoolkit by Geomatys.
the class GeometryMapping method readValue.
@Override
public void readValue(XMLStreamReader reader, GenericName propName, Feature feature) throws XMLStreamException {
final String localName = reader.getLocalName();
if (decorated) {
// check if we are dealing with a link href
String link = reader.getAttributeValue(GMLConvention.XLINK_NAMESPACE, "href");
if (link != null) {
toTagEnd(reader, localName);
Attribute attribute = (Attribute) feature.getProperty(propName.toString());
AttributeType<String> charType = (AttributeType) attribute.getType().characteristics().get(GMLConvention.XLINK_HREF.tip().toString());
Attribute<String> charValue = charType.newInstance();
charValue.setValue(link);
attribute.characteristics().put(GMLConvention.XLINK_HREF.tip().toString(), charValue);
return;
}
}
boolean skipCurrent = decorated;
int event;
Object value;
// backward compatible with incorrect old writings
final String propertyName = propertyType.getName().tip().toString();
if (propertyName.equals(localName)) {
skipCurrent = true;
}
// special case for SurfacePropertyType which may contain a simple polygon
boolean forceMultiPolygon = propertyName.equalsIgnoreCase("multipolygon");
if (skipCurrent) {
event = reader.next();
} else {
event = reader.getEventType();
}
while (event != START_ELEMENT) {
if (event == END_ELEMENT) {
return;
}
event = reader.next();
}
try {
Unmarshaller unmarshaller = pool.acquireUnmarshaller();
final Geometry jtsGeom;
final Object geometry = ((JAXBElement) unmarshaller.unmarshal(reader)).getValue();
if (geometry instanceof JTSGeometry) {
final JTSGeometry isoGeom = (JTSGeometry) geometry;
if (isoGeom instanceof JTSMultiCurve) {
((JTSMultiCurve) isoGeom).applyCRSonChild();
}
jtsGeom = isoGeom.getJTSGeometry();
} else if (geometry instanceof PolygonType) {
final PolygonType polygon = ((PolygonType) geometry);
jtsGeom = polygon.getJTSPolygon().getJTSGeometry();
if (polygon.getCoordinateReferenceSystem() != null) {
JTS.setCRS(jtsGeom, polygon.getCoordinateReferenceSystem());
}
} else if (geometry instanceof LineStringPosListType) {
final JTSLineString line = ((LineStringPosListType) geometry).getJTSLineString();
jtsGeom = line.getJTSGeometry();
if (line.getCoordinateReferenceSystem() != null) {
JTS.setCRS(jtsGeom, line.getCoordinateReferenceSystem());
}
} else if (geometry instanceof AbstractGeometry) {
try {
jtsGeom = GeometrytoJTS.toJTS((AbstractGeometry) geometry, longitudeFirst, forceMultiPolygon);
} catch (FactoryException ex) {
throw new XMLStreamException("Factory Exception while transforming GML object to JTS", ex);
}
} else {
throw new IllegalArgumentException("unexpected geometry type:" + geometry);
}
value = jtsGeom;
value = JTSMapping.convertType(jtsGeom, ((AttributeType) propertyType).getValueClass());
pool.recycle(unmarshaller);
} catch (JAXBException ex) {
String msg = ex.getMessage();
if (msg == null && ex.getLinkedException() != null) {
msg = ex.getLinkedException().getMessage();
}
throw new IllegalArgumentException("JAXB exception while reading the feature geometry: " + msg, ex);
}
JAXPStreamFeatureReader.setValue(feature, propertyType, propName, null, value);
}
Aggregations