mil.nga.geopackage.extension.style.StyleRow Java Examples

The following examples show how to use mil.nga.geopackage.extension.style.StyleRow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FeatureStylesUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
private static StyleRow randomStyle() {
	StyleRow styleRow = new StyleRow();

	if (Math.random() < .5) {
		styleRow.setName("Style Name");
	}
	if (Math.random() < .5) {
		styleRow.setDescription("Style Description");
	}
	styleRow.setColor(randomColor());
	if (Math.random() < .5) {
		styleRow.setWidth(1.0 + (Math.random() * 3));
	}
	styleRow.setFillColor(randomColor());

	return styleRow;
}
 
Example #2
Source File: StyleUtils.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * Set the style into the polygon options
 *
 * @param polygonOptions polygon options
 * @param style          style row
 * @param density        display density: {@link android.util.DisplayMetrics#density}
 * @return true if style was set into the polygon options
 */
public static boolean setStyle(PolygonOptions polygonOptions, StyleRow style, float density) {

    if (style != null) {

        Color color = style.getColorOrDefault();
        polygonOptions.strokeColor(color.getColorWithAlpha());

        double width = style.getWidthOrDefault();
        polygonOptions.strokeWidth((float) width * density);

        Color fillColor = style.getFillColor();
        if (fillColor != null) {
            polygonOptions.fillColor(fillColor.getColorWithAlpha());
        }
    }

    return style != null;
}
 
Example #3
Source File: FeatureStylesUtils.java    From geopackage-java with MIT License 6 votes vote down vote up
private static void validateTableStyles(
		FeatureTableStyles featureTableStyles, StyleRow styleRow,
		Map<GeometryType, StyleRow> geometryTypeStyles,
		Map<GeometryType, Map<GeometryType, ?>> geometryTypes) {

	if (geometryTypes != null) {
		for (Entry<GeometryType, Map<GeometryType, ?>> type : geometryTypes
				.entrySet()) {
			StyleRow typeStyleRow = styleRow;
			if (geometryTypeStyles.containsKey(type.getKey())) {
				typeStyleRow = geometryTypeStyles.get(type.getKey());
			}
			TestCase.assertEquals(typeStyleRow.getId(), featureTableStyles
					.getTableStyle(type.getKey()).getId());
			@SuppressWarnings("unchecked")
			Map<GeometryType, Map<GeometryType, ?>> childGeometryTypes = (Map<GeometryType, Map<GeometryType, ?>>) type
					.getValue();
			validateTableStyles(featureTableStyles, typeStyleRow,
					geometryTypeStyles, childGeometryTypes);
		}
	}
}
 
Example #4
Source File: FeatureStylesUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
private static StyleRow randomStyle() {
    StyleRow styleRow = new StyleRow();

    if (Math.random() < .5) {
        styleRow.setName("Style Name");
    }
    if (Math.random() < .5) {
        styleRow.setDescription("Style Description");
    }
    styleRow.setColor(randomColor());
    if (Math.random() < .5) {
        styleRow.setWidth(1.0 + (Math.random() * 3));
    }
    styleRow.setFillColor(randomColor());

    return styleRow;
}
 
Example #5
Source File: FeatureStylesUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
private static void validateTableStyles(
        FeatureTableStyles featureTableStyles, StyleRow styleRow,
        Map<GeometryType, StyleRow> geometryTypeStyles,
        Map<GeometryType, Map<GeometryType, ?>> geometryTypes) {

    if (geometryTypes != null) {
        for (Entry<GeometryType, Map<GeometryType, ?>> type : geometryTypes
                .entrySet()) {
            StyleRow typeStyleRow = styleRow;
            if (geometryTypeStyles.containsKey(type.getKey())) {
                typeStyleRow = geometryTypeStyles.get(type.getKey());
            }
            TestCase.assertEquals(typeStyleRow.getId(), featureTableStyles
                    .getTableStyle(type.getKey()).getId());
            @SuppressWarnings("unchecked")
            Map<GeometryType, Map<GeometryType, ?>> childGeometryTypes = (Map<GeometryType, Map<GeometryType, ?>>) type
                    .getValue();
            validateTableStyles(featureTableStyles, typeStyleRow,
                    geometryTypeStyles, childGeometryTypes);
        }
    }
}
 
Example #6
Source File: FeatureStylesUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void validateRowStyles(
        FeatureTableStyles featureTableStyles, FeatureRow featureRow,
        GeometryType geometryType, StyleRow tableStyleDefault,
        Map<GeometryType, StyleRow> geometryTypeTableStyles,
        Map<Long, Map<GeometryType, StyleRow>> featureResultsStyles) {

    StyleRow styleRow = null;
    if (geometryType == null) {
        styleRow = featureTableStyles.getStyle(featureRow);
        geometryType = featureRow.getGeometryType();
    } else {
        styleRow = featureTableStyles.getStyle(featureRow, geometryType);
    }

    StyleRow expectedStyleRow = getExpectedRowStyle(featureRow,
            geometryType, tableStyleDefault, geometryTypeTableStyles,
            featureResultsStyles);

    if (expectedStyleRow != null) {
        TestCase.assertEquals(expectedStyleRow.getId(), styleRow.getId());
        TestCase.assertNotNull(styleRow.getTable());
        TestCase.assertTrue(styleRow.getId() >= 0);
        styleRow.getName();
        styleRow.getDescription();
        styleRow.getColor();
        styleRow.getHexColor();
        styleRow.getOpacity();
        styleRow.getWidth();
        styleRow.getFillColor();
        styleRow.getFillHexColor();
        styleRow.getFillOpacity();
    } else {
        TestCase.assertNull(styleRow);
    }

}
 
Example #7
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void createFeatureStylesGeometry2(GeoPackage geoPackage,
		List<StyleRow> styles, List<IconRow> icons) throws IOException {

	FeatureDao featureDao = geoPackage.getFeatureDao("geometry2");
	FeatureTableStyles geometry2Styles = new FeatureTableStyles(geoPackage,
			featureDao.getTable());

	geometry2Styles.setTableStyle(GeometryType.POINT, styles.get(0));
	geometry2Styles.setTableStyle(GeometryType.LINESTRING, styles.get(1));
	geometry2Styles.setTableStyle(GeometryType.POLYGON, styles.get(0));
	geometry2Styles.setTableStyle(GeometryType.GEOMETRY, styles.get(2));

	geometry2Styles.createStyleRelationship();
	geometry2Styles.createIconRelationship();

	FeatureResultSet features = featureDao.queryForAll();
	while (features.moveToNext()) {
		FeatureRow featureRow = features.getRow();
		switch (featureRow.getGeometryType()) {
		case POINT:
			geometry2Styles.setIcon(featureRow, icons.get(0));
			break;
		case LINESTRING:
			geometry2Styles.setStyle(featureRow, styles.get(0));
			break;
		case POLYGON:
			geometry2Styles.setStyle(featureRow, styles.get(1));
			break;
		default:
		}
	}
	features.close();

}
 
Example #8
Source File: FeatureStylesUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void validateRowStyles(FeatureTableStyles featureTableStyles,
		FeatureRow featureRow, GeometryType geometryType,
		StyleRow tableStyleDefault,
		Map<GeometryType, StyleRow> geometryTypeTableStyles,
		Map<Long, Map<GeometryType, StyleRow>> featureResultsStyles) {

	StyleRow styleRow = null;
	if (geometryType == null) {
		styleRow = featureTableStyles.getStyle(featureRow);
		geometryType = featureRow.getGeometryType();
	} else {
		styleRow = featureTableStyles.getStyle(featureRow, geometryType);
	}

	StyleRow expectedStyleRow = getExpectedRowStyle(featureRow,
			geometryType, tableStyleDefault, geometryTypeTableStyles,
			featureResultsStyles);

	if (expectedStyleRow != null) {
		TestCase.assertEquals(expectedStyleRow.getId(), styleRow.getId());
		TestCase.assertNotNull(styleRow.getTable());
		TestCase.assertTrue(styleRow.getId() >= 0);
		styleRow.getName();
		styleRow.getDescription();
		styleRow.getColor();
		styleRow.getHexColor();
		styleRow.getOpacity();
		styleRow.getWidth();
		styleRow.getFillColor();
		styleRow.getFillHexColor();
		styleRow.getFillOpacity();
	} else {
		TestCase.assertNull(styleRow);
	}

}
 
Example #9
Source File: FeatureStylesUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void validateRowStyles(FeatureTableStyles featureTableStyles,
		FeatureRow featureRow, StyleRow tableStyleDefault,
		Map<GeometryType, StyleRow> geometryTypeTableStyles,
		Map<Long, Map<GeometryType, StyleRow>> featureResultsStyles) {

	GeometryType geometryType = featureRow.getGeometryType();

	validateRowStyles(featureTableStyles, featureRow, null,
			tableStyleDefault, geometryTypeTableStyles,
			featureResultsStyles);

	if (geometryType != null) {

		List<GeometryType> geometryTypes = GeometryUtils
				.parentHierarchy(geometryType);
		for (GeometryType parentGeometryType : geometryTypes) {
			validateRowStyles(featureTableStyles, featureRow,
					parentGeometryType, tableStyleDefault,
					geometryTypeTableStyles, featureResultsStyles);
		}

		List<GeometryType> childTypes = getAllChildTypes(geometryType);
		for (GeometryType childGeometryType : childTypes) {
			validateRowStyles(featureTableStyles, featureRow,
					childGeometryType, tableStyleDefault,
					geometryTypeTableStyles, featureResultsStyles);
		}
	}

}
 
Example #10
Source File: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void createFeatureStylesGeometry2(GeoPackage geoPackage,
                                                 List<StyleRow> styles, List<IconRow> icons) throws IOException {

    FeatureDao featureDao = geoPackage.getFeatureDao("geometry2");
    FeatureTableStyles geometry2Styles = new FeatureTableStyles(geoPackage,
            featureDao.getTable());

    geometry2Styles.setTableStyle(GeometryType.POINT, styles.get(0));
    geometry2Styles.setTableStyle(GeometryType.LINESTRING, styles.get(1));
    geometry2Styles.setTableStyle(GeometryType.POLYGON, styles.get(0));
    geometry2Styles.setTableStyle(GeometryType.GEOMETRY, styles.get(2));

    geometry2Styles.createStyleRelationship();
    geometry2Styles.createIconRelationship();

    FeatureCursor features = featureDao.queryForAll();
    while (features.moveToNext()) {
        FeatureRow featureRow = features.getRow();
        switch (featureRow.getGeometryType()) {
            case POINT:
                geometry2Styles.setIcon(featureRow, icons.get(0));
                break;
            case LINESTRING:
                geometry2Styles.setStyle(featureRow, styles.get(0));
                break;
            case POLYGON:
                geometry2Styles.setStyle(featureRow, styles.get(1));
                break;
            default:
        }
    }
    features.close();

}
 
Example #11
Source File: StyleUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Create new marker options populated with the style
 *
 * @param style style row
 * @return marker options populated with the style
 */
public static MarkerOptions createMarkerOptions(StyleRow style) {

    MarkerOptions markerOptions = new MarkerOptions();
    setStyle(markerOptions, style);

    return markerOptions;
}
 
Example #12
Source File: FeatureStylesUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void validateRowStyles(
        FeatureTableStyles featureTableStyles, FeatureRow featureRow,
        StyleRow tableStyleDefault,
        Map<GeometryType, StyleRow> geometryTypeTableStyles,
        Map<Long, Map<GeometryType, StyleRow>> featureResultsStyles) {

    GeometryType geometryType = featureRow.getGeometryType();

    validateRowStyles(featureTableStyles, featureRow, null,
            tableStyleDefault, geometryTypeTableStyles,
            featureResultsStyles);

    if (geometryType != null) {

        List<GeometryType> geometryTypes = GeometryUtils
                .parentHierarchy(geometryType);
        for (GeometryType parentGeometryType : geometryTypes) {
            validateRowStyles(featureTableStyles, featureRow,
                    parentGeometryType, tableStyleDefault,
                    geometryTypeTableStyles, featureResultsStyles);
        }

        List<GeometryType> childTypes = getAllChildTypes(geometryType);
        for (GeometryType childGeometryType : childTypes) {
            validateRowStyles(featureTableStyles, featureRow,
                    childGeometryType, tableStyleDefault,
                    geometryTypeTableStyles, featureResultsStyles);
        }
    }

}
 
Example #13
Source File: StyleUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Set the style into the marker options
 *
 * @param markerOptions marker options
 * @param style         style row
 * @return true if style was set into the marker options
 */
public static boolean setStyle(MarkerOptions markerOptions, StyleRow style) {

    boolean styleSet = false;

    if (style != null) {
        Color color = style.getColorOrDefault();
        float hue = color.getHue();
        markerOptions.icon(BitmapDescriptorFactory.defaultMarker(hue));
        styleSet = true;
    }

    return styleSet;
}
 
Example #14
Source File: StyleUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Create new polyline options populated with the style
 *
 * @param style   style row
 * @param density display density: {@link android.util.DisplayMetrics#density}
 * @return polyline options populated with the style
 */
public static PolylineOptions createPolylineOptions(StyleRow style, float density) {

    PolylineOptions polylineOptions = new PolylineOptions();
    setStyle(polylineOptions, style, density);

    return polylineOptions;
}
 
Example #15
Source File: StyleUtils.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Create new polygon options populated with the style
 *
 * @param style   style row
 * @param density display density: {@link android.util.DisplayMetrics#density}
 * @return polygon options populated with the style
 */
public static PolygonOptions createPolygonOptions(StyleRow style, float density) {

    PolygonOptions polygonOptions = new PolygonOptions();
    setStyle(polygonOptions, style, density);

    return polygonOptions;
}
 
Example #16
Source File: GeoPackageUtils.java    From geopackage-mapcache-android with MIT License 4 votes vote down vote up
/**
 * Prepare the feature draw limits and defaults
 *
 * @param context
 * @param geoPackage
 * @param featureTable
 * @param pointAlpha
 * @param lineAlpha
 * @param polygonAlpha
 * @param polygonFillAlpha
 * @param pointColor
 * @param lineColor
 * @param pointRadius
 * @param lineStroke
 * @param polygonColor
 * @param polygonStroke
 * @param polygonFill
 * @param polygonFillColor
 */
public static void prepareFeatureDraw(Context context, GeoPackage geoPackage, String featureTable, EditText pointAlpha, EditText lineAlpha, EditText polygonAlpha, EditText polygonFillAlpha,
                                      EditText pointColor, EditText lineColor, EditText pointRadius, EditText lineStroke,
                                      EditText polygonColor, EditText polygonStroke, CheckBox polygonFill, EditText polygonFillColor) {

    FeatureTableStyles featureTableStyles = new FeatureTableStyles(geoPackage, featureTable);

    // Set feature limits
    pointAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});
    lineAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});
    polygonAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});
    polygonFillAlpha.setFilters(new InputFilter[]{new InputFilterMinMax(
            0, 255)});

    // Set default feature attributes
    FeatureTiles featureTiles = new DefaultFeatureTiles(context);
    String defaultColor = "#000000";

    StyleRow pointStyle = featureTableStyles.getTableStyle(GeometryType.POINT);
    if(pointStyle != null){
        mil.nga.geopackage.style.Color pointStyleColor = pointStyle.getColorOrDefault();
        pointColor.setText(pointStyleColor.getColorHex());
        pointAlpha.setText(String.valueOf(pointStyleColor.getAlpha()));
        pointRadius.setText(new DecimalFormat("0.0#").format(pointStyle.getWidthOrDefault() / 2.0));
    }else{
        Paint pointPaint = featureTiles.getPointPaint();
        pointColor.setText(defaultColor);
        pointAlpha.setText(String.valueOf(pointPaint.getAlpha()));
        pointRadius.setText(String.valueOf(featureTiles.getPointRadius()));
    }

    StyleRow lineStyle = featureTableStyles.getTableStyle(GeometryType.LINESTRING);
    if(lineStyle != null){
        mil.nga.geopackage.style.Color lineStyleColor = lineStyle.getColorOrDefault();
        lineColor.setText(lineStyleColor.getColorHex());
        lineAlpha.setText(String.valueOf(lineStyleColor.getAlpha()));
        lineStroke.setText(new DecimalFormat("0.0#").format(lineStyle.getWidthOrDefault()));
    }else{
        Paint linePaint = featureTiles.getLinePaintCopy();
        lineColor.setText(defaultColor);
        lineAlpha.setText(String.valueOf(linePaint.getAlpha()));
        lineStroke.setText(String.valueOf(linePaint.getStrokeWidth()));
    }

    StyleRow polygonStyle = featureTableStyles.getTableStyle(GeometryType.POLYGON);
    if(polygonStyle != null){
        mil.nga.geopackage.style.Color polygonStyleColor = polygonStyle.getColorOrDefault();
        polygonColor.setText(polygonStyleColor.getColorHex());
        polygonAlpha.setText(String.valueOf(polygonStyleColor.getAlpha()));
        polygonStroke.setText(new DecimalFormat("0.0#").format(polygonStyle.getWidthOrDefault()));
        mil.nga.geopackage.style.Color polygonStyleFillColor = polygonStyle.getFillColor();
        polygonFill.setChecked(polygonStyleFillColor != null);
        if(polygonStyleFillColor != null){
            polygonFillColor.setText(polygonStyleFillColor.getColorHex());
            polygonFillAlpha.setText(String.valueOf(polygonStyleFillColor.getAlpha()));
        }else{
            polygonFillColor.setText(defaultColor);
            polygonFillAlpha.setText(String.valueOf(255));
        }
    }else{
        Paint polygonPaint = featureTiles.getPolygonPaintCopy();
        polygonColor.setText(defaultColor);
        polygonAlpha.setText(String.valueOf(polygonPaint.getAlpha()));
        polygonStroke.setText(String.valueOf(polygonPaint.getStrokeWidth()));

        polygonFill.setChecked(featureTiles.isFillPolygon());
        Paint polygonFillPaint = featureTiles.getPolygonFillPaintCopy();
        polygonFillColor.setText(defaultColor);
        polygonFillAlpha.setText(String.valueOf(polygonFillPaint.getAlpha()));
    }

}
 
