Java Code Examples for mil.nga.geopackage.extension.style.IconRow#setHeight()

The following examples show how to use mil.nga.geopackage.extension.style.IconRow#setHeight() . 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-android with MIT License 5 votes vote down vote up
private static IconRow randomIcon(GeoPackage geoPackage) throws IOException, NameNotFoundException {
    IconRow iconRow = new IconRow();

    TestUtils.copyAssetFileToInternalStorage(geoPackage.getContext(), TestUtils.getTestContext(geoPackage.getContext()), TestConstants.ICON_POINT_IMAGE);
    String iconImage = TestUtils.getAssetFileInternalStorageLocation(geoPackage.getContext(), TestConstants.ICON_POINT_IMAGE);
    Bitmap iconBitmap = BitmapFactory.decodeFile(iconImage);

    iconRow.setData(iconBitmap, Bitmap.CompressFormat.PNG);
    iconRow.setContentType("image/"
            + TestConstants.ICON_POINT_IMAGE_EXTENSION);
    if (Math.random() < .5) {
        iconRow.setName("Icon Name");
    }
    if (Math.random() < .5) {
        iconRow.setDescription("Icon Description");
    }
    if (Math.random() < .5) {
        iconRow.setWidth(Math.random() * iconBitmap.getWidth());
    }
    if (Math.random() < .5) {
        iconRow.setHeight(Math.random() * iconBitmap.getHeight());
    }
    if (Math.random() < .5) {
        iconRow.setAnchorU(Math.random());
    }
    if (Math.random() < .5) {
        iconRow.setAnchorV(Math.random());
    }

    return iconRow;
}
 
Example 2
Source File: FeatureStylesUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
private static IconRow randomIcon() throws IOException {
	IconRow iconRow = new IconRow();

	File iconImageFile = TestUtils
			.getTestFile(TestConstants.ICON_POINT_IMAGE);
	byte[] iconBytes = GeoPackageIOUtils.fileBytes(iconImageFile);
	BufferedImage iconImage = ImageUtils.getImage(iconBytes);

	iconRow.setData(iconBytes);
	iconRow.setContentType(
			"image/" + TestConstants.ICON_POINT_IMAGE_EXTENSION);
	if (Math.random() < .5) {
		iconRow.setName("Icon Name");
	}
	if (Math.random() < .5) {
		iconRow.setDescription("Icon Description");
	}
	if (Math.random() < .5) {
		iconRow.setWidth(Math.random() * iconImage.getWidth());
	}
	if (Math.random() < .5) {
		iconRow.setHeight(Math.random() * iconImage.getHeight());
	}
	if (Math.random() < .5) {
		iconRow.setAnchorU(Math.random());
	}
	if (Math.random() < .5) {
		iconRow.setAnchorV(Math.random());
	}

	return iconRow;
}
 
Example 3
Source File: StyleUtilsTest.java    From geopackage-android-map with MIT License 4 votes vote down vote up
private void testSetIcon(float density, int imageWidth, int imageHeight, Double iconWidth, Double iconHeight) throws Exception {

        Bitmap bitmap = Bitmap.createBitmap(imageWidth, imageHeight, Bitmap.Config.ARGB_8888);
        byte[] bytes = BitmapConverter.toBytes(bitmap, Bitmap.CompressFormat.PNG);

        IconRow icon = new IconRow();
        icon.setData(bytes);
        icon.setWidth(iconWidth);
        icon.setHeight(iconHeight);

        double styleWidth;
        double styleHeight;

        if (iconWidth == null && iconHeight == null) {
            styleWidth = imageWidth;
            styleHeight = imageHeight;
        } else if (iconWidth != null && iconHeight != null) {
            styleWidth = iconWidth;
            styleHeight = iconHeight;
        } else if (iconWidth != null) {
            styleWidth = iconWidth;
            styleHeight = (iconWidth / imageWidth) * imageHeight;
        } else {
            styleHeight = iconHeight;
            styleWidth = (iconHeight / imageHeight) * imageWidth;
        }

        Bitmap iconImage = StyleUtils.createIcon(icon, density);
        TestCase.assertNotNull(iconImage);

        double expectedWidth = density * styleWidth;
        double expectedHeight = density * styleHeight;

        int lowerWidth = (int) Math.floor(expectedWidth - 0.5);
        int upperWidth = (int) Math.ceil(expectedWidth + 0.5);
        int lowerHeight = (int) Math.floor(expectedHeight - 0.5);
        int upperHeight = (int) Math.ceil(expectedHeight + 0.5);

        TestCase.assertTrue(iconImage.getWidth() + " not between " + lowerWidth + " and " + upperWidth,
                iconImage.getWidth() >= lowerWidth
                        && iconImage.getWidth() <= upperWidth);
        TestCase.assertTrue(iconImage.getHeight() + " not between " + lowerHeight + " and " + upperHeight,
                iconImage.getHeight() >= lowerHeight
                        && iconImage.getHeight() <= upperHeight);

    }
 
Example 4
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 5
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);

}