Skip to content

Commit 9d65718

Browse files
committed
simple features proj refactor
1 parent 78eec20 commit 9d65718

File tree

4 files changed

+37
-42
lines changed

4 files changed

+37
-42
lines changed

mapcache/src/main/java/mil/nga/mapcache/GeoPackageManagerFragment.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@
8383
import mil.nga.geopackage.features.user.FeatureDao;
8484
import mil.nga.geopackage.io.GeoPackageIOUtils;
8585
import mil.nga.geopackage.io.GeoPackageProgress;
86-
import mil.nga.geopackage.projection.Projection;
87-
import mil.nga.geopackage.projection.ProjectionConstants;
88-
import mil.nga.geopackage.projection.ProjectionFactory;
89-
import mil.nga.geopackage.projection.ProjectionTransform;
9086
import mil.nga.geopackage.schema.TableColumnKey;
9187
import mil.nga.geopackage.tiles.TileBoundingBoxUtils;
9288
import mil.nga.geopackage.tiles.features.DefaultFeatureTiles;
@@ -111,6 +107,10 @@
111107
import mil.nga.mapcache.load.ILoadTilesTask;
112108
import mil.nga.mapcache.load.LoadTilesTask;
113109
import mil.nga.sf.GeometryType;
110+
import mil.nga.sf.proj.Projection;
111+
import mil.nga.sf.proj.ProjectionConstants;
112+
import mil.nga.sf.proj.ProjectionFactory;
113+
import mil.nga.sf.proj.ProjectionTransform;
114114
import mil.nga.sf.wkb.GeometryCodes;
115115