Example #17
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
private static void createFeatureStylesGeometry1(GeoPackage geoPackage,
		List<StyleRow> styles, List<IconRow> icons) throws IOException {

	FeatureDao featureDao = geoPackage.getFeatureDao("geometry1");
	FeatureTableStyles geometry1Styles = new FeatureTableStyles(geoPackage,
			featureDao.getTable());

	geometry1Styles.setTableStyleDefault(styles.get(0));
	geometry1Styles.setTableStyle(GeometryType.POLYGON, styles.get(1));
	geometry1Styles.setTableStyle(GeometryType.POINT, styles.get(2));

	geometry1Styles.createStyleRelationship();
	geometry1Styles.createIconRelationship();

	int pointCount = 0;
	int lineCount = 0;
	int polygonCount = 0;

	FeatureResultSet features = featureDao.queryForAll();
	while (features.moveToNext()) {
		FeatureRow featureRow = features.getRow();
		switch (featureRow.getGeometryType()) {
		case POINT:
			pointCount++;
			switch (pointCount) {
			case 1:
				geometry1Styles.setIcon(featureRow, icons.get(0));
				break;
			case 2:
				geometry1Styles.setIcon(featureRow, icons.get(1));
				break;
			case 3:
				geometry1Styles.setIcon(featureRow, icons.get(2));
				break;
			}
			break;
		case LINESTRING:
			lineCount++;
			switch (lineCount) {
			case 2:
				geometry1Styles.setStyle(featureRow, styles.get(1));
				break;
			case 3:
				geometry1Styles.setStyle(featureRow, styles.get(2));
				break;
			}
			break;
		case POLYGON:
			polygonCount++;
			switch (polygonCount) {
			case 2:
				geometry1Styles.setStyle(featureRow, styles.get(3));
				break;
			case 3:
				geometry1Styles.setStyle(featureRow, styles.get(2));
				break;
			}
			break;
		default:
		}
	}
	features.close();

}
 
