-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GIS #462: added GeometryCollections and tests for them
- Loading branch information
1 parent
47f040c
commit 2d817d3
Showing
10 changed files
with
506 additions
and
43 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
131 changes: 131 additions & 0 deletions
131
core/src/main/java/org/polypheny/db/type/entity/spatial/PolyGeometryCollection.java
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,131 @@ | ||
/* | ||
* Copyright 2019-2023 The Polypheny Project | ||
* | ||
* Licensed 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.polypheny.db.type.entity.spatial; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.activej.serializer.annotations.Deserialize; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.locationtech.jts.geom.Geometry; | ||
import org.locationtech.jts.geom.GeometryCollection; | ||
import org.polypheny.db.type.PolyType; | ||
|
||
/** | ||
* {@link PolyGeometryCollection} is collection that holds {@link PolyGeometry} | ||
* and it is a base class for all <strong>Multi</strong> spatial data types. | ||
* <p> | ||
* Collection of {@link PolyGeometry} of any {@link PolyGeometryType} and dimension. | ||
*/ | ||
public class PolyGeometryCollection extends PolyGeometry { | ||
|
||
private GeometryCollection jtsGeometryCollection; | ||
|
||
|
||
public PolyGeometryCollection( @JsonProperty("wkt") @Deserialize("wkt") String wkt ) throws InvalidGeometryException { | ||
super( wkt ); | ||
this.geometryType = getPolyGeometryType(); | ||
this.jtsGeometryCollection = (GeometryCollection) jtsGeometry; | ||
} | ||
|
||
|
||
public PolyGeometryCollection( @JsonProperty("wkt") @Deserialize("wkt") String wkt, int srid ) throws InvalidGeometryException { | ||
super( wkt, srid ); | ||
this.geometryType = getPolyGeometryType(); | ||
this.jtsGeometryCollection = (GeometryCollection) jtsGeometry; | ||
} | ||
|
||
|
||
public PolyGeometryCollection( Geometry geometry ) { | ||
super( geometry ); | ||
this.geometryType = getPolyGeometryType(); | ||
this.jtsGeometry = geometry; | ||
this.jtsGeometryCollection = (GeometryCollection) jtsGeometry; | ||
this.SRID = geometry.getSRID(); | ||
} | ||
|
||
|
||
protected PolyGeometryCollection( PolyType type ) { | ||
super( type ); | ||
this.geometryType = getPolyGeometryType(); | ||
} | ||
|
||
|
||
public static PolyGeometryCollection of( Geometry geometry ) { | ||
return new PolyGeometryCollection( geometry ); | ||
} | ||
|
||
|
||
/** | ||
* @return the number of {@link PolyGeometry} geometries in the {@link PolyGeometryCollection}. | ||
*/ | ||
public int getNumGeometries() { | ||
return jtsGeometryCollection.getNumGeometries(); | ||
} | ||
|
||
|
||
/** | ||
* Get the nth {@link PolyGeometry} in the collection. | ||
* | ||
* @param n number of the {@link PolyGeometry} in the collection | ||
* @return the nth {@link PolyGeometry} in the collection. | ||
*/ | ||
public PolyGeometry getGeometryN( int n ) { | ||
return PolyGeometry.of( jtsGeometryCollection.getGeometryN( n ) ); | ||
} | ||
|
||
|
||
public boolean isMultiPoint() { | ||
return geometryType.equals( PolyGeometryType.MULTIPOINT ); | ||
} | ||
|
||
|
||
@NotNull | ||
public PolyMultiPoint asMultiPoint() { | ||
if ( isMultiPoint() ) { | ||
return PolyMultiPoint.of( jtsGeometry ); | ||
} | ||
throw cannotParse( this, PolyMultiPoint.class ); | ||
} | ||
|
||
|
||
public boolean isMultiLineString() { | ||
return geometryType.equals( PolyGeometryType.MULTILINESTRING ); | ||
} | ||
|
||
|
||
@NotNull | ||
public PolyMultiLineString asMultiLineString() { | ||
if ( isMultiLineString() ) { | ||
return PolyMultiLineString.of( jtsGeometry ); | ||
} | ||
throw cannotParse( this, PolyMultiLineString.class ); | ||
} | ||
|
||
|
||
public boolean isMultiPolygon() { | ||
return geometryType.equals( PolyGeometryType.MULTIPOLYGON ); | ||
} | ||
|
||
|
||
@NotNull | ||
public PolyMultiPolygon asMultiPolygon() { | ||
if ( isMultiPolygon() ) { | ||
return PolyMultiPolygon.of( jtsGeometry ); | ||
} | ||
throw cannotParse( this, PolyMultiPolygon.class ); | ||
} | ||
|
||
} |
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
Oops, something went wrong.