use of org.opengis.geometry.primitive.CurveSegment 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.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.
the class GMLUtilities method getGMLFromISO.
/**
* @param geometry The ISO geometry to convert.
* @return A GML 3.1.1 geometry matching given geometry definition.
* @deprecated This method should not be used for multiple reasons:
* <ol>
* <li>OpenGIS definition is based on an obsolete ISO-19107 draft</li>
* <li>The GML version is fixed and obsolete</li>
* <li>Only partial management of geometries</li>
* </ol>
*/
public static AbstractGeometryType getGMLFromISO(final org.opengis.geometry.Geometry geometry) {
if (geometry instanceof Point) {
Point point = (Point) geometry;
PointType gmlPoint = new PointType(null, point.getDirectPosition());
return gmlPoint;
} else if (geometry instanceof OrientableSurface) {
OrientableSurface surface = (OrientableSurface) geometry;
SurfaceBoundary boundary = surface.getBoundary();
Ring exterior = boundary.getExterior();
List<CurvePropertyType> curves = new ArrayList<CurvePropertyType>();
for (Primitive p : exterior.getElements()) {
curves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlExterior = new RingType();
gmlExterior.getCurveMember().addAll(curves);
List<Ring> interiors = boundary.getInteriors();
List<RingType> gmlInteriors = new ArrayList<RingType>();
for (Ring interior : interiors) {
List<CurvePropertyType> intcurves = new ArrayList<CurvePropertyType>();
for (Primitive p : interior.getElements()) {
intcurves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlinterior = new RingType();
gmlinterior.getCurveMember().addAll(intcurves);
gmlInteriors.add(gmlinterior);
}
PolygonType poly = new PolygonType(gmlExterior, gmlInteriors);
return poly;
} else if (geometry instanceof MultiSurface) {
MultiSurface multiPrim = (MultiSurface) geometry;
List<PolygonPropertyType> geometries = new ArrayList<PolygonPropertyType>();
for (Geometry prim : multiPrim.getElements()) {
PolygonType element = (PolygonType) getGMLFromISO(prim);
PolygonPropertyType gp = new PolygonPropertyType((PolygonType) element);
geometries.add(gp);
}
MultiPolygonType gmlMulti = new MultiPolygonType(null, geometries);
return gmlMulti;
} else if (geometry instanceof MultiCurve) {
MultiCurve multiPrim = (MultiCurve) geometry;
List<CurvePropertyType> geometries = new ArrayList<CurvePropertyType>();
for (OrientableCurve prim : multiPrim.getElements()) {
AbstractCurveType element = (AbstractCurveType) getGMLFromISO(prim);
CurvePropertyType gp = new CurvePropertyType((AbstractCurveType) element);
geometries.add(gp);
}
MultiCurveType gmlMulti = new MultiCurveType(geometries);
return gmlMulti;
} else if (geometry instanceof MultiPoint) {
MultiPoint multiPrim = (MultiPoint) geometry;
List<PointPropertyType> geometries = new ArrayList<PointPropertyType>();
for (Point prim : multiPrim.getElements()) {
PointType element = (PointType) getGMLFromISO(prim);
PointPropertyType gp = new PointPropertyType((PointType) element);
geometries.add(gp);
}
MultiPointType gmlMulti = new MultiPointType(null, geometries);
return gmlMulti;
} else if (geometry instanceof MultiPrimitive) {
MultiPrimitive multiPrim = (MultiPrimitive) geometry;
List<GeometryPropertyType> geometries = new ArrayList<GeometryPropertyType>();
for (Primitive prim : multiPrim.getElements()) {
AbstractGMLType element = getGMLFromISO(prim);
GeometryPropertyType gp = new GeometryPropertyType((AbstractGeometryType) element);
geometries.add(gp);
}
MultiGeometryType gmlMulti = new MultiGeometryType(geometries);
return gmlMulti;
} else if (geometry instanceof Curve) {
Curve curve = (Curve) geometry;
List<? extends CurveSegment> segments = curve.getSegments();
List<LineStringSegmentType> gmlSegments = new ArrayList<LineStringSegmentType>();
for (CurveSegment segment : segments) {
CurveInterpolationType interpolation = CurveInterpolationType.fromValue(segment.getInterpolation().identifier());
PointArray array = GeometricUtilities.getSamplePoints(segment);
List<DirectPosition> positions = new ArrayList<DirectPosition>();
for (int i = 0; i < array.size(); i++) {
positions.add(array.getDirectPosition(i, null));
}
LineStringSegmentType gmlSegment = new LineStringSegmentType(segment.getNumDerivativesAtStart(), segment.getNumDerivativesAtEnd(), segment.getNumDerivativesInterior(), interpolation, positions);
gmlSegments.add(gmlSegment);
}
CurveType gmlCurve = new CurveType(gmlSegments);
return gmlCurve;
} else if (geometry instanceof LineString) {
LineString line = (LineString) geometry;
PointArray array = GeometricUtilities.getSamplePoints(line);
List<DirectPosition> positions = new ArrayList<DirectPosition>();
for (int i = 0; i < array.size(); i++) {
positions.add(array.getDirectPosition(i, null));
}
LineStringType gmlLine = new LineStringType(positions);
return gmlLine;
} else if (geometry instanceof Polygon) {
Polygon polygon = (Polygon) geometry;
SurfaceBoundary boundary = polygon.getBoundary();
Ring exterior = boundary.getExterior();
List<CurvePropertyType> curves = new ArrayList<CurvePropertyType>();
for (Primitive p : exterior.getElements()) {
curves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlExterior = new RingType();
gmlExterior.getCurveMember().addAll(curves);
List<Ring> interiors = boundary.getInteriors();
List<RingType> gmlInteriors = new ArrayList<RingType>();
for (Ring interior : interiors) {
List<CurvePropertyType> intcurves = new ArrayList<CurvePropertyType>();
for (Primitive p : interior.getElements()) {
intcurves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlinterior = new RingType();
gmlinterior.getCurveMember().addAll(intcurves);
gmlInteriors.add(gmlinterior);
}
PolygonType gmlPolygon = new PolygonType(gmlExterior, gmlInteriors);
return gmlPolygon;
} else if (geometry instanceof PolyhedralSurface) {
PolyhedralSurface polySurface = (PolyhedralSurface) geometry;
List<PolygonPatchType> gmlPatches = new ArrayList<PolygonPatchType>();
List<? extends Polygon> patches = polySurface.getPatches();
for (Polygon polygon : patches) {
SurfaceInterpolationType interpolation = SurfaceInterpolationType.fromValue(polygon.getInterpolation().identifier());
SurfaceBoundary boundary = polygon.getBoundary();
Ring exterior = boundary.getExterior();
List<CurvePropertyType> curves = new ArrayList<CurvePropertyType>();
for (Primitive p : exterior.getElements()) {
curves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlExterior = new RingType();
gmlExterior.getCurveMember().addAll(curves);
List<Ring> interiors = boundary.getInteriors();
List<RingType> gmlInteriors = new ArrayList<RingType>();
for (Ring interior : interiors) {
List<CurvePropertyType> intcurves = new ArrayList<CurvePropertyType>();
for (Primitive p : interior.getElements()) {
intcurves.add(new CurvePropertyType((CurveType) getGMLFromISO(p)));
}
RingType gmlinterior = new RingType();
gmlinterior.getCurveMember().addAll(intcurves);
gmlInteriors.add(gmlinterior);
}
PolygonPatchType patche = new PolygonPatchType(interpolation, gmlExterior, gmlInteriors);
gmlPatches.add(patche);
}
PolygonPatchArrayPropertyType pathArray = new PolygonPatchArrayPropertyType(gmlPatches);
PolyhedralSurfaceType gmlPolySurface = new PolyhedralSurfaceType(pathArray);
return gmlPolySurface;
} else {
System.out.println("unexpected iso geometry type:" + geometry.getClass().getName());
}
return null;
}
use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.
the class ISOGeometryJ2D method createRectangle.
/**
* Creates a jts Geometry object representing a rectangle with the given
* parameters
*
* @param x left coordinate
* @param y bottom coordinate
* @param w width
* @param h height
* @return a rectangle with the specified position and size
*/
private Geometry createRectangle(final double x, final double y, final double w, final double h) {
final GeometryFactory gf = new JTSGeometryFactory(geometry.getCoordinateReferenceSystem());
final PrimitiveFactory pf = new JTSPrimitiveFactory(geometry.getCoordinateReferenceSystem());
final List<Position> points = new ArrayList<Position>();
points.add(new DirectPosition2D(x, y));
points.add(new DirectPosition2D(x + w, y));
points.add(new DirectPosition2D(x + w, y + h));
points.add(new DirectPosition2D(x, y + h));
points.add(new DirectPosition2D(x, y));
CurveSegment segment = gf.createLineString(points);
OrientableCurve curve = pf.createCurve(Collections.singletonList(segment));
Ring exterior = pf.createRing(Collections.singletonList(curve));
SurfaceBoundary boundary = pf.createSurfaceBoundary(exterior, null);
return boundary;
}
use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.
the class GeometryParser method readLineStringText.
/**
* Creates a <code>LineString</code> using the next token in the stream.
*
* @param tokenizer tokenizer over a stream of text in Well-known Text
* format. The next tokens must form a <LineString Text>.
* @return a <code>LineString</code> specified by the next
* token in the stream
* @throws IOException if an I/O error occurs
* @throws ParseException if an unexpected token was encountered
*/
private Curve readLineStringText(final StreamTokenizer tokenizer) throws IOException, ParseException {
final List<Position> coordList = getCoordinates(tokenizer);
final LineString lineString = geometryFactory.createLineString(coordList);
final List<CurveSegment> curveSegmentList = Collections.singletonList((CurveSegment) lineString);
return primitiveFactory.createCurve(curveSegmentList);
}
use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.
the class GeometryUtils method getDirectPositions.
public static DirectPosition[] getDirectPositions(final Ring ring) {
final List directPositionList = new ArrayList();
// Cast below can be removed when Types will be allowed to abandon Java 1.4 support.
final List /*<Curve>*/
generators = (List) ring.getGenerators();
for (int i = 0; i < generators.size(); i++) {
final Curve curve = (Curve) generators.get(i);
final List /*<CurveSegments>*/
segments = curve.getSegments();
for (int j = 0; j < segments.size(); j++) {
final CurveSegment curveSegment = (CurveSegment) segments.get(j);
if (curveSegment instanceof LineString) {
final LineString lineString = (LineString) curveSegment;
final DirectPosition[] positions = getDirectPositions(lineString);
directPositionList.addAll(Arrays.asList(positions));
/*final List<Position> positions = lineString.getControlPoints().positions();
for (int k = 0; k < positions.size(); k++) {
Position position = (Position) positions.get(k);
directPositionList.add(position.getPosition());
}*/
}
}
}
if (directPositionList.size() > 0) {
return (DirectPosition[]) directPositionList.toArray(new DirectPosition[directPositionList.size()]);
}
return new DirectPosition[0];
}
Aggregations