Example #18
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
private static void createFeatureStyleExtension(GeoPackage geoPackage)
		throws IOException {

	List<StyleRow> styles = new ArrayList<>();

	StyleRow style1 = new StyleRow();
	style1.setName("Green");
	style1.setDescription("Green Style");
	style1.setColor(ColorConstants.GREEN);
	style1.setWidth(2.0);
	styles.add(style1);

	StyleRow style2 = new StyleRow();
	style2.setName("Blue with Red Fill");
	style2.setDescription("Blue with Red Fill Style");
	style2.setColor(new Color(ColorConstants.BLUE));
	style2.setFillColor(new Color(255, 0, 0, .4f));
	styles.add(style2);

	StyleRow style3 = new StyleRow();
	style3.setName("Orange");
	style3.setDescription("Orange Style");
	style3.setColor(new Color(0xFFA500));
	style3.setWidth(6.5);
	styles.add(style3);

	StyleRow style4 = new StyleRow();
	style4.setName("Violet with Yellow Fill");
	style4.setDescription("Violet with Yellow Fill Style");
	style4.setColor(new Color(138, 43, 226));
	style4.setWidth(4.1);
	style4.setFillColor(new Color(new float[] { 61, .89f, .72f }, .3f));
	styles.add(style4);

	List<IconRow> icons = new ArrayList<>();

	IconRow icon1 = new IconRow();
	icon1.setName("Building");
	icon1.setDescription("Building Icon");
	icon1.setData(GeoPackageIOUtils
			.fileBytes(TestUtils.getTestFile("building.png")));
	icon1.setContentType("image/png");
	icon1.setWidth(32.0);
	icon1.setAnchorU(0.5);
	icon1.setAnchorV(1.0);
	icons.add(icon1);

	IconRow icon2 = new IconRow();
	icon2.setName("College");
	icon2.setDescription("College Icon");
	icon2.setData(GeoPackageIOUtils
			.fileBytes(TestUtils.getTestFile("college.png")));
	icon2.setContentType("image/png");
	icon2.setWidth(32.0);
	icon2.setHeight(44.0);
	icons.add(icon2);

	IconRow icon3 = new IconRow();
	icon3.setName("Tractor");
	icon3.setDescription("Tractor Icon");
	icon3.setData(GeoPackageIOUtils
			.fileBytes(TestUtils.getTestFile("tractor.png")));
	icon3.setContentType("image/png");
	icon3.setAnchorV(1.0);
	icons.add(icon3);

	createFeatureStylesGeometry1(geoPackage, styles, icons);
	createFeatureStylesGeometry2(geoPackage, styles, icons);

}
 