116116
/**
@@ -2396,14 +2396,13 @@ private void createFeatureTilesTableOption(final GeoPackageTable table) {
23962396
ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE);
23972397
projection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
23982398
} else {
2399-
projection = ProjectionFactory.getProjection(
2400-
contents.getSrs());
2399+
projection = contents.getSrs().getProjection();
24012400
}
24022401

24032402
// Try to find a good zoom starting point
24042403
ProjectionTransform webMercatorTransform = projection.getTransformation(
24052404
ProjectionConstants.EPSG_WEB_MERCATOR);
2406-
BoundingBox webMercatorBoundingBox = webMercatorTransform.transform(boundingBox);
2405+
BoundingBox webMercatorBoundingBox = boundingBox.transform(webMercatorTransform);
24072406
int zoomLevel = TileBoundingBoxUtils.getZoomLevel(webMercatorBoundingBox);
24082407
int maxZoomLevel = getActivity().getResources().getInteger(
24092408
R.integer.load_tiles_max_zoom_default);
@@ -2414,7 +2413,7 @@ private void createFeatureTilesTableOption(final GeoPackageTable table) {
24142413

24152414
ProjectionTransform worldGeodeticTransform = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR).getTransformation(
24162415
ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
2417-
BoundingBox worldGeodeticBoundingBox = worldGeodeticTransform.transform(webMercatorBoundingBox);
2416+
BoundingBox worldGeodeticBoundingBox = webMercatorBoundingBox.transform(worldGeodeticTransform);
24182417
minLonInput.setText(String.valueOf(worldGeodeticBoundingBox.getMinLongitude()));
24192418
minLatInput.setText(String.valueOf(worldGeodeticBoundingBox.getMinLatitude()));
24202419
maxLonInput.setText(String.valueOf(worldGeodeticBoundingBox.getMaxLongitude()));
@@ -2679,19 +2678,18 @@ private void addFeatureOverlayTableOption(final GeoPackageTable table) {
26792678
BoundingBox boundingBox = contents.getBoundingBox();
26802679
BoundingBox worldGeodeticBoundingBox = null;
26812680
if (boundingBox != null) {
2682-
Projection projection = ProjectionFactory.getProjection(
2683-
contents.getSrs());
2681+
Projection projection = contents.getSrs().getProjection();
26842682

26852683
ProjectionTransform webMercatorTransform = projection.getTransformation(
26862684
ProjectionConstants.EPSG_WEB_MERCATOR);
26872685
if (projection.getUnit() instanceof DegreeUnit) {
26882686
boundingBox = TileBoundingBoxUtils.boundDegreesBoundingBoxWithWebMercatorLimits(boundingBox);
26892687
}
2690-
BoundingBox webMercatorBoundingBox = webMercatorTransform.transform(boundingBox);
2688+
BoundingBox webMercatorBoundingBox = boundingBox.transform(webMercatorTransform);
26912689

26922690
ProjectionTransform worldGeodeticTransform = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR).getTransformation(
26932691
ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
2694-
worldGeodeticBoundingBox = worldGeodeticTransform.transform(webMercatorBoundingBox);
2692+
worldGeodeticBoundingBox = webMercatorBoundingBox.transform(worldGeodeticTransform);
26952693
} else {
26962694
worldGeodeticBoundingBox = new BoundingBox(-ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH,
26972695
ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE,

mapcache/src/main/java/mil/nga/mapcache/GeoPackageMapFragment.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
import mil.nga.geopackage.core.srs.SpatialReferenceSystem;
9595
import mil.nga.geopackage.extension.link.FeatureTileTableLinker;
9696
import mil.nga.geopackage.extension.scale.TileScaling;
97-
import mil.nga.geopackage.extension.scale.TileScalingType;
9897
import mil.nga.geopackage.extension.scale.TileTableScaling;
9998
import mil.nga.geopackage.factory.GeoPackageFactory;
10099
import mil.nga.geopackage.features.columns.GeometryColumns;
@@ -128,9 +127,6 @@
128127
import mil.nga.geopackage.map.tiles.overlay.FeatureOverlay;
129128
import mil.nga.geopackage.map.tiles.overlay.FeatureOverlayQuery;
130129
import mil.nga.geopackage.map.tiles.overlay.GeoPackageOverlayFactory;
131-
import mil.nga.geopackage.projection.ProjectionConstants;
132-
import mil.nga.geopackage.projection.ProjectionFactory;
133-
import mil.nga.geopackage.projection.ProjectionTransform;
134130
import mil.nga.geopackage.schema.columns.DataColumns;
135131
import mil.nga.geopackage.schema.columns.DataColumnsDao;
136132
import mil.nga.geopackage.tiles.TileBoundingBoxUtils;
@@ -155,6 +151,9 @@
155151
import mil.nga.sf.GeometryEnvelope;
156152
import mil.nga.sf.GeometryType;
157153
import mil.nga.sf.LineString;
154+
import mil.nga.sf.proj.ProjectionConstants;
155+
import mil.nga.sf.proj.ProjectionFactory;
156+
import mil.nga.sf.proj.ProjectionTransform;
158157
import mil.nga.sf.util.GeometryEnvelopeBuilder;
159158
import mil.nga.sf.util.GeometryPrinter;
160159

@@ -1715,21 +1714,19 @@ private void zoomToActiveBounds() {
17151714
*/
17161715
private BoundingBox transformBoundingBoxToWgs84(BoundingBox boundingBox, SpatialReferenceSystem srs) {
17171716

1718-
mil.nga.geopackage.projection.Projection projection = ProjectionFactory.getProjection(
1719-
srs);
1717+
mil.nga.sf.proj.Projection projection = srs.getProjection();
17201718
if (projection.getUnit() instanceof DegreeUnit) {
17211719
boundingBox = TileBoundingBoxUtils.boundDegreesBoundingBoxWithWebMercatorLimits(boundingBox);
17221720
}
17231721
ProjectionTransform transformToWebMercator = projection
17241722
.getTransformation(
17251723
ProjectionConstants.EPSG_WEB_MERCATOR);
1726-
BoundingBox webMercatorBoundingBox = transformToWebMercator.transform(boundingBox);
1724+
BoundingBox webMercatorBoundingBox = boundingBox.transform(transformToWebMercator);
17271725
ProjectionTransform transform = ProjectionFactory.getProjection(
17281726
ProjectionConstants.EPSG_WEB_MERCATOR)
17291727
.getTransformation(
17301728
ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
1731-
boundingBox = transform
1732-
.transform(webMercatorBoundingBox);
1729+
boundingBox = webMercatorBoundingBox.transform(transform);
17331730
return boundingBox;
17341731
}
17351732

@@ -2230,7 +2227,7 @@ private void displayFeatures(MapFeaturesUpdateTask task,
22302227

22312228
if (!task.isCancelled() && count.get() < maxFeatures) {
22322229

2233-
mil.nga.geopackage.projection.Projection mapViewProjection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
2230+
mil.nga.sf.proj.Projection mapViewProjection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
22342231

22352232
FeatureIndexManager indexer = new FeatureIndexManager(getActivity(), geoPackage, featureDao);
22362233
if (filter && indexer.isIndexed()) {
@@ -2251,10 +2248,10 @@ private void displayFeatures(MapFeaturesUpdateTask task,
22512248
double filterMaxLongitude = 0;
22522249

22532250
if (filter) {
2254-
mil.nga.geopackage.projection.Projection featureProjection = featureDao.getProjection();
2251+
mil.nga.sf.proj.Projection featureProjection = featureDao.getProjection();
22552252
ProjectionTransform projectionTransform = mapViewProjection.getTransformation(featureProjection);
22562253
BoundingBox boundedMapViewBoundingBox = mapViewBoundingBox.boundWgs84Coordinates();
2257-
BoundingBox transformedBoundingBox = projectionTransform.transform(boundedMapViewBoundingBox);
2254+
BoundingBox transformedBoundingBox = boundedMapViewBoundingBox.transform(projectionTransform);
22582255
Unit unit = featureProjection.getUnit();
22592256
if (unit instanceof DegreeUnit) {
22602257
filterMaxLongitude = ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH;
@@ -2847,10 +2844,10 @@ private void displayTiles(GeoPackageTileTable tiles) {
28472844
Contents contents = tileMatrixSet.getContents();
28482845
BoundingBox contentsBoundingBox = contents.getBoundingBox();
28492846
if (contentsBoundingBox != null) {
2850-
ProjectionTransform transform = ProjectionFactory.getProjection(contents.getSrs()).getTransformation(tileMatrixSet.getSrs());
2847+
ProjectionTransform transform = contents.getSrs().getProjection().getTransformation(tileMatrixSet.getSrs().getProjection());
28512848
BoundingBox transformedContentsBoundingBox = contentsBoundingBox;
28522849
if (!transform.isSameProjection()) {
2853-
transformedContentsBoundingBox = transform.transform(transformedContentsBoundingBox);
2850+
transformedContentsBoundingBox = transformedContentsBoundingBox.transform(transform);
28542851
}
28552852
displayBoundingBox = TileBoundingBoxUtils.overlap(displayBoundingBox, transformedContentsBoundingBox);
28562853
}
@@ -3380,7 +3377,7 @@ public void onMapClick(LatLng point) {
33803377

33813378
BoundingBox clickBoundingBox = MapUtils.buildClickBoundingBox(point, view, map, screenClickPercentage);
33823379
clickBoundingBox = clickBoundingBox.expandWgs84Coordinates();
3383-
mil.nga.geopackage.projection.Projection clickProjection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
3380+
mil.nga.sf.proj.Projection clickProjection = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
33843381

33853382
double tolerance = MapUtils.getToleranceDistance(point, view, map, screenClickPercentage);
33863383

@@ -3409,10 +3406,10 @@ public void onMapClick(LatLng point) {
34093406

34103407
} else {
34113408

3412-
mil.nga.geopackage.projection.Projection featureProjection = featureDao.getProjection();
3409+
mil.nga.sf.proj.Projection featureProjection = featureDao.getProjection();
34133410
ProjectionTransform projectionTransform = clickProjection.getTransformation(featureProjection);
34143411
BoundingBox boundedClickBoundingBox = clickBoundingBox.boundWgs84Coordinates();
3415-
BoundingBox transformedBoundingBox = projectionTransform.transform(boundedClickBoundingBox);
3412+
BoundingBox transformedBoundingBox = boundedClickBoundingBox.transform(projectionTransform);
34163413
Unit unit = featureProjection.getUnit();
34173414
double filterMaxLongitude = 0;
34183415
if (unit instanceof DegreeUnit) {
@@ -4141,7 +4138,7 @@ private void createTiles() {
41414138
ProjectionTransform webMercatorTransform = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM)
41424139
.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
41434140
BoundingBox bbox = new BoundingBox(minLon, minLat, maxLon, maxLat);
4144-
BoundingBox webMercatorBoundingBox = webMercatorTransform.transform(bbox);
4141+
BoundingBox webMercatorBoundingBox = bbox.transform(webMercatorTransform);
41454142
int zoomLevel = TileBoundingBoxUtils.getZoomLevel(webMercatorBoundingBox);
41464143
int maxZoomLevel = getActivity().getResources().getInteger(
41474144
R.integer.load_tiles_max_zoom_default);
@@ -4445,7 +4442,7 @@ private void createFeatureTiles(final String database, final String featureTable
44454442
ProjectionTransform webMercatorTransform = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM)
44464443
.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
44474444
BoundingBox bbox = new BoundingBox(minLon, minLat, maxLon, maxLat);
4448-
BoundingBox webMercatorBoundingBox = webMercatorTransform.transform(bbox);
4445+
BoundingBox webMercatorBoundingBox = bbox.transform(webMercatorTransform);
44494446
int zoomLevel = TileBoundingBoxUtils.getZoomLevel(webMercatorBoundingBox);
44504447
int maxZoomLevel = getActivity().getResources().getInteger(
44514448
R.integer.load_tiles_max_zoom_default);

mapcache/src/main/java/mil/nga/mapcache/GeoPackageUtils.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
import mil.nga.geopackage.extension.scale.TileScaling;
1515
import mil.nga.geopackage.extension.scale.TileScalingType;
16-
import mil.nga.geopackage.projection.ProjectionConstants;
1716
import mil.nga.geopackage.tiles.features.FeatureTiles;
1817
import mil.nga.mapcache.filter.InputFilterDecimalMinMax;
1918
import mil.nga.mapcache.filter.InputFilterMinMax;
19+
import mil.nga.sf.proj.ProjectionConstants;
2020

2121
public class GeoPackageUtils {
2222

@@ -153,13 +153,13 @@ public static void prepareTileLoadInputs(final Activity activity,
153153
epsgInput.setText(String.valueOf(ProjectionConstants.EPSG_WEB_MERCATOR));
154154
}
155155

156-
if(tileScalingZoomOutInput != null){
156+
if (tileScalingZoomOutInput != null) {
157157
tileScalingZoomOutInput.setFilters(new InputFilter[]{new InputFilterMinMax(
158158
0, maxZoom)});
159159
tileScalingZoomOutInput.setText(String.valueOf(activity.getResources().getInteger(
160160
R.integer.tile_scaling_zoom_out_default)));
161161
}
162-
if(tileScalingZoomInInput != null){
162+
if (tileScalingZoomInInput != null) {
163163
tileScalingZoomInInput.setFilters(new InputFilter[]{new InputFilterMinMax(
164164
0, maxZoom)});
165165
tileScalingZoomInInput.setText(String.valueOf(activity.getResources().getInteger(
@@ -339,18 +339,18 @@ public void onClick(DialogInterface dialog, int item) {
339339

340340
public static TileScaling getTileScaling(Spinner tileScalingInput,
341341
EditText tileScalingZoomOutInput,
342-
EditText tileScalingZoomInInput){
342+
EditText tileScalingZoomInInput) {
343343
TileScaling scaling = null;
344344
if (tileScalingInput.getSelectedItemPosition() > 0) {
345345
TileScalingType tileScalingType = TileScalingType.values()[tileScalingInput.getSelectedItemPosition() - 1];
346346
Long zoomOut = null;
347347
String zoomOutText = tileScalingZoomOutInput.getText().toString();
348-
if(!zoomOutText.isEmpty()){
348+
if (!zoomOutText.isEmpty()) {
349349
zoomOut = Long.valueOf(zoomOutText);
350350
}
351351
Long zoomIn = null;
352352
String zoomInText = tileScalingZoomInInput.getText().toString();
353-
if(!zoomInText.isEmpty()){
353+
if (!zoomInText.isEmpty()) {
354354
zoomIn = Long.valueOf(zoomInText);
355355
}
356356
scaling = new TileScaling(tileScalingType, zoomIn, zoomOut);

mapcache/src/main/java/mil/nga/mapcache/load/LoadTilesTask.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
import mil.nga.geopackage.extension.scale.TileScaling;
1616
import mil.nga.geopackage.factory.GeoPackageFactory;
1717
import mil.nga.geopackage.io.GeoPackageProgress;
18-
import mil.nga.geopackage.projection.Projection;
19-
import mil.nga.geopackage.projection.ProjectionConstants;
20-
import mil.nga.geopackage.projection.ProjectionFactory;
21-
import mil.nga.geopackage.projection.ProjectionTransform;
2218
import mil.nga.geopackage.tiles.TileBoundingBoxUtils;
2319
import mil.nga.geopackage.tiles.TileGenerator;
2420
import mil.nga.geopackage.tiles.UrlTileGenerator;
@@ -27,6 +23,10 @@
2723
import mil.nga.mapcache.GeoPackageUtils;
2824
import mil.nga.mapcache.R;
2925
import mil.nga.mapcache.data.GeoPackageDatabases;
26+
import mil.nga.sf.proj.Projection;
27+
import mil.nga.sf.proj.ProjectionConstants;
28+
import mil.nga.sf.proj.ProjectionFactory;
29+
import mil.nga.sf.proj.ProjectionTransform;
3030

3131
/**
3232
* Load tiles task
@@ -126,7 +126,7 @@ public static BoundingBox transform(BoundingBox boundingBox, Projection projecti
126126
BoundingBox bounded = TileBoundingBoxUtils.boundWgs84BoundingBoxWithWebMercatorLimits(boundingBox);
127127
Projection wgs84 = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
128128
ProjectionTransform transform = wgs84.getTransformation(projection);
129-
transformedBox = transform.transform(bounded);
129+
transformedBox = bounded.transform(transform);
130130
}
131131

132132
return transformedBox;

0 commit comments

Comments
 (0)