Skip to content

Commit

Permalink
Merge pull request #1353 from lat-lon/implementPointListCopy-XPLANBOX…
Browse files Browse the repository at this point in the history
…-1020

Implement PointsList#copy() and JTSPoints#copy()
  • Loading branch information
stephanr committed Aug 10, 2022
2 parents 6958d95 + bf663e9 commit c5b9a42
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ public Reference( ReferenceResolver resolver, String uri, String baseURL ) {
this.baseURL = baseURL;
}

/**
* Returns the resolver.
*
* @return the resolver, never <code>null</code>
*/
public ReferenceResolver getResolver() {
return resolver;
}

/**
* Returns the URI of the object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
----------------------------------------------------------------------------*/
package org.deegree.geometry.primitive;

import java.util.List;

import org.deegree.commons.tom.gml.property.Property;

/**
* 0-dimensional primitive.
*
Expand All @@ -52,35 +48,35 @@ public interface Point extends GeometricPrimitive {

/**
* Must always return {@link GeometricPrimitive.PrimitiveType#Point}.
*
*
* @return {@link GeometricPrimitive.PrimitiveType#Point}
*/
public PrimitiveType getPrimitiveType();

/**
* Returns the value of the first ordinate.
*
*
* @return value of the first ordinate
*/
public double get0();

/**
* Returns the value of the second ordinate.
*
*
* @return value of the second ordinate, or <code>Double.NAN</code> if the point only has one dimension
*/
public double get1();

/**
* Returns the value of the third ordinate.
*
*
* @return value of the third ordinate, or <code>Double.NAN</code> if the point only has one or two dimensions
*/
public double get2();

/**
* Returns the value of the specified ordinate.
*
*
* @param dimension
* ordinate to be returned (first dimension=0)
* @return ordinate value of the passed dimension, or <code>Double.NAN</code> if <code>dimension</code> is greater
Expand All @@ -90,8 +86,13 @@ public interface Point extends GeometricPrimitive {

/**
* Returns all ordinates.
*
*
* @return all ordinates, the length of the array is equal to the number of dimensions
*/
public double[] getAsArray();

/**
* @return a copy of the point
*/
Point copy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@

import org.deegree.commons.tom.gml.GMLReferenceResolver;
import org.deegree.geometry.primitive.Point;
import org.deegree.geometry.standard.primitive.DefaultPoint;

import java.util.Arrays;

/**
* The <code></code> class TODO add class documentation here.
Expand Down Expand Up @@ -92,4 +95,10 @@ public double get1() {
public double get2() {
return getReferencedObject().get2();
}

@Override
public Point copy() {
return new PointReference( (GMLReferenceResolver) getResolver(), getURI(), getBaseURL() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ public Coordinate[] toCoordinateArray() {

@Override
public Object clone() {
throw new UnsupportedOperationException();
return copy();
}

@Override
public CoordinateSequence copy() {
throw new UnsupportedOperationException();
return new JTSPoints( crs, seq.copy() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
package org.deegree.geometry.standard.points;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

import org.deegree.commons.tom.Reference;
import org.deegree.geometry.points.Points;
Expand Down Expand Up @@ -203,12 +206,13 @@ public Coordinate[] toCoordinateArray() {

@Override
public Object clone() {
return new PointsList( new ArrayList<Point>( points ) );
return copy();
}

@Override
public CoordinateSequence copy() {
throw new UnsupportedOperationException();
List<Point> copiedPoints = points.stream().map( point -> point.copy() ).collect( Collectors.toList() );
return new PointsList( copiedPoints );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

import org.locationtech.jts.geom.Coordinate;

import java.util.Arrays;

/**
* Default implementation of {@link Point}.
*
Expand Down Expand Up @@ -115,6 +117,11 @@ public double get2() {
return Double.NaN;
}

@Override
public Point copy() {
return new DefaultPoint( id, crs, pm, Arrays.copyOf( coordinates, coordinates.length ) );
}

@Override
public boolean equals( Geometry geometry ) {
if ( !( geometry instanceof Point ) ) {
Expand Down

0 comments on commit c5b9a42

Please sign in to comment.