Skip to content

Commit 4d39d44

Browse files
committed
get all styles and icons. pixel bound calculations
1 parent a0f2da5 commit 4d39d44

5 files changed

Lines changed: 410 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Adheres to [Semantic Versioning](http://semver.org/).
99
* geopackage-core version 6.3.0
1010
* OGC Related Tables Extension additional mappings methods
1111
* NGA Feature Style Extension additional style and icon row methods
12+
* Feature Style expanded pixel bounds
1213

1314
## [6.2.1](https://github.com/ngageoint/geopackage-java/releases/tag/6.2.1) (03-11-2022)
1415

src/main/java/mil/nga/geopackage/extension/nga/style/FeatureStyleExtension.java

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mil.nga.geopackage.extension.nga.style;
22

33
import java.sql.SQLException;
4+
import java.util.HashMap;
45
import java.util.List;
56
import java.util.Map;
67
import java.util.Map.Entry;
@@ -9,8 +10,10 @@
910
import mil.nga.geopackage.attributes.AttributesDao;
1011
import mil.nga.geopackage.attributes.AttributesResultSet;
1112
import mil.nga.geopackage.extension.related.RelatedTablesExtension;
13+
import mil.nga.geopackage.extension.related.UserMappingTable;
1214
import mil.nga.geopackage.features.user.FeatureRow;
1315
import mil.nga.geopackage.features.user.FeatureTable;
16+
import mil.nga.geopackage.style.PixelBounds;
1417
import mil.nga.geopackage.user.custom.UserCustomResultSet;
1518
import mil.nga.sf.GeometryType;
1619

@@ -333,6 +336,134 @@ public IconRow getTableIcon(String featureTable,
333336
return iconRow;
334337
}
335338

339+
/**
340+
* Get all styles used by the feature table
341+
*
342+
* @param featureTable
343+
* feature table
344+
* @return style rows mapped by ids
345+
* @since 6.3.0
346+
*/
347+
public Map<Long, StyleRow> getStyles(String featureTable) {
348+
349+
Map<Long, StyleRow> styles = new HashMap<>();
350+
351+
Styles tableStyles = getTableStyles(featureTable);
352+
if (tableStyles != null) {
353+
StyleRow defaultStyleRow = tableStyles.getDefault();
354+
if (defaultStyleRow != null) {
355+
styles.put(defaultStyleRow.getId(), defaultStyleRow);
356+
}
357+
for (StyleRow styleRow : tableStyles.getStyles().values()) {
358+
styles.put(styleRow.getId(), styleRow);
359+
}
360+
}
361+
362+
styles.putAll(getFeatureStyles(featureTable));
363+
364+
return styles;
365+
}
366+
367+
/**
368+
* Get all styles used by feature rows in the table
369+
*
370+
* @param featureTable
371+
* feature table
372+
* @return style rows mapped by ids
373+
* @since 6.3.0
374+
*/
375+
public Map<Long, StyleRow> getFeatureStyles(String featureTable) {
376+
377+
Map<Long, StyleRow> styles = new HashMap<>();
378+
379+
StyleMappingDao mappingDao = getStyleMappingDao(featureTable);
380+
StyleDao styleDao = getStyleDao();
381+
382+
if (mappingDao != null && styleDao != null) {
383+
384+
UserCustomResultSet resultSet = mappingDao.query(true,
385+
new String[] { UserMappingTable.COLUMN_RELATED_ID });
386+
387+
try {
388+
while (resultSet.moveToNext()) {
389+
StyleMappingRow styleMappingRow = mappingDao
390+
.getRow(resultSet);
391+
StyleRow styleRow = styleDao.queryForRow(styleMappingRow);
392+
styles.put(styleRow.getId(), styleRow);
393+
}
394+
} finally {
395+
resultSet.close();
396+
}
397+
398+
}
399+
400+
return styles;
401+
}
402+
403+
/**
404+
* Get all icons used by the feature table
405+
*
406+
* @param featureTable
407+
* feature table
408+
* @return icon rows mapped by ids
409+
* @since 6.3.0
410+
*/
411+
public Map<Long, IconRow> getIcons(String featureTable) {
412+
413+
Map<Long, IconRow> icons = new HashMap<>();
414+
415+
Icons tableIcons = getTableIcons(featureTable);
416+
if (tableIcons != null) {
417+
IconRow defaultIconRow = tableIcons.getDefault();
418+
if (defaultIconRow != null) {
419+
icons.put(defaultIconRow.getId(), defaultIconRow);
420+
}
421+
for (IconRow iconRow : tableIcons.getIcons().values()) {
422+
icons.put(iconRow.getId(), iconRow);
423+
}
424+
}
425+
426+
icons.putAll(getFeatureIcons(featureTable));
427+
428+
return icons;
429+
}
430+
431+
/**
432+
* Get all icons used by feature rows in the table
433+
*
434+
* @param featureTable
435+
* feature table
436+
* @return icon rows mapped by ids
437+
* @since 6.3.0
438+
*/
439+
public Map<Long, IconRow> getFeatureIcons(String featureTable) {
440+
441+
Map<Long, IconRow> icons = new HashMap<>();
442+
443+
StyleMappingDao mappingDao = getIconMappingDao(featureTable);
444+
IconDao iconDao = getIconDao();
445+
446+
if (mappingDao != null && iconDao != null) {
447+
448+
UserCustomResultSet resultSet = mappingDao.query(true,
449+
new String[] { UserMappingTable.COLUMN_RELATED_ID });
450+
451+
try {
452+
while (resultSet.moveToNext()) {
453+
StyleMappingRow styleMappingRow = mappingDao
454+
.getRow(resultSet);
455+
IconRow iconRow = iconDao.queryForRow(styleMappingRow);
456+
icons.put(iconRow.getId(), iconRow);
457+
}
458+
} finally {
459+
resultSet.close();
460+
}
461+
462+
}
463+
464+
return icons;
465+
}
466+
336467
/**
337468
* Get the feature styles for the feature row
338469
*
@@ -2854,4 +2985,178 @@ public List<Long> getAllIconIds(String featureTable) {
28542985
return iconIds;
28552986
}
28562987

2988+
/**
2989+
* Calculate style pixel bounds
2990+
*
2991+
* @param featureTable
2992+
* feature table
2993+
* @return pixel bounds
2994+
* @since 6.3.0
2995+
*/
2996+
public PixelBounds calculatePixelBounds(String featureTable) {
2997+
return calculatePixelBounds(featureTable, 1.0f);
2998+
}
2999+
3000+
/**
3001+
* Calculate style pixel bounds for the feature table
3002+
*
3003+
* @param featureTable
3004+
* feature table
3005+
* @param scale
3006+
* scale factor
3007+
* @return pixel bounds
3008+
* @since 6.3.0
3009+
*/
3010+
public PixelBounds calculatePixelBounds(String featureTable, float scale) {
3011+
3012+
Map<Long, StyleRow> styles = getStyles(featureTable);
3013+
Map<Long, IconRow> icons = getIcons(featureTable);
3014+
3015+
PixelBounds pixelBounds = new PixelBounds();
3016+
3017+
for (StyleRow styleRow : styles.values()) {
3018+
calculatePixelBounds(pixelBounds, styleRow, scale);
3019+
}
3020+
3021+
for (IconRow iconRow : icons.values()) {
3022+
calculatePixelBounds(pixelBounds, iconRow, scale);
3023+
}
3024+
3025+
return pixelBounds;
3026+
}
3027+
3028+
/**
3029+
* Calculate style pixel bounds for the style row
3030+
*
3031+
* @param styleRow
3032+
* style row
3033+
* @return pixel bounds
3034+
* @since 6.3.0
3035+
*/
3036+
public static PixelBounds calculatePixelBounds(StyleRow styleRow) {
3037+
return calculatePixelBounds(styleRow, 1.0f);
3038+
}
3039+
3040+
/**
3041+
* Calculate style pixel bounds for the style row
3042+
*
3043+
* @param styleRow
3044+
* style row
3045+
* @param scale
3046+
* scale factor
3047+
* @return pixel bounds
3048+
* @since 6.3.0
3049+
*/
3050+
public static PixelBounds calculatePixelBounds(StyleRow styleRow,
3051+
float scale) {
3052+
PixelBounds pixelBounds = new PixelBounds();
3053+
calculatePixelBounds(pixelBounds, styleRow, scale);
3054+
return pixelBounds;
3055+
}
3056+
3057+
/**
3058+
* Calculate style pixel bounds for the style row
3059+
*
3060+
* @param pixelBounds
3061+
* pixel bounds to expand
3062+
* @param styleRow
3063+
* style row
3064+
* @since 6.3.0
3065+
*/
3066+
public static void calculatePixelBounds(PixelBounds pixelBounds,
3067+
StyleRow styleRow) {
3068+
calculatePixelBounds(pixelBounds, styleRow, 1.0f);
3069+
}
3070+
3071+
/**
3072+
* Calculate style pixel bounds for the style row
3073+
*
3074+
* @param pixelBounds
3075+
* pixel bounds to expand
3076+
* @param styleRow
3077+
* style row
3078+
* @param scale
3079+
* scale factor
3080+
* @since 6.3.0
3081+
*/
3082+
public static void calculatePixelBounds(PixelBounds pixelBounds,
3083+
StyleRow styleRow, float scale) {
3084+
double styleHalfWidth = scale * (styleRow.getWidthOrDefault() / 2.0);
3085+
pixelBounds.expandLength(styleHalfWidth);
3086+
}
3087+
3088+
/**
3089+
* Calculate style pixel bounds for the icon row
3090+
*
3091+
* @param iconRow
3092+
* icon row
3093+
* @return pixel bounds
3094+
* @since 6.3.0
3095+
*/
3096+
public static PixelBounds calculatePixelBounds(IconRow iconRow) {
3097+
return calculatePixelBounds(iconRow, 1.0f);
3098+
}
3099+
3100+
/**
3101+
* Calculate style pixel bounds for the icon row
3102+
*
3103+
* @param iconRow
3104+
* icon row
3105+
* @param scale
3106+
* scale factor
3107+
* @return pixel bounds
3108+
* @since 6.3.0
3109+
*/
3110+
public static PixelBounds calculatePixelBounds(IconRow iconRow,
3111+
float scale) {
3112+
PixelBounds pixelBounds = new PixelBounds();
3113+
calculatePixelBounds(pixelBounds, iconRow, scale);
3114+
return pixelBounds;
3115+
}
3116+
3117+
/**
3118+
* Calculate style pixel bounds for the icon row
3119+
*
3120+
* @param pixelBounds
3121+
* pixel bounds to expand
3122+
* @param iconRow
3123+
* icon row
3124+
* @since 6.3.0
3125+
*/
3126+
public static void calculatePixelBounds(PixelBounds pixelBounds,
3127+
IconRow iconRow) {
3128+
calculatePixelBounds(pixelBounds, iconRow, 1.0f);
3129+
}
3130+
3131+
/**
3132+
* Calculate style pixel bounds for the icon row
3133+
*
3134+
* @param pixelBounds
3135+
* pixel bounds to expand
3136+
* @param iconRow
3137+
* icon row
3138+
* @param scale
3139+
* scale factor
3140+
* @since 6.3.0
3141+
*/
3142+
public static void calculatePixelBounds(PixelBounds pixelBounds,
3143+
IconRow iconRow, float scale) {
3144+
double[] iconDimensions = iconRow.getDerivedDimensions();
3145+
double iconWidth = scale * Math.ceil(iconDimensions[0]);
3146+
double iconHeight = scale * Math.ceil(iconDimensions[1]);
3147+
double anchorU = iconRow.getAnchorUOrDefault();
3148+
double anchorV = iconRow.getAnchorVOrDefault();
3149+
3150+
double left = anchorU * iconWidth;
3151+
double right = iconWidth - left;
3152+
double top = anchorV * iconHeight;
3153+
double bottom = iconHeight - top;
3154+
3155+
// Expand in the opposite directions for queries
3156+
pixelBounds.expandLeft(right);
3157+
pixelBounds.expandRight(left);
3158+
pixelBounds.expandUp(bottom);
3159+
pixelBounds.expandDown(top);
3160+
}
3161+
28573162
}

0 commit comments

Comments
 (0)