Example #19
Source File: FeatureStylesUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
private static Map<GeometryType, StyleRow> randomStyles(
		Map<GeometryType, Map<GeometryType, ?>> geometryTypes) {
	return randomStyles(geometryTypes, null);
}
 
Example #20
Source File: FeatureTiles.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Get the style paint from cache, or create and cache it
 *
 * @param style
 *            style row
 * @param drawType
 *            draw type
 * @return paint
 */
private Paint getStylePaint(StyleRow style, FeatureDrawType drawType) {

	Paint paint = featurePaintCache.getPaint(style, drawType);

	if (paint == null) {

		mil.nga.geopackage.style.Color color = null;
		Float strokeWidth = null;

		switch (drawType) {
		case CIRCLE:
			color = style.getColorOrDefault();
			break;
		case STROKE:
			color = style.getColorOrDefault();
			strokeWidth = this.scale * (float) style.getWidthOrDefault();
			break;
		case FILL:
			color = style.getFillColor();
			strokeWidth = this.scale * (float) style.getWidthOrDefault();
			break;
		default:
			throw new GeoPackageException(
					"Unsupported Draw Type: " + drawType);
		}

		Paint stylePaint = new Paint();
		stylePaint.setColor(new Color(color.getColorWithAlpha(), true));
		if (strokeWidth != null) {
			stylePaint.setStrokeWidth(strokeWidth);
		}

		synchronized (featurePaintCache) {

			paint = featurePaintCache.getPaint(style, drawType);

			if (paint == null) {
				featurePaintCache.setPaint(style, drawType, stylePaint);
				paint = stylePaint;
			}

		}
	}

	return paint;
}
 
