Skip to content

Commit

Permalink
geodesic support
Browse files Browse the repository at this point in the history
  • Loading branch information
bosborn committed Feb 23, 2024
1 parent 6b7ad57 commit 2fd2451
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Adheres to [Semantic Versioning](http://semver.org/).
* R-tree update trigger modifications
* DAO column range support (including geometry envelopes & bounding boxes) to build where clauses & args for queries
* User Column integrated Data Columns Schema support
* RTree Index and Feature Table Index geodesic support
* sf-wkb version 2.2.3
* sf-wkt version 1.2.3
* sf-proj version 4.3.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import mil.nga.proj.Projection;
import mil.nga.sf.GeometryEnvelope;
import mil.nga.sf.proj.GeometryTransform;
import mil.nga.sf.proj.ProjectionGeometryUtils;

/**
* Abstract core Feature Table Index NGA Extension implementation. This
Expand Down Expand Up @@ -85,6 +86,13 @@ public abstract class FeatureTableCoreIndex extends BaseExtension {
*/
private final String columnName;

/**
* Index geometries using geodesic lines
*
* @since 6.6.7
*/
protected boolean geodesic = false;

/**
* Table Index DAO
*/
Expand Down Expand Up @@ -122,9 +130,28 @@ public abstract class FeatureTableCoreIndex extends BaseExtension {
*/
protected FeatureTableCoreIndex(GeoPackageCore geoPackage, String tableName,
String columnName) {
this(geoPackage, tableName, columnName, false);
}

/**
* Constructor
*
* @param geoPackage
* GeoPackage
* @param tableName
* table name
* @param columnName
* column name
* @param geodesic
* index using geodesic bounds
* @since 6.6.7
*/
protected FeatureTableCoreIndex(GeoPackageCore geoPackage, String tableName,
String columnName, boolean geodesic) {
super(geoPackage);
this.tableName = tableName;
this.columnName = columnName;
this.geodesic = geodesic;
tableIndexDao = getTableIndexDao();
geometryIndexDao = getGeometryIndexDao();
}
Expand Down Expand Up @@ -164,6 +191,27 @@ public String getColumnName() {
return columnName;
}

/**
* Geometries indexed using geodesic lines
*
* @return geodesic flag
* @since 6.6.7
*/
public boolean isGeodesic() {
return geodesic;
}

/**
* Set the geodestic flag, true to index geodesic geometries
*
* @param geodesic
* index geodesic geometries flag
* @since 6.6.7
*/
public void setGeodesic(boolean geodesic) {
this.geodesic = geodesic;
}

/**
* Set the progress tracker
*
Expand Down Expand Up @@ -278,6 +326,12 @@ protected boolean index(TableIndex tableIndex, long geomId,

// Create the new index row
if (envelope != null) {

if (geodesic) {
envelope = ProjectionGeometryUtils
.geodesicEnvelope(envelope, getProjection());
}

GeometryIndex geometryIndex = geometryIndexDao
.populate(tableIndex, geomId, envelope);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import mil.nga.geopackage.GeoPackageConstants;
import mil.nga.geopackage.GeoPackageCore;
Expand All @@ -17,9 +21,12 @@
import mil.nga.geopackage.geom.GeoPackageGeometryData;
import mil.nga.geopackage.property.GeoPackageProperties;
import mil.nga.geopackage.property.PropertyConstants;
import mil.nga.geopackage.srs.SpatialReferenceSystem;
import mil.nga.geopackage.user.custom.UserCustomColumn;
import mil.nga.geopackage.user.custom.UserCustomTable;
import mil.nga.proj.Projection;
import mil.nga.sf.GeometryEnvelope;
import mil.nga.sf.proj.ProjectionGeometryUtils;

/**
* RTree Index abstract core extension
Expand All @@ -32,6 +39,12 @@
*/
public abstract class RTreeIndexCoreExtension extends BaseExtension {

/**
* Logger
*/
private static final Logger log = Logger
.getLogger(RTreeIndexCoreExtension.class.getName());

/**
* Name
*/
Expand Down Expand Up @@ -252,6 +265,20 @@ public abstract class RTreeIndexCoreExtension extends BaseExtension {
*/
protected GeoPackageCoreConnection connection = null;

/**
* Index geometries using geodesic lines
*
* @since 6.6.7
*/
protected boolean geodesic = false;

/**
* Mapping between srs ids and projections
*
* @since 6.6.7
*/
protected Map<Integer, Projection> projections = new HashMap<>();

/**
* Constructor
*
Expand All @@ -260,8 +287,97 @@ public abstract class RTreeIndexCoreExtension extends BaseExtension {
*
*/
protected RTreeIndexCoreExtension(GeoPackageCore geoPackage) {
this(geoPackage, false);
}

/**
* Constructor
*
* @param geoPackage
* GeoPackage
* @param geodesic
* index using geodesic bounds
* @since 6.6.7
*
*/
protected RTreeIndexCoreExtension(GeoPackageCore geoPackage,
boolean geodesic) {
super(geoPackage);
connection = geoPackage.getDatabase();
this.geodesic = geodesic;
}

/**
* Geometries indexed using geodesic lines
*
* @return geodesic flag
* @since 6.6.7
*/
public boolean isGeodesic() {
return geodesic;
}

/**
* Set the geodestic flag, true to index geodesic geometries
*
* @param geodesic
* index geodesic geometries flag
* @since 6.6.7
*/
public void setGeodesic(boolean geodesic) {
this.geodesic = geodesic;
}

/**
* Expand the vertical bounds of a geometry envelope by geodesic bounds
*
* @param envelope
* geometry envelope
* @param srsId
* spatial reference system id
* @return geometry envelope
* @since 6.6.7
*/
protected GeometryEnvelope geodesicEnvelope(GeometryEnvelope envelope,
int srsId) {

GeometryEnvelope result = envelope;
if (geodesic) {
Projection projection = getProjection(srsId);
result = ProjectionGeometryUtils.geodesicEnvelope(envelope,
projection);
}

return result;
}

/**
* Get the projection of the spatial reference system id
*
* @param srsId
* spatial reference system id
* @return projection
* @since 6.6.7
*/
protected Projection getProjection(int srsId) {
Projection projection = projections.get(srsId);
if (projection == null) {
try {
SpatialReferenceSystem srs = geoPackage
.getSpatialReferenceSystemDao()
.queryForId((long) srsId);
if (srs != null) {
projection = srs.getProjection();
projections.put(srsId, projection);
}
} catch (SQLException e) {
log.log(Level.WARNING,
"Failed to retrieve projection through querying srs id: "
+ srsId,
e);
}
}
return projection;
}

/**
Expand Down

0 comments on commit 2fd2451

Please sign in to comment.