You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by js...@apache.org on 2026/10/09 14:15:07 UTC
(sis) 01/02: feat(Geometry): map GeometryType enum to matching Java class
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 3f5c1731b1d7d4d3a1c04175240790e4e5ea7105
Author: jsorel <jo...@geomatys.com>
AuthorDate: Fri Oct 9 12:25:04 2026 +0200
feat(Geometry): map GeometryType enum to matching Java class
---
.../main/org/apache/sis/geometries/Curve.java | 2 +
.../org/apache/sis/geometries/GeometryType.java | 184 ++++++++++++++-------
.../main/org/apache/sis/geometries/curve/Line.java | 161 ++++++++++++++++++
.../geometries/internal/shared/DefaultLine.java | 87 ++++++++++
4 files changed, 370 insertions(+), 64 deletions(-)
diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Curve.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Curve.java
index ffbeb07625..9d731eb4c8 100644
--- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Curve.java
+++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/Curve.java
@@ -28,6 +28,7 @@ import org.apache.sis.geometries.curve.CompoundCurve;
import org.apache.sis.geometries.curve.Conic;
import org.apache.sis.geometries.curve.FunctionCurve;
import org.apache.sis.geometries.curve.Geodesic;
+import org.apache.sis.geometries.curve.Line;
import org.apache.sis.geometries.curve.LineString;
import org.apache.sis.geometries.curve.OffsetCurve;
import org.apache.sis.geometries.curve.ProductCurve;
@@ -74,6 +75,7 @@ public sealed interface Curve extends Orientable
Conic,
FunctionCurve,
Geodesic,
+ Line,
LineString,
OffsetCurve,
ProductCurve,
diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/GeometryType.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/GeometryType.java
index 9a5a86d1bf..1c158f2b6d 100644
--- a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/GeometryType.java
+++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/GeometryType.java
@@ -16,6 +16,50 @@
*/
package org.apache.sis.geometries;
+import org.apache.sis.geometries.curve.Arc;
+import org.apache.sis.geometries.curve.ArcByBulge;
+import org.apache.sis.geometries.curve.ArcByCenterPoint;
+import org.apache.sis.geometries.curve.BSplineCurve;
+import org.apache.sis.geometries.curve.Bezier;
+import org.apache.sis.geometries.curve.Circle;
+import org.apache.sis.geometries.curve.CircularString;
+import org.apache.sis.geometries.curve.Clothoid;
+import org.apache.sis.geometries.curve.CompoundCurve;
+import org.apache.sis.geometries.curve.Conic;
+import org.apache.sis.geometries.curve.CubicSpline;
+import org.apache.sis.geometries.curve.EllipticArc;
+import org.apache.sis.geometries.curve.Geodesic;
+import org.apache.sis.geometries.curve.Line;
+import org.apache.sis.geometries.curve.LineString;
+import org.apache.sis.geometries.curve.LinearRing;
+import org.apache.sis.geometries.curve.MultiCurve;
+import org.apache.sis.geometries.curve.MultiLineString;
+import org.apache.sis.geometries.curve.NurbCurve;
+import org.apache.sis.geometries.curve.OffsetCurve;
+import org.apache.sis.geometries.curve.PolynomialSpline;
+import org.apache.sis.geometries.curve.ProductCurve;
+import org.apache.sis.geometries.curve.Rhumb;
+import org.apache.sis.geometries.curve.Spiral;
+import org.apache.sis.geometries.curve.SplineCurve;
+import org.apache.sis.geometries.point.MultiPoint;
+import org.apache.sis.geometries.solid.BSplineSolid;
+import org.apache.sis.geometries.solid.Capsule;
+import org.apache.sis.geometries.solid.Cylinder;
+import org.apache.sis.geometries.solid.Ellipsoid;
+import org.apache.sis.geometries.solid.Frustrum;
+import org.apache.sis.geometries.solid.MultiPolyhedron;
+import org.apache.sis.geometries.solid.Polyhedron;
+import org.apache.sis.geometries.solid.Sphere;
+import org.apache.sis.geometries.surface.BSplineSurface;
+import org.apache.sis.geometries.surface.BilinearGrid;
+import org.apache.sis.geometries.surface.CurvePolygon;
+import org.apache.sis.geometries.surface.MultiPolygon;
+import org.apache.sis.geometries.surface.MultiSurface;
+import org.apache.sis.geometries.surface.NurbSurface;
+import org.apache.sis.geometries.surface.Polygon;
+import org.apache.sis.geometries.surface.PolyhedralSurface;
+import org.apache.sis.geometries.surface.TIN;
+import org.apache.sis.geometries.surface.Triangle;
import static org.opengis.annotation.Specification.ISO_19107;
import org.opengis.annotation.UML;
@@ -41,227 +85,219 @@ public enum GeometryType {
/**
* The empty set, of topological dimension −1.
*/
- EMPTY,
+ EMPTY(Empty.class),
/**
* The abstract root of all geometry types.
*/
- GEOMETRY,
+ GEOMETRY(Geometry.class),
/**
* A collection behaving as the set union of its elements.
*/
- COLLECTION,
+ COLLECTION(GeometryCollection.class),
//point types
/**
* A single location, of topological dimension 0.
*/
- POINT,
+ POINT(Point.class),
/**
* A collection of points.
*/
- MULTIPOINT,
+ MULTIPOINT(MultiPoint.class),
//curve types
/**
* A curve of unspecified interpolation, of topological dimension 1.
*/
- CURVE,
+ CURVE(Curve.class),
/**
* A curve using a linear interpolation in the coordinate system.
*/
- LINE,
+ LINE(Line.class),
/**
* A sequence of segments using a linear interpolation.
*/
- LINESTRING,
+ LINESTRING(LineString.class),
/**
* A {@linkplain #LINESTRING} whose start point is its end point.
*/
- LINEARRING,
+ LINEARRING(LinearRing.class),
/**
* A sequence of segments using a circular interpolation.
*/
- CIRCULARSTRING,
+ CIRCULARSTRING(CircularString.class),
/**
* A curve made of contiguous curves of possibly different interpolations.
*/
- COMPOUNDCURVE,
+ COMPOUNDCURVE(CompoundCurve.class),
/**
* A curve following the shortest path on the geometric reference surface.
*/
- GEODESIC,
+ GEODESIC(Geodesic.class),
/**
* A curve of constant azimuth, also called loxodrome.
*/
- RHUMB,
+ RHUMB(Rhumb.class),
/**
* A portion of a circle defined by three points.
*/
- ARC,
+ ARC(Arc.class),
/**
* A portion of a circle defined by two points and a bulge factor.
*/
- ARCBYBULGE,
+ ARCBYBULGE(ArcByBulge.class),
/**
* A portion of a circle defined by its center, its radius and two angles.
*/
- ARCBYCENTERPOINT,
+ ARCBYCENTERPOINT(ArcByCenterPoint.class),
/**
* A closed {@linkplain #ARC}.
*/
- CIRCLE,
+ CIRCLE(Circle.class),
/**
* A portion of an ellipse.
*/
- ELLIPTICARC,
+ ELLIPTICARC(EllipticArc.class),
/**
* A curve defined by a conic section.
*/
- CONIC,
+ CONIC(Conic.class),
/**
* A curve whose curvature varies linearly with its length, also called Euler spiral.
*/
- CLOTHOID,
+ CLOTHOID(Clothoid.class),
/**
* A curve winding around a center point.
*/
- SPIRAL,
+ SPIRAL(Spiral.class),
/**
* A curve at a constant distance from another curve.
*/
- OFFSETCURVE,
+ OFFSETCURVE(OffsetCurve.class),
/**
* A curve defined as the product of two other curves.
*/
- PRODUCTCURVE,
+ PRODUCTCURVE(ProductCurve.class),
/**
* A curve interpolated by spline functions.
*/
- SPLINECURVE,
+ SPLINECURVE(SplineCurve.class),
/**
* A curve interpolated by B-spline basis functions.
*/
- BSPLINECURVE,
+ BSPLINECURVE(BSplineCurve.class),
/**
* A curve interpolated by cubic polynomials.
*/
- CUBICSPLINE,
+ CUBICSPLINE(CubicSpline.class),
/**
* A curve interpolated by polynomials of arbitrary degree.
*/
- POLYNOMIALSPLINE,
+ POLYNOMIALSPLINE(PolynomialSpline.class),
/**
* A curve interpolated by Bernstein polynomials over its control points.
*/
- BEZIER,
+ BEZIER(Bezier.class),
/**
* A curve interpolated by non-uniform rational B-spline basis functions.
*/
- NURBSCURVE,
+ NURBSCURVE(NurbCurve.class),
/**
* A collection of curves.
*/
- MULTICURVE,
+ MULTICURVE(MultiCurve.class),
/**
* A collection of {@linkplain #LINESTRING}.
*/
- MULTILINESTRING,
+ MULTILINESTRING(MultiLineString.class),
//surface types
/**
* A surface of unspecified interpolation, of topological dimension 2.
*/
- SURFACE,
+ SURFACE(Surface.class),
/**
* A surface defined only by its boundary rings and a spanning surface.
*/
- POLYGON,
+ POLYGON(Polygon.class),
/**
* A {@linkplain #POLYGON} with exactly three distinct non-collinear points and no interior ring.
*/
- TRIANGLE,
+ TRIANGLE(Triangle.class),
/**
* A {@linkplain #POLYGON} whose rings may use any curve interpolation.
*/
- CURVEPOLYGON,
+ CURVEPOLYGON(CurvePolygon.class),
/**
* A surface made of contiguous polygon patches.
*/
- POLYHEDRALSURFACE,
+ POLYHEDRALSURFACE(PolyhedralSurface.class),
/**
* A {@linkplain #POLYHEDRALSURFACE} whose patches are triangles.
*/
- TIN,
+ TIN(TIN.class),
/**
* A surface interpolated bilinearly over a grid of control points.
*/
- BILINEARGRID,
- /**
- * A surface interpolated by spline functions.
- */
- SPLINESURFACE,
+ BILINEARGRID(BilinearGrid.class),
/**
* A surface interpolated by B-spline basis functions.
*/
- BSPLINESURFACE,
+ BSPLINESURFACE(BSplineSurface.class),
/**
* A surface interpolated by non-uniform rational B-spline basis functions.
*/
- NURBSSURFACE,
+ NURBSSURFACE(NurbSurface.class),
/**
* A collection of {@linkplain #POLYGON}.
*/
- MULTIPOLYGON,
+ MULTIPOLYGON(MultiPolygon.class),
/**
* A collection of surfaces.
*/
- MULTISURFACE,
+ MULTISURFACE(MultiSurface.class),
//solid types
/**
* A solid of unspecified interpolation, of topological dimension 3.
*/
- SOLID,
+ SOLID(Solid.class),
/**
* A solid bounded by planar faces.
*/
- POLYHEDRON,
+ POLYHEDRON(Polyhedron.class),
/**
* A collection of {@linkplain #POLYHEDRON}.
*/
- MULTIPOLYHEDRON,
- /**
- * A solid interpolated by spline functions, of topological dimension 3.
- */
- SPLINESOLID,
+ MULTIPOLYHEDRON(MultiPolyhedron.class),
/**
* A solid interpolated by B-spline basis functions.
*/
- BSPLINESOLID,
+ BSPLINESOLID(BSplineSolid.class),
/**
* A solid bounded by the positions at a constant distance from a center point.
*/
- SPHERE,
+ SPHERE(Sphere.class),
/**
* A {@linkplain #SPHERE} scaled by a distinct factor along each axis of the coordinate system.
*/
- ELLIPSOID,
+ ELLIPSOID(Ellipsoid.class),
/**
* A solid bounded by a lateral surface and two parallel bases.
*/
- CYLINDER,
+ CYLINDER(Cylinder.class),
/**
* A {@linkplain #CYLINDER} closed by a half-sphere at each end.
*/
- CAPSULE,
+ CAPSULE(Capsule.class),
/**
* The portion of a solid lying between two parallel planes.
*/
- FRUSTRUM,
+ FRUSTRUM(Frustrum.class),
/**
* A solid swept by translating a surface along a direction.
*/
- PRISM,
+ PRISM(Prism.class),
/*
* Types having no equivalent in OGC Simple Feature Access.
@@ -269,17 +305,37 @@ public enum GeometryType {
/**
* A rectangle whose sides are parallel to the axes of the coordinate system.
*/
- BBOX,
+ BBOX(BBox.class),
/**
* An unbounded flat surface in a three-dimensional coordinate system.
*/
- PLANE,
+ PLANE(Plane.class),
/**
* A half-line, defined by an origin and a direction.
*/
- RAY,
+ RAY(Ray.class),
/**
* The generalization of {@link #PLANE} to a coordinate system of any dimension.
*/
- HYPERPLANE,
+ HYPERPLANE(HyperPlane.class);
+
+
+ final Class<? extends Geometry> javaClass;
+
+ private GeometryType(Class<? extends Geometry> c) {
+ this.javaClass = c;
+ }
+
+ public Class<? extends Geometry> getJavaClass() {
+ return javaClass;
+ }
+
+ public boolean isAssignableFrom(GeometryType type) {
+ return javaClass.isAssignableFrom(type.javaClass);
+ }
+
+ public boolean isInstance(Geometry geom) {
+ return javaClass.isInstance(geom);
+ }
+
}
diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/curve/Line.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/curve/Line.java
new file mode 100644
index 0000000000..7694226626
--- /dev/null
+++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/curve/Line.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.geometries.curve;
+
+import javax.measure.Quantity;
+import javax.print.attribute.standard.MediaSize.ISO;
+import static org.opengis.annotation.Specification.ISO_19107;
+import org.opengis.annotation.UML;
+import org.opengis.geometry.Envelope;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.apache.sis.geometries.Curve;
+import org.apache.sis.geometries.CurveInterpolation;
+import org.apache.sis.geometries.DataPoints;
+import org.apache.sis.geometries.GeometryType;
+import org.apache.sis.geometries.Point;
+import org.apache.sis.geometries.DataPointsType;
+import org.apache.sis.geometries.internal.shared.DefaultLine;
+import org.apache.sis.geometries.internal.shared.DefaultLineString;
+import org.apache.sis.maths.Array;
+
+
+/**
+ * A curve using a linear interpolation between two data points,
+ * each consecutive pair of points defining a line segment.
+ *
+ * <p>Constraints:</p>
+ * <ul>
+ * <li>At least two data points, the first one being the {@linkplain #getStartPoint() start point}
+ * and the last one the {@linkplain #getEndPoint() end point}.</li>
+ * <li>The position at the construction parameter <var>λ</var> between two consecutive data points
+ * <var>P<sub>i</sub></var> and <var>P<sub>i+1</sub></var> is
+ * (1 − <var>λ</var>)⋅<var>P<sub>i</sub></var> + <var>λ</var>⋅<var>P<sub>i+1</sub></var>
+ * for <var>λ</var> ∈ [0 … 1].</li>
+ * </ul>
+ *
+ * <p>Note: ISO 19107 names this class a {@code Line}, even if it has more than 2 points.</p>
+ *
+ * @author Johann Sorel (Geomatys)
+ *
+ * @see OGC Simple Feature Access 1.2.1 - 6.1.7
+ * @see ISO 19107:2019 - 7.1.2
+ */
+@UML(identifier="Line", specification=ISO_19107)
+public sealed interface Line extends Curve
+ permits DefaultLine
+{
+
+ /**
+ * Well-known text keyword of this geometry type.
+ */
+ static final String TYPE = "LINE";
+
+ /**
+ * Returns {@link GeometryType#LINE}.
+ *
+ * @see ISO 19107:2019 - 6.4.4.23
+ */
+ @Override
+ default GeometryType getGeometryType() {
+ return GeometryType.LINE;
+ }
+
+ /**
+ * Returns {@link CurveInterpolation#LINEAR}.
+ *
+ * @see ISO 19107:2019 - 7.1.2.2
+ */
+ @UML(identifier="interpolation", specification=ISO_19107)
+ @Override
+ default CurveInterpolation getInterpolation() {
+ return CurveInterpolation.LINEAR;
+ }
+
+ /**
+ * Returns {@code this}, since a line string is already a linear approximation of itself.
+ *
+ * @see ISO 19107:2019 - 6.4.18.17
+ */
+ @Override
+ default LineString asLine(Quantity<?> spacing, Quantity<?> offset) {
+ return new DefaultLineString(getDataPoints());
+ }
+
+ /**
+ * The number of Points in this LineString.
+ *
+ * @see OGC Simple Feature Access 1.2.1 - 6.1.7.2
+ * @return number of Points in this LineString.
+ */
+ default int getNumPoints() {
+ return getDataPoints().size();
+ }
+
+ /**
+ * Returns the specified Point N in this LineString.
+ *
+ * @see OGC Simple Feature Access 1.2.1 - 6.1.7.2
+ * @return the specified Point N in this LineString.
+ */
+ default Point getPointN(int n) {
+ return getDataPoints().getPoint(n);
+ }
+
+ /**
+ * @return null, a LineString has no control points
+ *
+ * @see ISO 19107:2019 - 6.4.18.2
+ */
+ @Override
+ default Array getControlPoints() {
+ return null;
+ }
+
+ @Override
+ default CoordinateReferenceSystem getCoordinateReferenceSystem() {
+ return getDataPoints().getCoordinateReferenceSystem();
+ }
+
+ @Override
+ default void setCoordinateReferenceSystem(CoordinateReferenceSystem cs) throws IllegalArgumentException {
+ getDataPoints().setCoordinateReferenceSystem(cs);
+ }
+
+ @Override
+ default DataPointsType getDataPointsType() {
+ return getDataPoints().getType();
+ }
+
+ /**
+ * A Line is a LineString with exactly 2 Points.
+ *
+ * @return true if lineString is a line.
+ */
+ default boolean isLine() {
+ return getDataPoints().size() == 2;
+ }
+
+ @Override
+ default Envelope getEnvelope() {
+ DataPoints points = getDataPoints();
+ if (points.isEmpty()) {
+ return null;
+ }
+ return points.getEnvelope();
+ }
+
+}
diff --git a/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/DefaultLine.java b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/DefaultLine.java
new file mode 100644
index 0000000000..61172ef87e
--- /dev/null
+++ b/incubator/src/org.apache.sis.geometry/main/org/apache/sis/geometries/internal/shared/DefaultLine.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.geometries.internal.shared;
+
+import javax.measure.Quantity;
+import org.apache.sis.geometries.DataPoints;
+import org.apache.sis.geometries.Geometries;
+import org.apache.sis.geometries.Point;
+import org.apache.sis.geometries.curve.Line;
+import org.apache.sis.measure.Quantities;
+
+
+/**
+ *
+ * @author Johann Sorel (Geomatys)
+ */
+public non-sealed class DefaultLine extends AbstractGeometry implements Line {
+
+ private final DataPoints points;
+
+ public DefaultLine(DataPoints points) {
+ this.points = points;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return points.isEmpty();
+ }
+
+ @Override
+ public DataPoints getDataPoints() {
+ return points;
+ }
+
+ @Override
+ public Quantity<?> getLength() {
+ //TODO : fallback on JTS until implemented
+ return Quantities.create(asJTS().getLength(), Geometries.getLinearUnit(this));
+ }
+
+ @Override
+ public Point getCentroid() {
+ if (isEmpty()) {
+ // The centroid of the empty set is undefined.
+ return null;
+ }
+ //TODO : fallback on JTS until implemented
+ return (Point) fromJTS(asJTS().getCentroid());
+ }
+
+ @Override
+ public Point getRepresentativePoint() {
+ if (isEmpty()) {
+ // The empty set has no interior position.
+ return null;
+ }
+ //TODO : fallback on JTS until implemented
+ return (Point) fromJTS(asJTS().getInteriorPoint());
+ }
+
+ @Override
+ public boolean isSimple() {
+ //TODO : fallback on JTS until implemented
+ return asJTS().isSimple();
+ }
+
+ @Override
+ public boolean isValid() {
+ //TODO : fallback on JTS until implemented
+ return asJTS().isValid();
+ }
+
+}