Example #21
Source File: FeatureTiles.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Get the feature style paint from cache, or create and cache it
 *
 * @param featureStyle
 *            feature style
 * @param drawType
 *            draw type
 * @return feature style paint
 */
private Paint getFeatureStylePaint(FeatureStyle featureStyle,
		FeatureDrawType drawType) {

	Paint paint = null;

	if (featureStyle != null) {

		StyleRow style = featureStyle.getStyle();

		if (style != null && style.hasColor()) {

			paint = getStylePaint(style, drawType);

		}
	}

	return paint;
}
 
Example #22
Source File: FeatureTiles.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Call after making changes to the point icon, point radius, or paint
 * stroke widths. Determines the pixel overlap between tiles
 */
public void calculateDrawOverlap() {

	if (pointIcon != null) {
		heightOverlap = this.scale * pointIcon.getHeight();
		widthOverlap = this.scale * pointIcon.getWidth();
	} else {
		heightOverlap = this.scale * pointRadius;
		widthOverlap = this.scale * pointRadius;
	}

	float linePaintHalfStroke = this.scale * lineStrokeWidth / 2.0f;
	heightOverlap = Math.max(heightOverlap, linePaintHalfStroke);
	widthOverlap = Math.max(widthOverlap, linePaintHalfStroke);

	float polygonPaintHalfStroke = this.scale * polygonStrokeWidth / 2.0f;
	heightOverlap = Math.max(heightOverlap, polygonPaintHalfStroke);
	widthOverlap = Math.max(widthOverlap, polygonPaintHalfStroke);

	if (featureTableStyles != null && featureTableStyles.has()) {

		// Style Rows
		Set<Long> styleRowIds = new HashSet<>();
		List<Long> tableStyleIds = featureTableStyles.getAllTableStyleIds();
		if (tableStyleIds != null) {
			styleRowIds.addAll(tableStyleIds);
		}
		List<Long> styleIds = featureTableStyles.getAllStyleIds();
		if (styleIds != null) {
			styleRowIds.addAll(styleIds);
		}

		StyleDao styleDao = featureTableStyles.getStyleDao();
		for (long styleRowId : styleRowIds) {
			StyleRow styleRow = styleDao
					.getRow(styleDao.queryForIdRow(styleRowId));
			float styleHalfWidth = this.scale
					* (float) (styleRow.getWidthOrDefault() / 2.0f);
			widthOverlap = Math.max(widthOverlap, styleHalfWidth);
			heightOverlap = Math.max(heightOverlap, styleHalfWidth);
		}

		// Icon Rows
		Set<Long> iconRowIds = new HashSet<>();
		List<Long> tableIconIds = featureTableStyles.getAllTableIconIds();
		if (tableIconIds != null) {
			iconRowIds.addAll(tableIconIds);
		}
		List<Long> iconIds = featureTableStyles.getAllIconIds();
		if (iconIds != null) {
			iconRowIds.addAll(iconIds);
		}

		IconDao iconDao = featureTableStyles.getIconDao();
		for (long iconRowId : iconRowIds) {
			IconRow iconRow = iconDao
					.getRow(iconDao.queryForIdRow(iconRowId));
			double[] iconDimensions = iconRow.getDerivedDimensions();
			float iconWidth = this.scale
					* (float) Math.ceil(iconDimensions[0]);
			float iconHeight = this.scale
					* (float) Math.ceil(iconDimensions[1]);
			widthOverlap = Math.max(widthOverlap, iconWidth);
			heightOverlap = Math.max(heightOverlap, iconHeight);
		}

	}

}
 
Example #23
Source File: FeatureTiles.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Call after making changes to the point icon, point radius, or paint stroke widths.
 * Determines the pixel overlap between tiles
 */
public void calculateDrawOverlap() {

    if (pointIcon != null) {
        heightOverlap = this.density * pointIcon.getHeight();
        widthOverlap = this.density * pointIcon.getWidth();
    } else {
        heightOverlap = this.density * pointRadius;
        widthOverlap = this.density * pointRadius;
    }

    float linePaintHalfStroke = this.density * lineStrokeWidth / 2.0f;
    heightOverlap = Math.max(heightOverlap, linePaintHalfStroke);
    widthOverlap = Math.max(widthOverlap, linePaintHalfStroke);

    float polygonPaintHalfStroke = this.density * polygonStrokeWidth / 2.0f;
    heightOverlap = Math.max(heightOverlap, polygonPaintHalfStroke);
    widthOverlap = Math.max(widthOverlap, polygonPaintHalfStroke);

    if (featureTableStyles != null && featureTableStyles.has()) {

        // Style Rows
        Set<Long> styleRowIds = new HashSet<>();
        List<Long> tableStyleIds = featureTableStyles.getAllTableStyleIds();
        if (tableStyleIds != null) {
            styleRowIds.addAll(tableStyleIds);
        }
        List<Long> styleIds = featureTableStyles.getAllStyleIds();
        if (styleIds != null) {
            styleRowIds.addAll(styleIds);
        }

        StyleDao styleDao = featureTableStyles.getStyleDao();
        for (long styleRowId : styleRowIds) {
            StyleRow styleRow = styleDao.getRow(styleDao.queryForIdRow(styleRowId));
            float styleHalfWidth = this.density * (float) (styleRow.getWidthOrDefault() / 2.0f);
            widthOverlap = Math.max(widthOverlap, styleHalfWidth);
            heightOverlap = Math.max(heightOverlap, styleHalfWidth);
        }

        // Icon Rows
        Set<Long> iconRowIds = new HashSet<>();
        List<Long> tableIconIds = featureTableStyles.getAllTableIconIds();
        if (tableIconIds != null) {
            iconRowIds.addAll(tableIconIds);
        }
        List<Long> iconIds = featureTableStyles.getAllIconIds();
        if (iconIds != null) {
            iconRowIds.addAll(iconIds);
        }

        IconDao iconDao = featureTableStyles.getIconDao();
        for (long iconRowId : iconRowIds) {
            IconRow iconRow = iconDao.getRow(iconDao.queryForIdRow(iconRowId));
            double[] iconDimensions = iconRow.getDerivedDimensions();
            float iconWidth = this.density * (float) Math.ceil(iconDimensions[0]);
            float iconHeight = this.density * (float) Math.ceil(iconDimensions[1]);
            widthOverlap = Math.max(widthOverlap, iconWidth);
            heightOverlap = Math.max(heightOverlap, iconHeight);
        }

    }

}
 
Example #24
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
private static void createFeatureStylesGeometry1(GeoPackage geoPackage,
                                                 List<StyleRow> styles, List<IconRow> icons) throws IOException {

    FeatureDao featureDao = geoPackage.getFeatureDao("geometry1");
    FeatureTableStyles geometry1Styles = new FeatureTableStyles(geoPackage,
            featureDao.getTable());

    geometry1Styles.setTableStyleDefault(styles.get(0));
    geometry1Styles.setTableStyle(GeometryType.POLYGON, styles.get(1));
    geometry1Styles.setTableStyle(GeometryType.POINT, styles.get(2));

    geometry1Styles.createStyleRelationship();
    geometry1Styles.createIconRelationship();

    int pointCount = 0;
    int lineCount = 0;
    int polygonCount = 0;

    FeatureCursor features = featureDao.queryForAll();
    while (features.moveToNext()) {
        FeatureRow featureRow = features.getRow();
        switch (featureRow.getGeometryType()) {
            case POINT:
                pointCount++;
                switch (pointCount) {
                    case 1:
                        geometry1Styles.setIcon(featureRow, icons.get(0));
                        break;
                    case 2:
                        geometry1Styles.setIcon(featureRow, icons.get(1));
                        break;
                    case 3:
                        geometry1Styles.setIcon(featureRow, icons.get(2));
                        break;
                }
                break;
            case LINESTRING:
                lineCount++;
                switch (lineCount) {
                    case 2:
                        geometry1Styles.setStyle(featureRow, styles.get(1));
                        break;
                    case 3:
                        geometry1Styles.setStyle(featureRow, styles.get(2));
                        break;
                }
                break;
            case POLYGON:
                polygonCount++;
                switch (polygonCount) {
                    case 2:
                        geometry1Styles.setStyle(featureRow, styles.get(3));
                        break;
                    case 3:
                        geometry1Styles.setStyle(featureRow, styles.get(2));
                        break;
                }
                break;
            default:
        }
    }
    features.close();

}
 
Example #25
Source File: FeatureStylesUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
private static Map<GeometryType, StyleRow> randomStyles(
        Map<GeometryType, Map<GeometryType, ?>> geometryTypes) {
    return randomStyles(geometryTypes, null);
}
 
Example #26
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
private static void createFeatureStyleExtension(GeoPackage geoPackage)
        throws IOException, NameNotFoundException {

    List<StyleRow> styles = new ArrayList<>();

    StyleRow style1 = new StyleRow();
    style1.setName("Green");
    style1.setDescription("Green Style");
    style1.setColor(ColorConstants.GREEN);
    style1.setWidth(2.0);
    styles.add(style1);

    StyleRow style2 = new StyleRow();
    style2.setName("Blue with Red Fill");
    style2.setDescription("Blue with Red Fill Style");
    style2.setColor(new Color(ColorConstants.BLUE));
    style2.setFillColor(new Color(255, 0, 0, .4f));
    styles.add(style2);

    StyleRow style3 = new StyleRow();
    style3.setName("Orange");
    style3.setDescription("Orange Style");
    style3.setColor(new Color(0xFFA500));
    style3.setWidth(6.5);
    styles.add(style3);

    StyleRow style4 = new StyleRow();
    style4.setName("Violet with Yellow Fill");
    style4.setDescription("Violet with Yellow Fill Style");
    style4.setColor(new Color(138, 43, 226));
    style4.setWidth(4.1);
    style4.setFillColor(new Color(new float[]{61, .89f, .72f}, .3f));
    styles.add(style4);

    List<IconRow> icons = new ArrayList<>();

    TestUtils.copyAssetFileToInternalStorage(geoPackage.getContext(), TestUtils.getTestContext(geoPackage.getContext()), "building.png");
    IconRow icon1 = new IconRow();
    icon1.setName("Building");
    icon1.setDescription("Building Icon");
    icon1.setData(BitmapFactory.decodeFile(
            TestUtils.getAssetFileInternalStorageLocation(geoPackage.getContext(), "building.png")),
            Bitmap.CompressFormat.PNG);
    icon1.setContentType("image/png");
    icon1.setWidth(32.0);
    icon1.setAnchorU(0.5);
    icon1.setAnchorV(1.0);
    icons.add(icon1);

    TestUtils.copyAssetFileToInternalStorage(geoPackage.getContext(), TestUtils.getTestContext(geoPackage.getContext()), "college.png");
    IconRow icon2 = new IconRow();
    icon2.setName("College");
    icon2.setDescription("College Icon");
    icon2.setData(BitmapFactory.decodeFile(
            TestUtils.getAssetFileInternalStorageLocation(geoPackage.getContext(), "college.png")),
            Bitmap.CompressFormat.PNG);
    icon2.setContentType("image/png");
    icon2.setWidth(32.0);
    icon2.setHeight(44.0);
    icons.add(icon2);

    TestUtils.copyAssetFileToInternalStorage(geoPackage.getContext(), TestUtils.getTestContext(geoPackage.getContext()), "tractor.png");
    IconRow icon3 = new IconRow();
    icon3.setName("Tractor");
    icon3.setDescription("Tractor Icon");
    icon3.setData(BitmapFactory.decodeFile(
            TestUtils.getAssetFileInternalStorageLocation(geoPackage.getContext(), "tractor.png")),
            Bitmap.CompressFormat.PNG);
    icon3.setContentType("image/png");
    icon3.setAnchorV(1.0);
    icons.add(icon3);

    createFeatureStylesGeometry1(geoPackage, styles, icons);
    createFeatureStylesGeometry2(geoPackage, styles, icons);
}
 
Example #27
Source File: FeatureTiles.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Get the feature style paint from cache, or create and cache it
 *
 * @param featureStyle feature style
 * @param drawType     draw type
 * @return feature style paint
 */
private Paint getFeatureStylePaint(FeatureStyle featureStyle, FeatureDrawType drawType) {

    Paint paint = null;

    if (featureStyle != null) {

        StyleRow style = featureStyle.getStyle();

        if (style != null && style.hasColor()) {

            paint = getStylePaint(style, drawType);

        }
    }

    return paint;
}
 
Example #28
Source File: FeatureTiles.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Get the style paint from cache, or create and cache it
 *
 * @param style    style row
 * @param drawType draw type
 * @return paint
 */
private Paint getStylePaint(StyleRow style, FeatureDrawType drawType) {

    Paint paint = featurePaintCache.getPaint(style, drawType);

    if (paint == null) {

        Color color = null;
        Style paintStyle = null;
        Float strokeWidth = null;

        switch (drawType) {
            case CIRCLE:
                color = style.getColorOrDefault();
                paintStyle = Style.FILL;
                break;
            case STROKE:
                color = style.getColorOrDefault();
                paintStyle = Style.STROKE;
                strokeWidth = this.density * (float) style.getWidthOrDefault();
                break;
            case FILL:
                color = style.getFillColor();
                paintStyle = Style.FILL;
                strokeWidth = this.density * (float) style.getWidthOrDefault();
                break;
            default:
                throw new GeoPackageException("Unsupported Draw Type: " + drawType);
        }

        Paint stylePaint = new Paint();
        stylePaint.setAntiAlias(true);
        stylePaint.setStyle(paintStyle);
        stylePaint.setColor(color.getColorWithAlpha());
        if (strokeWidth != null) {
            stylePaint.setStrokeWidth(strokeWidth);
        }

        synchronized (featurePaintCache) {

            paint = featurePaintCache.getPaint(style, drawType);

            if (paint == null) {
                featurePaintCache.setPaint(style, drawType, stylePaint);
                paint = stylePaint;
            }

        }
    }

    return paint;
}
 
Example #29
Source File: FeatureTiles.java    From geopackage-android with MIT License 3 votes vote down vote up
/**
 * Get the polygon fill paint for the feature style, or return the default paint
 *
 * @param featureStyle feature style
 * @return paint
 */
protected Paint getPolygonFillPaint(FeatureStyle featureStyle) {

    Paint paint = null;

    boolean hasStyleColor = false;

    if (featureStyle != null) {

        StyleRow style = featureStyle.getStyle();

        if (style != null) {

            if (style.hasFillColor()) {
                paint = getStylePaint(style, FeatureDrawType.FILL);
            } else {
                hasStyleColor = style.hasColor();
            }

        }

    }

    if (paint == null && !hasStyleColor && fillPolygon) {
        paint = polygonFillPaint;
    }

    return paint;
}
 
Example #30
Source File: StyleUtils.java    From geopackage-android-map with MIT License 3 votes vote down vote up
/**
 * Set the style into the polyline options
 *
 * @param polylineOptions polyline options
 * @param style           style row
 * @param density         display density: {@link android.util.DisplayMetrics#density}
 * @return true if style was set into the polyline options
 */
public static boolean setStyle(PolylineOptions polylineOptions, StyleRow style, float density) {

    if (style != null) {

        Color color = style.getColorOrDefault();
        polylineOptions.color(color.getColorWithAlpha());

        double width = style.getWidthOrDefault();
        polylineOptions.width((float) width * density);

    }

    return style != null;
}